Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/last_download_finder.h

Issue 663023007: Include high-fidelity metadata about a download in incident reports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: added DCHECK Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector> 9 #include <vector>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/history/download_row.h" 16 #include "chrome/browser/history/download_row.h"
17 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana ger.h"
16 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
18 20
19 class HistoryService; 21 class HistoryService;
20 class Profile; 22 class Profile;
21 23
22 namespace content { 24 namespace content {
23 class NotificationDetails; 25 class NotificationDetails;
24 class NotificationSource; 26 class NotificationSource;
25 } 27 }
26 28
27 namespace history { 29 namespace history {
28 struct DownloadRow; 30 struct DownloadRow;
29 } 31 }
30 32
31 namespace safe_browsing { 33 namespace safe_browsing {
32 34
33 class ClientIncidentReport_DownloadDetails; 35 class ClientIncidentReport_DownloadDetails;
34 36
35 // Finds the most recent executable downloaded by any on-the-record profile with 37 // Finds the most recent executable downloaded by any on-the-record profile with
36 // history that participates in safe browsing. 38 // history that participates in safe browsing.
37 class LastDownloadFinder : public content::NotificationObserver { 39 class LastDownloadFinder : public content::NotificationObserver {
38 public: 40 public:
41 typedef base::Callback<void(
42 content::BrowserContext* context,
43 const DownloadMetadataManager::GetDownloadDetailsCallback&)>
44 DownloadDetailsGetter;
45
39 // The type of a callback run by the finder upon completion. The argument is a 46 // 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 47 // protobuf containing details of the download that was found, or an empty
41 // pointer if none was found. 48 // pointer if none was found.
42 typedef base::Callback<void(scoped_ptr<ClientIncidentReport_DownloadDetails>)> 49 typedef base::Callback<void(scoped_ptr<ClientIncidentReport_DownloadDetails>)>
43 LastDownloadCallback; 50 LastDownloadCallback;
44 51
45 ~LastDownloadFinder() override; 52 ~LastDownloadFinder() override;
46 53
47 // Initiates an asynchronous search for the most recent download. |callback| 54 // Initiates an asynchronous search for the most recent download. |callback|
48 // will be run when the search is complete. The returned instance can be 55 // 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. 56 // deleted to terminate the search, in which case |callback| is not invoked.
50 // Returns NULL without running |callback| if there are no eligible profiles 57 // Returns NULL without running |callback| if there are no eligible profiles
51 // to search. 58 // to search.
52 static scoped_ptr<LastDownloadFinder> Create( 59 static scoped_ptr<LastDownloadFinder> Create(
60 const DownloadDetailsGetter& download_details_getter,
53 const LastDownloadCallback& callback); 61 const LastDownloadCallback& callback);
54 62
55 protected: 63 protected:
56 // Protected constructor so that unit tests can create a fake finder. 64 // Protected constructor so that unit tests can create a fake finder.
57 LastDownloadFinder(); 65 LastDownloadFinder();
58 66
59 private: 67 private:
60 LastDownloadFinder(const std::vector<Profile*>& profiles, 68 enum ProfileWaitState {
69 WAITING_FOR_METADATA,
70 WAITING_FOR_HISTORY,
71 };
72
73 LastDownloadFinder(const DownloadDetailsGetter& download_details_getter,
74 const std::vector<Profile*>& profiles,
61 const LastDownloadCallback& callback); 75 const LastDownloadCallback& callback);
62 76
63 // Adds |profile| to the set of profiles to be searched if it is an 77 // Adds |profile| to the set of profiles to be searched if it is an
64 // on-the-record profile with history that participates in safe browsing. The 78 // on-the-record profile with history that participates in safe browsing. A
65 // search is initiated if the profile has already loaded history. 79 // search for metadata is initiated immediately.
66 void SearchInProfile(Profile* profile); 80 void SearchInProfile(Profile* profile);
67 81
82 // DownloadMetadataManager::GetDownloadDetailsCallback. If |details| are
83 // provided, retrieves them if they are the most relevant results. Otherwise
84 // begins a search in history. Reports results if there are no more pending
85 // queries.
86 void OnMetadataQuery(
87 Profile* profile,
88 scoped_ptr<ClientIncidentReport_DownloadDetails> details);
89
68 // Initiates a search in |profile| if it is in the set of profiles to be 90 // Initiates a search in |profile| if it is in the set of profiles to be
69 // searched. 91 // searched.
70 void OnProfileHistoryLoaded(Profile* profile, 92 void OnProfileHistoryLoaded(Profile* profile,
71 HistoryService* history_service); 93 HistoryService* history_service);
72 94
73 // Abandons the search for downloads in |profile|, reporting results if there 95 // Abandons the search for downloads in |profile|, reporting results if there
74 // are no more pending queries. 96 // are no more pending queries.
75 void AbandonSearchInProfile(Profile* profile); 97 void AbandonSearchInProfile(Profile* profile);
76 98
77 // HistoryService::DownloadQueryCallback. Retrieves the most recent completed 99 // HistoryService::DownloadQueryCallback. Retrieves the most recent completed
78 // executable download from |downloads| and reports results if there are no 100 // executable download from |downloads| and reports results if there are no
79 // more pending queries. 101 // more pending queries.
80 void OnDownloadQuery( 102 void OnDownloadQuery(
81 Profile* profile, 103 Profile* profile,
82 scoped_ptr<std::vector<history::DownloadRow> > downloads); 104 scoped_ptr<std::vector<history::DownloadRow> > downloads);
83 105
84 // Removes the profile pointed to by |it| from profiles_ and reports results 106 // Removes the profile pointed to by |it| from profile_states_ and reports
85 // if there are no more pending queries. 107 // results if there are no more pending queries.
86 void RemoveProfileAndReportIfDone(std::vector<Profile*>::iterator it); 108 void RemoveProfileAndReportIfDone(
109 std::map<Profile*, ProfileWaitState>::iterator iter);
87 110
88 // Invokes the caller-supplied callback with the download found. 111 // Invokes the caller-supplied callback with the download found.
89 void ReportResults(); 112 void ReportResults();
90 113
91 // content::NotificationObserver methods. 114 // content::NotificationObserver methods.
92 void Observe(int type, 115 void Observe(int type,
93 const content::NotificationSource& source, 116 const content::NotificationSource& source,
94 const content::NotificationDetails& details) override; 117 const content::NotificationDetails& details) override;
95 118
119 // Caller-supplied callback to make an asynchronous request for a profile's
120 // persistent download details.
121 DownloadDetailsGetter download_details_getter_;
122
96 // Caller-supplied callback to be invoked when the most recent download is 123 // Caller-supplied callback to be invoked when the most recent download is
97 // found. 124 // found.
98 LastDownloadCallback callback_; 125 LastDownloadCallback callback_;
99 126
100 // The profiles for which a download query is pending. 127 // A mapping of profiles for which a download query is pending to their
101 std::vector<Profile*> profiles_; 128 // respective states.
129 std::map<Profile*, ProfileWaitState> profile_states_;
102 130
103 // Registrar for observing profile lifecycle notifications. 131 // Registrar for observing profile lifecycle notifications.
104 content::NotificationRegistrar notification_registrar_; 132 content::NotificationRegistrar notification_registrar_;
105 133
134 // The most interesting download details retrieved from download metadata.
135 scoped_ptr<ClientIncidentReport_DownloadDetails> details_;
136
106 // The most recent download, updated progressively as query results arrive. 137 // The most recent download, updated progressively as query results arrive.
107 history::DownloadRow most_recent_row_; 138 history::DownloadRow most_recent_row_;
108 139
109 // A factory for asynchronous operations on profiles' HistoryService. 140 // A factory for asynchronous operations on profiles' HistoryService.
110 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; 141 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_;
111 142
112 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); 143 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder);
113 }; 144 };
114 145
115 } // namespace safe_browsing 146 } // namespace safe_browsing
116 147
117 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_ H_ 148 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698