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