| 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 // 'ResourcePrefetchPredictorObserver' calls the below functions to inform the |
| 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 // Returns true if the main page request is supported for prediction. |
| 53 static bool IsHandledMainPage(net::URLRequest* request); |
| 54 |
| 55 // Returns true if the subresource request is supported for prediction. |
| 56 static bool IsHandledSubresource(net::URLRequest* request, |
| 57 content::ResourceType resource_type); |
| 58 |
| 59 // Returns true if the subresource has a supported type. |
| 60 static bool IsHandledResourceType(content::ResourceType resource_type, |
| 61 const std::string& mime_type); |
| 62 |
| 63 static void SetAllowPortInUrlsForTesting(bool state); |
| 64 |
| 65 predictors::ResourcePrefetchPredictor* const predictor_; |
| 66 }; |
| 67 |
| 68 } // namespace predictors |
| 69 |
| 70 #endif // CHROME_BROWSER_PREDICTORS_LOADING_DATA_COLLECTOR_H_ |
| OLD | NEW |