Chromium Code Reviews| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 if (!IsOmniboxEnabled(profile_)) | 290 if (!IsOmniboxEnabled(profile_)) |
| 291 return NULL; | 291 return NULL; |
| 292 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), size, | 292 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), size, |
| 293 session_storage_namespace); | 293 session_storage_namespace); |
| 294 } | 294 } |
| 295 | 295 |
| 296 PrerenderHandle* PrerenderManager::AddPrerenderFromExternalRequest( | 296 PrerenderHandle* PrerenderManager::AddPrerenderFromExternalRequest( |
| 297 const GURL& url, | 297 const GURL& url, |
| 298 const content::Referrer& referrer, | 298 const content::Referrer& referrer, |
| 299 SessionStorageNamespace* session_storage_namespace, | 299 SessionStorageNamespace* session_storage_namespace, |
| 300 const gfx::Size& size) { | 300 const gfx::Size& size, |
| 301 return AddPrerender(ORIGIN_EXTERNAL_REQUEST, url, referrer, size, | 301 bool prerender_on_mobile) { |
| 302 session_storage_namespace); | 302 Origin origin = prerender_on_mobile ? ORIGIN_EXTERNAL_REQUEST_MOBILE |
| 303 : ORIGIN_EXTERNAL_REQUEST; | |
| 304 return AddPrerender(origin, url, referrer, size, session_storage_namespace); | |
| 303 } | 305 } |
| 304 | 306 |
| 305 PrerenderHandle* PrerenderManager::AddPrerenderForInstant( | 307 PrerenderHandle* PrerenderManager::AddPrerenderForInstant( |
| 306 const GURL& url, | 308 const GURL& url, |
| 307 content::SessionStorageNamespace* session_storage_namespace, | 309 content::SessionStorageNamespace* session_storage_namespace, |
| 308 const gfx::Size& size) { | 310 const gfx::Size& size) { |
| 309 DCHECK(search::ShouldPrefetchSearchResults()); | 311 DCHECK(search::ShouldPrefetchSearchResults()); |
| 310 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size, | 312 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size, |
| 311 session_storage_namespace); | 313 session_storage_namespace); |
| 312 } | 314 } |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 927 | 929 |
| 928 GURL url = url_arg; | 930 GURL url = url_arg; |
| 929 GURL alias_url; | 931 GURL alias_url; |
| 930 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url)) | 932 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url)) |
| 931 url = alias_url; | 933 url = alias_url; |
| 932 | 934 |
| 933 // From here on, we will record a FinalStatus so we need to register with the | 935 // From here on, we will record a FinalStatus so we need to register with the |
| 934 // histogram tracking. | 936 // histogram tracking. |
| 935 histograms_->RecordPrerender(origin, url_arg); | 937 histograms_->RecordPrerender(origin, url_arg); |
| 936 | 938 |
| 937 NetworkPredictionStatus prerendering_status = GetPredictionStatus(); | 939 NetworkPredictionStatus prerendering_status = |
| 940 GetPredictionStatusForOrigin(origin); | |
| 938 if (prerendering_status != NetworkPredictionStatus::ENABLED) { | 941 if (prerendering_status != NetworkPredictionStatus::ENABLED) { |
| 939 FinalStatus final_status = | 942 FinalStatus final_status = |
| 940 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK | 943 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK |
| 941 ? FINAL_STATUS_CELLULAR_NETWORK | 944 ? FINAL_STATUS_CELLULAR_NETWORK |
| 942 : FINAL_STATUS_PRERENDERING_DISABLED; | 945 : FINAL_STATUS_PRERENDERING_DISABLED; |
| 943 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin, | 946 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin, |
| 944 final_status); | 947 final_status); |
| 945 return nullptr; | 948 return nullptr; |
| 946 } | 949 } |
| 947 | 950 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1278 DCHECK_GE(recent_profile_bytes, 0); | 1281 DCHECK_GE(recent_profile_bytes, 0); |
| 1279 histograms_->RecordNetworkBytes( | 1282 histograms_->RecordNetworkBytes( |
| 1280 origin, used, prerender_bytes, recent_profile_bytes); | 1283 origin, used, prerender_bytes, recent_profile_bytes); |
| 1281 } | 1284 } |
| 1282 | 1285 |
| 1283 NetworkPredictionStatus PrerenderManager::GetPredictionStatus() const { | 1286 NetworkPredictionStatus PrerenderManager::GetPredictionStatus() const { |
| 1284 DCHECK(CalledOnValidThread()); | 1287 DCHECK(CalledOnValidThread()); |
| 1285 return CanPrefetchAndPrerenderUI(profile_->GetPrefs()); | 1288 return CanPrefetchAndPrerenderUI(profile_->GetPrefs()); |
| 1286 } | 1289 } |
| 1287 | 1290 |
| 1291 NetworkPredictionStatus PrerenderManager::GetPredictionStatusForOrigin( | |
| 1292 Origin origin) const { | |
| 1293 NetworkPredictionStatus prerender_status = GetPredictionStatus(); | |
|
pasko
2016/03/10 14:21:37
nit: s/prerender_status/prediction_status/
Yusuf
2016/03/10 18:55:53
Done.
| |
| 1294 if (prerender_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK | |
| 1295 && origin == ORIGIN_EXTERNAL_REQUEST_MOBILE) { | |
| 1296 prerender_status = NetworkPredictionStatus::ENABLED; | |
| 1297 } | |
| 1298 return prerender_status; | |
| 1299 } | |
| 1300 | |
| 1288 void PrerenderManager::AddProfileNetworkBytesIfEnabled(int64_t bytes) { | 1301 void PrerenderManager::AddProfileNetworkBytesIfEnabled(int64_t bytes) { |
| 1289 DCHECK_GE(bytes, 0); | 1302 DCHECK_GE(bytes, 0); |
| 1290 if (GetPredictionStatus() == NetworkPredictionStatus::ENABLED && | 1303 if (GetPredictionStatus() == NetworkPredictionStatus::ENABLED && |
| 1291 ActuallyPrerendering()) | 1304 ActuallyPrerendering()) |
| 1292 profile_network_bytes_ += bytes; | 1305 profile_network_bytes_ += bytes; |
| 1293 } | 1306 } |
| 1294 | 1307 |
| 1295 void PrerenderManager::AddPrerenderProcessHost( | 1308 void PrerenderManager::AddPrerenderProcessHost( |
| 1296 content::RenderProcessHost* process_host) { | 1309 content::RenderProcessHost* process_host) { |
| 1297 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1310 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1311 } | 1324 } |
| 1312 | 1325 |
| 1313 void PrerenderManager::RenderProcessHostDestroyed( | 1326 void PrerenderManager::RenderProcessHostDestroyed( |
| 1314 content::RenderProcessHost* host) { | 1327 content::RenderProcessHost* host) { |
| 1315 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1328 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1316 size_t erased = prerender_process_hosts_.erase(host); | 1329 size_t erased = prerender_process_hosts_.erase(host); |
| 1317 DCHECK_EQ(1u, erased); | 1330 DCHECK_EQ(1u, erased); |
| 1318 } | 1331 } |
| 1319 | 1332 |
| 1320 } // namespace prerender | 1333 } // namespace prerender |
| OLD | NEW |