Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: include/AdblockPlus/FilterEngine.h

Issue 10100009: FilterEngine API improvements (Closed)
Left Patch Set: Added filter access and addressed review comments Created April 5, 2013, 12:10 p.m.
Right Patch Set: Changed filter type enum Created April 9, 2013, 5:55 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | shell/src/FiltersCommand.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #ifndef ADBLOCKPLUS_FILTER_ENGINE_H 1 #ifndef ADBLOCKPLUS_FILTER_ENGINE_H
2 #define ADBLOCKPLUS_FILTER_ENGINE_H 2 #define ADBLOCKPLUS_FILTER_ENGINE_H
3 3
4 #include <vector> 4 #include <vector>
5 #include <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 #include <tr1/memory>
7 8
8 namespace AdblockPlus 9 namespace AdblockPlus
9 { 10 {
10 class JsEngine; 11 class JsEngine;
11 class FilterEngine; 12 class FilterEngine;
12 13
13 class JSObject 14 class JsObject
14 { 15 {
15 public: 16 public:
16 std::string GetProperty(const std::string& name, const std::string& defaultV alue) const; 17 std::string GetProperty(const std::string& name, const std::string& defaultV alue) const;
17 int GetProperty(const std::string& name, int defaultValue) const; 18 int GetProperty(const std::string& name, int defaultValue) const;
18 bool GetProperty(const std::string& name, bool defaultValue) const; 19 bool GetProperty(const std::string& name, bool defaultValue) const;
19 inline std::string GetProperty(const std::string& name, const char* defaultV alue) const 20 inline std::string GetProperty(const std::string& name, const char* defaultV alue) const
20 { 21 {
21 return GetProperty(name, std::string(defaultValue)); 22 return GetProperty(name, std::string(defaultValue));
22 } 23 }
23 24
24 void SetProperty(const std::string& name, const std::string& value); 25 void SetProperty(const std::string& name, const std::string& value);
25 void SetProperty(const std::string& name, int value); 26 void SetProperty(const std::string& name, int value);
26 void SetProperty(const std::string& name, bool value); 27 void SetProperty(const std::string& name, bool value);
27 inline void SetProperty(const std::string& name, const char* value) 28 inline void SetProperty(const std::string& name, const char* value)
28 { 29 {
29 SetProperty(name, std::string(value)); 30 SetProperty(name, std::string(value));
30 } 31 }
31 32
32 protected: 33 protected:
33 #if FILTER_ENGINE_STUBS 34 #if FILTER_ENGINE_STUBS
34 JSObject(FilterEngine& filterEngine); 35 JsObject(FilterEngine& filterEngine);
35 36
36 FilterEngine& filterEngine; 37 FilterEngine& filterEngine;
37 std::map<std::string, std::string> stringProperties; 38 std::map<std::string, std::string> stringProperties;
38 std::map<std::string, int> intProperties; 39 std::map<std::string, int> intProperties;
39 std::map<std::string, bool> boolProperties; 40 std::map<std::string, bool> boolProperties;
40 #else 41 #else
41 JSObject(); 42 JsObject();
42 #endif 43 #endif
43 }; 44 };
44 45
45 class Filter : public JSObject 46 class Filter : public JsObject,
47 public std::tr1::enable_shared_from_this<Filter>
46 { 48 {
47 friend class FilterEngine; 49 friend class FilterEngine;
48 50
49 public: 51 public:
52 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION,
53 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION,
54 TYPE_COMMENT, TYPE_INVALID};
55
50 bool IsListed() const; 56 bool IsListed() const;
51 void AddToList(); 57 void AddToList();
52 void RemoveFromList(); 58 void RemoveFromList();
53 59
54 private: 60 private:
55 #if FILTER_ENGINE_STUBS 61 #if FILTER_ENGINE_STUBS
56 Filter(FilterEngine& filterEngine, const std::string& text); 62 Filter(FilterEngine& filterEngine, const std::string& text);
57 #else 63 #else
58 Filter(); 64 Filter();
59 #endif 65 #endif
60 }; 66 };
61 67
62 class Subscription : public JSObject 68 class Subscription : public JsObject,
69 public std::tr1::enable_shared_from_this<Subscription>
63 { 70 {
64 friend class FilterEngine; 71 friend class FilterEngine;
65 72
66 public: 73 public:
67 bool IsListed() const; 74 bool IsListed() const;
68 void AddToList(); 75 void AddToList();
69 void RemoveFromList(); 76 void RemoveFromList();
70 void UpdateFilters(); 77 void UpdateFilters();
71 78
72 private: 79 private:
73 #if FILTER_ENGINE_STUBS 80 #if FILTER_ENGINE_STUBS
74 Subscription(FilterEngine& filterEngine, const std::string& url); 81 Subscription(FilterEngine& filterEngine, const std::string& url);
75 #else 82 #else
76 Subscription(); 83 Subscription();
77 #endif 84 #endif
78 }; 85 };
79 86
80 typedef void (*SubscriptionsCallback)(const std::vector<Subscription*>&); 87 typedef std::tr1::shared_ptr<Filter> FilterPtr;
88 typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr;
89 typedef void (*SubscriptionsCallback)(const std::vector<SubscriptionPtr>&);
81 90
82 class FilterEngine 91 class FilterEngine
83 { 92 {
84 friend class Filter; 93 friend class Filter;
85 friend class Subscription; 94 friend class Subscription;
86 public: 95 public:
87 explicit FilterEngine(JsEngine& jsEngine); 96 explicit FilterEngine(JsEngine& jsEngine);
88 Filter& GetFilter(const std::string& text); 97 Filter& GetFilter(const std::string& text);
89 Subscription& GetSubscription(const std::string& url); 98 Subscription& GetSubscription(const std::string& url);
90 const std::vector<Filter*>& GetListedFilters() const; 99 const std::vector<FilterPtr>& GetListedFilters() const;
91 const std::vector<Subscription*>& GetListedSubscriptions() const; 100 const std::vector<SubscriptionPtr>& GetListedSubscriptions() const;
92 void FetchAvailableSubscriptions(SubscriptionsCallback callback); 101 void FetchAvailableSubscriptions(SubscriptionsCallback callback);
93 Filter* Matches(const std::string& url, 102 FilterPtr Matches(const std::string& url,
94 const std::string& contentType, 103 const std::string& contentType,
95 const std::string& documentUrl); 104 const std::string& documentUrl);
Oleksandr 2013/04/05 14:09:07 Might be just me, but based on this signature I mi
Felix Dahlke 2013/04/05 14:20:59 How would that be any less ambigous? IMO, we shou
Wladimir Palant 2013/04/05 14:31:45 Actually, the idea was that filters and subscripti
Felix Dahlke 2013/04/05 14:43:55 Then a pointer should be fine. You have a point i
Wladimir Palant 2013/04/08 13:51:47 I am using shared_ptr instead of raw pointers now.
96 std::vector<std::string> GetElementHidingRules() const; 105 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) const;
97 106
98 private: 107 private:
99 JsEngine& jsEngine; 108 JsEngine& jsEngine;
100 #if FILTER_ENGINE_STUBS 109 #if FILTER_ENGINE_STUBS
101 std::map<std::string, Filter*> knownFilters; 110 std::map<std::string, FilterPtr> knownFilters;
102 std::vector<Filter*> listedFilters; 111 std::vector<FilterPtr> listedFilters;
103 std::map<std::string, Subscription*> knownSubscriptions; 112 std::map<std::string, SubscriptionPtr> knownSubscriptions;
104 std::vector<Subscription*> listedSubscriptions; 113 std::vector<SubscriptionPtr> listedSubscriptions;
105 #endif 114 #endif
106 }; 115 };
107 } 116 }
108 117
109 #endif 118 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld