| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_FAKE_SAFE_BROWSING_DATABASE_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_FAKE_SAFE_BROWSING_DATABASE_MANAGER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_FAKE_SAFE_BROWSING_DATABASE_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_FAKE_SAFE_BROWSING_DATABASE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "chrome/browser/safe_browsing/database_manager.h" | 11 #include "chrome/browser/safe_browsing/database_manager.h" |
| 12 | 12 |
| 13 namespace extensions { | 13 namespace extensions { |
| 14 | 14 |
| 15 // A fake safe browsing database manager for use with extensions tests. | 15 // A fake safe browsing database manager for use with extensions tests. |
| 16 // | 16 // |
| 17 // By default it is disabled (returning true and ignoring |unsafe_ids_|); | 17 // By default it is disabled (returning true and ignoring |unsafe_ids_|); |
| 18 // call set_enabled to enable it. | 18 // call set_enabled to enable it. |
| 19 class FakeSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { | 19 class FakeSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager { |
| 20 public: | 20 public: |
| 21 explicit FakeSafeBrowsingDatabaseManager(bool enabled); | 21 explicit FakeSafeBrowsingDatabaseManager(bool enabled); |
| 22 | 22 |
| 23 // Returns true if synchronously safe, false if not in which case the unsafe | 23 // Returns true if synchronously safe, false if not in which case the unsafe |
| 24 // IDs taken from |unsafe_ids_| are passed to to |client| on the current | 24 // IDs taken from |unsafe_ids_| are passed to to |client| on the current |
| 25 // message loop. | 25 // message loop. |
| 26 virtual bool CheckExtensionIDs(const std::set<std::string>& extension_ids, | 26 bool CheckExtensionIDs(const std::set<std::string>& extension_ids, |
| 27 Client* client) override; | 27 Client* client) override; |
| 28 | 28 |
| 29 // Return |this| to chain together SetUnsafe(...).NotifyUpdate() conveniently. | 29 // Return |this| to chain together SetUnsafe(...).NotifyUpdate() conveniently. |
| 30 FakeSafeBrowsingDatabaseManager& Enable(); | 30 FakeSafeBrowsingDatabaseManager& Enable(); |
| 31 FakeSafeBrowsingDatabaseManager& Disable(); | 31 FakeSafeBrowsingDatabaseManager& Disable(); |
| 32 FakeSafeBrowsingDatabaseManager& ClearUnsafe(); | 32 FakeSafeBrowsingDatabaseManager& ClearUnsafe(); |
| 33 FakeSafeBrowsingDatabaseManager& SetUnsafe(const std::string& a); | 33 FakeSafeBrowsingDatabaseManager& SetUnsafe(const std::string& a); |
| 34 FakeSafeBrowsingDatabaseManager& SetUnsafe(const std::string& a, | 34 FakeSafeBrowsingDatabaseManager& SetUnsafe(const std::string& a, |
| 35 const std::string& b); | 35 const std::string& b); |
| 36 FakeSafeBrowsingDatabaseManager& SetUnsafe(const std::string& a, | 36 FakeSafeBrowsingDatabaseManager& SetUnsafe(const std::string& a, |
| 37 const std::string& b, | 37 const std::string& b, |
| 38 const std::string& c); | 38 const std::string& c); |
| 39 FakeSafeBrowsingDatabaseManager& SetUnsafe(const std::string& a, | 39 FakeSafeBrowsingDatabaseManager& SetUnsafe(const std::string& a, |
| 40 const std::string& b, | 40 const std::string& b, |
| 41 const std::string& c, | 41 const std::string& c, |
| 42 const std::string& d); | 42 const std::string& d); |
| 43 FakeSafeBrowsingDatabaseManager& AddUnsafe(const std::string& a); | 43 FakeSafeBrowsingDatabaseManager& AddUnsafe(const std::string& a); |
| 44 FakeSafeBrowsingDatabaseManager& RemoveUnsafe(const std::string& a); | 44 FakeSafeBrowsingDatabaseManager& RemoveUnsafe(const std::string& a); |
| 45 | 45 |
| 46 // Send the update notification. | 46 // Send the update notification. |
| 47 void NotifyUpdate(); | 47 void NotifyUpdate(); |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 virtual ~FakeSafeBrowsingDatabaseManager(); | 50 ~FakeSafeBrowsingDatabaseManager() override; |
| 51 | 51 |
| 52 // Runs client->SafeBrowsingResult(result). | 52 // Runs client->SafeBrowsingResult(result). |
| 53 void OnSafeBrowsingResult(scoped_ptr<SafeBrowsingCheck> result, | 53 void OnSafeBrowsingResult(scoped_ptr<SafeBrowsingCheck> result, |
| 54 Client* client); | 54 Client* client); |
| 55 | 55 |
| 56 // Whether to respond to CheckExtensionIDs immediately with true (indicating | 56 // Whether to respond to CheckExtensionIDs immediately with true (indicating |
| 57 // that there is definitely no extension ID match). | 57 // that there is definitely no extension ID match). |
| 58 bool enabled_; | 58 bool enabled_; |
| 59 | 59 |
| 60 // The extension IDs considered unsafe. | 60 // The extension IDs considered unsafe. |
| 61 std::set<std::string> unsafe_ids_; | 61 std::set<std::string> unsafe_ids_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 } // namespace extensions | 64 } // namespace extensions |
| 65 | 65 |
| 66 #endif // CHROME_BROWSER_EXTENSIONS_FAKE_SAFE_BROWSING_DATABASE_MANAGER_H_ | 66 #endif // CHROME_BROWSER_EXTENSIONS_FAKE_SAFE_BROWSING_DATABASE_MANAGER_H_ |
| OLD | NEW |