Index: chrome/browser/safe_browsing/incident_reporting/last_download_finder.h |
diff --git a/chrome/browser/safe_browsing/incident_reporting/last_download_finder.h b/chrome/browser/safe_browsing/incident_reporting/last_download_finder.h |
index 233773be4426e7b8a02ba1fc0eb4d54da6ee986f..62db1e476b5f3f057eed7254efe50d1fb145f218 100644 |
--- a/chrome/browser/safe_browsing/incident_reporting/last_download_finder.h |
+++ b/chrome/browser/safe_browsing/incident_reporting/last_download_finder.h |
@@ -5,6 +5,7 @@ |
#ifndef CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_H_ |
#define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_H_ |
+#include <map> |
#include <vector> |
#include "base/callback.h" |
@@ -13,6 +14,7 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/weak_ptr.h" |
#include "chrome/browser/history/download_row.h" |
+#include "chrome/browser/safe_browsing/incident_reporting/download_metadata_manager.h" |
#include "content/public/browser/notification_observer.h" |
#include "content/public/browser/notification_registrar.h" |
@@ -36,6 +38,11 @@ class ClientIncidentReport_DownloadDetails; |
// history that participates in safe browsing. |
class LastDownloadFinder : public content::NotificationObserver { |
public: |
+ typedef base::Callback<void( |
+ content::BrowserContext* context, |
+ const DownloadMetadataManager::GetDownloadDetailsCallback&)> |
+ DownloadDetailsGetter; |
+ |
// The type of a callback run by the finder upon completion. The argument is a |
// protobuf containing details of the download that was found, or an empty |
// pointer if none was found. |
@@ -50,6 +57,7 @@ class LastDownloadFinder : public content::NotificationObserver { |
// Returns NULL without running |callback| if there are no eligible profiles |
// to search. |
static scoped_ptr<LastDownloadFinder> Create( |
+ const DownloadDetailsGetter& download_details_getter, |
const LastDownloadCallback& callback); |
protected: |
@@ -57,14 +65,28 @@ class LastDownloadFinder : public content::NotificationObserver { |
LastDownloadFinder(); |
private: |
- LastDownloadFinder(const std::vector<Profile*>& profiles, |
+ enum ProfileWaitState { |
+ WAITING_FOR_METADATA, |
+ WAITING_FOR_HISTORY, |
+ }; |
+ |
+ LastDownloadFinder(const DownloadDetailsGetter& download_details_getter, |
+ const std::vector<Profile*>& profiles, |
const LastDownloadCallback& callback); |
// Adds |profile| to the set of profiles to be searched if it is an |
- // on-the-record profile with history that participates in safe browsing. The |
- // search is initiated if the profile has already loaded history. |
+ // on-the-record profile with history that participates in safe browsing. A |
+ // search for metadata is initiated immediately. |
void SearchInProfile(Profile* profile); |
+ // DownloadMetadataManager::GetDownloadDetailsCallback. If |details| are |
+ // provided, retrieves them if they are the most relevant results. Otherwise |
+ // begins a search in history. Reports results if there are no more pending |
+ // queries. |
+ void OnMetadataQuery( |
+ Profile* profile, |
+ scoped_ptr<ClientIncidentReport_DownloadDetails> details); |
+ |
// Initiates a search in |profile| if it is in the set of profiles to be |
// searched. |
void OnProfileHistoryLoaded(Profile* profile, |
@@ -81,9 +103,10 @@ class LastDownloadFinder : public content::NotificationObserver { |
Profile* profile, |
scoped_ptr<std::vector<history::DownloadRow> > downloads); |
- // Removes the profile pointed to by |it| from profiles_ and reports results |
- // if there are no more pending queries. |
- void RemoveProfileAndReportIfDone(std::vector<Profile*>::iterator it); |
+ // Removes the profile pointed to by |it| from profile_states_ and reports |
+ // results if there are no more pending queries. |
+ void RemoveProfileAndReportIfDone( |
+ std::map<Profile*, ProfileWaitState>::iterator iter); |
// Invokes the caller-supplied callback with the download found. |
void ReportResults(); |
@@ -93,16 +116,24 @@ class LastDownloadFinder : public content::NotificationObserver { |
const content::NotificationSource& source, |
const content::NotificationDetails& details) override; |
+ // Caller-supplied callback to make an asynchronous request for a profile's |
+ // persistent download details. |
+ DownloadDetailsGetter download_details_getter_; |
+ |
// Caller-supplied callback to be invoked when the most recent download is |
// found. |
LastDownloadCallback callback_; |
- // The profiles for which a download query is pending. |
- std::vector<Profile*> profiles_; |
+ // A mapping of profiles for which a download query is pending to their |
+ // respective states. |
+ std::map<Profile*, ProfileWaitState> profile_states_; |
// Registrar for observing profile lifecycle notifications. |
content::NotificationRegistrar notification_registrar_; |
+ // The most interesting download details retrieved from download metadata. |
+ scoped_ptr<ClientIncidentReport_DownloadDetails> details_; |
+ |
// The most recent download, updated progressively as query results arrive. |
history::DownloadRow most_recent_row_; |