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

Unified Diff: include/AdblockPlus/FilterEngine.h

Issue 10100009: FilterEngine API improvements (Closed)
Patch Set: Addressed review comments Created April 8, 2013, 1:51 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « .hgsubstate ('k') | shell/src/FiltersCommand.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/FilterEngine.h
===================================================================
--- a/include/AdblockPlus/FilterEngine.h
+++ b/include/AdblockPlus/FilterEngine.h
@@ -1,21 +1,22 @@
#ifndef ADBLOCKPLUS_FILTER_ENGINE_H
#define ADBLOCKPLUS_FILTER_ENGINE_H
#include <vector>
#include <map>
#include <string>
+#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
namespace AdblockPlus
{
class JsEngine;
class FilterEngine;
- class JSObject
+ class JsObject
{
public:
std::string GetProperty(const std::string& name, const std::string& defaultValue) const;
int GetProperty(const std::string& name, int defaultValue) const;
bool GetProperty(const std::string& name, bool defaultValue) const;
inline std::string GetProperty(const std::string& name, const char* defaultValue) const
{
return GetProperty(name, std::string(defaultValue));
@@ -26,45 +27,51 @@ namespace AdblockPlus
void SetProperty(const std::string& name, bool value);
inline void SetProperty(const std::string& name, const char* value)
{
SetProperty(name, std::string(value));
}
protected:
#if FILTER_ENGINE_STUBS
- JSObject(FilterEngine& filterEngine);
+ JsObject(FilterEngine& filterEngine);
FilterEngine& filterEngine;
std::map<std::string, std::string> stringProperties;
std::map<std::string, int> intProperties;
std::map<std::string, bool> boolProperties;
#else
- JSObject();
+ JsObject();
#endif
};
- class Filter : public JSObject
+ 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
+ ELEMHIDE_RULE, ELEMHIDE_EXCEPTION_RULE,
+ COMMENT_RULE, INVALID_RULE};
+
+ class Filter : public JsObject,
+ public std::tr1::enable_shared_from_this<Filter>
{
friend class FilterEngine;
public:
bool IsListed() const;
void AddToList();
void RemoveFromList();
private:
#if FILTER_ENGINE_STUBS
Filter(FilterEngine& filterEngine, const std::string& text);
#else
Filter();
#endif
};
- class Subscription : public JSObject
+ class Subscription : public JsObject,
+ public std::tr1::enable_shared_from_this<Subscription>
{
friend class FilterEngine;
public:
bool IsListed() const;
void AddToList();
void RemoveFromList();
void UpdateFilters();
@@ -72,38 +79,40 @@ namespace AdblockPlus
private:
#if FILTER_ENGINE_STUBS
Subscription(FilterEngine& filterEngine, const std::string& url);
#else
Subscription();
#endif
};
- typedef void (*SubscriptionsCallback)(const std::vector<Subscription*>&);
+ typedef std::tr1::shared_ptr<Filter> FilterPtr;
+ typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr;
+ typedef void (*SubscriptionsCallback)(const std::vector<SubscriptionPtr>&);
class FilterEngine
{
friend class Filter;
friend class Subscription;
public:
explicit FilterEngine(JsEngine& jsEngine);
Filter& GetFilter(const std::string& text);
Subscription& GetSubscription(const std::string& url);
- const std::vector<Filter*>& GetListedFilters() const;
- const std::vector<Subscription*>& GetListedSubscriptions() const;
+ const std::vector<FilterPtr>& GetListedFilters() const;
+ const std::vector<SubscriptionPtr>& GetListedSubscriptions() const;
void FetchAvailableSubscriptions(SubscriptionsCallback callback);
- Filter* Matches(const std::string& url,
- const std::string& contentType,
- const std::string& documentUrl);
+ FilterPtr Matches(const std::string& url,
+ const std::string& contentType,
+ const std::string& documentUrl);
std::vector<std::string> GetElementHidingSelectors(const std::string& domain) const;
private:
JsEngine& jsEngine;
#if FILTER_ENGINE_STUBS
- std::map<std::string, Filter*> knownFilters;
- std::vector<Filter*> listedFilters;
- std::map<std::string, Subscription*> knownSubscriptions;
- std::vector<Subscription*> listedSubscriptions;
+ std::map<std::string, FilterPtr> knownFilters;
+ std::vector<FilterPtr> listedFilters;
+ std::map<std::string, SubscriptionPtr> knownSubscriptions;
+ std::vector<SubscriptionPtr> listedSubscriptions;
#endif
};
}
#endif
« 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