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