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 <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 // Check if enough time has passed since the last prerender. | 1311 // Check if enough time has passed since the last prerender. |
1312 if (!DoesRateLimitAllowPrerender(origin)) { | 1312 if (!DoesRateLimitAllowPrerender(origin)) { |
1313 // Cancel the prerender. We could add it to the pending prerender list but | 1313 // Cancel the prerender. We could add it to the pending prerender list but |
1314 // this doesn't make sense as the next prerender request will be triggered | 1314 // this doesn't make sense as the next prerender request will be triggered |
1315 // by a navigation and is unlikely to be the same site. | 1315 // by a navigation and is unlikely to be the same site. |
1316 RecordFinalStatusWithoutCreatingPrerenderContents( | 1316 RecordFinalStatusWithoutCreatingPrerenderContents( |
1317 url, origin, experiment, FINAL_STATUS_RATE_LIMIT_EXCEEDED); | 1317 url, origin, experiment, FINAL_STATUS_RATE_LIMIT_EXCEEDED); |
1318 return NULL; | 1318 return NULL; |
1319 } | 1319 } |
1320 | 1320 |
1321 if (!cookie_store_loaded()) { | 1321 if (IsPrerenderCookieStoreEnabled() && !cookie_store_loaded()) { |
1322 // Only prerender if the cookie store for this profile has been loaded. | 1322 // Only prerender if the cookie store for this profile has been loaded. |
1323 // This is required by PrerenderCookieMonster. | 1323 // This is required by PrerenderCookieMonster. |
1324 RecordFinalStatusWithoutCreatingPrerenderContents( | 1324 RecordFinalStatusWithoutCreatingPrerenderContents( |
1325 url, origin, experiment, FINAL_STATUS_COOKIE_STORE_NOT_LOADED); | 1325 url, origin, experiment, FINAL_STATUS_COOKIE_STORE_NOT_LOADED); |
1326 return NULL; | 1326 return NULL; |
1327 } | 1327 } |
1328 | 1328 |
1329 PrerenderContents* prerender_contents = CreatePrerenderContents( | 1329 PrerenderContents* prerender_contents = CreatePrerenderContents( |
1330 url, referrer, origin, experiment); | 1330 url, referrer, origin, experiment); |
1331 DCHECK(prerender_contents); | 1331 DCHECK(prerender_contents); |
(...skipping 11 matching lines...) Expand all Loading... |
1343 | 1343 |
1344 PrerenderHandle* prerender_handle = | 1344 PrerenderHandle* prerender_handle = |
1345 new PrerenderHandle(active_prerenders_.back()); | 1345 new PrerenderHandle(active_prerenders_.back()); |
1346 SortActivePrerenders(); | 1346 SortActivePrerenders(); |
1347 | 1347 |
1348 last_prerender_start_time_ = GetCurrentTimeTicks(); | 1348 last_prerender_start_time_ = GetCurrentTimeTicks(); |
1349 | 1349 |
1350 gfx::Size contents_size = | 1350 gfx::Size contents_size = |
1351 size.IsEmpty() ? config_.default_tab_bounds.size() : size; | 1351 size.IsEmpty() ? config_.default_tab_bounds.size() : size; |
1352 | 1352 |
1353 net::URLRequestContextGetter* request_context = GetURLRequestContext(); | 1353 net::URLRequestContextGetter* request_context = |
| 1354 (IsPrerenderCookieStoreEnabled() ? GetURLRequestContext() : NULL); |
1354 | 1355 |
1355 prerender_contents->StartPrerendering(process_id, contents_size, | 1356 prerender_contents->StartPrerendering(process_id, contents_size, |
1356 session_storage_namespace, | 1357 session_storage_namespace, |
1357 request_context); | 1358 request_context); |
1358 | 1359 |
1359 DCHECK(IsControlGroup(experiment) || | 1360 DCHECK(IsControlGroup(experiment) || |
1360 prerender_contents->prerendering_has_started() || | 1361 prerender_contents->prerendering_has_started() || |
1361 (origin == ORIGIN_LOCAL_PREDICTOR && | 1362 (origin == ORIGIN_LOCAL_PREDICTOR && |
1362 IsLocalPredictorPrerenderAlwaysControlEnabled())); | 1363 IsLocalPredictorPrerenderAlwaysControlEnabled())); |
1363 | 1364 |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 | 1891 |
1891 void PrerenderManager::AddPrerenderProcessHost( | 1892 void PrerenderManager::AddPrerenderProcessHost( |
1892 content::RenderProcessHost* process_host) { | 1893 content::RenderProcessHost* process_host) { |
1893 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1894 DCHECK(prerender_process_hosts_.find(process_host) == | 1895 DCHECK(prerender_process_hosts_.find(process_host) == |
1895 prerender_process_hosts_.end()); | 1896 prerender_process_hosts_.end()); |
1896 prerender_process_hosts_.insert(process_host); | 1897 prerender_process_hosts_.insert(process_host); |
1897 process_host->AddObserver(this); | 1898 process_host->AddObserver(this); |
1898 } | 1899 } |
1899 | 1900 |
1900 bool PrerenderManager::IsProcessPrerendering( | 1901 bool PrerenderManager::MayReuseProcessHost( |
1901 content::RenderProcessHost* process_host) { | 1902 content::RenderProcessHost* process_host) { |
1902 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1903 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1903 return (prerender_process_hosts_.find(process_host) != | 1904 // If prerender cookie stores are disabled, there is no need to require |
| 1905 // isolated prerender processes. |
| 1906 if (!IsPrerenderCookieStoreEnabled()) |
| 1907 return true; |
| 1908 return (prerender_process_hosts_.find(process_host) == |
1904 prerender_process_hosts_.end()); | 1909 prerender_process_hosts_.end()); |
1905 } | 1910 } |
1906 | 1911 |
1907 void PrerenderManager::RenderProcessHostDestroyed( | 1912 void PrerenderManager::RenderProcessHostDestroyed( |
1908 content::RenderProcessHost* host) { | 1913 content::RenderProcessHost* host) { |
1909 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1914 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1910 prerender_process_hosts_.erase(host); | 1915 prerender_process_hosts_.erase(host); |
1911 BrowserThread::PostTask( | 1916 BrowserThread::PostTask( |
1912 BrowserThread::IO, FROM_HERE, | 1917 BrowserThread::IO, FROM_HERE, |
1913 base::Bind(&PrerenderTracker::RemovePrerenderCookieStoreOnIOThread, | 1918 base::Bind(&PrerenderTracker::RemovePrerenderCookieStoreOnIOThread, |
1914 base::Unretained(prerender_tracker()), host->GetID(), false)); | 1919 base::Unretained(prerender_tracker()), host->GetID(), false)); |
1915 } | 1920 } |
1916 | 1921 |
1917 } // namespace prerender | 1922 } // namespace prerender |
OLD | NEW |