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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 void PrerenderManager::Shutdown() { | 262 void PrerenderManager::Shutdown() { |
263 DoShutdown(); | 263 DoShutdown(); |
264 } | 264 } |
265 | 265 |
266 bool PrerenderManager::AddPrerenderFromLinkRelPrerender( | 266 bool PrerenderManager::AddPrerenderFromLinkRelPrerender( |
267 int process_id, | 267 int process_id, |
268 int route_id, | 268 int route_id, |
269 const GURL& url, | 269 const GURL& url, |
270 const content::Referrer& referrer) { | 270 const content::Referrer& referrer) { |
| 271 #if defined(OS_ANDROID) |
| 272 // TODO(jcivelli): http://crbug.com/113322 We should have an option to disable |
| 273 // link-prerender and enable omnibox-prerender only. |
| 274 return false; |
| 275 #else |
271 std::pair<int, int> child_route_id_pair = std::make_pair(process_id, | 276 std::pair<int, int> child_route_id_pair = std::make_pair(process_id, |
272 route_id); | 277 route_id); |
273 | 278 |
274 return AddPrerender(ORIGIN_LINK_REL_PRERENDER, child_route_id_pair, | 279 return AddPrerender(ORIGIN_LINK_REL_PRERENDER, child_route_id_pair, |
275 url, referrer, NULL); | 280 url, referrer, NULL); |
| 281 #endif |
276 } | 282 } |
277 | 283 |
278 bool PrerenderManager::AddPrerenderFromOmnibox( | 284 bool PrerenderManager::AddPrerenderFromOmnibox( |
279 const GURL& url, | 285 const GURL& url, |
280 SessionStorageNamespace* session_storage_namespace) { | 286 SessionStorageNamespace* session_storage_namespace) { |
281 if (!IsOmniboxEnabled(profile_)) | 287 if (!IsOmniboxEnabled(profile_)) |
282 return false; | 288 return false; |
283 return AddPrerender(ORIGIN_OMNIBOX, std::make_pair(-1, -1), url, | 289 return AddPrerender(ORIGIN_OMNIBOX, std::make_pair(-1, -1), url, |
284 content::Referrer(), session_storage_namespace); | 290 content::Referrer(), session_storage_namespace); |
285 } | 291 } |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 TabContentsWrapper* prerender_tab_contents_wrapper = | 633 TabContentsWrapper* prerender_tab_contents_wrapper = |
628 (*it)->prerender_contents(); | 634 (*it)->prerender_contents(); |
629 if (prerender_tab_contents_wrapper && | 635 if (prerender_tab_contents_wrapper && |
630 prerender_tab_contents_wrapper->web_contents() == web_contents) | 636 prerender_tab_contents_wrapper->web_contents() == web_contents) |
631 return true; | 637 return true; |
632 } | 638 } |
633 | 639 |
634 return false; | 640 return false; |
635 } | 641 } |
636 | 642 |
| 643 bool PrerenderManager::DidPrerenderFinishLoading(const GURL& url) const { |
| 644 DCHECK(CalledOnValidThread()); |
| 645 PrerenderContents* contents = FindEntry(url); |
| 646 return contents ? contents->has_finished_loading() : false; |
| 647 } |
| 648 |
637 void PrerenderManager::MarkWebContentsAsPrerendered(WebContents* web_contents) { | 649 void PrerenderManager::MarkWebContentsAsPrerendered(WebContents* web_contents) { |
638 DCHECK(CalledOnValidThread()); | 650 DCHECK(CalledOnValidThread()); |
639 prerendered_tab_contents_set_.insert(web_contents); | 651 prerendered_tab_contents_set_.insert(web_contents); |
640 } | 652 } |
641 | 653 |
642 void PrerenderManager::MarkWebContentsAsWouldBePrerendered( | 654 void PrerenderManager::MarkWebContentsAsWouldBePrerendered( |
643 WebContents* web_contents) { | 655 WebContents* web_contents) { |
644 DCHECK(CalledOnValidThread()); | 656 DCHECK(CalledOnValidThread()); |
645 would_be_prerendered_tab_contents_set_.insert(web_contents); | 657 would_be_prerendered_tab_contents_set_.insert(web_contents); |
646 } | 658 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 } | 833 } |
822 | 834 |
823 // Do not prerender if there are too many render processes, and we would | 835 // Do not prerender if there are too many render processes, and we would |
824 // have to use an existing one. We do not want prerendering to happen in | 836 // have to use an existing one. We do not want prerendering to happen in |
825 // a shared process, so that we can always reliably lower the CPU | 837 // a shared process, so that we can always reliably lower the CPU |
826 // priority for prerendering. | 838 // priority for prerendering. |
827 // In single-process mode, ShouldTryToUseExistingProcessHost() always returns | 839 // In single-process mode, ShouldTryToUseExistingProcessHost() always returns |
828 // true, so that case needs to be explicitly checked for. | 840 // true, so that case needs to be explicitly checked for. |
829 // TODO(tburkard): Figure out how to cancel prerendering in the opposite | 841 // TODO(tburkard): Figure out how to cancel prerendering in the opposite |
830 // case, when a new tab is added to a process used for prerendering. | 842 // case, when a new tab is added to a process used for prerendering. |
| 843 // On Android we do reuse processes as we have a limited number of them and we |
| 844 // still want the benefits of prerendering even when several tabs are open. |
| 845 #if !defined(OS_ANDROID) |
831 if (content::RenderProcessHost::ShouldTryToUseExistingProcessHost() && | 846 if (content::RenderProcessHost::ShouldTryToUseExistingProcessHost() && |
832 !content::RenderProcessHost::run_renderer_in_process()) { | 847 !content::RenderProcessHost::run_renderer_in_process()) { |
833 RecordFinalStatus(origin, experiment, FINAL_STATUS_TOO_MANY_PROCESSES); | 848 RecordFinalStatus(origin, experiment, FINAL_STATUS_TOO_MANY_PROCESSES); |
834 return false; | 849 return false; |
835 } | 850 } |
| 851 #endif |
836 | 852 |
837 // Check if enough time has passed since the last prerender. | 853 // Check if enough time has passed since the last prerender. |
838 if (!DoesRateLimitAllowPrerender()) { | 854 if (!DoesRateLimitAllowPrerender()) { |
839 // Cancel the prerender. We could add it to the pending prerender list but | 855 // Cancel the prerender. We could add it to the pending prerender list but |
840 // this doesn't make sense as the next prerender request will be triggered | 856 // this doesn't make sense as the next prerender request will be triggered |
841 // by a navigation and is unlikely to be the same site. | 857 // by a navigation and is unlikely to be the same site. |
842 RecordFinalStatus(origin, experiment, FINAL_STATUS_RATE_LIMIT_EXCEEDED); | 858 RecordFinalStatus(origin, experiment, FINAL_STATUS_RATE_LIMIT_EXCEEDED); |
843 return false; | 859 return false; |
844 } | 860 } |
845 | 861 |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 if (!render_process_host || !render_process_host->GetBrowserContext()) | 1192 if (!render_process_host || !render_process_host->GetBrowserContext()) |
1177 return NULL; | 1193 return NULL; |
1178 Profile* profile = Profile::FromBrowserContext( | 1194 Profile* profile = Profile::FromBrowserContext( |
1179 render_process_host->GetBrowserContext()); | 1195 render_process_host->GetBrowserContext()); |
1180 if (!profile) | 1196 if (!profile) |
1181 return NULL; | 1197 return NULL; |
1182 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1198 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
1183 } | 1199 } |
1184 | 1200 |
1185 } // namespace prerender | 1201 } // namespace prerender |
OLD | NEW |