Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "chrome/browser/history/download_row.h" | 15 #include "chrome/browser/history/download_row.h" |
| 16 #include "components/history/core/browser/history_service_observer.h" | |
| 16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 18 | 19 |
| 19 class HistoryService; | 20 class HistoryService; |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 class NotificationDetails; | 24 class NotificationDetails; |
| 24 class NotificationSource; | 25 class NotificationSource; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace history { | 28 namespace history { |
| 28 struct DownloadRow; | 29 struct DownloadRow; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace safe_browsing { | 32 namespace safe_browsing { |
| 32 | 33 |
| 33 class ClientIncidentReport_DownloadDetails; | 34 class ClientIncidentReport_DownloadDetails; |
| 34 | 35 |
| 35 // Finds the most recent executable downloaded by any on-the-record profile with | 36 // Finds the most recent executable downloaded by any on-the-record profile with |
| 36 // history that participates in safe browsing. | 37 // history that participates in safe browsing. |
| 37 class LastDownloadFinder : public content::NotificationObserver { | 38 class LastDownloadFinder : public history::HistoryServiceObserver, |
| 39 public content::NotificationObserver { | |
| 38 public: | 40 public: |
| 39 // The type of a callback run by the finder upon completion. The argument is a | 41 // The type of a callback run by the finder upon completion. The argument is a |
| 40 // protobuf containing details of the download that was found, or an empty | 42 // protobuf containing details of the download that was found, or an empty |
| 41 // pointer if none was found. | 43 // pointer if none was found. |
| 42 typedef base::Callback<void(scoped_ptr<ClientIncidentReport_DownloadDetails>)> | 44 typedef base::Callback<void(scoped_ptr<ClientIncidentReport_DownloadDetails>)> |
| 43 LastDownloadCallback; | 45 LastDownloadCallback; |
| 44 | 46 |
| 45 virtual ~LastDownloadFinder(); | 47 virtual ~LastDownloadFinder(); |
| 46 | 48 |
| 47 // Initiates an asynchronous search for the most recent download. |callback| | 49 // Initiates an asynchronous search for the most recent download. |callback| |
| 48 // will be run when the search is complete. The returned instance can be | 50 // will be run when the search is complete. The returned instance can be |
| 49 // deleted to terminate the search, in which case |callback| is not invoked. | 51 // deleted to terminate the search, in which case |callback| is not invoked. |
| 50 // Returns NULL without running |callback| if there are no eligible profiles | 52 // Returns NULL without running |callback| if there are no eligible profiles |
| 51 // to search. | 53 // to search. |
| 52 static scoped_ptr<LastDownloadFinder> Create( | 54 static scoped_ptr<LastDownloadFinder> Create( |
| 53 const LastDownloadCallback& callback); | 55 const LastDownloadCallback& callback); |
| 54 | 56 |
| 57 // Is called when |service| is loaded. | |
|
sdefresne
2014/10/20 13:15:42
// history::HistoryServiceObserver:
| |
| 58 virtual void HistoryServiceLoaded(HistoryService* service) OVERRIDE; | |
|
sdefresne
2014/10/20 13:15:42
OVERRIDE -> override
| |
| 59 | |
| 55 protected: | 60 protected: |
| 56 // Protected constructor so that unit tests can create a fake finder. | 61 // Protected constructor so that unit tests can create a fake finder. |
| 57 LastDownloadFinder(); | 62 LastDownloadFinder(); |
| 58 | 63 |
| 59 private: | 64 private: |
| 60 LastDownloadFinder(const std::vector<Profile*>& profiles, | 65 LastDownloadFinder(const std::vector<Profile*>& profiles, |
| 61 const LastDownloadCallback& callback); | 66 const LastDownloadCallback& callback); |
| 62 | 67 |
| 63 // Adds |profile| to the set of profiles to be searched if it is an | 68 // Adds |profile| to the set of profiles to be searched if it is an |
| 64 // on-the-record profile with history that participates in safe browsing. The | 69 // on-the-record profile with history that participates in safe browsing. The |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 | 113 |
| 109 // A factory for asynchronous operations on profiles' HistoryService. | 114 // A factory for asynchronous operations on profiles' HistoryService. |
| 110 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; | 115 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; |
| 111 | 116 |
| 112 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); | 117 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); |
| 113 }; | 118 }; |
| 114 | 119 |
| 115 } // namespace safe_browsing | 120 } // namespace safe_browsing |
| 116 | 121 |
| 117 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_ H_ | 122 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_ H_ |
| OLD | NEW |