| OLD | NEW |
| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 struct URLRequestSummary { | 125 struct URLRequestSummary { |
| 126 URLRequestSummary(); | 126 URLRequestSummary(); |
| 127 URLRequestSummary(const URLRequestSummary& other); | 127 URLRequestSummary(const URLRequestSummary& other); |
| 128 ~URLRequestSummary(); | 128 ~URLRequestSummary(); |
| 129 | 129 |
| 130 NavigationID navigation_id; | 130 NavigationID navigation_id; |
| 131 GURL resource_url; | 131 GURL resource_url; |
| 132 GURL request_url; // URL after all redirects. | 132 GURL request_url; // URL after all redirects. |
| 133 content::ResourceType resource_type; | 133 content::ResourceType resource_type; |
| 134 net::RequestPriority priority; | 134 net::RequestPriority priority; |
| 135 base::TimeTicks response_time; |
| 136 bool before_first_contentful_paint; |
| 135 | 137 |
| 136 // Only for responses. | 138 // Only for responses. |
| 137 std::string mime_type; | 139 std::string mime_type; |
| 138 bool was_cached; | 140 bool was_cached; |
| 139 GURL redirect_url; // Empty unless request was redirected to a valid url. | 141 GURL redirect_url; // Empty unless request was redirected to a valid url. |
| 140 | 142 |
| 141 bool has_validators; | 143 bool has_validators; |
| 142 bool always_revalidate; | 144 bool always_revalidate; |
| 143 bool is_no_store; | 145 bool is_no_store; |
| 144 bool network_accessed; | 146 bool network_accessed; |
| 145 | 147 |
| 146 // Initializes a |URLRequestSummary| from a |URLRequest| response. | 148 // Initializes a |URLRequestSummary| from a |URLRequest| response. |
| 147 // Returns true for success. Note: NavigationID is NOT initialized | 149 // Returns true for success. Note: NavigationID is NOT initialized |
| 148 // by this function. | 150 // by this function. |
| 149 static bool SummarizeResponse(const net::URLRequest& request, | 151 static bool SummarizeResponse(const net::URLRequest& request, |
| 150 URLRequestSummary* summary); | 152 URLRequestSummary* summary); |
| 151 }; | 153 }; |
| 152 | 154 |
| 153 // Stores the data learned from a single navigation. | 155 // Stores the data learned from a single navigation. |
| 154 struct PageRequestSummary { | 156 struct PageRequestSummary { |
| 155 explicit PageRequestSummary(const GURL& main_frame_url); | 157 explicit PageRequestSummary(const GURL& main_frame_url); |
| 156 PageRequestSummary(const PageRequestSummary& other); | 158 PageRequestSummary(const PageRequestSummary& other); |
| 157 ~PageRequestSummary(); | 159 ~PageRequestSummary(); |
| 158 | 160 |
| 159 GURL main_frame_url; | 161 GURL main_frame_url; |
| 160 GURL initial_url; | 162 GURL initial_url; |
| 163 base::TimeTicks first_contentful_paint; |
| 161 | 164 |
| 162 // Stores all subresource requests within a single navigation, from initial | 165 // Stores all subresource requests within a single navigation, from initial |
| 163 // main frame request to navigation completion. | 166 // main frame request to navigation completion. |
| 164 std::vector<URLRequestSummary> subresource_requests; | 167 std::vector<URLRequestSummary> subresource_requests; |
| 165 // Map of origin -> OriginRequestSummary. Only one instance of each origin | 168 // Map of origin -> OriginRequestSummary. Only one instance of each origin |
| 166 // is kept per navigation, but the summary is updated several times. | 169 // is kept per navigation, but the summary is updated several times. |
| 167 std::map<GURL, OriginRequestSummary> origins; | 170 std::map<GURL, OriginRequestSummary> origins; |
| 168 }; | 171 }; |
| 169 | 172 |
| 170 // Stores a result of prediction. Essentially, |subresource_urls| is main | 173 // Stores a result of prediction. Essentially, |subresource_urls| is main |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // 'ResourcePrefetchPredictorObserver' calls the below functions to inform the | 224 // 'ResourcePrefetchPredictorObserver' calls the below functions to inform the |
| 222 // predictor of main frame and resource requests. Should only be called if the | 225 // predictor of main frame and resource requests. Should only be called if the |
| 223 // corresponding Should* functions return true. | 226 // corresponding Should* functions return true. |
| 224 void RecordURLRequest(const URLRequestSummary& request); | 227 void RecordURLRequest(const URLRequestSummary& request); |
| 225 void RecordURLResponse(const URLRequestSummary& response); | 228 void RecordURLResponse(const URLRequestSummary& response); |
| 226 void RecordURLRedirect(const URLRequestSummary& response); | 229 void RecordURLRedirect(const URLRequestSummary& response); |
| 227 | 230 |
| 228 // Called when the main frame of a page completes loading. | 231 // Called when the main frame of a page completes loading. |
| 229 void RecordMainFrameLoadComplete(const NavigationID& navigation_id); | 232 void RecordMainFrameLoadComplete(const NavigationID& navigation_id); |
| 230 | 233 |
| 234 // Called after the main frame's first contentful paint. |
| 235 void RecordFirstContentfulPaint( |
| 236 const NavigationID& navigation_id, |
| 237 const base::TimeTicks& first_contentful_paint); |
| 238 |
| 231 // Starts prefetching if it is enabled for |origin| and prefetching data | 239 // Starts prefetching if it is enabled for |origin| and prefetching data |
| 232 // exists for the |main_frame_url| either at the URL or at the host level. | 240 // exists for the |main_frame_url| either at the URL or at the host level. |
| 233 void StartPrefetching(const GURL& main_frame_url, PrefetchOrigin origin); | 241 void StartPrefetching(const GURL& main_frame_url, PrefetchOrigin origin); |
| 234 | 242 |
| 235 // Stops prefetching that may be in progress corresponding to | 243 // Stops prefetching that may be in progress corresponding to |
| 236 // |main_frame_url|. | 244 // |main_frame_url|. |
| 237 void StopPrefetching(const GURL& main_frame_url); | 245 void StopPrefetching(const GURL& main_frame_url); |
| 238 | 246 |
| 239 // Called when ResourcePrefetcher is finished, i.e. there is nothing pending | 247 // Called when ResourcePrefetcher is finished, i.e. there is nothing pending |
| 240 // in flight. | 248 // in flight. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, HandledResourceTypes); | 298 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, HandledResourceTypes); |
| 291 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, | 299 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
| 292 PopulatePrefetcherRequest); | 300 PopulatePrefetcherRequest); |
| 293 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, PopulateFromManifest); | 301 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, PopulateFromManifest); |
| 294 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetRedirectEndpoint); | 302 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetRedirectEndpoint); |
| 295 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetPrefetchData); | 303 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, GetPrefetchData); |
| 296 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, | 304 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
| 297 TestPrecisionRecallHistograms); | 305 TestPrecisionRecallHistograms); |
| 298 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, | 306 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
| 299 TestPrefetchingDurationHistogram); | 307 TestPrefetchingDurationHistogram); |
| 308 FRIEND_TEST_ALL_PREFIXES(ResourcePrefetchPredictorTest, |
| 309 TestRecordFirstContentfulPaint); |
| 300 | 310 |
| 301 enum InitializationState { | 311 enum InitializationState { |
| 302 NOT_INITIALIZED = 0, | 312 NOT_INITIALIZED = 0, |
| 303 INITIALIZING = 1, | 313 INITIALIZING = 1, |
| 304 INITIALIZED = 2 | 314 INITIALIZED = 2 |
| 305 }; | 315 }; |
| 306 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; | 316 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; |
| 307 typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap; | 317 typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap; |
| 308 typedef ResourcePrefetchPredictorTables::ManifestDataMap ManifestDataMap; | 318 typedef ResourcePrefetchPredictorTables::ManifestDataMap ManifestDataMap; |
| 309 typedef ResourcePrefetchPredictorTables::OriginDataMap OriginDataMap; | 319 typedef ResourcePrefetchPredictorTables::OriginDataMap OriginDataMap; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 528 |
| 519 private: | 529 private: |
| 520 ResourcePrefetchPredictor* predictor_; | 530 ResourcePrefetchPredictor* predictor_; |
| 521 | 531 |
| 522 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 532 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 523 }; | 533 }; |
| 524 | 534 |
| 525 } // namespace predictors | 535 } // namespace predictors |
| 526 | 536 |
| 527 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ | 537 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ |
| OLD | NEW |