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

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: Renaming nits 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
mmenke 2016/03/14 20:38:01 This is weird, for a couple reasons: * This metho
Yusuf 2016/03/14 23:08:19 Done. Added AddPrerenderOnCellularFromExternalRequ
302 session_storage_namespace); 302 Origin origin = prerender_on_mobile
303 ? ORIGIN_EXTERNAL_REQUEST_FORCED_CUSTOMTABS
mmenke 2016/03/14 20:38:01 Mapping "prerender_on_mobile == true" to "ORIGIN_E
Yusuf 2016/03/14 23:08:20 Done.
304 : ORIGIN_EXTERNAL_REQUEST;
305 return AddPrerender(origin, url, referrer, size, session_storage_namespace);
303 } 306 }
304 307
305 PrerenderHandle* PrerenderManager::AddPrerenderForInstant( 308 PrerenderHandle* PrerenderManager::AddPrerenderForInstant(
306 const GURL& url, 309 const GURL& url,
307 content::SessionStorageNamespace* session_storage_namespace, 310 content::SessionStorageNamespace* session_storage_namespace,
308 const gfx::Size& size) { 311 const gfx::Size& size) {
309 DCHECK(search::ShouldPrefetchSearchResults()); 312 DCHECK(search::ShouldPrefetchSearchResults());
310 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size, 313 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size,
311 session_storage_namespace); 314 session_storage_namespace);
312 } 315 }
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 bool PrerenderManager::DoesSubresourceURLHaveValidScheme(const GURL& url) { 784 bool PrerenderManager::DoesSubresourceURLHaveValidScheme(const GURL& url) {
782 return DoesURLHaveValidScheme(url) || url == GURL(url::kAboutBlankURL); 785 return DoesURLHaveValidScheme(url) || url == GURL(url::kAboutBlankURL);
783 } 786 }
784 787
785 base::DictionaryValue* PrerenderManager::GetAsValue() const { 788 base::DictionaryValue* PrerenderManager::GetAsValue() const {
786 DCHECK(CalledOnValidThread()); 789 DCHECK(CalledOnValidThread());
787 base::DictionaryValue* dict_value = new base::DictionaryValue(); 790 base::DictionaryValue* dict_value = new base::DictionaryValue();
788 dict_value->Set("history", prerender_history_->GetEntriesAsValue()); 791 dict_value->Set("history", prerender_history_->GetEntriesAsValue());
789 dict_value->Set("active", GetActivePrerendersAsValue()); 792 dict_value->Set("active", GetActivePrerendersAsValue());
790 dict_value->SetBoolean("enabled", 793 dict_value->SetBoolean("enabled",
791 GetPredictionStatus() == NetworkPredictionStatus::ENABLED); 794 GetPredictionStatus() == NetworkPredictionStatus::ENABLED);
mmenke 2016/03/14 20:38:01 The reason for disabling seems more relevant here,
Yusuf 2016/03/14 23:08:20 By three states do you mean NetworkPredictionStatu
mmenke 2016/03/15 14:34:21 The two other pre-existing calls to GetPredictionS
Yusuf 2016/03/20 06:48:29 Done. Added a disabled note. Removed two calls to
792 dict_value->SetBoolean("omnibox_enabled", IsOmniboxEnabled(profile_)); 795 dict_value->SetBoolean("omnibox_enabled", IsOmniboxEnabled(profile_));
793 // If prerender is disabled via a flag this method is not even called. 796 // If prerender is disabled via a flag this method is not even called.
794 std::string enabled_note; 797 std::string enabled_note;
795 if (IsControlGroup()) 798 if (IsControlGroup())
796 enabled_note += "(Control group: Not actually prerendering) "; 799 enabled_note += "(Control group: Not actually prerendering) ";
797 if (IsNoUseGroup()) 800 if (IsNoUseGroup())
798 enabled_note += "(No-use group: Not swapping in prerendered pages) "; 801 enabled_note += "(No-use group: Not swapping in prerendered pages) ";
799 if (GetMode() == PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP) 802 if (GetMode() == PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP)
800 enabled_note += 803 enabled_note +=
801 "(15 min TTL group: Extended prerender eviction to 15 mins) "; 804 "(15 min TTL group: Extended prerender eviction to 15 mins) ";
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 930
928 GURL url = url_arg; 931 GURL url = url_arg;
929 GURL alias_url; 932 GURL alias_url;
930 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url)) 933 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url))
931 url = alias_url; 934 url = alias_url;
932 935
933 // From here on, we will record a FinalStatus so we need to register with the 936 // From here on, we will record a FinalStatus so we need to register with the
934 // histogram tracking. 937 // histogram tracking.
935 histograms_->RecordPrerender(origin, url_arg); 938 histograms_->RecordPrerender(origin, url_arg);
936 939
937 NetworkPredictionStatus prerendering_status = GetPredictionStatus(); 940 NetworkPredictionStatus prerendering_status =
941 GetPredictionStatusForOrigin(origin);
938 if (prerendering_status != NetworkPredictionStatus::ENABLED) { 942 if (prerendering_status != NetworkPredictionStatus::ENABLED) {
939 FinalStatus final_status = 943 FinalStatus final_status =
940 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK 944 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK
941 ? FINAL_STATUS_CELLULAR_NETWORK 945 ? FINAL_STATUS_CELLULAR_NETWORK
942 : FINAL_STATUS_PRERENDERING_DISABLED; 946 : FINAL_STATUS_PRERENDERING_DISABLED;
943 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin, 947 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin,
944 final_status); 948 final_status);
945 return nullptr; 949 return nullptr;
946 } 950 }
947 951
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 DCHECK_GE(recent_profile_bytes, 0); 1282 DCHECK_GE(recent_profile_bytes, 0);
1279 histograms_->RecordNetworkBytes( 1283 histograms_->RecordNetworkBytes(
1280 origin, used, prerender_bytes, recent_profile_bytes); 1284 origin, used, prerender_bytes, recent_profile_bytes);
1281 } 1285 }
1282 1286
1283 NetworkPredictionStatus PrerenderManager::GetPredictionStatus() const { 1287 NetworkPredictionStatus PrerenderManager::GetPredictionStatus() const {
1284 DCHECK(CalledOnValidThread()); 1288 DCHECK(CalledOnValidThread());
1285 return CanPrefetchAndPrerenderUI(profile_->GetPrefs()); 1289 return CanPrefetchAndPrerenderUI(profile_->GetPrefs());
1286 } 1290 }
1287 1291
1292 NetworkPredictionStatus PrerenderManager::GetPredictionStatusForOrigin(
1293 Origin origin) const {
1294 NetworkPredictionStatus prediction_status = GetPredictionStatus();
1295 if (prediction_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK
1296 && origin == ORIGIN_EXTERNAL_REQUEST_FORCED_CUSTOMTABS) {
mmenke 2016/03/14 20:38:01 Do we really want to do this? How large are AMP p
Yusuf 2016/03/14 23:08:20 AMP in general is pretty cheap. On our end, we nev
1297 prediction_status = NetworkPredictionStatus::ENABLED;
1298 }
1299 return prediction_status;
1300 }
1301
1288 void PrerenderManager::AddProfileNetworkBytesIfEnabled(int64_t bytes) { 1302 void PrerenderManager::AddProfileNetworkBytesIfEnabled(int64_t bytes) {
1289 DCHECK_GE(bytes, 0); 1303 DCHECK_GE(bytes, 0);
1290 if (GetPredictionStatus() == NetworkPredictionStatus::ENABLED && 1304 if (GetPredictionStatus() == NetworkPredictionStatus::ENABLED &&
1291 ActuallyPrerendering()) 1305 ActuallyPrerendering())
1292 profile_network_bytes_ += bytes; 1306 profile_network_bytes_ += bytes;
1293 } 1307 }
1294 1308
1295 void PrerenderManager::AddPrerenderProcessHost( 1309 void PrerenderManager::AddPrerenderProcessHost(
1296 content::RenderProcessHost* process_host) { 1310 content::RenderProcessHost* process_host) {
1297 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1311 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 13 matching lines...) Expand all
1311 } 1325 }
1312 1326
1313 void PrerenderManager::RenderProcessHostDestroyed( 1327 void PrerenderManager::RenderProcessHostDestroyed(
1314 content::RenderProcessHost* host) { 1328 content::RenderProcessHost* host) {
1315 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1329 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1316 size_t erased = prerender_process_hosts_.erase(host); 1330 size_t erased = prerender_process_hosts_.erase(host);
1317 DCHECK_EQ(1u, erased); 1331 DCHECK_EQ(1u, erased);
1318 } 1332 }
1319 1333
1320 } // namespace prerender 1334 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698