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

Side by Side Diff: include/AdblockPlus/FilterEngine.h

Issue 10100009: FilterEngine API improvements (Closed)
Patch Set: Addressed review comments Created April 8, 2013, 1:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « .hgsubstate ('k') | shell/src/FiltersCommand.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
Felix Dahlke 2013/04/08 15:03:59 As of GCC 4.6 (we can assume that on Android with
Wladimir Palant 2013/04/09 05:56:34 Not sure about the NDK but on Linux #include <memo
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 enum FilterType {BLOCKING_RULE, EXCEPTION_RULE,
Felix Dahlke 2013/04/08 15:03:59 I'd move this into the public section of Filter, s
47 ELEMHIDE_RULE, ELEMHIDE_EXCEPTION_RULE,
48 COMMENT_RULE, INVALID_RULE};
49
50 class Filter : public JsObject,
51 public std::tr1::enable_shared_from_this<Filter>
46 { 52 {
47 friend class FilterEngine; 53 friend class FilterEngine;
48 54
49 public: 55 public:
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);
96 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) 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
OLDNEW
« no previous file with comments | « .hgsubstate ('k') | shell/src/FiltersCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld