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" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // Finds the most recent executable downloaded by any on-the-record profile with | 35 // Finds the most recent executable downloaded by any on-the-record profile with |
36 // history that participates in safe browsing. | 36 // history that participates in safe browsing. |
37 class LastDownloadFinder : public content::NotificationObserver { | 37 class LastDownloadFinder : public content::NotificationObserver { |
38 public: | 38 public: |
39 // The type of a callback run by the finder upon completion. The argument is a | 39 // 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 | 40 // protobuf containing details of the download that was found, or an empty |
41 // pointer if none was found. | 41 // pointer if none was found. |
42 typedef base::Callback<void(scoped_ptr<ClientIncidentReport_DownloadDetails>)> | 42 typedef base::Callback<void(scoped_ptr<ClientIncidentReport_DownloadDetails>)> |
43 LastDownloadCallback; | 43 LastDownloadCallback; |
44 | 44 |
45 virtual ~LastDownloadFinder(); | 45 ~LastDownloadFinder() override; |
46 | 46 |
47 // Initiates an asynchronous search for the most recent download. |callback| | 47 // Initiates an asynchronous search for the most recent download. |callback| |
48 // will be run when the search is complete. The returned instance can be | 48 // 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. | 49 // deleted to terminate the search, in which case |callback| is not invoked. |
50 // Returns NULL without running |callback| if there are no eligible profiles | 50 // Returns NULL without running |callback| if there are no eligible profiles |
51 // to search. | 51 // to search. |
52 static scoped_ptr<LastDownloadFinder> Create( | 52 static scoped_ptr<LastDownloadFinder> Create( |
53 const LastDownloadCallback& callback); | 53 const LastDownloadCallback& callback); |
54 | 54 |
55 protected: | 55 protected: |
(...skipping 26 matching lines...) Expand all Loading... |
82 scoped_ptr<std::vector<history::DownloadRow> > downloads); | 82 scoped_ptr<std::vector<history::DownloadRow> > downloads); |
83 | 83 |
84 // Removes the profile pointed to by |it| from profiles_ and reports results | 84 // Removes the profile pointed to by |it| from profiles_ and reports results |
85 // if there are no more pending queries. | 85 // if there are no more pending queries. |
86 void RemoveProfileAndReportIfDone(std::vector<Profile*>::iterator it); | 86 void RemoveProfileAndReportIfDone(std::vector<Profile*>::iterator it); |
87 | 87 |
88 // Invokes the caller-supplied callback with the download found. | 88 // Invokes the caller-supplied callback with the download found. |
89 void ReportResults(); | 89 void ReportResults(); |
90 | 90 |
91 // content::NotificationObserver methods. | 91 // content::NotificationObserver methods. |
92 virtual void Observe(int type, | 92 void Observe(int type, |
93 const content::NotificationSource& source, | 93 const content::NotificationSource& source, |
94 const content::NotificationDetails& details) override; | 94 const content::NotificationDetails& details) override; |
95 | 95 |
96 // Caller-supplied callback to be invoked when the most recent download is | 96 // Caller-supplied callback to be invoked when the most recent download is |
97 // found. | 97 // found. |
98 LastDownloadCallback callback_; | 98 LastDownloadCallback callback_; |
99 | 99 |
100 // The profiles for which a download query is pending. | 100 // The profiles for which a download query is pending. |
101 std::vector<Profile*> profiles_; | 101 std::vector<Profile*> profiles_; |
102 | 102 |
103 // Registrar for observing profile lifecycle notifications. | 103 // Registrar for observing profile lifecycle notifications. |
104 content::NotificationRegistrar notification_registrar_; | 104 content::NotificationRegistrar notification_registrar_; |
105 | 105 |
106 // The most recent download, updated progressively as query results arrive. | 106 // The most recent download, updated progressively as query results arrive. |
107 history::DownloadRow most_recent_row_; | 107 history::DownloadRow most_recent_row_; |
108 | 108 |
109 // A factory for asynchronous operations on profiles' HistoryService. | 109 // A factory for asynchronous operations on profiles' HistoryService. |
110 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; | 110 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; |
111 | 111 |
112 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); | 112 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); |
113 }; | 113 }; |
114 | 114 |
115 } // namespace safe_browsing | 115 } // namespace safe_browsing |
116 | 116 |
117 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_
H_ | 117 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_
H_ |
OLD | NEW |