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 <string> |
| 9 |
| 10 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 11 #include "content/public/common/resource_type.h" |
| 12 |
| 13 namespace net { |
| 14 class URLRequest; |
| 15 } |
| 16 |
| 17 namespace predictors { |
| 18 |
| 19 // Records navigation events as reported by various observers to the database |
| 20 // and stats collection classes. All the non-static methods of this class need |
| 21 // to be called on the UI thread. |
| 22 class LoadingDataCollector |
| 23 : public base::SupportsWeakPtr<LoadingDataCollector> { |
| 24 public: |
| 25 explicit LoadingDataCollector( |
| 26 predictors::ResourcePrefetchPredictor* predictor); |
| 27 ~LoadingDataCollector(); |
| 28 |
| 29 // Thread safe. |
| 30 static bool ShouldRecordRequest(net::URLRequest* request, |
| 31 content::ResourceType resource_type); |
| 32 static bool ShouldRecordResponse(net::URLRequest* response); |
| 33 static bool ShouldRecordRedirect(net::URLRequest* response); |
| 34 |
| 35 // 'LoadingPredictorObserver' and 'ResourcePrefetchPredictorTabHelper' call |
| 36 // the below functions to inform the predictor of main frame and resource |
| 37 // requests. Should only be called if the corresponding Should* functions |
| 38 // return true. |
| 39 void RecordURLRequest( |
| 40 const predictors::ResourcePrefetchPredictor::URLRequestSummary& request); |
| 41 void RecordURLResponse( |
| 42 const predictors::ResourcePrefetchPredictor::URLRequestSummary& response); |
| 43 void RecordURLRedirect( |
| 44 const predictors::ResourcePrefetchPredictor::URLRequestSummary& response); |
| 45 |
| 46 // Called when the main frame of a page completes loading. |
| 47 void RecordMainFrameLoadComplete(const NavigationID& navigation_id); |
| 48 |
| 49 // Called after the main frame's first contentful paint. |
| 50 void RecordFirstContentfulPaint( |
| 51 const NavigationID& navigation_id, |
| 52 const base::TimeTicks& first_contentful_paint); |
| 53 |
| 54 private: |
| 55 friend class ResourcePrefetchPredictorBrowserTest; |
| 56 |
| 57 FRIEND_TEST_ALL_PREFIXES(LoadingDataCollectorTest, HandledResourceTypes); |
| 58 |
| 59 // Returns true if the main page request is supported for prediction. |
| 60 static bool IsHandledMainPage(net::URLRequest* request); |
| 61 |
| 62 // Returns true if the subresource request is supported for prediction. |
| 63 static bool IsHandledSubresource(net::URLRequest* request, |
| 64 content::ResourceType resource_type); |
| 65 |
| 66 // Returns true if the subresource has a supported type. |
| 67 static bool IsHandledResourceType(content::ResourceType resource_type, |
| 68 const std::string& mime_type); |
| 69 |
| 70 static void SetAllowPortInUrlsForTesting(bool state); |
| 71 |
| 72 predictors::ResourcePrefetchPredictor* const predictor_; |
| 73 }; |
| 74 |
| 75 } // namespace predictors |
| 76 |
| 77 #endif // CHROME_BROWSER_PREDICTORS_LOADING_DATA_COLLECTOR_H_ |
OLD | NEW |