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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor.h

Issue 773103004: Remove NOTIFICATION_HISTORY_URLS_DELETED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to tip Created 5 years, 10 months 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_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ 5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ 6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.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 "base/scoped_observer.h"
17 #include "base/task/cancelable_task_tracker.h" 17 #include "base/task/cancelable_task_tracker.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "chrome/browser/predictors/resource_prefetch_common.h" 19 #include "chrome/browser/predictors/resource_prefetch_common.h"
20 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" 20 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
21 #include "chrome/browser/predictors/resource_prefetcher.h" 21 #include "chrome/browser/predictors/resource_prefetcher.h"
22 #include "components/history/core/browser/history_service_observer.h" 22 #include "components/history/core/browser/history_service_observer.h"
23 #include "components/history/core/browser/history_types.h" 23 #include "components/history/core/browser/history_types.h"
24 #include "components/keyed_service/core/keyed_service.h" 24 #include "components/keyed_service/core/keyed_service.h"
25 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_registrar.h"
27 #include "content/public/common/resource_type.h" 25 #include "content/public/common/resource_type.h"
28 #include "url/gurl.h" 26 #include "url/gurl.h"
29 27
30 class PredictorsHandler; 28 class PredictorsHandler;
31 class Profile; 29 class Profile;
32 30
33 namespace content {
34 class WebContents;
35 }
36
37 namespace net { 31 namespace net {
38 class URLRequest; 32 class URLRequest;
39 } 33 }
40 34
41 namespace predictors { 35 namespace predictors {
42 36
43 class ResourcePrefetcherManager; 37 class ResourcePrefetcherManager;
44 38
45 // Contains logic for learning what can be prefetched and for kicking off 39 // Contains logic for learning what can be prefetched and for kicking off
46 // speculative prefetching. 40 // speculative prefetching.
(...skipping 22 matching lines...) Expand all
69 // * ResourcePrefetcher - Lives entirely on the IO thread, owned by the 63 // * ResourcePrefetcher - Lives entirely on the IO thread, owned by the
70 // ResourcePrefetcherManager, and issues net::URLRequest to fetch resources. 64 // ResourcePrefetcherManager, and issues net::URLRequest to fetch resources.
71 // 65 //
72 // TODO(shishir): Do speculative prefetching for https resources and/or https 66 // TODO(shishir): Do speculative prefetching for https resources and/or https
73 // main frame urls. 67 // main frame urls.
74 // TODO(zhenw): Currently only main frame requests/redirects/responses are 68 // TODO(zhenw): Currently only main frame requests/redirects/responses are
75 // recorded. Consider recording sub-frame responses independently or together 69 // recorded. Consider recording sub-frame responses independently or together
76 // with main frame. 70 // with main frame.
77 class ResourcePrefetchPredictor 71 class ResourcePrefetchPredictor
78 : public KeyedService, 72 : public KeyedService,
79 public content::NotificationObserver,
80 public history::HistoryServiceObserver, 73 public history::HistoryServiceObserver,
81 public base::SupportsWeakPtr<ResourcePrefetchPredictor> { 74 public base::SupportsWeakPtr<ResourcePrefetchPredictor> {
82 public: 75 public:
83 // Stores the data that we need to get from the URLRequest. 76 // Stores the data that we need to get from the URLRequest.
84 struct URLRequestSummary { 77 struct URLRequestSummary {
85 URLRequestSummary(); 78 URLRequestSummary();
86 URLRequestSummary(const URLRequestSummary& other); 79 URLRequestSummary(const URLRequestSummary& other);
87 ~URLRequestSummary(); 80 ~URLRequestSummary();
88 81
89 NavigationID navigation_id; 82 NavigationID navigation_id;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 172
180 // Returns true if the main page request is supported for prediction. 173 // Returns true if the main page request is supported for prediction.
181 static bool IsHandledMainPage(net::URLRequest* request); 174 static bool IsHandledMainPage(net::URLRequest* request);
182 175
183 // Returns true if the subresource request is supported for prediction. 176 // Returns true if the subresource request is supported for prediction.
184 static bool IsHandledSubresource(net::URLRequest* request); 177 static bool IsHandledSubresource(net::URLRequest* request);
185 178
186 // Returns true if the request (should have a response in it) is cacheable. 179 // Returns true if the request (should have a response in it) is cacheable.
187 static bool IsCacheable(const net::URLRequest* request); 180 static bool IsCacheable(const net::URLRequest* request);
188 181
189 // content::NotificationObserver methods override.
190 void Observe(int type,
191 const content::NotificationSource& source,
192 const content::NotificationDetails& details) override;
193
194 // KeyedService methods override. 182 // KeyedService methods override.
195 void Shutdown() override; 183 void Shutdown() override;
196 184
197 // Functions called on different network events pertaining to the loading of 185 // Functions called on different network events pertaining to the loading of
198 // main frame resource or sub resources. 186 // main frame resource or sub resources.
199 void OnMainFrameRequest(const URLRequestSummary& request); 187 void OnMainFrameRequest(const URLRequestSummary& request);
200 void OnMainFrameResponse(const URLRequestSummary& response); 188 void OnMainFrameResponse(const URLRequestSummary& response);
201 void OnMainFrameRedirect(const URLRequestSummary& response); 189 void OnMainFrameRedirect(const URLRequestSummary& response);
202 void OnSubresourceResponse(const URLRequestSummary& response); 190 void OnSubresourceResponse(const URLRequestSummary& response);
203 191
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 const std::vector<URLRequestSummary>& actual, 278 const std::vector<URLRequestSummary>& actual,
291 const ResourcePrefetcher::RequestVector& predicted) const; 279 const ResourcePrefetcher::RequestVector& predicted) const;
292 void ReportPredictedAccuracyStatsHelper( 280 void ReportPredictedAccuracyStatsHelper(
293 PrefetchKeyType key_type, 281 PrefetchKeyType key_type,
294 const ResourcePrefetcher::RequestVector& predicted, 282 const ResourcePrefetcher::RequestVector& predicted,
295 const std::map<GURL, bool>& actual, 283 const std::map<GURL, bool>& actual,
296 size_t total_resources_fetched_from_network, 284 size_t total_resources_fetched_from_network,
297 size_t max_assumed_prefetched) const; 285 size_t max_assumed_prefetched) const;
298 286
299 // history::HistoryServiceObserver: 287 // history::HistoryServiceObserver:
288 void OnURLsDeleted(HistoryService* history_service,
289 bool all_history,
290 bool expired,
291 const history::URLRows& deleted_rows,
292 const std::set<GURL>& favicon_urls) override;
300 void OnHistoryServiceLoaded(HistoryService* history_service) override; 293 void OnHistoryServiceLoaded(HistoryService* history_service) override;
301 294
302 // Used to connect to HistoryService or register for service loaded 295 // Used to connect to HistoryService or register for service loaded
303 // notificatioan. 296 // notificatioan.
304 void ConnectToHistoryService(); 297 void ConnectToHistoryService();
305 298
306 // Used for testing to inject mock tables. 299 // Used for testing to inject mock tables.
307 void set_mock_tables(scoped_refptr<ResourcePrefetchPredictorTables> tables) { 300 void set_mock_tables(scoped_refptr<ResourcePrefetchPredictorTables> tables) {
308 tables_ = tables; 301 tables_ = tables;
309 } 302 }
310 303
311 Profile* const profile_; 304 Profile* const profile_;
312 ResourcePrefetchPredictorConfig const config_; 305 ResourcePrefetchPredictorConfig const config_;
313 InitializationState initialization_state_; 306 InitializationState initialization_state_;
314 scoped_refptr<ResourcePrefetchPredictorTables> tables_; 307 scoped_refptr<ResourcePrefetchPredictorTables> tables_;
315 scoped_refptr<ResourcePrefetcherManager> prefetch_manager_; 308 scoped_refptr<ResourcePrefetcherManager> prefetch_manager_;
316 content::NotificationRegistrar notification_registrar_;
317 base::CancelableTaskTracker history_lookup_consumer_; 309 base::CancelableTaskTracker history_lookup_consumer_;
318 310
319 // Map of all the navigations in flight to their resource requests. 311 // Map of all the navigations in flight to their resource requests.
320 NavigationMap inflight_navigations_; 312 NavigationMap inflight_navigations_;
321 313
322 // Copy of the data in the predictor tables. 314 // Copy of the data in the predictor tables.
323 scoped_ptr<PrefetchDataMap> url_table_cache_; 315 scoped_ptr<PrefetchDataMap> url_table_cache_;
324 scoped_ptr<PrefetchDataMap> host_table_cache_; 316 scoped_ptr<PrefetchDataMap> host_table_cache_;
325 317
326 ResultsMap results_map_; 318 ResultsMap results_map_;
327 STLValueDeleter<ResultsMap> results_map_deleter_; 319 STLValueDeleter<ResultsMap> results_map_deleter_;
328 320
329 ScopedObserver<HistoryService, history::HistoryServiceObserver> 321 ScopedObserver<HistoryService, history::HistoryServiceObserver>
330 history_service_observer_; 322 history_service_observer_;
331 323
332 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); 324 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor);
333 }; 325 };
334 326
335 } // namespace predictors 327 } // namespace predictors
336 328
337 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ 329 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/predictors/autocomplete_action_predictor.cc ('k') | chrome/browser/predictors/resource_prefetch_predictor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698