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

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

Issue 2719533002: predictors: Add RedirectStatus histogram + fix redirects related bug. (Closed)
Patch Set: Nit. Created 3 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/predictors/resource_prefetch_predictor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 constexpr char kResourcePrefetchPredictorPrefetchMissesCountNotCached[] = 52 constexpr char kResourcePrefetchPredictorPrefetchMissesCountNotCached[] =
53 "ResourcePrefetchPredictor.PrefetchMissesCount.NotCached"; 53 "ResourcePrefetchPredictor.PrefetchMissesCount.NotCached";
54 constexpr char kResourcePrefetchPredictorPrefetchHitsCountCached[] = 54 constexpr char kResourcePrefetchPredictorPrefetchHitsCountCached[] =
55 "ResourcePrefetchPredictor.PrefetchHitsCount.Cached"; 55 "ResourcePrefetchPredictor.PrefetchHitsCount.Cached";
56 constexpr char kResourcePrefetchPredictorPrefetchHitsCountNotCached[] = 56 constexpr char kResourcePrefetchPredictorPrefetchHitsCountNotCached[] =
57 "ResourcePrefetchPredictor.PrefetchHitsCount.NotCached"; 57 "ResourcePrefetchPredictor.PrefetchHitsCount.NotCached";
58 constexpr char kResourcePrefetchPredictorPrefetchHitsSize[] = 58 constexpr char kResourcePrefetchPredictorPrefetchHitsSize[] =
59 "ResourcePrefetchPredictor.PrefetchHitsSizeKB"; 59 "ResourcePrefetchPredictor.PrefetchHitsSizeKB";
60 constexpr char kResourcePrefetchPredictorPrefetchMissesSize[] = 60 constexpr char kResourcePrefetchPredictorPrefetchMissesSize[] =
61 "ResourcePrefetchPredictor.PrefetchMissesSizeKB"; 61 "ResourcePrefetchPredictor.PrefetchMissesSizeKB";
62 constexpr char kResourcePrefetchPredictorRedirectStatusHistogram[] =
63 "ResourcePrefetchPredictor.RedirectStatus";
62 } // namespace internal 64 } // namespace internal
63 65
64 class TestObserver; 66 class TestObserver;
65 class ResourcePrefetcherManager; 67 class ResourcePrefetcherManager;
66 68
67 // Contains logic for learning what can be prefetched and for kicking off 69 // Contains logic for learning what can be prefetched and for kicking off
68 // speculative prefetching. 70 // speculative prefetching.
69 // - The class is a profile keyed service owned by the profile. 71 // - The class is a profile keyed service owned by the profile.
70 // - All the non-static methods of this class need to be called on the UI 72 // - All the non-static methods of this class need to be called on the UI
71 // thread. 73 // thread.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 ~PageRequestSummary(); 135 ~PageRequestSummary();
134 136
135 GURL main_frame_url; 137 GURL main_frame_url;
136 GURL initial_url; 138 GURL initial_url;
137 139
138 // Stores all subresource requests within a single navigation, from initial 140 // Stores all subresource requests within a single navigation, from initial
139 // main frame request to navigation completion. 141 // main frame request to navigation completion.
140 std::vector<URLRequestSummary> subresource_requests; 142 std::vector<URLRequestSummary> subresource_requests;
141 }; 143 };
142 144
145 // Stores a result of prediction. Essentially, |subresource_urls| is main
146 // result and other fields are used for diagnosis and histograms reporting.
147 struct Prediction {
148 Prediction();
149 Prediction(const Prediction& other);
150 ~Prediction();
151
152 bool is_host;
153 bool is_redirected;
154 std::string main_frame_key;
155 std::vector<GURL> subresource_urls;
156 };
157
158 // Used for reporting redirect prediction success/failure in histograms.
159 // NOTE: This enumeration is used in histograms, so please do not add entries
160 // in the middle.
161 enum class RedirectStatus {
162 NO_REDIRECT,
163 NO_REDIRECT_BUT_PREDICTED,
164 REDIRECT_NOT_PREDICTED,
165 REDIRECT_WRONG_PREDICTED,
166 REDIRECT_CORRECTLY_PREDICTED,
167 MAX
168 };
169
143 ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config, 170 ResourcePrefetchPredictor(const ResourcePrefetchPredictorConfig& config,
144 Profile* profile); 171 Profile* profile);
145 ~ResourcePrefetchPredictor() override; 172 ~ResourcePrefetchPredictor() override;
146 173
147 // Starts initialization by posting a task to the DB thread to read the 174 // Starts initialization by posting a task to the DB thread to read the
148 // predictor database. 175 // predictor database.
149 void StartInitialization(); 176 void StartInitialization();
150 177
151 // Thread safe. 178 // Thread safe.
152 static bool ShouldRecordRequest(net::URLRequest* request, 179 static bool ShouldRecordRequest(net::URLRequest* request,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 void OnMainFrameResponse(const URLRequestSummary& response); 298 void OnMainFrameResponse(const URLRequestSummary& response);
272 void OnMainFrameRedirect(const URLRequestSummary& response); 299 void OnMainFrameRedirect(const URLRequestSummary& response);
273 void OnSubresourceResponse(const URLRequestSummary& response); 300 void OnSubresourceResponse(const URLRequestSummary& response);
274 301
275 // Called when onload completes for a navigation. We treat this point as the 302 // Called when onload completes for a navigation. We treat this point as the
276 // "completion" of the navigation. The resources requested by the page up to 303 // "completion" of the navigation. The resources requested by the page up to
277 // this point are the only ones considered for prefetching. 304 // this point are the only ones considered for prefetching.
278 void OnNavigationComplete(const NavigationID& nav_id_without_timing_info); 305 void OnNavigationComplete(const NavigationID& nav_id_without_timing_info);
279 306
280 // Returns true iff there is PrefetchData that can be used for a 307 // Returns true iff there is PrefetchData that can be used for a
281 // |main_frame_url| and fills |urls| with resources that need to be 308 // |main_frame_url| and fills |prediction| with resources that need to be
282 // prefetched. |urls| pointer may be equal nullptr to get return value only. 309 // prefetched. |prediction| pointer may be equal nullptr to get return value
310 // only.
283 bool GetPrefetchData(const GURL& main_frame_url, 311 bool GetPrefetchData(const GURL& main_frame_url,
284 std::vector<GURL>* urls) const; 312 Prediction* prediction) const;
285 313
286 // Returns true iff the |data_map| contains PrefetchData that can be used 314 // Returns true iff the |data_map| contains PrefetchData that can be used
287 // for a |main_frame_key| and fills |urls| with resources that need to be 315 // for a |main_frame_key| and fills |urls| with resources that need to be
288 // prefetched. |urls| pointer may be equal nullptr to get return value only. 316 // prefetched. |urls| pointer may be equal nullptr to get return value only.
289 bool PopulatePrefetcherRequest(const std::string& main_frame_key, 317 bool PopulatePrefetcherRequest(const std::string& main_frame_key,
290 const PrefetchDataMap& data_map, 318 const PrefetchDataMap& data_map,
291 std::vector<GURL>* urls) const; 319 std::vector<GURL>* urls) const;
292 320
293 // Callback for task to read predictor database. Takes ownership of 321 // Callback for task to read predictor database. Takes ownership of
294 // all arguments. 322 // all arguments.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 444
417 private: 445 private:
418 ResourcePrefetchPredictor* predictor_; 446 ResourcePrefetchPredictor* predictor_;
419 447
420 DISALLOW_COPY_AND_ASSIGN(TestObserver); 448 DISALLOW_COPY_AND_ASSIGN(TestObserver);
421 }; 449 };
422 450
423 } // namespace predictors 451 } // namespace predictors
424 452
425 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ 453 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/predictors/resource_prefetch_predictor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698