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 #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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 29 matching lines...) Expand all Loading... | |
40 | 40 |
41 namespace internal { | 41 namespace internal { |
42 constexpr char kResourcePrefetchPredictorPrecisionHistogram[] = | 42 constexpr char kResourcePrefetchPredictorPrecisionHistogram[] = |
43 "ResourcePrefetchPredictor.LearningPrecision"; | 43 "ResourcePrefetchPredictor.LearningPrecision"; |
44 constexpr char kResourcePrefetchPredictorRecallHistogram[] = | 44 constexpr char kResourcePrefetchPredictorRecallHistogram[] = |
45 "ResourcePrefetchPredictor.LearningRecall"; | 45 "ResourcePrefetchPredictor.LearningRecall"; |
46 constexpr char kResourcePrefetchPredictorCountHistogram[] = | 46 constexpr char kResourcePrefetchPredictorCountHistogram[] = |
47 "ResourcePrefetchPredictor.LearningCount"; | 47 "ResourcePrefetchPredictor.LearningCount"; |
48 constexpr char kResourcePrefetchPredictorPrefetchingDurationHistogram[] = | 48 constexpr char kResourcePrefetchPredictorPrefetchingDurationHistogram[] = |
49 "ResourcePrefetchPredictor.PrefetchingDuration"; | 49 "ResourcePrefetchPredictor.PrefetchingDuration"; |
50 constexpr char kResourcePrefetchPredictorPrefetchMissesCountCached[] = | |
51 "ResourcePrefetchPredictor.PrefetchMissesCount.Cached"; | |
52 constexpr char kResourcePrefetchPredictorPrefetchMissesCountNotCached[] = | |
53 "ResourcePrefetchPredictor.PrefetchMissesCount.NotCached"; | |
54 constexpr char kResourcePrefetchPredictorPrefetchHitsCountCached[] = | |
55 "ResourcePrefetchPredictor.PrefetchHitsCount.Cached"; | |
56 constexpr char kResourcePrefetchPredictorPrefetchHitsCountNotCached[] = | |
57 "ResourcePrefetchPredictor.PrefetchHitsCount.NotCached"; | |
58 constexpr char kResourcePrefetchPredictorPrefetchHitsSize[] = | |
59 "ResourcePrefetchPredictor.PrefetchHitsSizeKB"; | |
60 constexpr char kResourcePrefetchPredictorPrefetchMissesSize[] = | |
61 "ResourcePrefetchPredictor.PrefetchMissesSizeKB"; | |
50 } // namespace internal | 62 } // namespace internal |
51 | 63 |
52 class TestObserver; | 64 class TestObserver; |
53 class ResourcePrefetcherManager; | 65 class ResourcePrefetcherManager; |
54 | 66 |
55 // Contains logic for learning what can be prefetched and for kicking off | 67 // Contains logic for learning what can be prefetched and for kicking off |
56 // speculative prefetching. | 68 // speculative prefetching. |
57 // - The class is a profile keyed service owned by the profile. | 69 // - The class is a profile keyed service owned by the profile. |
58 // - All the non-static methods of this class need to be called on the UI | 70 // - All the non-static methods of this class need to be called on the UI |
59 // thread. | 71 // thread. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 // Starts prefetching if it is enabled for |origin| and prefetching data | 179 // Starts prefetching if it is enabled for |origin| and prefetching data |
168 // exists for the |main_frame_url| either at the URL or at the host level. | 180 // exists for the |main_frame_url| either at the URL or at the host level. |
169 void StartPrefetching(const GURL& main_frame_url, PrefetchOrigin origin); | 181 void StartPrefetching(const GURL& main_frame_url, PrefetchOrigin origin); |
170 | 182 |
171 // Stops prefetching that may be in progress corresponding to | 183 // Stops prefetching that may be in progress corresponding to |
172 // |main_frame_url|. | 184 // |main_frame_url|. |
173 void StopPrefetching(const GURL& main_frame_url); | 185 void StopPrefetching(const GURL& main_frame_url); |
174 | 186 |
175 // Called when ResourcePrefetcher is finished, i.e. there is nothing pending | 187 // Called when ResourcePrefetcher is finished, i.e. there is nothing pending |
176 // in flight. | 188 // in flight. |
177 void OnPrefetchingFinished(const GURL& main_frame_url); | 189 void OnPrefetchingFinished( |
190 const GURL& main_frame_url, | |
191 std::unique_ptr<ResourcePrefetcher::PrefetcherStats> stats); | |
178 | 192 |
179 // Returns true if prefetching data exists for the |main_frame_url|. | 193 // Returns true if prefetching data exists for the |main_frame_url|. |
180 virtual bool IsUrlPrefetchable(const GURL& main_frame_url); | 194 virtual bool IsUrlPrefetchable(const GURL& main_frame_url); |
181 | 195 |
182 // Sets the |observer| to be notified when the resource prefetch predictor | 196 // Sets the |observer| to be notified when the resource prefetch predictor |
183 // data changes. Previously registered observer will be discarded. Call | 197 // data changes. Previously registered observer will be discarded. Call |
184 // this with nullptr parameter to de-register observer. | 198 // this with nullptr parameter to de-register observer. |
185 void SetObserverForTesting(TestObserver* observer); | 199 void SetObserverForTesting(TestObserver* observer); |
186 | 200 |
187 private: | 201 private: |
(...skipping 27 matching lines...) Expand all Loading... | |
215 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, | 229 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
216 TestPrecisionRecallHistograms); | 230 TestPrecisionRecallHistograms); |
217 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, | 231 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
218 TestPrefetchingDurationHistogram); | 232 TestPrefetchingDurationHistogram); |
219 | 233 |
220 enum InitializationState { | 234 enum InitializationState { |
221 NOT_INITIALIZED = 0, | 235 NOT_INITIALIZED = 0, |
222 INITIALIZING = 1, | 236 INITIALIZING = 1, |
223 INITIALIZED = 2 | 237 INITIALIZED = 2 |
224 }; | 238 }; |
225 | |
226 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; | 239 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; |
227 typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap; | 240 typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap; |
228 | 241 |
229 typedef std::map<NavigationID, std::unique_ptr<PageRequestSummary>> | 242 typedef std::map<NavigationID, std::unique_ptr<PageRequestSummary>> |
230 NavigationMap; | 243 NavigationMap; |
231 | 244 |
232 // Returns true if the main page request is supported for prediction. | 245 // Returns true if the main page request is supported for prediction. |
233 static bool IsHandledMainPage(net::URLRequest* request); | 246 static bool IsHandledMainPage(net::URLRequest* request); |
234 | 247 |
235 // Returns true if the subresource request is supported for prediction. | 248 // Returns true if the subresource request is supported for prediction. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, | 295 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, |
283 std::unique_ptr<PrefetchDataMap> host_data_map, | 296 std::unique_ptr<PrefetchDataMap> host_data_map, |
284 std::unique_ptr<RedirectDataMap> url_redirect_data_map, | 297 std::unique_ptr<RedirectDataMap> url_redirect_data_map, |
285 std::unique_ptr<RedirectDataMap> host_redirect_data_map); | 298 std::unique_ptr<RedirectDataMap> host_redirect_data_map); |
286 | 299 |
287 // Called during initialization when history is read and the predictor | 300 // Called during initialization when history is read and the predictor |
288 // database has been read. | 301 // database has been read. |
289 void OnHistoryAndCacheLoaded(); | 302 void OnHistoryAndCacheLoaded(); |
290 | 303 |
291 // Removes data for navigations where the onload never fired. Will cleanup | 304 // Removes data for navigations where the onload never fired. Will cleanup |
292 // inflight_navigations_ and inflight_prefetches_. | 305 // inflight_navigations_ and inflight_prefetches_. |
alexilin
2017/02/13 17:07:05
nit:
Need to clarify this comment. Add prefetcher_
Benoit L
2017/02/13 17:32:51
Done.
| |
293 void CleanupAbandonedNavigations(const NavigationID& navigation_id); | 306 void CleanupAbandonedNavigations(const NavigationID& navigation_id); |
294 | 307 |
295 // Deletes all URLs from the predictor database, the caches and removes all | 308 // Deletes all URLs from the predictor database, the caches and removes all |
296 // inflight navigations. | 309 // inflight navigations. |
297 void DeleteAllUrls(); | 310 void DeleteAllUrls(); |
298 | 311 |
299 // Deletes data for the input |urls| and their corresponding hosts from the | 312 // Deletes data for the input |urls| and their corresponding hosts from the |
300 // predictor database and caches. | 313 // predictor database and caches. |
301 void DeleteUrls(const history::URLRows& urls); | 314 void DeleteUrls(const history::URLRows& urls); |
302 | 315 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 | 379 |
367 // Copy of the data in the predictor tables. | 380 // Copy of the data in the predictor tables. |
368 std::unique_ptr<PrefetchDataMap> url_table_cache_; | 381 std::unique_ptr<PrefetchDataMap> url_table_cache_; |
369 std::unique_ptr<PrefetchDataMap> host_table_cache_; | 382 std::unique_ptr<PrefetchDataMap> host_table_cache_; |
370 std::unique_ptr<RedirectDataMap> url_redirect_table_cache_; | 383 std::unique_ptr<RedirectDataMap> url_redirect_table_cache_; |
371 std::unique_ptr<RedirectDataMap> host_redirect_table_cache_; | 384 std::unique_ptr<RedirectDataMap> host_redirect_table_cache_; |
372 | 385 |
373 std::map<GURL, base::TimeTicks> inflight_prefetches_; | 386 std::map<GURL, base::TimeTicks> inflight_prefetches_; |
374 NavigationMap inflight_navigations_; | 387 NavigationMap inflight_navigations_; |
375 | 388 |
389 std::map<GURL, std::unique_ptr<ResourcePrefetcher::PrefetcherStats>> | |
390 prefetcher_stats_; | |
391 | |
376 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 392 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
377 history_service_observer_; | 393 history_service_observer_; |
378 | 394 |
379 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); | 395 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); |
380 }; | 396 }; |
381 | 397 |
382 // An interface used to notify that data in the ResourcePrefetchPredictor | 398 // An interface used to notify that data in the ResourcePrefetchPredictor |
383 // has changed. All methods are invoked on the UI thread. | 399 // has changed. All methods are invoked on the UI thread. |
384 class TestObserver { | 400 class TestObserver { |
385 public: | 401 public: |
(...skipping 15 matching lines...) Expand all Loading... | |
401 | 417 |
402 private: | 418 private: |
403 ResourcePrefetchPredictor* predictor_; | 419 ResourcePrefetchPredictor* predictor_; |
404 | 420 |
405 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 421 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
406 }; | 422 }; |
407 | 423 |
408 } // namespace predictors | 424 } // namespace predictors |
409 | 425 |
410 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ | 426 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
OLD | NEW |