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 #include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h
" | 5 #include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h
" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 LastDownloadFinder::LastDownloadFinder(const std::vector<Profile*>& profiles, | 118 LastDownloadFinder::LastDownloadFinder(const std::vector<Profile*>& profiles, |
119 const LastDownloadCallback& callback) | 119 const LastDownloadCallback& callback) |
120 : callback_(callback), weak_ptr_factory_(this) { | 120 : callback_(callback), weak_ptr_factory_(this) { |
121 // Observe profile lifecycle events so that the finder can begin or abandon | 121 // Observe profile lifecycle events so that the finder can begin or abandon |
122 // the search in profiles while it is running. | 122 // the search in profiles while it is running. |
123 notification_registrar_.Add(this, | 123 notification_registrar_.Add(this, |
124 chrome::NOTIFICATION_PROFILE_ADDED, | 124 chrome::NOTIFICATION_PROFILE_ADDED, |
125 content::NotificationService::AllSources()); | 125 content::NotificationService::AllSources()); |
126 notification_registrar_.Add(this, | 126 notification_registrar_.Add(this, |
127 chrome::NOTIFICATION_HISTORY_LOADED, | |
128 content::NotificationService::AllSources()); | |
129 notification_registrar_.Add(this, | |
130 chrome::NOTIFICATION_PROFILE_DESTROYED, | 127 chrome::NOTIFICATION_PROFILE_DESTROYED, |
131 content::NotificationService::AllSources()); | 128 content::NotificationService::AllSources()); |
132 | 129 |
133 // Begin the seach for all given profiles. | 130 // Begin the seach for all given profiles. |
134 std::for_each( | 131 std::for_each( |
135 profiles.begin(), | 132 profiles.begin(), |
136 profiles.end(), | 133 profiles.end(), |
137 std::bind1st(std::mem_fun(&LastDownloadFinder::SearchInProfile), this)); | 134 std::bind1st(std::mem_fun(&LastDownloadFinder::SearchInProfile), this)); |
138 } | 135 } |
139 | 136 |
(...skipping 18 matching lines...) Expand all Loading... |
158 // No history service is returned for profiles that do not save history. | 155 // No history service is returned for profiles that do not save history. |
159 if (!history_service) | 156 if (!history_service) |
160 return; | 157 return; |
161 | 158 |
162 profiles_.push_back(profile); | 159 profiles_.push_back(profile); |
163 if (history_service->BackendLoaded()) { | 160 if (history_service->BackendLoaded()) { |
164 history_service->QueryDownloads( | 161 history_service->QueryDownloads( |
165 base::Bind(&LastDownloadFinder::OnDownloadQuery, | 162 base::Bind(&LastDownloadFinder::OnDownloadQuery, |
166 weak_ptr_factory_.GetWeakPtr(), | 163 weak_ptr_factory_.GetWeakPtr(), |
167 profile)); | 164 profile)); |
168 } // else wait until history is loaded. | 165 } else { |
| 166 // else wait until history is loaded. |
| 167 history_service->AddHistoryServiceObserver(this); |
| 168 } |
169 } | 169 } |
170 | 170 |
171 void LastDownloadFinder::OnProfileHistoryLoaded( | 171 void LastDownloadFinder::OnProfileHistoryLoaded( |
172 Profile* profile, | 172 Profile* profile, |
173 HistoryService* history_service) { | 173 HistoryService* history_service) { |
174 if (std::find(profiles_.begin(), profiles_.end(), profile) != | 174 if (std::find(profiles_.begin(), profiles_.end(), profile) != |
175 profiles_.end()) { | 175 profiles_.end()) { |
176 history_service->QueryDownloads( | 176 history_service->QueryDownloads( |
177 base::Bind(&LastDownloadFinder::OnDownloadQuery, | 177 base::Bind(&LastDownloadFinder::OnDownloadQuery, |
178 weak_ptr_factory_.GetWeakPtr(), | 178 weak_ptr_factory_.GetWeakPtr(), |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 235 } |
236 } | 236 } |
237 | 237 |
238 void LastDownloadFinder::Observe(int type, | 238 void LastDownloadFinder::Observe(int type, |
239 const content::NotificationSource& source, | 239 const content::NotificationSource& source, |
240 const content::NotificationDetails& details) { | 240 const content::NotificationDetails& details) { |
241 switch (type) { | 241 switch (type) { |
242 case chrome::NOTIFICATION_PROFILE_ADDED: | 242 case chrome::NOTIFICATION_PROFILE_ADDED: |
243 SearchInProfile(content::Source<Profile>(source).ptr()); | 243 SearchInProfile(content::Source<Profile>(source).ptr()); |
244 break; | 244 break; |
245 case chrome::NOTIFICATION_HISTORY_LOADED: | |
246 OnProfileHistoryLoaded(content::Source<Profile>(source).ptr(), | |
247 content::Details<HistoryService>(details).ptr()); | |
248 break; | |
249 case chrome::NOTIFICATION_PROFILE_DESTROYED: | 245 case chrome::NOTIFICATION_PROFILE_DESTROYED: |
250 AbandonSearchInProfile(content::Source<Profile>(source).ptr()); | 246 AbandonSearchInProfile(content::Source<Profile>(source).ptr()); |
251 break; | 247 break; |
252 default: | 248 default: |
253 break; | 249 break; |
254 } | 250 } |
255 } | 251 } |
256 | 252 |
| 253 void LastDownloadFinder::HistoryServiceLoaded(HistoryService* history_service) { |
| 254 OnProfileHistoryLoaded(history_service->profile(), history_service); |
| 255 history_service->RemoveHistoryServiceObserver(this); |
| 256 } |
| 257 |
257 } // namespace safe_browsing | 258 } // namespace safe_browsing |
OLD | NEW |