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

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

Issue 573553004: Eliminate NOTIFICATION_HISTORY_LOADED notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ScopedObserver to InMemoryHistoryBackend,PrerenderLocalPredictor,ChromeTemplateURLServiceClient Created 6 years 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 <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.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 "chrome/browser/history/download_row.h" 17 #include "chrome/browser/history/download_row.h"
17 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana ger.h" 18 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana ger.h"
19 #include "components/history/core/browser/history_service_observer.h"
18 #include "content/public/browser/notification_observer.h" 20 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 21 #include "content/public/browser/notification_registrar.h"
20 22
21 class HistoryService; 23 class HistoryService;
22 class Profile; 24 class Profile;
23 25
24 namespace content { 26 namespace content {
25 class NotificationDetails; 27 class NotificationDetails;
26 class NotificationSource; 28 class NotificationSource;
27 } 29 }
28 30
29 namespace history { 31 namespace history {
30 struct DownloadRow; 32 struct DownloadRow;
31 } 33 }
32 34
33 namespace safe_browsing { 35 namespace safe_browsing {
34 36
35 class ClientIncidentReport_DownloadDetails; 37 class ClientIncidentReport_DownloadDetails;
36 38
37 // Finds the most recent executable downloaded by any on-the-record profile with 39 // Finds the most recent executable downloaded by any on-the-record profile with
38 // history that participates in safe browsing. 40 // history that participates in safe browsing.
39 class LastDownloadFinder : public content::NotificationObserver { 41 class LastDownloadFinder : public content::NotificationObserver,
42 public history::HistoryServiceObserver {
40 public: 43 public:
41 typedef base::Callback<void( 44 typedef base::Callback<void(
42 content::BrowserContext* context, 45 content::BrowserContext* context,
43 const DownloadMetadataManager::GetDownloadDetailsCallback&)> 46 const DownloadMetadataManager::GetDownloadDetailsCallback&)>
44 DownloadDetailsGetter; 47 DownloadDetailsGetter;
45 48
46 // The type of a callback run by the finder upon completion. The argument is a 49 // The type of a callback run by the finder upon completion. The argument is a
47 // protobuf containing details of the download that was found, or an empty 50 // protobuf containing details of the download that was found, or an empty
48 // pointer if none was found. 51 // pointer if none was found.
49 typedef base::Callback<void(scoped_ptr<ClientIncidentReport_DownloadDetails>)> 52 typedef base::Callback<void(scoped_ptr<ClientIncidentReport_DownloadDetails>)>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 std::map<Profile*, ProfileWaitState>::iterator iter); 112 std::map<Profile*, ProfileWaitState>::iterator iter);
110 113
111 // Invokes the caller-supplied callback with the download found. 114 // Invokes the caller-supplied callback with the download found.
112 void ReportResults(); 115 void ReportResults();
113 116
114 // content::NotificationObserver methods. 117 // content::NotificationObserver methods.
115 void Observe(int type, 118 void Observe(int type,
116 const content::NotificationSource& source, 119 const content::NotificationSource& source,
117 const content::NotificationDetails& details) override; 120 const content::NotificationDetails& details) override;
118 121
122 // history::HistoryServiceObserver:
123 void OnHistoryServiceLoaded(HistoryService* service) override;
124 void HistoryServiceBeingDeleted(HistoryService* history_service) override;
125
119 // Caller-supplied callback to make an asynchronous request for a profile's 126 // Caller-supplied callback to make an asynchronous request for a profile's
120 // persistent download details. 127 // persistent download details.
121 DownloadDetailsGetter download_details_getter_; 128 DownloadDetailsGetter download_details_getter_;
122 129
123 // Caller-supplied callback to be invoked when the most recent download is 130 // Caller-supplied callback to be invoked when the most recent download is
124 // found. 131 // found.
125 LastDownloadCallback callback_; 132 LastDownloadCallback callback_;
126 133
127 // A mapping of profiles for which a download query is pending to their 134 // A mapping of profiles for which a download query is pending to their
128 // respective states. 135 // respective states.
129 std::map<Profile*, ProfileWaitState> profile_states_; 136 std::map<Profile*, ProfileWaitState> profile_states_;
130 137
131 // Registrar for observing profile lifecycle notifications. 138 // Registrar for observing profile lifecycle notifications.
132 content::NotificationRegistrar notification_registrar_; 139 content::NotificationRegistrar notification_registrar_;
133 140
134 // The most interesting download details retrieved from download metadata. 141 // The most interesting download details retrieved from download metadata.
135 scoped_ptr<ClientIncidentReport_DownloadDetails> details_; 142 scoped_ptr<ClientIncidentReport_DownloadDetails> details_;
136 143
137 // The most recent download, updated progressively as query results arrive. 144 // The most recent download, updated progressively as query results arrive.
138 history::DownloadRow most_recent_row_; 145 history::DownloadRow most_recent_row_;
139 146
147 // HistoryServiceObserver
148 ScopedObserver<HistoryService, HistoryServiceObserver>
149 history_service_observer_;
150
140 // A factory for asynchronous operations on profiles' HistoryService. 151 // A factory for asynchronous operations on profiles' HistoryService.
141 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_; 152 base::WeakPtrFactory<LastDownloadFinder> weak_ptr_factory_;
142 153
143 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder); 154 DISALLOW_COPY_AND_ASSIGN(LastDownloadFinder);
144 }; 155 };
145 156
146 } // namespace safe_browsing 157 } // namespace safe_browsing
147 158
148 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_ H_ 159 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_LAST_DOWNLOAD_FINDER_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698