| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_ |
| 7 | 7 |
| 8 #include <list> |
| 8 #include <map> | 9 #include <map> |
| 9 #include <set> | 10 #include <set> |
| 10 #include <string> | 11 #include <string> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 15 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 16 #include "chrome/browser/safe_browsing/database_manager.h" | 18 #include "chrome/browser/safe_browsing/database_manager.h" |
| 17 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
| 19 | 21 |
| 20 namespace extensions { | 22 namespace extensions { |
| 21 | 23 |
| 24 class BlacklistStateFetcher; |
| 22 class Extension; | 25 class Extension; |
| 23 class ExtensionPrefs; | 26 class ExtensionPrefs; |
| 24 | 27 |
| 25 // The blacklist of extensions backed by safe browsing. | 28 // The blacklist of extensions backed by safe browsing. |
| 26 class Blacklist : public content::NotificationObserver, | 29 class Blacklist : public content::NotificationObserver, |
| 27 public base::SupportsWeakPtr<Blacklist> { | 30 public base::SupportsWeakPtr<Blacklist> { |
| 28 public: | 31 public: |
| 29 class Observer { | 32 class Observer { |
| 30 public: | 33 public: |
| 31 // Observes |blacklist| on construction and unobserves on destruction. | 34 // Observes |blacklist| on construction and unobserves on destruction. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 46 scoped_refptr<SafeBrowsingDatabaseManager> database_manager); | 49 scoped_refptr<SafeBrowsingDatabaseManager> database_manager); |
| 47 | 50 |
| 48 ~ScopedDatabaseManagerForTest(); | 51 ~ScopedDatabaseManagerForTest(); |
| 49 | 52 |
| 50 private: | 53 private: |
| 51 scoped_refptr<SafeBrowsingDatabaseManager> original_; | 54 scoped_refptr<SafeBrowsingDatabaseManager> original_; |
| 52 | 55 |
| 53 DISALLOW_COPY_AND_ASSIGN(ScopedDatabaseManagerForTest); | 56 DISALLOW_COPY_AND_ASSIGN(ScopedDatabaseManagerForTest); |
| 54 }; | 57 }; |
| 55 | 58 |
| 56 // The numeric values here match the values of the respective enum in proto | 59 // The numeric values here match the values of the respective enum in |
| 57 // received from SafeBrowsing server. | 60 // ClientCRXListInfoResponse proto. |
| 58 enum BlacklistState { | 61 enum BlacklistState { |
| 59 NOT_BLACKLISTED = 0, | 62 NOT_BLACKLISTED = 0, |
| 60 BLACKLISTED_MALWARE = 1, | 63 BLACKLISTED_MALWARE = 1, |
| 61 BLACKLISTED_SECURITY_VULNERABILITY = 2, | 64 BLACKLISTED_SECURITY_VULNERABILITY = 2, |
| 62 BLACKLISTED_CWS_POLICY_VIOLATION = 3, | 65 BLACKLISTED_CWS_POLICY_VIOLATION = 3, |
| 63 BLACKLISTED_POTENTIALLY_UNWANTED = 4 | 66 BLACKLISTED_POTENTIALLY_UNWANTED = 4, |
| 67 BLACKLISTED_UNKNOWN // Used when we couldn't connect to server, |
| 68 // e.g. when offline. |
| 64 }; | 69 }; |
| 65 | 70 |
| 66 typedef std::map<std::string, BlacklistState> BlacklistStateMap; | 71 typedef std::map<std::string, BlacklistState> BlacklistStateMap; |
| 67 | 72 |
| 68 typedef base::Callback<void(const BlacklistStateMap&)> | 73 typedef base::Callback<void(const BlacklistStateMap&)> |
| 69 GetBlacklistedIDsCallback; | 74 GetBlacklistedIDsCallback; |
| 70 | 75 |
| 71 typedef base::Callback<void(const std::set<std::string>&)> | 76 typedef base::Callback<void(const std::set<std::string>&)> |
| 72 GetMalwareIDsCallback; | 77 GetMalwareIDsCallback; |
| 73 | 78 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 92 // marked in the blacklist as BLACKLISTED_MALWARE and asynchronously pass | 97 // marked in the blacklist as BLACKLISTED_MALWARE and asynchronously pass |
| 93 // to |callback|. Basically, will call GetBlacklistedIDs and filter its | 98 // to |callback|. Basically, will call GetBlacklistedIDs and filter its |
| 94 // results. | 99 // results. |
| 95 void GetMalwareIDs(const std::set<std::string>& ids, | 100 void GetMalwareIDs(const std::set<std::string>& ids, |
| 96 const GetMalwareIDsCallback& callback); | 101 const GetMalwareIDsCallback& callback); |
| 97 | 102 |
| 98 // More convenient form of GetBlacklistedIDs for checking a single extension. | 103 // More convenient form of GetBlacklistedIDs for checking a single extension. |
| 99 void IsBlacklisted(const std::string& extension_id, | 104 void IsBlacklisted(const std::string& extension_id, |
| 100 const IsBlacklistedCallback& callback); | 105 const IsBlacklistedCallback& callback); |
| 101 | 106 |
| 107 // Used to mock BlacklistStateFetcher in unit tests. |
| 108 void SetBlacklistStateFetcherForTest(BlacklistStateFetcher* fetcher); |
| 109 |
| 102 // Adds/removes an observer to the blacklist. | 110 // Adds/removes an observer to the blacklist. |
| 103 void AddObserver(Observer* observer); | 111 void AddObserver(Observer* observer); |
| 104 void RemoveObserver(Observer* observer); | 112 void RemoveObserver(Observer* observer); |
| 105 | 113 |
| 106 private: | 114 private: |
| 107 // Use via ScopedDatabaseManagerForTest. | 115 // Use via ScopedDatabaseManagerForTest. |
| 108 static void SetDatabaseManager( | 116 static void SetDatabaseManager( |
| 109 scoped_refptr<SafeBrowsingDatabaseManager> database_manager); | 117 scoped_refptr<SafeBrowsingDatabaseManager> database_manager); |
| 110 static scoped_refptr<SafeBrowsingDatabaseManager> GetDatabaseManager(); | 118 static scoped_refptr<SafeBrowsingDatabaseManager> GetDatabaseManager(); |
| 111 | 119 |
| 112 // content::NotificationObserver | 120 // content::NotificationObserver |
| 113 virtual void Observe(int type, | 121 virtual void Observe(int type, |
| 114 const content::NotificationSource& source, | 122 const content::NotificationSource& source, |
| 115 const content::NotificationDetails& details) OVERRIDE; | 123 const content::NotificationDetails& details) OVERRIDE; |
| 116 | 124 |
| 117 void GetBlacklistStateForIDs(const GetBlacklistedIDsCallback& callback, | 125 void GetBlacklistStateForIDs(const GetBlacklistedIDsCallback& callback, |
| 118 const std::set<std::string>& blacklisted_ids); | 126 const std::set<std::string>& blacklisted_ids); |
| 119 | 127 |
| 120 void RequestExtensionsBlacklistState(const std::set<std::string> ids, | 128 void RequestExtensionsBlacklistState(const std::set<std::string>& ids, |
| 121 base::Callback<void()> callback); | 129 const base::Callback<void()>& callback); |
| 130 |
| 131 void OnBlacklistStateReceived(const std::string& id, BlacklistState state); |
| 122 | 132 |
| 123 void ReturnBlacklistStateMap(const GetBlacklistedIDsCallback& callback, | 133 void ReturnBlacklistStateMap(const GetBlacklistedIDsCallback& callback, |
| 124 const std::set<std::string>& blacklisted_ids); | 134 const std::set<std::string>& blacklisted_ids); |
| 125 | 135 |
| 126 ObserverList<Observer> observers_; | 136 ObserverList<Observer> observers_; |
| 127 | 137 |
| 128 content::NotificationRegistrar registrar_; | 138 content::NotificationRegistrar registrar_; |
| 129 | 139 |
| 140 // The cached BlacklistState's, received from BlacklistStateFetcher. |
| 130 BlacklistStateMap blacklist_state_cache_; | 141 BlacklistStateMap blacklist_state_cache_; |
| 131 | 142 |
| 143 scoped_ptr<BlacklistStateFetcher> state_fetcher_; |
| 144 |
| 145 typedef std::list<std::pair<std::vector<std::string>, |
| 146 base::Callback<void()> > > |
| 147 StateRequestsList; |
| 148 |
| 149 // The list of ongoing requests for blacklist states that couldn't be |
| 150 // served directly from the cache. A new request is created in |
| 151 // GetBlacklistedIDs and deleted when the callback is called from |
| 152 // OnBlacklistStateReceived. |
| 153 StateRequestsList state_requests_; |
| 154 |
| 132 DISALLOW_COPY_AND_ASSIGN(Blacklist); | 155 DISALLOW_COPY_AND_ASSIGN(Blacklist); |
| 133 }; | 156 }; |
| 134 | 157 |
| 135 } // namespace extensions | 158 } // namespace extensions |
| 136 | 159 |
| 137 #endif // CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_ | 160 #endif // CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_ |
| OLD | NEW |