| 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 <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "chrome/browser/safe_browsing/database_manager.h" | 15 #include "chrome/browser/safe_browsing/database_manager.h" |
| 16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 | 18 |
| 19 namespace extensions { | 19 namespace extensions { |
| 20 | 20 |
| 21 class Extension; | 21 class Extension; |
| 22 class ExtensionPrefs; | 22 class ExtensionPrefs; |
| 23 | 23 |
| 24 // A blacklist of extensions. | 24 // The blacklist of extensions backed by safe browsing. |
| 25 class Blacklist : public content::NotificationObserver, | 25 class Blacklist : public content::NotificationObserver, |
| 26 public base::SupportsWeakPtr<Blacklist> { | 26 public base::SupportsWeakPtr<Blacklist> { |
| 27 public: | 27 public: |
| 28 class Observer { | 28 class Observer { |
| 29 public: | 29 public: |
| 30 // Observes |blacklist| on construction and unobserves on destruction. | 30 // Observes |blacklist| on construction and unobserves on destruction. |
| 31 explicit Observer(Blacklist* blacklist); | 31 explicit Observer(Blacklist* blacklist); |
| 32 | 32 |
| 33 virtual void OnBlacklistUpdated() = 0; | 33 virtual void OnBlacklistUpdated() = 0; |
| 34 | 34 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 55 enum BlacklistState { | 55 enum BlacklistState { |
| 56 NOT_BLACKLISTED, | 56 NOT_BLACKLISTED, |
| 57 BLACKLISTED, | 57 BLACKLISTED, |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 typedef base::Callback<void(const std::set<std::string>&)> | 60 typedef base::Callback<void(const std::set<std::string>&)> |
| 61 GetBlacklistedIDsCallback; | 61 GetBlacklistedIDsCallback; |
| 62 | 62 |
| 63 typedef base::Callback<void(BlacklistState)> IsBlacklistedCallback; | 63 typedef base::Callback<void(BlacklistState)> IsBlacklistedCallback; |
| 64 | 64 |
| 65 // |prefs_| must outlive this. | |
| 66 explicit Blacklist(ExtensionPrefs* prefs); | 65 explicit Blacklist(ExtensionPrefs* prefs); |
| 67 | 66 |
| 68 virtual ~Blacklist(); | 67 virtual ~Blacklist(); |
| 69 | 68 |
| 70 // From the set of extension IDs passed in via |ids|, asynchronously checks | 69 // From the set of extension IDs passed in via |ids|, asynchronously checks |
| 71 // which are blacklisted and includes them in the resulting set passed | 70 // which are blacklisted and includes them in the resulting set passed |
| 72 // via |callback|, which will be sent on the caller's message loop. | 71 // via |callback|, which will be sent on the caller's message loop. |
| 73 // | 72 // |
| 74 // For a synchronous version which ONLY CHECKS CURRENTLY INSTALLED EXTENSIONS | 73 // For a synchronous version which ONLY CHECKS CURRENTLY INSTALLED EXTENSIONS |
| 75 // see ExtensionPrefs::IsExtensionBlacklisted. | 74 // see ExtensionPrefs::IsExtensionBlacklisted. |
| 76 void GetBlacklistedIDs(const std::set<std::string>& ids, | 75 void GetBlacklistedIDs(const std::set<std::string>& ids, |
| 77 const GetBlacklistedIDsCallback& callback); | 76 const GetBlacklistedIDsCallback& callback); |
| 78 | 77 |
| 79 // More convenient form of GetBlacklistedIDs for checking a single extension. | 78 // More convenient form of GetBlacklistedIDs for checking a single extension. |
| 80 void IsBlacklisted(const std::string& extension_id, | 79 void IsBlacklisted(const std::string& extension_id, |
| 81 const IsBlacklistedCallback& callback); | 80 const IsBlacklistedCallback& callback); |
| 82 | 81 |
| 83 // Sets the blacklist from the updater to contain the extension IDs in |ids| | |
| 84 void SetFromUpdater(const std::vector<std::string>& ids, | |
| 85 const std::string& version); | |
| 86 | |
| 87 // Adds/removes an observer to the blacklist. | 82 // Adds/removes an observer to the blacklist. |
| 88 void AddObserver(Observer* observer); | 83 void AddObserver(Observer* observer); |
| 89 void RemoveObserver(Observer* observer); | 84 void RemoveObserver(Observer* observer); |
| 90 | 85 |
| 91 private: | 86 private: |
| 92 // Use via ScopedDatabaseManagerForTest. | 87 // Use via ScopedDatabaseManagerForTest. |
| 93 static void SetDatabaseManager( | 88 static void SetDatabaseManager( |
| 94 scoped_refptr<SafeBrowsingDatabaseManager> database_manager); | 89 scoped_refptr<SafeBrowsingDatabaseManager> database_manager); |
| 95 static scoped_refptr<SafeBrowsingDatabaseManager> GetDatabaseManager(); | 90 static scoped_refptr<SafeBrowsingDatabaseManager> GetDatabaseManager(); |
| 96 | 91 |
| 97 // Handles the |safebrowsing_blacklisted_ids| response from querying the | |
| 98 // safebrowsing blacklist, given that we know |pref_blacklisted_ids| are | |
| 99 // already blacklisted. Responds to |callback| with the union. | |
| 100 void OnSafeBrowsingResponse( | |
| 101 const std::set<std::string>& pref_blacklisted_ids, | |
| 102 const GetBlacklistedIDsCallback& callback, | |
| 103 const std::set<std::string>& safebrowsing_blacklisted_ids); | |
| 104 | |
| 105 // content::NotificationObserver | 92 // content::NotificationObserver |
| 106 virtual void Observe(int type, | 93 virtual void Observe(int type, |
| 107 const content::NotificationSource& source, | 94 const content::NotificationSource& source, |
| 108 const content::NotificationDetails& details) OVERRIDE; | 95 const content::NotificationDetails& details) OVERRIDE; |
| 109 | 96 |
| 110 ObserverList<Observer> observers_; | 97 ObserverList<Observer> observers_; |
| 111 | 98 |
| 112 ExtensionPrefs* const prefs_; | |
| 113 | |
| 114 std::set<std::string> prefs_blacklist_; | |
| 115 | |
| 116 content::NotificationRegistrar registrar_; | 99 content::NotificationRegistrar registrar_; |
| 117 | 100 |
| 118 DISALLOW_COPY_AND_ASSIGN(Blacklist); | 101 DISALLOW_COPY_AND_ASSIGN(Blacklist); |
| 119 }; | 102 }; |
| 120 | 103 |
| 121 } // namespace extensions | 104 } // namespace extensions |
| 122 | 105 |
| 123 #endif // CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_ | 106 #endif // CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_ |
| OLD | NEW |