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

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

Issue 2688633002: predictors: Add prefetching hit/miss histograms. (Closed)
Patch Set: Add units. Created 3 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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 29 matching lines...) Expand all
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
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
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // all arguments. 294 // all arguments.
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 // Cleanup inflight_navigations_, inflight_prefetches_, and prefetcher_stats_.
292 // inflight_navigations_ and inflight_prefetches_.
293 void CleanupAbandonedNavigations(const NavigationID& navigation_id); 305 void CleanupAbandonedNavigations(const NavigationID& navigation_id);
294 306
295 // Deletes all URLs from the predictor database, the caches and removes all 307 // Deletes all URLs from the predictor database, the caches and removes all
296 // inflight navigations. 308 // inflight navigations.
297 void DeleteAllUrls(); 309 void DeleteAllUrls();
298 310
299 // Deletes data for the input |urls| and their corresponding hosts from the 311 // Deletes data for the input |urls| and their corresponding hosts from the
300 // predictor database and caches. 312 // predictor database and caches.
301 void DeleteUrls(const history::URLRows& urls); 313 void DeleteUrls(const history::URLRows& urls);
302 314
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 378
367 // Copy of the data in the predictor tables. 379 // Copy of the data in the predictor tables.
368 std::unique_ptr<PrefetchDataMap> url_table_cache_; 380 std::unique_ptr<PrefetchDataMap> url_table_cache_;
369 std::unique_ptr<PrefetchDataMap> host_table_cache_; 381 std::unique_ptr<PrefetchDataMap> host_table_cache_;
370 std::unique_ptr<RedirectDataMap> url_redirect_table_cache_; 382 std::unique_ptr<RedirectDataMap> url_redirect_table_cache_;
371 std::unique_ptr<RedirectDataMap> host_redirect_table_cache_; 383 std::unique_ptr<RedirectDataMap> host_redirect_table_cache_;
372 384
373 std::map<GURL, base::TimeTicks> inflight_prefetches_; 385 std::map<GURL, base::TimeTicks> inflight_prefetches_;
374 NavigationMap inflight_navigations_; 386 NavigationMap inflight_navigations_;
375 387
388 std::map<GURL, std::unique_ptr<ResourcePrefetcher::PrefetcherStats>>
389 prefetcher_stats_;
390
376 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> 391 ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
377 history_service_observer_; 392 history_service_observer_;
378 393
379 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); 394 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor);
380 }; 395 };
381 396
382 // An interface used to notify that data in the ResourcePrefetchPredictor 397 // An interface used to notify that data in the ResourcePrefetchPredictor
383 // has changed. All methods are invoked on the UI thread. 398 // has changed. All methods are invoked on the UI thread.
384 class TestObserver { 399 class TestObserver {
385 public: 400 public:
(...skipping 15 matching lines...) Expand all
401 416
402 private: 417 private:
403 ResourcePrefetchPredictor* predictor_; 418 ResourcePrefetchPredictor* predictor_;
404 419
405 DISALLOW_COPY_AND_ASSIGN(TestObserver); 420 DISALLOW_COPY_AND_ASSIGN(TestObserver);
406 }; 421 };
407 422
408 } // namespace predictors 423 } // namespace predictors
409 424
410 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ 425 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698