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 "base/scoped_observer.h" |
15 #include "chrome/browser/history/download_row.h" | 16 #include "chrome/browser/history/download_row.h" |
| 17 #include "components/history/core/browser/history_service_observer.h" |
16 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
18 | 20 |
19 class HistoryService; | 21 class HistoryService; |
20 class Profile; | 22 class Profile; |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 class NotificationDetails; | 25 class NotificationDetails; |
24 class NotificationSource; | 26 class NotificationSource; |
25 } | 27 } |
26 | 28 |
27 namespace history { | 29 namespace history { |
28 struct DownloadRow; | 30 struct DownloadRow; |
29 } | 31 } |
30 | 32 |
31 namespace safe_browsing { | 33 namespace safe_browsing { |
32 | 34 |
33 class ClientIncidentReport_DownloadDetails; | 35 class ClientIncidentReport_DownloadDetails; |
34 | 36 |
35 // Finds the most recent executable downloaded by any on-the-record profile with | 37 // Finds the most recent executable downloaded by any on-the-record profile with |
36 // history that participates in safe browsing. | 38 // history that participates in safe browsing. |
37 class LastDownloadFinder : public content::NotificationObserver { | 39 class LastDownloadFinder : public content::NotificationObserver, |
| 40 public history::HistoryServiceObserver { |
38 public: | 41 public: |
39 // The type of a callback run by the finder upon completion. The argument is a | 42 // 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 | 43 // protobuf containing details of the download that was found, or an empty |
41 // pointer if none was found. | 44 // pointer if none was found. |
42 typedef base::Callback<void(scoped_ptr<ClientIncidentReport_DownloadDetails>)> | 45 typedef base::Callback<void(scoped_ptr<ClientIncidentReport_DownloadDetails>)> |
43 LastDownloadCallback; | 46 LastDownloadCallback; |
44 | 47 |
45 ~LastDownloadFinder() override; | 48 ~LastDownloadFinder() override; |
46 | 49 |
47 // Initiates an asynchronous search for the most recent download. |callback| | 50 // Initiates an asynchronous search for the most recent download. |callback| |
48 // will be run when the search is complete. The returned instance can be | 51 // 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. | 52 // deleted to terminate the search, in which case |callback| is not invoked. |
50 // Returns NULL without running |callback| if there are no eligible profiles | 53 // Returns NULL without running |callback| if there are no eligible profiles |
51 // to search. | 54 // to search. |
52 static scoped_ptr<LastDownloadFinder> Create( | 55 static scoped_ptr<LastDownloadFinder> Create( |
53 const LastDownloadCallback& callback); | 56 const LastDownloadCallback& callback); |
54 | 57 |
| 58 // history::HistoryServiceObserver: |
| 59 void OnHistoryServiceLoaded(HistoryService* service) override; |
| 60 |
55 protected: | 61 protected: |
56 // Protected constructor so that unit tests can create a fake finder. | 62 // Protected constructor so that unit tests can create a fake finder. |
57 LastDownloadFinder(); | 63 LastDownloadFinder(); |
58 | 64 |
59 private: | 65 private: |
60 LastDownloadFinder(const std::vector<Profile*>& profiles, | 66 LastDownloadFinder(const std::vector<Profile*>& profiles, |
61 const LastDownloadCallback& callback); | 67 const LastDownloadCallback& callback); |
62 | 68 |
63 // Adds |profile| to the set of profiles to be searched if it is an | 69 // 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 | 70 // on-the-record profile with history that participates in safe browsing. The |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 108 |
103 // Registrar for observing profile lifecycle notifications. | 109 // Registrar for observing profile lifecycle notifications. |
104 content::NotificationRegistrar notification_registrar_; | 110 content::NotificationRegistrar notification_registrar_; |
105 | 111 |
106 // The most recent download, updated progressively as query results arrive. | 112 // The most recent download, updated progressively as query results arrive. |
107 history::DownloadRow most_recent_row_; | 113 history::DownloadRow most_recent_row_; |
108 | 114 |
109 // A factory for asynchronous operations on profiles' HistoryService. | 115 // A factory for asynchronous operations on profiles' HistoryService. |
110 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; | 116 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; |
111 | 117 |
| 118 // HistoryServiceObserver |
| 119 ScopedObserver<HistoryService, HistoryServiceObserver> |
| 120 history_service_observer_; |
| 121 |
112 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); | 122 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); |
113 }; | 123 }; |
114 | 124 |
115 } // namespace safe_browsing | 125 } // namespace safe_browsing |
116 | 126 |
117 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_
H_ | 127 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_
H_ |
OLD | NEW |