| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ | 5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ |
| 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ | 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ |
| 7 | 7 |
| 8 // A class that provides the interface between the SafeBrowsing protocol manager | 8 // A class that provides the interface between the SafeBrowsing protocol manager |
| 9 // and database that holds the downloaded updates. | 9 // and database that holds the downloaded updates. |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "components/safe_browsing_db/database_manager.h" | 13 #include "components/safe_browsing_db/database_manager.h" |
| 14 #include "components/safe_browsing_db/hit_report.h" | 14 #include "components/safe_browsing_db/hit_report.h" |
| 15 #include "components/safe_browsing_db/v4_database.h" | 15 #include "components/safe_browsing_db/v4_database.h" |
| 16 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 16 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
| 17 #include "components/safe_browsing_db/v4_update_protocol_manager.h" | 17 #include "components/safe_browsing_db/v4_update_protocol_manager.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 | 19 |
| 20 using content::ResourceType; | 20 using content::ResourceType; |
| 21 | 21 |
| 22 namespace safe_browsing { | 22 namespace safe_browsing { |
| 23 | 23 |
| 24 // Manages the local, on-disk database of updates downloaded from the | 24 // Manages the local, on-disk database of updates downloaded from the |
| 25 // SafeBrowsing service and interfaces with the protocol manager. | 25 // SafeBrowsing service and interfaces with the protocol manager. |
| 26 class V4LocalDatabaseManager : public SafeBrowsingDatabaseManager { | 26 class V4LocalDatabaseManager : public SafeBrowsingDatabaseManager { |
| 27 public: | 27 public: |
| 28 // Construct V4LocalDatabaseManager. | 28 // Construct V4LocalDatabaseManager. |
| 29 // Must be initialized by calling StartOnIOThread() before using. | 29 // Must be initialized by calling StartOnIOThread() before using. |
| 30 V4LocalDatabaseManager(); | 30 V4LocalDatabaseManager(const base::FilePath& base_path); |
| 31 | 31 |
| 32 // | 32 // |
| 33 // SafeBrowsingDatabaseManager implementation | 33 // SafeBrowsingDatabaseManager implementation |
| 34 // | 34 // |
| 35 | 35 |
| 36 bool IsSupported() const override; | 36 bool IsSupported() const override; |
| 37 safe_browsing::ThreatSource GetThreatSource() const override; | 37 safe_browsing::ThreatSource GetThreatSource() const override; |
| 38 bool ChecksAreAlwaysAsync() const override; | 38 bool ChecksAreAlwaysAsync() const override; |
| 39 bool CanCheckResourceType(content::ResourceType resource_type) const override; | 39 bool CanCheckResourceType(content::ResourceType resource_type) const override; |
| 40 bool CanCheckUrl(const GURL& url) const override; | 40 bool CanCheckUrl(const GURL& url) const override; |
| 41 bool IsDownloadProtectionEnabled() const override; | 41 bool IsDownloadProtectionEnabled() const override; |
| 42 bool CheckBrowseUrl(const GURL& url, Client* client) override; | 42 bool CheckBrowseUrl(const GURL& url, Client* client) override; |
| 43 void CancelCheck(Client* client) override; | 43 void CancelCheck(Client* client) override; |
| 44 void StartOnIOThread( | 44 void StartOnIOThread(net::URLRequestContextGetter* request_context_getter, |
| 45 net::URLRequestContextGetter* request_context_getter, | 45 const V4ProtocolConfig& config) override; |
| 46 const V4ProtocolConfig& config) override; | |
| 47 void StopOnIOThread(bool shutdown) override; | 46 void StopOnIOThread(bool shutdown) override; |
| 48 bool CheckDownloadUrl(const std::vector<GURL>& url_chain, | 47 bool CheckDownloadUrl(const std::vector<GURL>& url_chain, |
| 49 Client* client) override; | 48 Client* client) override; |
| 50 bool CheckExtensionIDs(const std::set<std::string>& extension_ids, | 49 bool CheckExtensionIDs(const std::set<std::string>& extension_ids, |
| 51 Client* client) override; | 50 Client* client) override; |
| 52 bool MatchCsdWhitelistUrl(const GURL& url) override; | 51 bool MatchCsdWhitelistUrl(const GURL& url) override; |
| 53 bool MatchMalwareIP(const std::string& ip_address) override; | 52 bool MatchMalwareIP(const std::string& ip_address) override; |
| 54 bool MatchDownloadWhitelistUrl(const GURL& url) override; | 53 bool MatchDownloadWhitelistUrl(const GURL& url) override; |
| 55 bool MatchDownloadWhitelistString(const std::string& str) override; | 54 bool MatchDownloadWhitelistString(const std::string& str) override; |
| 56 bool MatchInclusionWhitelistUrl(const GURL& url) override; | 55 bool MatchInclusionWhitelistUrl(const GURL& url) override; |
| 57 bool MatchModuleWhitelistString(const std::string& str) override; | 56 bool MatchModuleWhitelistString(const std::string& str) override; |
| 58 bool CheckResourceUrl(const GURL& url, Client* client) override; | 57 bool CheckResourceUrl(const GURL& url, Client* client) override; |
| 59 bool IsMalwareKillSwitchOn() override; | 58 bool IsMalwareKillSwitchOn() override; |
| 60 bool IsCsdWhitelistKillSwitchOn() override; | 59 bool IsCsdWhitelistKillSwitchOn() override; |
| 61 | 60 |
| 62 private: | 61 private: |
| 63 ~V4LocalDatabaseManager() override; | 62 ~V4LocalDatabaseManager() override; |
| 64 | 63 |
| 65 // The callback called each time the protocol manager downloads updates | 64 // The callback called each time the protocol manager downloads updates |
| 66 // successfully. | 65 // successfully. |
| 67 void UpdateRequestCompleted(const std::vector<ListUpdateResponse>& responses); | 66 void UpdateRequestCompleted(const std::vector<ListUpdateResponse>& responses); |
| 68 | 67 |
| 68 void SetupUpdateProtocolManager( |
| 69 net::URLRequestContextGetter* request_context_getter, |
| 70 const V4ProtocolConfig& config); |
| 71 |
| 72 void SetupDatabase(); |
| 73 |
| 74 void DatabaseReady(std::unique_ptr<V4Database> v4_database); |
| 75 |
| 76 void OnCloseDatabase(); |
| 77 |
| 78 // The base directory under which to create the files that contain hashes. |
| 79 const base::FilePath base_path_; |
| 80 |
| 81 // Whether the service is running. |
| 69 bool enabled_; | 82 bool enabled_; |
| 70 | 83 |
| 71 // Stores the current status of the lists to download from the SafeBrowsing | 84 // Stores the current status of the lists to download from the SafeBrowsing |
| 72 // servers. | 85 // servers. |
| 73 // TODO(vakh): current_list_states_ doesn't really belong here. | 86 // TODO(vakh): current_list_states_ doesn't really belong here. |
| 74 // It should come through the database, from the various V4Stores. | 87 // It should come through the database, from the various V4Stores. |
| 75 base::hash_map<UpdateListIdentifier, std::string> current_list_states_; | 88 base::hash_map<UpdateListIdentifier, std::string> current_list_states_; |
| 76 | 89 |
| 77 // The protocol manager that downloads the hash prefix updates. | 90 // The protocol manager that downloads the hash prefix updates. |
| 78 std::unique_ptr<V4UpdateProtocolManager> v4_update_protocol_manager_; | 91 std::unique_ptr<V4UpdateProtocolManager> v4_update_protocol_manager_; |
| 79 | 92 |
| 80 // The database that manages the stores containing the hash prefix updates. | 93 // The database that manages the stores containing the hash prefix updates. |
| 94 // All writes to this variable must happen on the IO thread only. |
| 81 std::unique_ptr<V4Database> v4_database_; | 95 std::unique_ptr<V4Database> v4_database_; |
| 82 | 96 |
| 97 // The sequenced task runner for running safe browsing database operations. |
| 98 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 99 |
| 83 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; | 100 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; |
| 84 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); | 101 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); |
| 85 }; // class V4LocalDatabaseManager | 102 }; // class V4LocalDatabaseManager |
| 86 | 103 |
| 87 } // namespace safe_browsing | 104 } // namespace safe_browsing |
| 88 | 105 |
| 89 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ | 106 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ |
| OLD | NEW |