| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/prerender/prerender_manager.h" | 5 #include "chrome/browser/prerender/prerender_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 net::HttpRequestHeaders parsed_headers; | 98 net::HttpRequestHeaders parsed_headers; |
| 99 parsed_headers.AddHeadersFromString(extra_headers); | 99 parsed_headers.AddHeadersFromString(extra_headers); |
| 100 parsed_headers.RemoveHeader("upgrade-insecure-requests"); | 100 parsed_headers.RemoveHeader("upgrade-insecure-requests"); |
| 101 return parsed_headers.IsEmpty(); | 101 return parsed_headers.IsEmpty(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Returns true if prerendering is forced, because it is needed as a feature, as | 104 // Returns true if prerendering is forced, because it is needed as a feature, as |
| 105 // opposed to a performance optimization. | 105 // opposed to a performance optimization. |
| 106 bool IsPrerenderingForced(Origin origin) { | 106 bool IsPrerenderingForced(Origin origin) { |
| 107 return origin == ORIGIN_OFFLINE || | 107 return origin == ORIGIN_OFFLINE || |
| 108 origin == ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR; | 108 origin == ORIGIN_EXTERNAL_REQUEST_FORCED_PRERENDER; |
| 109 } | 109 } |
| 110 | 110 |
| 111 } // namespace | 111 } // namespace |
| 112 | 112 |
| 113 class PrerenderManager::OnCloseWebContentsDeleter | 113 class PrerenderManager::OnCloseWebContentsDeleter |
| 114 : public content::WebContentsDelegate, | 114 : public content::WebContentsDelegate, |
| 115 public base::SupportsWeakPtr< | 115 public base::SupportsWeakPtr< |
| 116 PrerenderManager::OnCloseWebContentsDeleter> { | 116 PrerenderManager::OnCloseWebContentsDeleter> { |
| 117 public: | 117 public: |
| 118 OnCloseWebContentsDeleter(PrerenderManager* manager, | 118 OnCloseWebContentsDeleter(PrerenderManager* manager, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 PrerenderManager::AddPrerenderFromExternalRequest( | 270 PrerenderManager::AddPrerenderFromExternalRequest( |
| 271 const GURL& url, | 271 const GURL& url, |
| 272 const content::Referrer& referrer, | 272 const content::Referrer& referrer, |
| 273 SessionStorageNamespace* session_storage_namespace, | 273 SessionStorageNamespace* session_storage_namespace, |
| 274 const gfx::Rect& bounds) { | 274 const gfx::Rect& bounds) { |
| 275 return AddPrerender(ORIGIN_EXTERNAL_REQUEST, url, referrer, | 275 return AddPrerender(ORIGIN_EXTERNAL_REQUEST, url, referrer, |
| 276 bounds, session_storage_namespace); | 276 bounds, session_storage_namespace); |
| 277 } | 277 } |
| 278 | 278 |
| 279 std::unique_ptr<PrerenderHandle> | 279 std::unique_ptr<PrerenderHandle> |
| 280 PrerenderManager::AddPrerenderOnCellularFromExternalRequest( | 280 PrerenderManager::AddForcedPrerenderFromExternalRequest( |
| 281 const GURL& url, | 281 const GURL& url, |
| 282 const content::Referrer& referrer, | 282 const content::Referrer& referrer, |
| 283 SessionStorageNamespace* session_storage_namespace, | 283 SessionStorageNamespace* session_storage_namespace, |
| 284 const gfx::Rect& bounds) { | 284 const gfx::Rect& bounds) { |
| 285 return AddPrerender(ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR, | 285 return AddPrerender(ORIGIN_EXTERNAL_REQUEST_FORCED_PRERENDER, url, referrer, |
| 286 url, | 286 bounds, session_storage_namespace); |
| 287 referrer, | |
| 288 bounds, | |
| 289 session_storage_namespace); | |
| 290 } | 287 } |
| 291 | 288 |
| 292 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForInstant( | 289 std::unique_ptr<PrerenderHandle> PrerenderManager::AddPrerenderForInstant( |
| 293 const GURL& url, | 290 const GURL& url, |
| 294 content::SessionStorageNamespace* session_storage_namespace, | 291 content::SessionStorageNamespace* session_storage_namespace, |
| 295 const gfx::Size& size) { | 292 const gfx::Size& size) { |
| 296 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), gfx::Rect(size), | 293 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), gfx::Rect(size), |
| 297 session_storage_namespace); | 294 session_storage_namespace); |
| 298 } | 295 } |
| 299 | 296 |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 int64_t recent_profile_bytes = | 1331 int64_t recent_profile_bytes = |
| 1335 profile_network_bytes_ - last_recorded_profile_network_bytes_; | 1332 profile_network_bytes_ - last_recorded_profile_network_bytes_; |
| 1336 last_recorded_profile_network_bytes_ = profile_network_bytes_; | 1333 last_recorded_profile_network_bytes_ = profile_network_bytes_; |
| 1337 DCHECK_GE(recent_profile_bytes, 0); | 1334 DCHECK_GE(recent_profile_bytes, 0); |
| 1338 histograms_->RecordNetworkBytes( | 1335 histograms_->RecordNetworkBytes( |
| 1339 origin, used, prerender_bytes, recent_profile_bytes); | 1336 origin, used, prerender_bytes, recent_profile_bytes); |
| 1340 } | 1337 } |
| 1341 | 1338 |
| 1342 bool PrerenderManager::IsPrerenderSilenceExperiment(Origin origin) const { | 1339 bool PrerenderManager::IsPrerenderSilenceExperiment(Origin origin) const { |
| 1343 if (origin == ORIGIN_OFFLINE || | 1340 if (origin == ORIGIN_OFFLINE || |
| 1344 origin == ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR) { | 1341 origin == ORIGIN_EXTERNAL_REQUEST_FORCED_PRERENDER) { |
| 1345 return false; | 1342 return false; |
| 1346 } | 1343 } |
| 1347 | 1344 |
| 1348 // The group name should contain expiration time formatted as: | 1345 // The group name should contain expiration time formatted as: |
| 1349 // "ExperimentYes_expires_YYYY-MM-DDTHH:MM:SSZ". | 1346 // "ExperimentYes_expires_YYYY-MM-DDTHH:MM:SSZ". |
| 1350 std::string group_name = | 1347 std::string group_name = |
| 1351 base::FieldTrialList::FindFullName("PrerenderSilence"); | 1348 base::FieldTrialList::FindFullName("PrerenderSilence"); |
| 1352 const char kExperimentPrefix[] = "ExperimentYes"; | 1349 const char kExperimentPrefix[] = "ExperimentYes"; |
| 1353 if (!base::StartsWith(group_name, kExperimentPrefix, | 1350 if (!base::StartsWith(group_name, kExperimentPrefix, |
| 1354 base::CompareCase::INSENSITIVE_ASCII)) { | 1351 base::CompareCase::INSENSITIVE_ASCII)) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 if (origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN || | 1389 if (origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN || |
| 1393 origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || | 1390 origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || |
| 1394 origin == ORIGIN_OFFLINE) { | 1391 origin == ORIGIN_OFFLINE) { |
| 1395 return NetworkPredictionStatus::ENABLED; | 1392 return NetworkPredictionStatus::ENABLED; |
| 1396 } | 1393 } |
| 1397 | 1394 |
| 1398 // Prerendering forced for cellular networks still prevents navigation with | 1395 // Prerendering forced for cellular networks still prevents navigation with |
| 1399 // the DISABLED_ALWAYS selected via privacy settings. | 1396 // the DISABLED_ALWAYS selected via privacy settings. |
| 1400 NetworkPredictionStatus prediction_status = | 1397 NetworkPredictionStatus prediction_status = |
| 1401 chrome_browser_net::CanPrefetchAndPrerenderUI(profile_->GetPrefs()); | 1398 chrome_browser_net::CanPrefetchAndPrerenderUI(profile_->GetPrefs()); |
| 1402 if (origin == ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR && | 1399 if (origin == ORIGIN_EXTERNAL_REQUEST_FORCED_PRERENDER && |
| 1403 prediction_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK) { | 1400 prediction_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK) { |
| 1404 return NetworkPredictionStatus::ENABLED; | 1401 return NetworkPredictionStatus::ENABLED; |
| 1405 } | 1402 } |
| 1406 return prediction_status; | 1403 return prediction_status; |
| 1407 } | 1404 } |
| 1408 | 1405 |
| 1409 void PrerenderManager::AddProfileNetworkBytesIfEnabled(int64_t bytes) { | 1406 void PrerenderManager::AddProfileNetworkBytesIfEnabled(int64_t bytes) { |
| 1410 DCHECK_GE(bytes, 0); | 1407 DCHECK_GE(bytes, 0); |
| 1411 if (GetPredictionStatus() == NetworkPredictionStatus::ENABLED && | 1408 if (GetPredictionStatus() == NetworkPredictionStatus::ENABLED && |
| 1412 IsPrerenderingPossible()) | 1409 IsPrerenderingPossible()) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1442 return weak_factory_.GetWeakPtr(); | 1439 return weak_factory_.GetWeakPtr(); |
| 1443 } | 1440 } |
| 1444 | 1441 |
| 1445 void PrerenderManager::SetPrerenderContentsFactoryForTest( | 1442 void PrerenderManager::SetPrerenderContentsFactoryForTest( |
| 1446 PrerenderContents::Factory* prerender_contents_factory) { | 1443 PrerenderContents::Factory* prerender_contents_factory) { |
| 1447 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1444 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1448 prerender_contents_factory_.reset(prerender_contents_factory); | 1445 prerender_contents_factory_.reset(prerender_contents_factory); |
| 1449 } | 1446 } |
| 1450 | 1447 |
| 1451 } // namespace prerender | 1448 } // namespace prerender |
| OLD | NEW |