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

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

Issue 2688633002: predictors: Add prefetching hit/miss histograms. (Closed)
Patch Set: Now with a test. 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 25 matching lines...) Expand all
36 class URLRequest; 36 class URLRequest;
37 } 37 }
38 38
39 namespace predictors { 39 namespace predictors {
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 kResourcePrefetchPredictorPrefetchMissesCountCached[] =
47 "ResourcePrefetchPredictor.PrefetchMissesCount.Cached";
48 constexpr char kResourcePrefetchPredictorPrefetchMissesCountNotCached[] =
49 "ResourcePrefetchPredictor.PrefetchMissesCount.NotCached";
50 constexpr char kResourcePrefetchPredictorPrefetchHitsCountCached[] =
51 "ResourcePrefetchPredictor.PrefetchHitsCount.Cached";
52 constexpr char kResourcePrefetchPredictorPrefetchHitsCountNotCached[] =
53 "ResourcePrefetchPredictor.PrefetchHitsCount.NotCached";
54 constexpr char kResourcePrefetchPredictorPrefetchHitsSize[] =
55 "ResourcePrefetchPredictor.PrefetchHitsSizeKB";
56 constexpr char kResourcePrefetchPredictorPrefetchMissesSize[] =
57 "ResourcePrefetchPredictor.PrefetchMissesSizeKB";
58
46 } // namespace internal 59 } // namespace internal
47 60
48 class TestObserver; 61 class TestObserver;
49 class ResourcePrefetcherManager; 62 class ResourcePrefetcherManager;
50 63
51 // Contains logic for learning what can be prefetched and for kicking off 64 // Contains logic for learning what can be prefetched and for kicking off
52 // speculative prefetching. 65 // speculative prefetching.
53 // - The class is a profile keyed service owned by the profile. 66 // - The class is a profile keyed service owned by the profile.
54 // - All the non-static methods of this class need to be called on the UI 67 // - All the non-static methods of this class need to be called on the UI
55 // thread. 68 // thread.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Starts prefetching if it is enabled for |origin| and prefetching data 176 // Starts prefetching if it is enabled for |origin| and prefetching data
164 // exists for the |main_frame_url| either at the URL or at the host level. 177 // exists for the |main_frame_url| either at the URL or at the host level.
165 void StartPrefetching(const GURL& main_frame_url, PrefetchOrigin origin); 178 void StartPrefetching(const GURL& main_frame_url, PrefetchOrigin origin);
166 179
167 // Stops prefetching that may be in progress corresponding to 180 // Stops prefetching that may be in progress corresponding to
168 // |main_frame_url|. 181 // |main_frame_url|.
169 void StopPrefetching(const GURL& main_frame_url); 182 void StopPrefetching(const GURL& main_frame_url);
170 183
171 // Called when ResourcePrefetcher is finished, i.e. there is nothing pending 184 // Called when ResourcePrefetcher is finished, i.e. there is nothing pending
172 // in flight. 185 // in flight.
173 void OnPrefetchingFinished(const GURL& main_frame_url); 186 void OnPrefetchingFinished(const GURL& main_frame_url,
187 const ResourcePrefetcher::PrefetcherStats& stats);
174 188
175 // Returns true if prefetching data exists for the |main_frame_url|. 189 // Returns true if prefetching data exists for the |main_frame_url|.
176 virtual bool IsUrlPrefetchable(const GURL& main_frame_url); 190 virtual bool IsUrlPrefetchable(const GURL& main_frame_url);
177 191
178 // Sets the |observer| to be notified when the resource prefetch predictor 192 // Sets the |observer| to be notified when the resource prefetch predictor
179 // data changes. Previously registered observer will be discarded. Call 193 // data changes. Previously registered observer will be discarded. Call
180 // this with nullptr parameter to de-register observer. 194 // this with nullptr parameter to de-register observer.
181 void SetObserverForTesting(TestObserver* observer); 195 void SetObserverForTesting(TestObserver* observer);
182 196
183 private: 197 private:
(...skipping 25 matching lines...) Expand all
209 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetRedirectEndpoint); 223 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetRedirectEndpoint);
210 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetPrefetchData); 224 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetPrefetchData);
211 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, 225 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest,
212 TestPrecisionRecallHistograms); 226 TestPrecisionRecallHistograms);
213 227
214 enum InitializationState { 228 enum InitializationState {
215 NOT_INITIALIZED = 0, 229 NOT_INITIALIZED = 0,
216 INITIALIZING = 1, 230 INITIALIZING = 1,
217 INITIALIZED = 2 231 INITIALIZED = 2
218 }; 232 };
219
220 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; 233 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap;
221 typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap; 234 typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap;
222 235
223 typedef std::map<NavigationID, std::unique_ptr<PageRequestSummary>> 236 typedef std::map<NavigationID, std::unique_ptr<PageRequestSummary>>
224 NavigationMap; 237 NavigationMap;
225 238
226 // Returns true if the main page request is supported for prediction. 239 // Returns true if the main page request is supported for prediction.
227 static bool IsHandledMainPage(net::URLRequest* request); 240 static bool IsHandledMainPage(net::URLRequest* request);
228 241
229 // Returns true if the subresource request is supported for prediction. 242 // Returns true if the subresource request is supported for prediction.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 base::CancelableTaskTracker history_lookup_consumer_; 372 base::CancelableTaskTracker history_lookup_consumer_;
360 373
361 // Copy of the data in the predictor tables. 374 // Copy of the data in the predictor tables.
362 std::unique_ptr<PrefetchDataMap> url_table_cache_; 375 std::unique_ptr<PrefetchDataMap> url_table_cache_;
363 std::unique_ptr<PrefetchDataMap> host_table_cache_; 376 std::unique_ptr<PrefetchDataMap> host_table_cache_;
364 std::unique_ptr<RedirectDataMap> url_redirect_table_cache_; 377 std::unique_ptr<RedirectDataMap> url_redirect_table_cache_;
365 std::unique_ptr<RedirectDataMap> host_redirect_table_cache_; 378 std::unique_ptr<RedirectDataMap> host_redirect_table_cache_;
366 379
367 NavigationMap inflight_navigations_; 380 NavigationMap inflight_navigations_;
368 381
382 std::map<GURL, ResourcePrefetcher::PrefetcherStats> prefetcher_stats_;
383
369 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> 384 ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
370 history_service_observer_; 385 history_service_observer_;
371 386
372 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); 387 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor);
373 }; 388 };
374 389
375 // An interface used to notify that data in the ResourcePrefetchPredictor 390 // An interface used to notify that data in the ResourcePrefetchPredictor
376 // has changed. All methods are invoked on the UI thread. 391 // has changed. All methods are invoked on the UI thread.
377 class TestObserver { 392 class TestObserver {
378 public: 393 public:
379 // De-registers itself from |predictor_| on destruction. 394 // De-registers itself from |predictor_| on destruction.
380 virtual ~TestObserver(); 395 virtual ~TestObserver();
381 396
382 virtual void OnNavigationLearned( 397 virtual void OnNavigationLearned(
383 size_t url_visit_count, 398 size_t url_visit_count,
384 const ResourcePrefetchPredictor::PageRequestSummary& summary) {} 399 const ResourcePrefetchPredictor::PageRequestSummary& summary) {}
385 400
386 virtual void OnPrefetchingFinished(const GURL& main_frame_url) {} 401 virtual void OnPrefetchingFinished(
402 const GURL& main_frame_url,
403 const ResourcePrefetcher::PrefetcherStats& stats) {}
387 404
388 virtual void OnPredictorInitialized() {} 405 virtual void OnPredictorInitialized() {}
389 406
390 protected: 407 protected:
391 // |predictor| must be non-NULL and has to outlive the TestObserver. 408 // |predictor| must be non-NULL and has to outlive the TestObserver.
392 // Also the predictor must not have a TestObserver set. 409 // Also the predictor must not have a TestObserver set.
393 explicit TestObserver(ResourcePrefetchPredictor* predictor); 410 explicit TestObserver(ResourcePrefetchPredictor* predictor);
394 411
395 private: 412 private:
396 ResourcePrefetchPredictor* predictor_; 413 ResourcePrefetchPredictor* predictor_;
397 414
398 DISALLOW_COPY_AND_ASSIGN(TestObserver); 415 DISALLOW_COPY_AND_ASSIGN(TestObserver);
399 }; 416 };
400 417
401 } // namespace predictors 418 } // namespace predictors
402 419
403 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ 420 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698