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

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

Issue 1854643002: Implement PrerenderManager::AddPrerenderForOffline() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses mmenke's comments Created 4 years, 8 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 318
319 PrerenderHandle* PrerenderManager::AddPrerenderForInstant( 319 PrerenderHandle* PrerenderManager::AddPrerenderForInstant(
320 const GURL& url, 320 const GURL& url,
321 content::SessionStorageNamespace* session_storage_namespace, 321 content::SessionStorageNamespace* session_storage_namespace,
322 const gfx::Size& size) { 322 const gfx::Size& size) {
323 DCHECK(search::ShouldPrefetchSearchResults()); 323 DCHECK(search::ShouldPrefetchSearchResults());
324 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size, 324 return AddPrerender(ORIGIN_INSTANT, url, content::Referrer(), size,
325 session_storage_namespace); 325 session_storage_namespace);
326 } 326 }
327 327
328 PrerenderHandle* PrerenderManager::AddPrerenderForOffline(
329 const GURL& url,
330 content::SessionStorageNamespace* session_storage_namespace,
331 const gfx::Size& size) {
332 return AddPrerender(ORIGIN_OFFLINE, url, content::Referrer(), size,
333 session_storage_namespace);
334 }
335
328 void PrerenderManager::CancelAllPrerenders() { 336 void PrerenderManager::CancelAllPrerenders() {
329 DCHECK(CalledOnValidThread()); 337 DCHECK(CalledOnValidThread());
330 while (!active_prerenders_.empty()) { 338 while (!active_prerenders_.empty()) {
331 PrerenderContents* prerender_contents = 339 PrerenderContents* prerender_contents =
332 active_prerenders_.front()->contents(); 340 active_prerenders_.front()->contents();
333 prerender_contents->Destroy(FINAL_STATUS_CANCELLED); 341 prerender_contents->Destroy(FINAL_STATUS_CANCELLED);
334 } 342 }
335 } 343 }
336 344
337 bool PrerenderManager::MaybeUsePrerenderedPage(const GURL& url, 345 bool PrerenderManager::MaybeUsePrerenderedPage(const GURL& url,
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 // Schedule the delete to occur after the tab has run its unload handlers. 533 // Schedule the delete to occur after the tab has run its unload handlers.
526 // TODO(davidben): Honor the beforeunload event. http://crbug.com/304932 534 // TODO(davidben): Honor the beforeunload event. http://crbug.com/304932
527 on_close_web_contents_deleters_.push_back( 535 on_close_web_contents_deleters_.push_back(
528 new OnCloseWebContentsDeleter(this, old_web_contents)); 536 new OnCloseWebContentsDeleter(this, old_web_contents));
529 old_web_contents->DispatchBeforeUnload(false); 537 old_web_contents->DispatchBeforeUnload(false);
530 } else { 538 } else {
531 // No unload handler to run, so delete asap. 539 // No unload handler to run, so delete asap.
532 ScheduleDeleteOldWebContents(old_web_contents, NULL); 540 ScheduleDeleteOldWebContents(old_web_contents, NULL);
533 } 541 }
534 542
543 // Offline originated prerenders should never ever be swapped-in.
544 CHECK_NE(ORIGIN_OFFLINE, prerender_contents->origin());
pasko 2016/04/25 11:29:11 This comment does not propose to change anything,
gabadie 2016/04/25 12:35:11 I have uploaded a new CL that removed that CHECK,
545
535 // TODO(cbentzel): Should prerender_contents move to the pending delete 546 // TODO(cbentzel): Should prerender_contents move to the pending delete
536 // list, instead of deleting directly here? 547 // list, instead of deleting directly here?
537 AddToHistory(prerender_contents.get()); 548 AddToHistory(prerender_contents.get());
538 RecordNavigation(url); 549 RecordNavigation(url);
539 return new_web_contents; 550 return new_web_contents;
540 } 551 }
541 552
542 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry, 553 void PrerenderManager::MoveEntryToPendingDelete(PrerenderContents* entry,
543 FinalStatus final_status) { 554 FinalStatus final_status) {
544 DCHECK(CalledOnValidThread()); 555 DCHECK(CalledOnValidThread());
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 960
950 GURL url = url_arg; 961 GURL url = url_arg;
951 GURL alias_url; 962 GURL alias_url;
952 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url)) 963 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url))
953 url = alias_url; 964 url = alias_url;
954 965
955 // From here on, we will record a FinalStatus so we need to register with the 966 // From here on, we will record a FinalStatus so we need to register with the
956 // histogram tracking. 967 // histogram tracking.
957 histograms_->RecordPrerender(origin, url_arg); 968 histograms_->RecordPrerender(origin, url_arg);
958 969
959 if (profile_->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies)) { 970 if (profile_->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies) &&
971 origin != ORIGIN_OFFLINE) {
960 RecordFinalStatusWithoutCreatingPrerenderContents( 972 RecordFinalStatusWithoutCreatingPrerenderContents(
961 url, origin, FINAL_STATUS_BLOCK_THIRD_PARTY_COOKIES); 973 url, origin, FINAL_STATUS_BLOCK_THIRD_PARTY_COOKIES);
962 return nullptr; 974 return nullptr;
963 } 975 }
964 976
965 NetworkPredictionStatus prerendering_status = 977 NetworkPredictionStatus prerendering_status =
966 GetPredictionStatusForOrigin(origin); 978 GetPredictionStatusForOrigin(origin);
967 if (prerendering_status != NetworkPredictionStatus::ENABLED) { 979 if (prerendering_status != NetworkPredictionStatus::ENABLED) {
968 FinalStatus final_status = 980 FinalStatus final_status =
969 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK 981 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 return it; 1179 return it;
1168 } 1180 }
1169 return active_prerenders_.end(); 1181 return active_prerenders_.end();
1170 } 1182 }
1171 1183
1172 bool PrerenderManager::DoesRateLimitAllowPrerender(Origin origin) const { 1184 bool PrerenderManager::DoesRateLimitAllowPrerender(Origin origin) const {
1173 DCHECK(CalledOnValidThread()); 1185 DCHECK(CalledOnValidThread());
1174 base::TimeDelta elapsed_time = 1186 base::TimeDelta elapsed_time =
1175 GetCurrentTimeTicks() - last_prerender_start_time_; 1187 GetCurrentTimeTicks() - last_prerender_start_time_;
1176 histograms_->RecordTimeBetweenPrerenderRequests(origin, elapsed_time); 1188 histograms_->RecordTimeBetweenPrerenderRequests(origin, elapsed_time);
1189 // TODO(gabadie,pasko): Re-implement missing tests for
1190 // FINAL_STATUS_RATE_LIMIT_EXCEEDED that where removed by:
1191 // http://crrev.com/a2439eeab37f7cb7a118493fb55ec0cb07f93b49.
1192 if (origin == ORIGIN_OFFLINE)
1193 return true;
1177 if (!config_.rate_limit_enabled) 1194 if (!config_.rate_limit_enabled)
1178 return true; 1195 return true;
1179 return elapsed_time >= 1196 return elapsed_time >=
1180 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs); 1197 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs);
1181 } 1198 }
1182 1199
1183 void PrerenderManager::DeleteOldWebContents() { 1200 void PrerenderManager::DeleteOldWebContents() {
1184 while (!old_web_contents_list_.empty()) { 1201 while (!old_web_contents_list_.empty()) {
1185 WebContents* web_contents = old_web_contents_list_.front(); 1202 WebContents* web_contents = old_web_contents_list_.front();
1186 old_web_contents_list_.pop_front(); 1203 old_web_contents_list_.pop_front();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 1326
1310 NetworkPredictionStatus PrerenderManager::GetPredictionStatus() const { 1327 NetworkPredictionStatus PrerenderManager::GetPredictionStatus() const {
1311 DCHECK(CalledOnValidThread()); 1328 DCHECK(CalledOnValidThread());
1312 return CanPrefetchAndPrerenderUI(profile_->GetPrefs()); 1329 return CanPrefetchAndPrerenderUI(profile_->GetPrefs());
1313 } 1330 }
1314 1331
1315 NetworkPredictionStatus PrerenderManager::GetPredictionStatusForOrigin( 1332 NetworkPredictionStatus PrerenderManager::GetPredictionStatusForOrigin(
1316 Origin origin) const { 1333 Origin origin) const {
1317 DCHECK(CalledOnValidThread()); 1334 DCHECK(CalledOnValidThread());
1318 1335
1319 // LINK rel=prerender origins ignore the network state and the privacy 1336 // <link rel=prerender> origins ignore the network state and the privacy
1320 // settings. 1337 // settings. Web developers should be able prefetch with all possible privacy
1338 // settings and with all possible network types. This would avoid web devs
1339 // coming up with creative ways to prefetch in cases they are not allowed to
1340 // do so.
1341 //
1342 // Offline originated prerenders also ignore the network state and privacy
1343 // settings because they are controlled by the offliner logic via
1344 // PrerenderHandle.
1321 if (origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN || 1345 if (origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN ||
1322 origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN) { 1346 origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN ||
1347 origin == ORIGIN_OFFLINE) {
1323 return NetworkPredictionStatus::ENABLED; 1348 return NetworkPredictionStatus::ENABLED;
1324 } 1349 }
1325 1350
1326 // Prerendering forced for cellular networks still prevents navigation with 1351 // Prerendering forced for cellular networks still prevents navigation with
1327 // the DISABLED_ALWAYS selected via privacy settings. 1352 // the DISABLED_ALWAYS selected via privacy settings.
1328 NetworkPredictionStatus prediction_status = 1353 NetworkPredictionStatus prediction_status =
1329 CanPrefetchAndPrerenderUI(profile_->GetPrefs()); 1354 CanPrefetchAndPrerenderUI(profile_->GetPrefs());
1330 if (origin == ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR && 1355 if (origin == ORIGIN_EXTERNAL_REQUEST_FORCED_CELLULAR &&
1331 prediction_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK) { 1356 prediction_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK) {
1332 return NetworkPredictionStatus::ENABLED; 1357 return NetworkPredictionStatus::ENABLED;
(...skipping 27 matching lines...) Expand all
1360 } 1385 }
1361 1386
1362 void PrerenderManager::RenderProcessHostDestroyed( 1387 void PrerenderManager::RenderProcessHostDestroyed(
1363 content::RenderProcessHost* host) { 1388 content::RenderProcessHost* host) {
1364 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1389 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1365 size_t erased = prerender_process_hosts_.erase(host); 1390 size_t erased = prerender_process_hosts_.erase(host);
1366 DCHECK_EQ(1u, erased); 1391 DCHECK_EQ(1u, erased);
1367 } 1392 }
1368 1393
1369 } // namespace prerender 1394 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698