| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Helper class which handles communication with the SafeBrowsing backends for | 5 // Helper class which handles communication with the SafeBrowsing backends for |
| 6 // client-side phishing detection. This class is used to fetch the client-side | 6 // client-side phishing detection. This class is used to fetch the client-side |
| 7 // model and send it to all renderers. This class is also used to send a ping | 7 // model and send it to all renderers. This class is also used to send a ping |
| 8 // back to Google to verify if a particular site is really phishing or not. | 8 // back to Google to verify if a particular site is really phishing or not. |
| 9 // | 9 // |
| 10 // This class is not thread-safe and expects all calls to be made on the UI | 10 // This class is not thread-safe and expects all calls to be made on the UI |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 class ClientSideDetectionService : public URLFetcher::Delegate, | 55 class ClientSideDetectionService : public URLFetcher::Delegate, |
| 56 public NotificationObserver { | 56 public NotificationObserver { |
| 57 public: | 57 public: |
| 58 typedef Callback2<GURL /* phishing URL */, bool /* is phishing */>::Type | 58 typedef Callback2<GURL /* phishing URL */, bool /* is phishing */>::Type |
| 59 ClientReportPhishingRequestCallback; | 59 ClientReportPhishingRequestCallback; |
| 60 | 60 |
| 61 virtual ~ClientSideDetectionService(); | 61 virtual ~ClientSideDetectionService(); |
| 62 | 62 |
| 63 // Creates a client-side detection service. The service is initially | 63 // Creates a client-side detection service. The service is initially |
| 64 // disabled, use SetEnabled() to start it. The caller takes ownership of the | 64 // disabled, use SetEnabledAndRefreshState() to start it. The caller takes |
| 65 // object. This function may return NULL. | 65 // ownership of the object. This function may return NULL. |
| 66 static ClientSideDetectionService* Create( | 66 static ClientSideDetectionService* Create( |
| 67 net::URLRequestContextGetter* request_context_getter); | 67 net::URLRequestContextGetter* request_context_getter); |
| 68 | 68 |
| 69 // Enables or disables the service. This is usually called by the | 69 // Enables or disables the service, and refreshes the state of all renderers. |
| 70 // SafeBrowsingService, which tracks whether any profile uses these services | 70 // This is usually called by the SafeBrowsingService, which tracks whether |
| 71 // at all. Disabling cancels any pending requests; existing | 71 // any profile uses these services at all. Disabling cancels any pending |
| 72 // ClientSideDetectionHosts will have their callbacks called with "false" | 72 // requests; existing ClientSideDetectionHosts will have their callbacks |
| 73 // verdicts. Enabling starts downloading the model after a delay. | 73 // called with "false" verdicts. Enabling starts downloading the model after |
| 74 void SetEnabled(bool enabled); | 74 // a delay. In all cases, each render process is updated to match the state |
| 75 // of the SafeBrowsing preference for that profile. |
| 76 void SetEnabledAndRefreshState(bool enabled); |
| 75 | 77 |
| 76 bool enabled() const { | 78 bool enabled() const { |
| 77 return enabled_; | 79 return enabled_; |
| 78 } | 80 } |
| 79 | 81 |
| 80 // From the URLFetcher::Delegate interface. | 82 // From the URLFetcher::Delegate interface. |
| 81 virtual void OnURLFetchComplete(const URLFetcher* source, | 83 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 82 const GURL& url, | 84 const GURL& url, |
| 83 const net::URLRequestStatus& status, | 85 const net::URLRequestStatus& status, |
| 84 int response_code, | 86 int response_code, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 159 |
| 158 // This method is called when we're done fetching the model either because | 160 // This method is called when we're done fetching the model either because |
| 159 // we hit an error somewhere or because we're actually done fetch and | 161 // we hit an error somewhere or because we're actually done fetch and |
| 160 // validating the model. | 162 // validating the model. |
| 161 virtual void EndFetchModel(ClientModelStatus status); // Virtual for testing. | 163 virtual void EndFetchModel(ClientModelStatus status); // Virtual for testing. |
| 162 | 164 |
| 163 private: | 165 private: |
| 164 friend class ClientSideDetectionServiceTest; | 166 friend class ClientSideDetectionServiceTest; |
| 165 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, FetchModelTest); | 167 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, FetchModelTest); |
| 166 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetBadSubnets); | 168 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetBadSubnets); |
| 167 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, SetEnabled); | 169 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, |
| 170 SetEnabledAndRefreshState); |
| 168 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, IsBadIpAddress); | 171 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, IsBadIpAddress); |
| 169 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, | 172 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, |
| 170 IsFalsePositiveResponse); | 173 IsFalsePositiveResponse); |
| 171 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, | 174 FRIEND_TEST_ALL_PREFIXES(ClientSideDetectionServiceTest, |
| 172 ModelHasValidHashIds); | 175 ModelHasValidHashIds); |
| 173 | 176 |
| 174 // CacheState holds all information necessary to respond to a caller without | 177 // CacheState holds all information necessary to respond to a caller without |
| 175 // actually making a HTTP request. | 178 // actually making a HTTP request. |
| 176 struct CacheState { | 179 struct CacheState { |
| 177 bool is_phishing; | 180 bool is_phishing; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 // this map to speed up lookups. | 301 // this map to speed up lookups. |
| 299 BadSubnetMap bad_subnets_; | 302 BadSubnetMap bad_subnets_; |
| 300 | 303 |
| 301 NotificationRegistrar registrar_; | 304 NotificationRegistrar registrar_; |
| 302 | 305 |
| 303 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); | 306 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); |
| 304 }; | 307 }; |
| 305 } // namepsace safe_browsing | 308 } // namepsace safe_browsing |
| 306 | 309 |
| 307 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ | 310 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ |
| OLD | NEW |