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; | |
brettw
2014/11/14 21:13:07
Private or protected.
nshaik
2014/11/15 07:04:15
Done.
| |
60 void HistoryServiceBeingDeleted(HistoryService* history_service) override; | |
61 | |
55 protected: | 62 protected: |
56 // Protected constructor so that unit tests can create a fake finder. | 63 // Protected constructor so that unit tests can create a fake finder. |
57 LastDownloadFinder(); | 64 LastDownloadFinder(); |
58 | 65 |
59 private: | 66 private: |
60 LastDownloadFinder(const std::vector<Profile*>& profiles, | 67 LastDownloadFinder(const std::vector<Profile*>& profiles, |
61 const LastDownloadCallback& callback); | 68 const LastDownloadCallback& callback); |
62 | 69 |
63 // Adds |profile| to the set of profiles to be searched if it is an | 70 // 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 | 71 // 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 | 109 |
103 // Registrar for observing profile lifecycle notifications. | 110 // Registrar for observing profile lifecycle notifications. |
104 content::NotificationRegistrar notification_registrar_; | 111 content::NotificationRegistrar notification_registrar_; |
105 | 112 |
106 // The most recent download, updated progressively as query results arrive. | 113 // The most recent download, updated progressively as query results arrive. |
107 history::DownloadRow most_recent_row_; | 114 history::DownloadRow most_recent_row_; |
108 | 115 |
109 // A factory for asynchronous operations on profiles' HistoryService. | 116 // A factory for asynchronous operations on profiles' HistoryService. |
110 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; | 117 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; |
111 | 118 |
119 // HistoryServiceObserver | |
120 ScopedObserver<HistoryService, HistoryServiceObserver> | |
121 history_service_observer_; | |
122 | |
112 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); | 123 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); |
113 }; | 124 }; |
114 | 125 |
115 } // namespace safe_browsing | 126 } // namespace safe_browsing |
116 | 127 |
117 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_ H_ | 128 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_ H_ |
OLD | NEW |