| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 // The Safe Browsing service is responsible for downloading anti-phishing and | 5 // The Safe Browsing service is responsible for downloading anti-phishing and |
| 6 // anti-malware tables and checking urls against them. | 6 // anti-malware tables and checking urls against them. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
| 9 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/callback_list.h" | |
| 17 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 18 #include "base/macros.h" | 17 #include "base/macros.h" |
| 19 #include "base/memory/ref_counted.h" | |
| 20 #include "base/observer_list.h" | |
| 21 #include "base/sequenced_task_runner_helpers.h" | 18 #include "base/sequenced_task_runner_helpers.h" |
| 22 #include "chrome/browser/safe_browsing/services_delegate.h" | 19 #include "chrome/browser/safe_browsing/services_delegate.h" |
| 23 #include "components/safe_browsing_db/util.h" | 20 #include "components/safe_browsing/base_safe_browsing_service.h" |
| 24 #include "content/public/browser/browser_thread.h" | |
| 25 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 26 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 27 | 23 |
| 28 #if defined(FULL_SAFE_BROWSING) | 24 #if defined(FULL_SAFE_BROWSING) |
| 29 #include "chrome/browser/safe_browsing/incident_reporting/delayed_analysis_callb
ack.h" | 25 #include "chrome/browser/safe_browsing/incident_reporting/delayed_analysis_callb
ack.h" |
| 30 #endif | 26 #endif |
| 31 | 27 |
| 32 class PrefChangeRegistrar; | 28 class PrefChangeRegistrar; |
| 33 class PrefService; | 29 class PrefService; |
| 34 class Profile; | 30 class Profile; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 56 class SafeBrowsingServiceFactory; | 52 class SafeBrowsingServiceFactory; |
| 57 class SafeBrowsingUIManager; | 53 class SafeBrowsingUIManager; |
| 58 class SafeBrowsingURLRequestContextGetter; | 54 class SafeBrowsingURLRequestContextGetter; |
| 59 struct V4ProtocolConfig; | 55 struct V4ProtocolConfig; |
| 60 | 56 |
| 61 // Construction needs to happen on the main thread. | 57 // Construction needs to happen on the main thread. |
| 62 // The SafeBrowsingService owns both the UI and Database managers which do | 58 // The SafeBrowsingService owns both the UI and Database managers which do |
| 63 // the heavylifting of safebrowsing service. Both of these managers stay | 59 // the heavylifting of safebrowsing service. Both of these managers stay |
| 64 // alive until SafeBrowsingService is destroyed, however, they are disabled | 60 // alive until SafeBrowsingService is destroyed, however, they are disabled |
| 65 // permanently when Shutdown method is called. | 61 // permanently when Shutdown method is called. |
| 66 class SafeBrowsingService : public base::RefCountedThreadSafe< | 62 class SafeBrowsingService : public BaseSafeBrowsingService, |
| 67 SafeBrowsingService, | |
| 68 content::BrowserThread::DeleteOnUIThread>, | |
| 69 public content::NotificationObserver { | 63 public content::NotificationObserver { |
| 70 public: | 64 public: |
| 71 // Makes the passed |factory| the factory used to instanciate | 65 // Makes the passed |factory| the factory used to instanciate |
| 72 // a SafeBrowsingService. Useful for tests. | 66 // a SafeBrowsingService. Useful for tests. |
| 73 static void RegisterFactory(SafeBrowsingServiceFactory* factory) { | 67 static void RegisterFactory(SafeBrowsingServiceFactory* factory) { |
| 74 factory_ = factory; | 68 factory_ = factory; |
| 75 } | 69 } |
| 76 | 70 |
| 77 static base::FilePath GetCookieFilePathForTesting(); | 71 static base::FilePath GetCookieFilePathForTesting(); |
| 78 | 72 |
| 79 static base::FilePath GetBaseFilename(); | 73 static base::FilePath GetBaseFilename(); |
| 80 | 74 |
| 81 // Create an instance of the safe browsing service. | 75 // Create an instance of the safe browsing service. |
| 82 static SafeBrowsingService* CreateSafeBrowsingService(); | 76 static SafeBrowsingService* CreateSafeBrowsingService(); |
| 83 | 77 |
| 84 // Called on the UI thread to initialize the service. | 78 // Called on the UI thread to initialize the service. |
| 85 void Initialize(); | 79 void Initialize() override; |
| 86 | 80 |
| 87 // Called on the main thread to let us know that the io_thread is going away. | 81 // Called on the main thread to let us know that the io_thread is going away. |
| 88 void ShutDown(); | 82 void ShutDown() override; |
| 89 | 83 |
| 90 // Called on UI thread to decide if the download file's sha256 hash | 84 // Called on UI thread to decide if the download file's sha256 hash |
| 91 // should be calculated for safebrowsing. | 85 // should be calculated for safebrowsing. |
| 92 bool DownloadBinHashNeeded() const; | 86 bool DownloadBinHashNeeded() const; |
| 93 | 87 |
| 94 // Create a protocol config struct. | 88 // Create a protocol config struct. |
| 95 virtual SafeBrowsingProtocolConfig GetProtocolConfig() const; | 89 virtual SafeBrowsingProtocolConfig GetProtocolConfig() const; |
| 96 | 90 |
| 97 // Create a v4 protocol config struct. | 91 // Create a v4 protocol config struct. |
| 98 virtual V4ProtocolConfig GetV4ProtocolConfig() const; | 92 virtual V4ProtocolConfig GetV4ProtocolConfig() const; |
| 99 | 93 |
| 100 // Returns the client_name field for both V3 and V4 protocol manager configs. | 94 // Returns the client_name field for both V3 and V4 protocol manager configs. |
| 101 std::string GetProtocolConfigClientName() const; | 95 std::string GetProtocolConfigClientName() const; |
| 102 | 96 |
| 103 // Get current enabled status. Must be called on IO thread. | |
| 104 bool enabled() const { | |
| 105 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 106 return enabled_; | |
| 107 } | |
| 108 | |
| 109 // Whether the service is enabled by the current set of profiles. | 97 // Whether the service is enabled by the current set of profiles. |
| 110 bool enabled_by_prefs() const { | 98 bool enabled_by_prefs() const { |
| 111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 99 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 112 return enabled_by_prefs_; | 100 return enabled_by_prefs_; |
| 113 } | 101 } |
| 114 | 102 |
| 115 ClientSideDetectionService* safe_browsing_detection_service() const { | 103 ClientSideDetectionService* safe_browsing_detection_service() const { |
| 116 return services_delegate_->GetCsdService(); | 104 return services_delegate_->GetCsdService(); |
| 117 } | 105 } |
| 118 | 106 |
| 119 // The DownloadProtectionService is not valid after the SafeBrowsingService | 107 // The DownloadProtectionService is not valid after the SafeBrowsingService |
| 120 // is destroyed. | 108 // is destroyed. |
| 121 DownloadProtectionService* download_protection_service() const { | 109 DownloadProtectionService* download_protection_service() const { |
| 122 return services_delegate_->GetDownloadService(); | 110 return services_delegate_->GetDownloadService(); |
| 123 } | 111 } |
| 124 | 112 |
| 125 scoped_refptr<net::URLRequestContextGetter> url_request_context(); | 113 scoped_refptr<net::URLRequestContextGetter> url_request_context() override; |
| 126 | 114 |
| 127 const scoped_refptr<SafeBrowsingUIManager>& ui_manager() const; | 115 const scoped_refptr<SafeBrowsingUIManager>& ui_manager() const; |
| 128 | 116 |
| 129 // This returns either the v3 or the v4 database manager, depending on | 117 // This returns either the v3 or the v4 database manager, depending on |
| 130 // the experiment settings. | 118 // the experiment settings. |
| 131 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager() const; | 119 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager() |
| 120 const override; |
| 132 | 121 |
| 133 scoped_refptr<SafeBrowsingNavigationObserverManager> | 122 scoped_refptr<SafeBrowsingNavigationObserverManager> |
| 134 navigation_observer_manager(); | 123 navigation_observer_manager(); |
| 135 | 124 |
| 136 SafeBrowsingProtocolManager* protocol_manager() const; | 125 SafeBrowsingProtocolManager* protocol_manager() const; |
| 137 | 126 |
| 138 SafeBrowsingPingManager* ping_manager() const; | 127 SafeBrowsingPingManager* ping_manager() const; |
| 139 | 128 |
| 140 // This may be NULL if v4 is not enabled by experiment. | 129 // This may be NULL if v4 is not enabled by experiment. |
| 141 const scoped_refptr<SafeBrowsingDatabaseManager>& v4_local_database_manager() | 130 const scoped_refptr<SafeBrowsingDatabaseManager>& v4_local_database_manager() |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 168 |
| 180 // Sends serialized download report to backend. | 169 // Sends serialized download report to backend. |
| 181 virtual void SendSerializedDownloadReport(const std::string& report); | 170 virtual void SendSerializedDownloadReport(const std::string& report); |
| 182 | 171 |
| 183 protected: | 172 protected: |
| 184 // Creates the safe browsing service. Need to initialize before using. | 173 // Creates the safe browsing service. Need to initialize before using. |
| 185 SafeBrowsingService(); | 174 SafeBrowsingService(); |
| 186 | 175 |
| 187 ~SafeBrowsingService() override; | 176 ~SafeBrowsingService() override; |
| 188 | 177 |
| 189 virtual SafeBrowsingDatabaseManager* CreateDatabaseManager(); | 178 SafeBrowsingDatabaseManager* CreateDatabaseManager() override; |
| 190 | 179 |
| 191 virtual SafeBrowsingUIManager* CreateUIManager(); | 180 virtual SafeBrowsingUIManager* CreateUIManager(); |
| 192 | 181 |
| 193 // Registers all the delayed analysis with the incident reporting service. | 182 // Registers all the delayed analysis with the incident reporting service. |
| 194 // This is where you register your process-wide, profile-independent analysis. | 183 // This is where you register your process-wide, profile-independent analysis. |
| 195 virtual void RegisterAllDelayedAnalysis(); | 184 virtual void RegisterAllDelayedAnalysis(); |
| 196 | 185 |
| 197 // Return a ptr to DatabaseManager's delegate, or NULL if it doesn't have one. | 186 // Return a ptr to DatabaseManager's delegate, or NULL if it doesn't have one. |
| 198 virtual SafeBrowsingProtocolManagerDelegate* GetProtocolManagerDelegate(); | 187 virtual SafeBrowsingProtocolManagerDelegate* GetProtocolManagerDelegate(); |
| 199 | 188 |
| 200 std::unique_ptr<ServicesDelegate> services_delegate_; | 189 std::unique_ptr<ServicesDelegate> services_delegate_; |
| 201 | 190 |
| 202 private: | 191 private: |
| 203 friend class SafeBrowsingServiceFactoryImpl; | 192 friend class SafeBrowsingServiceFactoryImpl; |
| 204 friend struct content::BrowserThread::DeleteOnThread< | |
| 205 content::BrowserThread::UI>; | |
| 206 friend class base::DeleteHelper<SafeBrowsingService>; | 193 friend class base::DeleteHelper<SafeBrowsingService>; |
| 207 friend class SafeBrowsingServerTest; | 194 friend class SafeBrowsingServerTest; |
| 208 friend class SafeBrowsingServiceTest; | 195 friend class SafeBrowsingServiceTest; |
| 209 friend class SafeBrowsingURLRequestContextGetter; | 196 friend class SafeBrowsingURLRequestContextGetter; |
| 210 friend class TestSafeBrowsingService; | 197 friend class TestSafeBrowsingService; |
| 211 friend class TestSafeBrowsingServiceFactory; | 198 friend class TestSafeBrowsingServiceFactory; |
| 212 | 199 |
| 213 // Called to initialize objects that are used on the io_thread. This may be | 200 // Called to initialize objects that are used on the io_thread. This may be |
| 214 // called multiple times during the life of the SafeBrowsingService. | 201 // called multiple times during the life of the SafeBrowsingService. |
| 215 void StartOnIOThread( | 202 void StartOnIOThread( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 url_request_context_getter_; | 249 url_request_context_getter_; |
| 263 | 250 |
| 264 #if defined(SAFE_BROWSING_DB_LOCAL) | 251 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 265 // Handles interaction with SafeBrowsing servers. Accessed on IO thread. | 252 // Handles interaction with SafeBrowsing servers. Accessed on IO thread. |
| 266 std::unique_ptr<SafeBrowsingProtocolManager> protocol_manager_; | 253 std::unique_ptr<SafeBrowsingProtocolManager> protocol_manager_; |
| 267 #endif | 254 #endif |
| 268 | 255 |
| 269 // Provides phishing and malware statistics. Accessed on IO thread. | 256 // Provides phishing and malware statistics. Accessed on IO thread. |
| 270 std::unique_ptr<SafeBrowsingPingManager> ping_manager_; | 257 std::unique_ptr<SafeBrowsingPingManager> ping_manager_; |
| 271 | 258 |
| 272 // Whether the service is running. 'enabled_' is used by SafeBrowsingService | |
| 273 // on the IO thread during normal operations. | |
| 274 bool enabled_; | |
| 275 | |
| 276 // Whether SafeBrowsing is enabled by the current set of profiles. | 259 // Whether SafeBrowsing is enabled by the current set of profiles. |
| 277 // Accessed on UI thread. | 260 // Accessed on UI thread. |
| 278 bool enabled_by_prefs_; | 261 bool enabled_by_prefs_; |
| 279 | 262 |
| 280 // Whether SafeBrowsing needs to be enabled in V4Only mode. In this mode, all | 263 // Whether SafeBrowsing needs to be enabled in V4Only mode. In this mode, all |
| 281 // SafeBrowsing decisions are made using the PVer4 implementation. | 264 // SafeBrowsing decisions are made using the PVer4 implementation. |
| 282 bool enabled_v4_only_; | 265 bool enabled_v4_only_; |
| 283 | 266 |
| 284 // Tracks existing PrefServices, and the safe browsing preference on each. | 267 // Tracks existing PrefServices, and the safe browsing preference on each. |
| 285 // This is used to determine if any profile is currently using the safe | 268 // This is used to determine if any profile is currently using the safe |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 SafeBrowsingServiceFactory() { } | 302 SafeBrowsingServiceFactory() { } |
| 320 virtual ~SafeBrowsingServiceFactory() { } | 303 virtual ~SafeBrowsingServiceFactory() { } |
| 321 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; | 304 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; |
| 322 private: | 305 private: |
| 323 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); | 306 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); |
| 324 }; | 307 }; |
| 325 | 308 |
| 326 } // namespace safe_browsing | 309 } // namespace safe_browsing |
| 327 | 310 |
| 328 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 311 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
| OLD | NEW |