Index: chrome/browser/safe_browsing/protocol_manager.h |
=================================================================== |
--- chrome/browser/safe_browsing/protocol_manager.h (revision 68365) |
+++ chrome/browser/safe_browsing/protocol_manager.h (working copy) |
@@ -42,6 +42,25 @@ |
} |
#endif |
+class SafeBrowsingProtocolManager; |
+// Interface of a factory to create ProtocolManager. Useful for tests. |
+class ProtocolManagerFactory { |
Scott Hess - ex-Googler
2010/12/07 21:22:57
This seems like a bit generic of a name to be in t
lzheng
2010/12/08 01:57:32
Done.
|
+ public: |
+ ProtocolManagerFactory() {} |
+ virtual ~ProtocolManagerFactory() {} |
+ virtual SafeBrowsingProtocolManager* CreateProtocolManager( |
+ SafeBrowsingService* sb_service, |
+ const std::string& client_name, |
+ const std::string& client_key, |
+ const std::string& wrapped_key, |
+ URLRequestContextGetter* request_context_getter, |
+ const std::string& info_url_prefix, |
+ const std::string& mackey_url_prefix, |
+ bool disable_auto_update) = 0; |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(ProtocolManagerFactory); |
+}; |
+ |
class SafeBrowsingProtocolManager : public URLFetcher::Delegate { |
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestBackOffTimes); |
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestChunkStrings); |
@@ -56,23 +75,28 @@ |
friend class SafeBrowsingServiceTest; |
public: |
- // Constructs a SafeBrowsingProtocolManager for |sb_service| that issues |
- // network requests using |request_context_getter|. When |disable_auto_update| |
- // is true, protocol manager won't schedule next update until |
- // ForceScheduleNextUpdate is called. |
- SafeBrowsingProtocolManager(SafeBrowsingService* sb_service, |
- const std::string& client_name, |
- const std::string& client_key, |
- const std::string& wrapped_key, |
- URLRequestContextGetter* request_context_getter, |
- const std::string& info_url_prefix, |
- const std::string& mackey_url_prefix, |
- bool disable_auto_update); |
virtual ~SafeBrowsingProtocolManager(); |
+ // Makes the passed |factory| the factory used to instanciate |
Scott Hess - ex-Googler
2010/12/07 21:22:57
instantiate.
lzheng
2010/12/08 01:57:32
Done.
|
+ // a SafeBrowsingService. Useful for tests. |
+ static void RegisterFactory(ProtocolManagerFactory* factory) { |
+ factory_ = factory; |
+ } |
+ |
+ // Create an instance of the safe browsing service. |
+ static SafeBrowsingProtocolManager* Create( |
+ SafeBrowsingService* sb_service, |
+ const std::string& client_name, |
+ const std::string& client_key, |
+ const std::string& wrapped_key, |
+ URLRequestContextGetter* request_context_getter, |
+ const std::string& info_url_prefix, |
+ const std::string& mackey_url_prefix, |
+ bool disable_auto_update); |
+ |
// Sets up the update schedule and internal state for making periodic requests |
// of the SafeBrowsing service. |
- void Initialize(); |
+ virtual void Initialize(); |
// URLFetcher::Delegate interface. |
virtual void OnURLFetchComplete(const URLFetcher* source, |
@@ -84,14 +108,12 @@ |
// API used by the SafeBrowsingService for issuing queries. When the results |
// are available, SafeBrowsingService::HandleGetHashResults is called. |
- void GetFullHash(SafeBrowsingService::SafeBrowsingCheck* check, |
- const std::vector<SBPrefix>& prefixes); |
+ virtual void GetFullHash(SafeBrowsingService::SafeBrowsingCheck* check, |
+ const std::vector<SBPrefix>& prefixes); |
// Forces the start of next update after |next_update_msec| in msec. |
void ForceScheduleNextUpdate(int next_update_msec); |
- bool is_initial_request() const { return initial_request_; } |
- |
// Scheduled update callback. |
void GetNextUpdate(); |
@@ -105,9 +127,6 @@ |
// Called after the chunks that were parsed were inserted in the database. |
void OnChunkInserted(); |
- // The last time we received an update. |
- base::Time last_update() const { return last_update_; } |
- |
// For UMA users we report to Google when a SafeBrowsing interstitial is shown |
// to the user. We assume that the threat type is either URL_MALWARE or |
// URL_PHISHING. |
@@ -117,7 +136,9 @@ |
bool is_subresource, |
SafeBrowsingService::UrlCheckResult threat_type); |
- |
+ bool is_initial_request() const { return initial_request_; } |
+ // The last time we received an update. |
+ base::Time last_update() const { return last_update_; } |
// Setter for additional_query_. To make sure the additional_query_ won't |
// be changed in the middle of an update, caller (e.g.: SafeBrowsingService) |
// should call this after callbacks triggered in UpdateFinished() or before |
@@ -129,7 +150,22 @@ |
return additional_query_; |
} |
+ protected: |
+ // Constructs a SafeBrowsingProtocolManager for |sb_service| that issues |
+ // network requests using |request_context_getter|. When |disable_auto_update| |
+ // is true, protocol manager won't schedule next update until |
+ // ForceScheduleNextUpdate is called. |
+ SafeBrowsingProtocolManager(SafeBrowsingService* sb_service, |
+ const std::string& client_name, |
+ const std::string& client_key, |
+ const std::string& wrapped_key, |
+ URLRequestContextGetter* request_context_getter, |
+ const std::string& info_url_prefix, |
+ const std::string& mackey_url_prefix, |
+ bool disable_auto_update); |
private: |
+ friend class ProtocolManagerFactoryImpl; |
+ |
// Internal API for fetching information from the SafeBrowsing servers. The |
// GetHash requests are higher priority since they can block user requests |
// so are handled separately. |
@@ -222,6 +258,9 @@ |
void UpdateResponseTimeout(); |
private: |
+ // The factory that controlls the creation of SafeBrowsingProtocolManager. |
+ // This is used by tests. |
+ static ProtocolManagerFactory* factory_; |
Scott Hess - ex-Googler
2010/12/07 21:22:57
"controls", and a newline between this variable an
lzheng
2010/12/08 01:57:32
Done.
|
// Main SafeBrowsing interface object. |
SafeBrowsingService* sb_service_; |