| 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 // 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 class ClientSideDetectionService : public net::URLFetcherDelegate, | 60 class ClientSideDetectionService : public net::URLFetcherDelegate, |
| 61 public content::NotificationObserver { | 61 public content::NotificationObserver { |
| 62 public: | 62 public: |
| 63 // void(GURL phishing_url, bool is_phishing). | 63 // void(GURL phishing_url, bool is_phishing). |
| 64 typedef base::Callback<void(GURL, bool)> ClientReportPhishingRequestCallback; | 64 typedef base::Callback<void(GURL, bool)> ClientReportPhishingRequestCallback; |
| 65 // void(GURL original_url, GURL malware_url, bool is_malware). | 65 // void(GURL original_url, GURL malware_url, bool is_malware). |
| 66 typedef base::Callback<void(GURL, GURL, bool)> | 66 typedef base::Callback<void(GURL, GURL, bool)> |
| 67 ClientReportMalwareRequestCallback; | 67 ClientReportMalwareRequestCallback; |
| 68 | 68 |
| 69 virtual ~ClientSideDetectionService(); | 69 ~ClientSideDetectionService() override; |
| 70 | 70 |
| 71 // Creates a client-side detection service. The service is initially | 71 // Creates a client-side detection service. The service is initially |
| 72 // disabled, use SetEnabledAndRefreshState() to start it. The caller takes | 72 // disabled, use SetEnabledAndRefreshState() to start it. The caller takes |
| 73 // ownership of the object. This function may return NULL. | 73 // ownership of the object. This function may return NULL. |
| 74 static ClientSideDetectionService* Create( | 74 static ClientSideDetectionService* Create( |
| 75 net::URLRequestContextGetter* request_context_getter); | 75 net::URLRequestContextGetter* request_context_getter); |
| 76 | 76 |
| 77 // Enables or disables the service, and refreshes the state of all renderers. | 77 // Enables or disables the service, and refreshes the state of all renderers. |
| 78 // This is usually called by the SafeBrowsingService, which tracks whether | 78 // This is usually called by the SafeBrowsingService, which tracks whether |
| 79 // any profile uses these services at all. Disabling cancels any pending | 79 // any profile uses these services at all. Disabling cancels any pending |
| 80 // requests; existing ClientSideDetectionHosts will have their callbacks | 80 // requests; existing ClientSideDetectionHosts will have their callbacks |
| 81 // called with "false" verdicts. Enabling starts downloading the model after | 81 // called with "false" verdicts. Enabling starts downloading the model after |
| 82 // a delay. In all cases, each render process is updated to match the state | 82 // a delay. In all cases, each render process is updated to match the state |
| 83 // of the SafeBrowsing preference for that profile. | 83 // of the SafeBrowsing preference for that profile. |
| 84 void SetEnabledAndRefreshState(bool enabled); | 84 void SetEnabledAndRefreshState(bool enabled); |
| 85 | 85 |
| 86 bool enabled() const { | 86 bool enabled() const { |
| 87 return enabled_; | 87 return enabled_; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // From the net::URLFetcherDelegate interface. | 90 // From the net::URLFetcherDelegate interface. |
| 91 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; | 91 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 92 | 92 |
| 93 // content::NotificationObserver overrides: | 93 // content::NotificationObserver overrides: |
| 94 virtual void Observe(int type, | 94 void Observe(int type, |
| 95 const content::NotificationSource& source, | 95 const content::NotificationSource& source, |
| 96 const content::NotificationDetails& details) override; | 96 const content::NotificationDetails& details) override; |
| 97 | 97 |
| 98 // Sends a request to the SafeBrowsing servers with the ClientPhishingRequest. | 98 // Sends a request to the SafeBrowsing servers with the ClientPhishingRequest. |
| 99 // The URL scheme of the |url()| in the request should be HTTP. This method | 99 // The URL scheme of the |url()| in the request should be HTTP. This method |
| 100 // takes ownership of the |verdict| as well as the |callback| and calls the | 100 // takes ownership of the |verdict| as well as the |callback| and calls the |
| 101 // the callback once the result has come back from the server or if an error | 101 // the callback once the result has come back from the server or if an error |
| 102 // occurs during the fetch. If the service is disabled or an error occurs | 102 // occurs during the fetch. If the service is disabled or an error occurs |
| 103 // the phishing verdict will always be false. The callback is always called | 103 // the phishing verdict will always be false. The callback is always called |
| 104 // after SendClientReportPhishingRequest() returns and on the same thread as | 104 // after SendClientReportPhishingRequest() returns and on the same thread as |
| 105 // SendClientReportPhishingRequest() was called. You may set |callback| to | 105 // SendClientReportPhishingRequest() was called. You may set |callback| to |
| 106 // NULL if you don't care about the server verdict. | 106 // NULL if you don't care about the server verdict. |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 327 |
| 328 // Used to asynchronously call the callbacks for | 328 // Used to asynchronously call the callbacks for |
| 329 // SendClientReportPhishingRequest. | 329 // SendClientReportPhishingRequest. |
| 330 base::WeakPtrFactory<ClientSideDetectionService> weak_factory_; | 330 base::WeakPtrFactory<ClientSideDetectionService> weak_factory_; |
| 331 | 331 |
| 332 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); | 332 DISALLOW_COPY_AND_ASSIGN(ClientSideDetectionService); |
| 333 }; | 333 }; |
| 334 } // namespace safe_browsing | 334 } // namespace safe_browsing |
| 335 | 335 |
| 336 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ | 336 #endif // CHROME_BROWSER_SAFE_BROWSING_CLIENT_SIDE_DETECTION_SERVICE_H_ |
| OLD | NEW |