Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: chrome/browser/prerender/prerender_manager.cc

Issue 1767243002: Update prerender policy for custom tabs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mmenke@'s comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 return NULL; 293 return NULL;
294 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), size, 294 return AddPrerender(ORIGIN_OMNIBOX, url, content::Referrer(), size,
295 session_storage_namespace); 295 session_storage_namespace);
296 } 296 }
297 297
298 PrerenderHandle* PrerenderManager::AddPrerenderFromExternalRequest( 298 PrerenderHandle* PrerenderManager::AddPrerenderFromExternalRequest(
299 const GURL& url, 299 const GURL& url,
300 const content::Referrer& referrer, 300 const content::Referrer& referrer,
301 SessionStorageNamespace* session_storage_namespace, 301 SessionStorageNamespace* session_storage_namespace,
302 const gfx::Size& size) { 302 const gfx::Size& size) {
303 return AddPrerender(ORIGIN_EXTERNAL_REQUEST, url, referrer, size, 303 return AddPrerender(
304 ORIGIN_EXTERNAL_REQUEST, url, referrer, size, session_storage_namespace);
305 }
306
307 PrerenderHandle* PrerenderManager::AddPrerenderOnCellularFromExternalRequest(
308 const GURL& url,
309 const content::Referrer& referrer,
310 SessionStorageNamespace* session_storage_namespace,
311 const gfx::Size& size) {
312 return AddPrerender(ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR,
313 url,
314 referrer,
315 size,
304 session_storage_namespace); 316 session_storage_namespace);
305 } 317 }
306 318
307 PrerenderHandle* PrerenderManager::AddPrerenderForInstant( 319 PrerenderHandle* PrerenderManager::AddPrerenderForInstant(
308 const GURL& url, 320 const GURL& url,
309 content::SessionStorageNamespace* session_storage_namespace, 321 content::SessionStorageNamespace* session_storage_namespace,
310 const gfx::Size& size) { 322 const gfx::Size& size) {
311 DCHECK(search::ShouldPrefetchSearchResults()); 323 DCHECK(search::ShouldPrefetchSearchResults());
312 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size, 324 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size,
313 session_storage_namespace); 325 session_storage_namespace);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 histograms_->RecordPageLoadTimeNotSwappedIn(origin, page_load_time, url); 582 histograms_->RecordPageLoadTimeNotSwappedIn(origin, page_load_time, url);
571 } 583 }
572 584
573 void PrerenderManager::RecordPerceivedPageLoadTime( 585 void PrerenderManager::RecordPerceivedPageLoadTime(
574 Origin origin, 586 Origin origin,
575 NavigationType navigation_type, 587 NavigationType navigation_type,
576 base::TimeDelta perceived_page_load_time, 588 base::TimeDelta perceived_page_load_time,
577 double fraction_plt_elapsed_at_swap_in, 589 double fraction_plt_elapsed_at_swap_in,
578 const GURL& url) { 590 const GURL& url) {
579 DCHECK_CURRENTLY_ON(BrowserThread::UI); 591 DCHECK_CURRENTLY_ON(BrowserThread::UI);
580 if (GetPredictionStatus() != NetworkPredictionStatus::ENABLED) 592 if (GetPredictionStatusForOrigin(origin)
593 != NetworkPredictionStatus::ENABLED) {
581 return; 594 return;
595 }
582 596
583 histograms_->RecordPerceivedPageLoadTime( 597 histograms_->RecordPerceivedPageLoadTime(
584 origin, perceived_page_load_time, navigation_type, url); 598 origin, perceived_page_load_time, navigation_type, url);
585 599
586 if (navigation_type == NAVIGATION_TYPE_PRERENDERED) { 600 if (navigation_type == NAVIGATION_TYPE_PRERENDERED) {
587 histograms_->RecordPercentLoadDoneAtSwapin( 601 histograms_->RecordPercentLoadDoneAtSwapin(
588 origin, fraction_plt_elapsed_at_swap_in); 602 origin, fraction_plt_elapsed_at_swap_in);
589 } 603 }
590 } 604 }
591 605
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 return DoesURLHaveValidScheme(url) || url == GURL(url::kAboutBlankURL); 798 return DoesURLHaveValidScheme(url) || url == GURL(url::kAboutBlankURL);
785 } 799 }
786 800
787 base::DictionaryValue* PrerenderManager::GetAsValue() const { 801 base::DictionaryValue* PrerenderManager::GetAsValue() const {
788 DCHECK(CalledOnValidThread()); 802 DCHECK(CalledOnValidThread());
789 base::DictionaryValue* dict_value = new base::DictionaryValue(); 803 base::DictionaryValue* dict_value = new base::DictionaryValue();
790 dict_value->Set("history", prerender_history_->GetEntriesAsValue()); 804 dict_value->Set("history", prerender_history_->GetEntriesAsValue());
791 dict_value->Set("active", GetActivePrerendersAsValue()); 805 dict_value->Set("active", GetActivePrerendersAsValue());
792 dict_value->SetBoolean("enabled", 806 dict_value->SetBoolean("enabled",
793 GetPredictionStatus() == NetworkPredictionStatus::ENABLED); 807 GetPredictionStatus() == NetworkPredictionStatus::ENABLED);
808 std::string disabled_note;
809 if (GetPredictionStatus() == NetworkPredictionStatus::DISABLED_ALWAYS)
810 disabled_note = "Disabled by user setting";
811 if (GetPredictionStatus() == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK)
812 disabled_note = "Disabled on cellular connection by default";
813 dict_value->SetString("disabled_note", disabled_note);
794 dict_value->SetBoolean("omnibox_enabled", IsOmniboxEnabled(profile_)); 814 dict_value->SetBoolean("omnibox_enabled", IsOmniboxEnabled(profile_));
795 // If prerender is disabled via a flag this method is not even called. 815 // If prerender is disabled via a flag this method is not even called.
796 std::string enabled_note; 816 std::string enabled_note;
797 if (IsControlGroup()) 817 if (IsControlGroup())
798 enabled_note += "(Control group: Not actually prerendering) "; 818 enabled_note += "(Control group: Not actually prerendering) ";
799 if (IsNoUseGroup()) 819 if (IsNoUseGroup())
800 enabled_note += "(No-use group: Not swapping in prerendered pages) "; 820 enabled_note += "(No-use group: Not swapping in prerendered pages) ";
801 if (GetMode() == PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP) 821 if (GetMode() == PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP)
802 enabled_note += 822 enabled_note +=
803 "(15 min TTL group: Extended prerender eviction to 15 mins) "; 823 "(15 min TTL group: Extended prerender eviction to 15 mins) ";
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 // From here on, we will record a FinalStatus so we need to register with the 955 // From here on, we will record a FinalStatus so we need to register with the
936 // histogram tracking. 956 // histogram tracking.
937 histograms_->RecordPrerender(origin, url_arg); 957 histograms_->RecordPrerender(origin, url_arg);
938 958
939 if (profile_->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies)) { 959 if (profile_->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies)) {
940 RecordFinalStatusWithoutCreatingPrerenderContents( 960 RecordFinalStatusWithoutCreatingPrerenderContents(
941 url, origin, FINAL_STATUS_BLOCK_THIRD_PARTY_COOKIES); 961 url, origin, FINAL_STATUS_BLOCK_THIRD_PARTY_COOKIES);
942 return nullptr; 962 return nullptr;
943 } 963 }
944 964
945 NetworkPredictionStatus prerendering_status = GetPredictionStatus(); 965 NetworkPredictionStatus prerendering_status =
966 GetPredictionStatusForOrigin(origin);
946 if (prerendering_status != NetworkPredictionStatus::ENABLED) { 967 if (prerendering_status != NetworkPredictionStatus::ENABLED) {
947 FinalStatus final_status = 968 FinalStatus final_status =
948 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK 969 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK
949 ? FINAL_STATUS_CELLULAR_NETWORK 970 ? FINAL_STATUS_CELLULAR_NETWORK
950 : FINAL_STATUS_PRERENDERING_DISABLED; 971 : FINAL_STATUS_PRERENDERING_DISABLED;
951 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin, 972 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin,
952 final_status); 973 final_status);
953 return nullptr; 974 return nullptr;
954 } 975 }
955 976
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 DCHECK_GE(recent_profile_bytes, 0); 1305 DCHECK_GE(recent_profile_bytes, 0);
1285 histograms_->RecordNetworkBytes( 1306 histograms_->RecordNetworkBytes(
1286 origin, used, prerender_bytes, recent_profile_bytes); 1307 origin, used, prerender_bytes, recent_profile_bytes);
1287 } 1308 }
1288 1309
1289 NetworkPredictionStatus PrerenderManager::GetPredictionStatus() const { 1310 NetworkPredictionStatus PrerenderManager::GetPredictionStatus() const {
1290 DCHECK(CalledOnValidThread()); 1311 DCHECK(CalledOnValidThread());
1291 return CanPrefetchAndPrerenderUI(profile_->GetPrefs()); 1312 return CanPrefetchAndPrerenderUI(profile_->GetPrefs());
1292 } 1313 }
1293 1314
1315 NetworkPredictionStatus PrerenderManager::GetPredictionStatusForOrigin(
1316 Origin origin) const {
1317 DCHECK(CalledOnValidThread());
1318 NetworkPredictionStatus prediction_status =
1319 CanPrefetchAndPrerenderUI(profile_->GetPrefs());
1320 if (prediction_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK
1321 && origin == ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR) {
1322 prediction_status = NetworkPredictionStatus::ENABLED;
1323 }
1324 return prediction_status;
1325 }
1326
1294 void PrerenderManager::AddProfileNetworkBytesIfEnabled(int64_t bytes) { 1327 void PrerenderManager::AddProfileNetworkBytesIfEnabled(int64_t bytes) {
1295 DCHECK_GE(bytes, 0); 1328 DCHECK_GE(bytes, 0);
1296 if (GetPredictionStatus() == NetworkPredictionStatus::ENABLED && 1329 if (GetPredictionStatus() == NetworkPredictionStatus::ENABLED &&
1297 ActuallyPrerendering()) 1330 ActuallyPrerendering())
1298 profile_network_bytes_ += bytes; 1331 profile_network_bytes_ += bytes;
1299 } 1332 }
1300 1333
1301 void PrerenderManager::AddPrerenderProcessHost( 1334 void PrerenderManager::AddPrerenderProcessHost(
1302 content::RenderProcessHost* process_host) { 1335 content::RenderProcessHost* process_host) {
1303 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1336 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 13 matching lines...) Expand all
1317 } 1350 }
1318 1351
1319 void PrerenderManager::RenderProcessHostDestroyed( 1352 void PrerenderManager::RenderProcessHostDestroyed(
1320 content::RenderProcessHost* host) { 1353 content::RenderProcessHost* host) {
1321 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1354 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1322 size_t erased = prerender_process_hosts_.erase(host); 1355 size_t erased = prerender_process_hosts_.erase(host);
1323 DCHECK_EQ(1u, erased); 1356 DCHECK_EQ(1u, erased);
1324 } 1357 }
1325 1358
1326 } // namespace prerender 1359 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_manager.h ('k') | chrome/browser/prerender/prerender_origin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698