| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 scoped_ptr<LastDownloadFinder> LastDownloadFinder::Create( | 231 scoped_ptr<LastDownloadFinder> LastDownloadFinder::Create( |
| 232 const DownloadDetailsGetter& download_details_getter, | 232 const DownloadDetailsGetter& download_details_getter, |
| 233 const LastDownloadCallback& callback) { | 233 const LastDownloadCallback& callback) { |
| 234 scoped_ptr<LastDownloadFinder> finder(make_scoped_ptr(new LastDownloadFinder( | 234 scoped_ptr<LastDownloadFinder> finder(make_scoped_ptr(new LastDownloadFinder( |
| 235 download_details_getter, | 235 download_details_getter, |
| 236 g_browser_process->profile_manager()->GetLoadedProfiles(), | 236 g_browser_process->profile_manager()->GetLoadedProfiles(), |
| 237 callback))); | 237 callback))); |
| 238 // Return NULL if there is no work to do. | 238 // Return NULL if there is no work to do. |
| 239 if (finder->profile_states_.empty()) | 239 if (finder->profile_states_.empty()) |
| 240 return scoped_ptr<LastDownloadFinder>(); | 240 return scoped_ptr<LastDownloadFinder>(); |
| 241 return finder.Pass(); | 241 return finder; |
| 242 } | 242 } |
| 243 | 243 |
| 244 LastDownloadFinder::LastDownloadFinder() | 244 LastDownloadFinder::LastDownloadFinder() |
| 245 : history_service_observer_(this), weak_ptr_factory_(this) { | 245 : history_service_observer_(this), weak_ptr_factory_(this) { |
| 246 } | 246 } |
| 247 | 247 |
| 248 LastDownloadFinder::LastDownloadFinder( | 248 LastDownloadFinder::LastDownloadFinder( |
| 249 const DownloadDetailsGetter& download_details_getter, | 249 const DownloadDetailsGetter& download_details_getter, |
| 250 const std::vector<Profile*>& profiles, | 250 const std::vector<Profile*>& profiles, |
| 251 const LastDownloadCallback& callback) | 251 const LastDownloadCallback& callback) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 Profile* profile, | 291 Profile* profile, |
| 292 scoped_ptr<ClientIncidentReport_DownloadDetails> details) { | 292 scoped_ptr<ClientIncidentReport_DownloadDetails> details) { |
| 293 auto iter = profile_states_.find(profile); | 293 auto iter = profile_states_.find(profile); |
| 294 // Early-exit if the search for this profile was abandoned. | 294 // Early-exit if the search for this profile was abandoned. |
| 295 if (iter == profile_states_.end()) | 295 if (iter == profile_states_.end()) |
| 296 return; | 296 return; |
| 297 | 297 |
| 298 if (details) { | 298 if (details) { |
| 299 if (IsMostInterestingBinary(*details, details_.get(), | 299 if (IsMostInterestingBinary(*details, details_.get(), |
| 300 most_recent_binary_row_)) { | 300 most_recent_binary_row_)) { |
| 301 details_ = details.Pass(); | 301 details_ = std::move(details); |
| 302 most_recent_binary_row_.end_time = base::Time(); | 302 most_recent_binary_row_.end_time = base::Time(); |
| 303 } | 303 } |
| 304 iter->second = WAITING_FOR_NON_BINARY_HISTORY; | 304 iter->second = WAITING_FOR_NON_BINARY_HISTORY; |
| 305 } else { | 305 } else { |
| 306 iter->second = WAITING_FOR_HISTORY; | 306 iter->second = WAITING_FOR_HISTORY; |
| 307 } | 307 } |
| 308 | 308 |
| 309 // Initiate a history search | 309 // Initiate a history search |
| 310 history::HistoryService* history_service = | 310 history::HistoryService* history_service = |
| 311 HistoryServiceFactory::GetForProfile(profile, | 311 HistoryServiceFactory::GetForProfile(profile, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 PopulateDetailsFromRow(most_recent_binary_row_, binary_details.get()); | 390 PopulateDetailsFromRow(most_recent_binary_row_, binary_details.get()); |
| 391 } | 391 } |
| 392 | 392 |
| 393 if (!most_recent_non_binary_row_.end_time.is_null()) { | 393 if (!most_recent_non_binary_row_.end_time.is_null()) { |
| 394 non_binary_details.reset( | 394 non_binary_details.reset( |
| 395 new ClientIncidentReport_NonBinaryDownloadDetails()); | 395 new ClientIncidentReport_NonBinaryDownloadDetails()); |
| 396 PopulateNonBinaryDetailsFromRow(most_recent_non_binary_row_, | 396 PopulateNonBinaryDetailsFromRow(most_recent_non_binary_row_, |
| 397 non_binary_details.get()); | 397 non_binary_details.get()); |
| 398 } | 398 } |
| 399 | 399 |
| 400 callback_.Run(binary_details.Pass(), non_binary_details.Pass()); | 400 callback_.Run(std::move(binary_details), std::move(non_binary_details)); |
| 401 // Do not touch this LastDownloadFinder after running the callback, since it | 401 // Do not touch this LastDownloadFinder after running the callback, since it |
| 402 // may have been deleted. | 402 // may have been deleted. |
| 403 } | 403 } |
| 404 | 404 |
| 405 void LastDownloadFinder::Observe(int type, | 405 void LastDownloadFinder::Observe(int type, |
| 406 const content::NotificationSource& source, | 406 const content::NotificationSource& source, |
| 407 const content::NotificationDetails& details) { | 407 const content::NotificationDetails& details) { |
| 408 switch (type) { | 408 switch (type) { |
| 409 case chrome::NOTIFICATION_PROFILE_ADDED: | 409 case chrome::NOTIFICATION_PROFILE_ADDED: |
| 410 SearchInProfile(content::Source<Profile>(source).ptr()); | 410 SearchInProfile(content::Source<Profile>(source).ptr()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 } | 438 } |
| 439 | 439 |
| 440 void LastDownloadFinder::HistoryServiceBeingDeleted( | 440 void LastDownloadFinder::HistoryServiceBeingDeleted( |
| 441 history::HistoryService* history_service) { | 441 history::HistoryService* history_service) { |
| 442 history_service_observer_.Remove(history_service); | 442 history_service_observer_.Remove(history_service); |
| 443 } | 443 } |
| 444 | 444 |
| 445 } // namespace safe_browsing | 445 } // namespace safe_browsing |
| OLD | NEW |