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

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

Issue 2937623007: predictors: Move more methods from ResourcePrefetchPredictor into LoadingDataCollector. (Closed)
Patch Set: Make InitializationState type public. Created 3 years, 6 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 Prediction(); 172 Prediction();
173 Prediction(const Prediction& other); 173 Prediction(const Prediction& other);
174 ~Prediction(); 174 ~Prediction();
175 175
176 bool is_host; 176 bool is_host;
177 bool is_redirected; 177 bool is_redirected;
178 std::string main_frame_key; 178 std::string main_frame_key;
179 std::vector<GURL> subresource_urls; 179 std::vector<GURL> subresource_urls;
180 }; 180 };
181 181
182 enum InitializationState {
183 NOT_INITIALIZED = 0,
184 INITIALIZING = 1,
185 INITIALIZED = 2
186 };
187
182 // Used for reporting redirect prediction success/failure in histograms. 188 // Used for reporting redirect prediction success/failure in histograms.
183 // NOTE: This enumeration is used in histograms, so please do not add entries 189 // NOTE: This enumeration is used in histograms, so please do not add entries
184 // in the middle. 190 // in the middle.
185 enum class RedirectStatus { 191 enum class RedirectStatus {
186 NO_REDIRECT, 192 NO_REDIRECT,
187 NO_REDIRECT_BUT_PREDICTED, 193 NO_REDIRECT_BUT_PREDICTED,
188 REDIRECT_NOT_PREDICTED, 194 REDIRECT_NOT_PREDICTED,
189 REDIRECT_WRONG_PREDICTED, 195 REDIRECT_WRONG_PREDICTED,
190 REDIRECT_CORRECTLY_PREDICTED, 196 REDIRECT_CORRECTLY_PREDICTED,
191 MAX 197 MAX
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // Sets the |stats_collector| which is used to report histograms. 243 // Sets the |stats_collector| which is used to report histograms.
238 void SetStatsCollector(LoadingStatsCollector* stats_collector); 244 void SetStatsCollector(LoadingStatsCollector* stats_collector);
239 245
240 // Returns true iff there is PrefetchData that can be used for a 246 // Returns true iff there is PrefetchData that can be used for a
241 // |main_frame_url| and fills |prediction| with resources that need to be 247 // |main_frame_url| and fills |prediction| with resources that need to be
242 // prefetched. |prediction| pointer may be nullptr to get return value only. 248 // prefetched. |prediction| pointer may be nullptr to get return value only.
243 virtual bool GetPrefetchData(const GURL& main_frame_url, 249 virtual bool GetPrefetchData(const GURL& main_frame_url,
244 Prediction* prediction) const; 250 Prediction* prediction) const;
245 251
246 private: 252 private:
247 // 'LoadingPredictorObserver' calls the below functions to inform the
248 // predictor of main frame and resource requests. Should only be called if the
249 // corresponding Should* functions return true.
250 void RecordURLRequest(const URLRequestSummary& request);
251 void RecordURLResponse(const URLRequestSummary& response);
252 void RecordURLRedirect(const URLRequestSummary& response);
253
254 // Called when the main frame of a page completes loading.
255 void RecordMainFrameLoadComplete(const NavigationID& navigation_id);
256
257 // Called after the main frame's first contentful paint.
258 void RecordFirstContentfulPaint(
259 const NavigationID& navigation_id,
260 const base::TimeTicks& first_contentful_paint);
261
262 // Starts prefetching for |main_frame_url| from a |prediction|. 253 // Starts prefetching for |main_frame_url| from a |prediction|.
263 void StartPrefetching(const GURL& main_frame_url, 254 void StartPrefetching(const GURL& main_frame_url,
264 const Prediction& prediction); 255 const Prediction& prediction);
265 256
266 // Stops prefetching that may be in progress corresponding to 257 // Stops prefetching that may be in progress corresponding to
267 // |main_frame_url|. 258 // |main_frame_url|.
268 void StopPrefetching(const GURL& main_frame_url); 259 void StopPrefetching(const GURL& main_frame_url);
269 260
270 friend class LoadingPredictor; 261 friend class LoadingPredictor;
271 friend class ::PredictorsHandler; 262 friend class ::PredictorsHandler;
(...skipping 30 matching lines...) Expand all
302 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, PopulateFromManifest); 293 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, PopulateFromManifest);
303 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetRedirectEndpoint); 294 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetRedirectEndpoint);
304 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetPrefetchData); 295 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetPrefetchData);
305 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, 296 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest,
306 TestPrecisionRecallHistograms); 297 TestPrecisionRecallHistograms);
307 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, 298 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest,
308 TestPrefetchingDurationHistogram); 299 TestPrefetchingDurationHistogram);
309 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, 300 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest,
310 TestRecordFirstContentfulPaint); 301 TestRecordFirstContentfulPaint);
311 302
312 enum InitializationState {
313 NOT_INITIALIZED = 0,
314 INITIALIZING = 1,
315 INITIALIZED = 2
316 };
317 typedef GlowplugKeyValueData<PrefetchData, internal::LastVisitTimeCompare> 303 typedef GlowplugKeyValueData<PrefetchData, internal::LastVisitTimeCompare>
318 PrefetchDataMap; 304 PrefetchDataMap;
319 typedef GlowplugKeyValueData<RedirectData, internal::LastVisitTimeCompare> 305 typedef GlowplugKeyValueData<RedirectData, internal::LastVisitTimeCompare>
320 RedirectDataMap; 306 RedirectDataMap;
321 typedef GlowplugKeyValueData<precache::PrecacheManifest, 307 typedef GlowplugKeyValueData<precache::PrecacheManifest,
322 internal::ManifestCompare> 308 internal::ManifestCompare>
323 ManifestDataMap; 309 ManifestDataMap;
324 typedef GlowplugKeyValueData<OriginData, internal::LastVisitTimeCompare> 310 typedef GlowplugKeyValueData<OriginData, internal::LastVisitTimeCompare>
325 OriginDataMap; 311 OriginDataMap;
326 typedef std::map<NavigationID, std::unique_ptr<PageRequestSummary>> 312 typedef std::map<NavigationID, std::unique_ptr<PageRequestSummary>>
327 NavigationMap; 313 NavigationMap;
328 314
329 // Returns true if the request (should have a response in it) is "no-store". 315 // Returns true if the request (should have a response in it) is "no-store".
330 static bool IsNoStore(const net::URLRequest& request); 316 static bool IsNoStore(const net::URLRequest& request);
331 317
332 // Functions called on different network events pertaining to the loading of 318 // Called by the collector after a page has finished loading resources and
333 // main frame resource or sub resources. 319 // assembled a PageRequestSummary.
334 void OnMainFrameRequest(const URLRequestSummary& request); 320 void HandlePageRequestSummary(std::unique_ptr<PageRequestSummary> summary);
alexilin 2017/06/14 11:41:54 s/HandlePageRequestSummary/RecordPageRequestSummar
trevordixon 2017/06/16 05:11:28 Done.
alexilin 2017/06/16 09:31:57 You didn't rename the method :)
trevordixon 2017/06/16 10:53:19 Oops, missed that line! Done.
335 void OnMainFrameRedirect(const URLRequestSummary& response);
336 void OnSubresourceResponse(const URLRequestSummary& response);
337 void OnSubresourceRedirect(const URLRequestSummary& response);
338
339 // Called when onload completes for a navigation. We treat this point as the
340 // "completion" of the navigation. The resources requested by the page up to
341 // this point are the only ones considered for prefetching.
342 void OnNavigationComplete(const NavigationID& nav_id_without_timing_info);
343 321
344 // Returns true iff one of the following conditions is true 322 // Returns true iff one of the following conditions is true
345 // * |redirect_data| contains confident redirect endpoint for |entry_point| 323 // * |redirect_data| contains confident redirect endpoint for |entry_point|
346 // and assigns it to the |redirect_endpoint| 324 // and assigns it to the |redirect_endpoint|
347 // 325 //
348 // * |redirect_data| doens't contain an entry for |entry_point| and assigns 326 // * |redirect_data| doens't contain an entry for |entry_point| and assigns
349 // |entry_point| to the |redirect_endpoint|. 327 // |entry_point| to the |redirect_endpoint|.
350 bool GetRedirectEndpoint(const std::string& entry_point, 328 bool GetRedirectEndpoint(const std::string& entry_point,
351 const RedirectDataMap& redirect_data, 329 const RedirectDataMap& redirect_data,
352 std::string* redirect_endpoint) const; 330 std::string* redirect_endpoint) const;
(...skipping 10 matching lines...) Expand all
363 // prefetched. |urls| may be nullptr to get the return value only. 341 // prefetched. |urls| may be nullptr to get the return value only.
364 bool PopulateFromManifest(const std::string& manifest_host, 342 bool PopulateFromManifest(const std::string& manifest_host,
365 std::vector<GURL>* urls) const; 343 std::vector<GURL>* urls) const;
366 344
367 void InitializeOnDBThread(); 345 void InitializeOnDBThread();
368 346
369 // Called during initialization when history is read and the predictor 347 // Called during initialization when history is read and the predictor
370 // database has been read. 348 // database has been read.
371 void OnHistoryAndCacheLoaded(); 349 void OnHistoryAndCacheLoaded();
372 350
373 // Cleanup inflight_navigations_ and call a cleanup for stats_collector_.
374 void CleanupAbandonedNavigations(const NavigationID& navigation_id);
375
376 // Deletes all URLs from the predictor database, the caches and removes all 351 // Deletes all URLs from the predictor database, the caches and removes all
377 // inflight navigations. 352 // inflight navigations.
378 void DeleteAllUrls(); 353 void DeleteAllUrls();
379 354
380 // Deletes data for the input |urls| and their corresponding hosts from the 355 // Deletes data for the input |urls| and their corresponding hosts from the
381 // predictor database and caches. 356 // predictor database and caches.
382 void DeleteUrls(const history::URLRows& urls); 357 void DeleteUrls(const history::URLRows& urls);
383 358
384 // Callback for GetUrlVisitCountTask. 359 // Callback for GetUrlVisitCountTask.
385 void OnVisitCountLookup(size_t url_visit_count, 360 void OnVisitCountLookup(size_t url_visit_count,
(...skipping 30 matching lines...) Expand all
416 // Updates list of resources in the |resource_data| for the |key| according to 391 // Updates list of resources in the |resource_data| for the |key| according to
417 // the |manifest|. 392 // the |manifest|.
418 void UpdatePrefetchDataByManifest(const std::string& key, 393 void UpdatePrefetchDataByManifest(const std::string& key,
419 PrefetchDataMap* resource_data, 394 PrefetchDataMap* resource_data,
420 const precache::PrecacheManifest& manifest); 395 const precache::PrecacheManifest& manifest);
421 396
422 // Used to connect to HistoryService or register for service loaded 397 // Used to connect to HistoryService or register for service loaded
423 // notificatioan. 398 // notificatioan.
424 void ConnectToHistoryService(); 399 void ConnectToHistoryService();
425 400
401 InitializationState initialization_state() { return initialization_state_; }
402
426 // Used for testing to inject mock tables. 403 // Used for testing to inject mock tables.
427 void set_mock_tables(scoped_refptr<ResourcePrefetchPredictorTables> tables) { 404 void set_mock_tables(scoped_refptr<ResourcePrefetchPredictorTables> tables) {
428 tables_ = tables; 405 tables_ = tables;
429 } 406 }
430 407
431 // For testing. 408 // For testing.
432 void set_mock_resource_prefetcher_manager( 409 void set_mock_resource_prefetcher_manager(
433 scoped_refptr<ResourcePrefetcherManager> prefetch_manager) { 410 scoped_refptr<ResourcePrefetcherManager> prefetch_manager) {
434 prefetch_manager_ = prefetch_manager; 411 prefetch_manager_ = prefetch_manager;
435 } 412 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 461
485 private: 462 private:
486 ResourcePrefetchPredictor* predictor_; 463 ResourcePrefetchPredictor* predictor_;
487 464
488 DISALLOW_COPY_AND_ASSIGN(TestObserver); 465 DISALLOW_COPY_AND_ASSIGN(TestObserver);
489 }; 466 };
490 467
491 } // namespace predictors 468 } // namespace predictors
492 469
493 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ 470 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698