Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_PREDICTORS_LOADING_DATA_COLLECTOR_H_ | |
| 6 #define CHROME_BROWSER_PREDICTORS_LOADING_DATA_COLLECTOR_H_ | |
| 7 | |
| 8 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | |
| 9 #include "content/public/common/resource_type.h" | |
| 10 | |
| 11 namespace net { | |
| 12 class URLRequest; | |
| 13 } | |
| 14 | |
| 15 namespace predictors { | |
| 16 | |
| 17 // Records navigation events as reported by various observers to the database | |
| 18 // and stats collection classes. All the non-static methods of this class need | |
| 19 // to be called on the UI thread. | |
| 20 class LoadingDataCollector | |
| 21 : public base::SupportsWeakPtr<LoadingDataCollector> { | |
| 22 public: | |
| 23 explicit LoadingDataCollector( | |
| 24 predictors::ResourcePrefetchPredictor* predictor); | |
| 25 ~LoadingDataCollector(); | |
| 26 | |
| 27 // Thread safe. | |
| 28 static bool ShouldRecordRequest(net::URLRequest* request, | |
| 29 content::ResourceType resource_type); | |
| 30 static bool ShouldRecordResponse(net::URLRequest* response); | |
| 31 static bool ShouldRecordRedirect(net::URLRequest* response); | |
| 32 | |
| 33 // 'LoadingPredictorObserver' calls the below functions to inform the | |
|
Benoit L
2017/06/02 12:43:59
and LoadingPredictorTabHelper, right?
trevordixon
2017/06/06 13:08:03
Done.
| |
| 34 // predictor of main frame and resource requests. Should only be called if the | |
| 35 // corresponding Should* functions return true. | |
| 36 void RecordURLRequest( | |
| 37 const predictors::ResourcePrefetchPredictor::URLRequestSummary& request); | |
| 38 void RecordURLResponse( | |
| 39 const predictors::ResourcePrefetchPredictor::URLRequestSummary& response); | |
| 40 void RecordURLRedirect( | |
| 41 const predictors::ResourcePrefetchPredictor::URLRequestSummary& response); | |
| 42 | |
| 43 // Called when the main frame of a page completes loading. | |
| 44 void RecordMainFrameLoadComplete(const NavigationID& navigation_id); | |
| 45 | |
| 46 // Called after the main frame's first contentful paint. | |
| 47 void RecordFirstContentfulPaint( | |
| 48 const NavigationID& navigation_id, | |
| 49 const base::TimeTicks& first_contentful_paint); | |
| 50 | |
| 51 private: | |
| 52 friend class ResourcePrefetchPredictorBrowserTest; | |
| 53 | |
| 54 FRIEND_TEST_ALL_PREFIXES(LoadingDataCollectorTest, HandledResourceTypes); | |
| 55 | |
| 56 // Returns true if the main page request is supported for prediction. | |
| 57 static bool IsHandledMainPage(net::URLRequest* request); | |
| 58 | |
| 59 // Returns true if the subresource request is supported for prediction. | |
| 60 static bool IsHandledSubresource(net::URLRequest* request, | |
| 61 content::ResourceType resource_type); | |
| 62 | |
| 63 // Returns true if the subresource has a supported type. | |
| 64 static bool IsHandledResourceType(content::ResourceType resource_type, | |
| 65 const std::string& mime_type); | |
| 66 | |
| 67 static void SetAllowPortInUrlsForTesting(bool state); | |
| 68 | |
| 69 predictors::ResourcePrefetchPredictor* const predictor_; | |
| 70 }; | |
| 71 | |
| 72 } // namespace predictors | |
| 73 | |
| 74 #endif // CHROME_BROWSER_PREDICTORS_LOADING_DATA_COLLECTOR_H_ | |
| OLD | NEW |