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 <map> | 8 #include <map> |
| 9 #include <memory> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/scoped_observer.h" | 16 #include "base/scoped_observer.h" |
17 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana
ger.h" | 17 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana
ger.h" |
18 #include "components/history/core/browser/download_row.h" | 18 #include "components/history/core/browser/download_row.h" |
19 #include "components/history/core/browser/history_service_observer.h" | 19 #include "components/history/core/browser/history_service_observer.h" |
20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
22 | 22 |
23 class Profile; | 23 class Profile; |
24 | 24 |
(...skipping 18 matching lines...) Expand all Loading... |
43 public: | 43 public: |
44 typedef base::Callback<void( | 44 typedef base::Callback<void( |
45 content::BrowserContext* context, | 45 content::BrowserContext* context, |
46 const DownloadMetadataManager::GetDownloadDetailsCallback&)> | 46 const DownloadMetadataManager::GetDownloadDetailsCallback&)> |
47 DownloadDetailsGetter; | 47 DownloadDetailsGetter; |
48 | 48 |
49 // The type of a callback run by the finder upon completion. Each argument is | 49 // The type of a callback run by the finder upon completion. Each argument is |
50 // a protobuf containing details of the respective download that was found, | 50 // a protobuf containing details of the respective download that was found, |
51 // or an empty pointer if none was found. | 51 // or an empty pointer if none was found. |
52 typedef base::Callback<void( | 52 typedef base::Callback<void( |
53 scoped_ptr<ClientIncidentReport_DownloadDetails>, | 53 std::unique_ptr<ClientIncidentReport_DownloadDetails>, |
54 scoped_ptr<ClientIncidentReport_NonBinaryDownloadDetails>)> | 54 std::unique_ptr<ClientIncidentReport_NonBinaryDownloadDetails>)> |
55 LastDownloadCallback; | 55 LastDownloadCallback; |
56 | 56 |
57 ~LastDownloadFinder() override; | 57 ~LastDownloadFinder() override; |
58 | 58 |
59 // Initiates an asynchronous search for the most recent downloads. |callback| | 59 // Initiates an asynchronous search for the most recent downloads. |callback| |
60 // will be run when the search is complete. The returned instance can be | 60 // will be run when the search is complete. The returned instance can be |
61 // deleted to terminate the search, in which case |callback| is not invoked. | 61 // deleted to terminate the search, in which case |callback| is not invoked. |
62 // Returns NULL without running |callback| if there are no eligible profiles | 62 // Returns NULL without running |callback| if there are no eligible profiles |
63 // to search. | 63 // to search. |
64 static scoped_ptr<LastDownloadFinder> Create( | 64 static std::unique_ptr<LastDownloadFinder> Create( |
65 const DownloadDetailsGetter& download_details_getter, | 65 const DownloadDetailsGetter& download_details_getter, |
66 const LastDownloadCallback& callback); | 66 const LastDownloadCallback& callback); |
67 | 67 |
68 protected: | 68 protected: |
69 // Protected constructor so that unit tests can create a fake finder. | 69 // Protected constructor so that unit tests can create a fake finder. |
70 LastDownloadFinder(); | 70 LastDownloadFinder(); |
71 | 71 |
72 private: | 72 private: |
73 enum ProfileWaitState { | 73 enum ProfileWaitState { |
74 WAITING_FOR_METADATA, | 74 WAITING_FOR_METADATA, |
75 WAITING_FOR_HISTORY, | 75 WAITING_FOR_HISTORY, |
76 WAITING_FOR_NON_BINARY_HISTORY, | 76 WAITING_FOR_NON_BINARY_HISTORY, |
77 }; | 77 }; |
78 | 78 |
79 LastDownloadFinder(const DownloadDetailsGetter& download_details_getter, | 79 LastDownloadFinder(const DownloadDetailsGetter& download_details_getter, |
80 const std::vector<Profile*>& profiles, | 80 const std::vector<Profile*>& profiles, |
81 const LastDownloadCallback& callback); | 81 const LastDownloadCallback& callback); |
82 | 82 |
83 // Adds |profile| to the set of profiles to be searched if it is an | 83 // Adds |profile| to the set of profiles to be searched if it is an |
84 // on-the-record profile with history that participates in safe browsing. A | 84 // on-the-record profile with history that participates in safe browsing. A |
85 // search for metadata is initiated immediately. | 85 // search for metadata is initiated immediately. |
86 void SearchInProfile(Profile* profile); | 86 void SearchInProfile(Profile* profile); |
87 | 87 |
88 // DownloadMetadataManager::GetDownloadDetailsCallback. If |details| are | 88 // DownloadMetadataManager::GetDownloadDetailsCallback. If |details| are |
89 // provided, retrieves them if they are the most relevant results. Otherwise | 89 // provided, retrieves them if they are the most relevant results. Otherwise |
90 // begins a search in history. Reports results if there are no more pending | 90 // begins a search in history. Reports results if there are no more pending |
91 // queries. | 91 // queries. |
92 void OnMetadataQuery( | 92 void OnMetadataQuery( |
93 Profile* profile, | 93 Profile* profile, |
94 scoped_ptr<ClientIncidentReport_DownloadDetails> details); | 94 std::unique_ptr<ClientIncidentReport_DownloadDetails> details); |
95 | 95 |
96 // Abandons the search for downloads in |profile|, reporting results if there | 96 // Abandons the search for downloads in |profile|, reporting results if there |
97 // are no more pending queries. | 97 // are no more pending queries. |
98 void AbandonSearchInProfile(Profile* profile); | 98 void AbandonSearchInProfile(Profile* profile); |
99 | 99 |
100 // HistoryService::DownloadQueryCallback. Retrieves the most recent completed | 100 // HistoryService::DownloadQueryCallback. Retrieves the most recent completed |
101 // executable download from |downloads| and reports results if there are no | 101 // executable download from |downloads| and reports results if there are no |
102 // more pending queries. | 102 // more pending queries. |
103 void OnDownloadQuery( | 103 void OnDownloadQuery( |
104 Profile* profile, | 104 Profile* profile, |
105 scoped_ptr<std::vector<history::DownloadRow> > downloads); | 105 std::unique_ptr<std::vector<history::DownloadRow>> downloads); |
106 | 106 |
107 // Removes the profile pointed to by |it| from profile_states_ and reports | 107 // Removes the profile pointed to by |it| from profile_states_ and reports |
108 // results if there are no more pending queries. | 108 // results if there are no more pending queries. |
109 void RemoveProfileAndReportIfDone( | 109 void RemoveProfileAndReportIfDone( |
110 std::map<Profile*, ProfileWaitState>::iterator iter); | 110 std::map<Profile*, ProfileWaitState>::iterator iter); |
111 | 111 |
112 // Invokes the caller-supplied callback with the download found. | 112 // Invokes the caller-supplied callback with the download found. |
113 void ReportResults(); | 113 void ReportResults(); |
114 | 114 |
115 // content::NotificationObserver methods. | 115 // content::NotificationObserver methods. |
(...skipping 15 matching lines...) Expand all Loading... |
131 LastDownloadCallback callback_; | 131 LastDownloadCallback callback_; |
132 | 132 |
133 // A mapping of profiles for which a download query is pending to their | 133 // A mapping of profiles for which a download query is pending to their |
134 // respective states. | 134 // respective states. |
135 std::map<Profile*, ProfileWaitState> profile_states_; | 135 std::map<Profile*, ProfileWaitState> profile_states_; |
136 | 136 |
137 // Registrar for observing profile lifecycle notifications. | 137 // Registrar for observing profile lifecycle notifications. |
138 content::NotificationRegistrar notification_registrar_; | 138 content::NotificationRegistrar notification_registrar_; |
139 | 139 |
140 // The most interesting download details retrieved from download metadata. | 140 // The most interesting download details retrieved from download metadata. |
141 scoped_ptr<ClientIncidentReport_DownloadDetails> details_; | 141 std::unique_ptr<ClientIncidentReport_DownloadDetails> details_; |
142 | 142 |
143 // The most recent download, updated progressively as query results arrive. | 143 // The most recent download, updated progressively as query results arrive. |
144 history::DownloadRow most_recent_binary_row_; | 144 history::DownloadRow most_recent_binary_row_; |
145 | 145 |
146 // The most recent non-binary download, updated progressively as query results | 146 // The most recent non-binary download, updated progressively as query results |
147 // arrive. | 147 // arrive. |
148 history::DownloadRow most_recent_non_binary_row_; | 148 history::DownloadRow most_recent_non_binary_row_; |
149 | 149 |
150 // HistoryServiceObserver | 150 // HistoryServiceObserver |
151 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 151 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
152 history_service_observer_; | 152 history_service_observer_; |
153 | 153 |
154 // A factory for asynchronous operations on profiles' HistoryService. | 154 // A factory for asynchronous operations on profiles' HistoryService. |
155 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; | 155 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; |
156 | 156 |
157 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); | 157 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); |
158 }; | 158 }; |
159 | 159 |
160 } // namespace safe_browsing | 160 } // namespace safe_browsing |
161 | 161 |
162 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_
H_ | 162 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_
H_ |
OLD | NEW |