OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 } | 499 } |
500 | 500 |
501 bool PrerenderManager::MaybeUsePreloadedPage(TabContents* tab_contents, | 501 bool PrerenderManager::MaybeUsePreloadedPage(TabContents* tab_contents, |
502 const GURL& url) { | 502 const GURL& url) { |
503 if (!PrerenderContents::UseTabContents()) { | 503 if (!PrerenderContents::UseTabContents()) { |
504 VLOG(1) << "Checking for prerender with LEGACY code"; | 504 VLOG(1) << "Checking for prerender with LEGACY code"; |
505 return PrerenderManager::MaybeUsePreloadedPageOld(tab_contents, url); | 505 return PrerenderManager::MaybeUsePreloadedPageOld(tab_contents, url); |
506 } | 506 } |
507 VLOG(1) << "Checking for prerender with NEW code"; | 507 VLOG(1) << "Checking for prerender with NEW code"; |
508 DCHECK(CalledOnValidThread()); | 508 DCHECK(CalledOnValidThread()); |
| 509 |
509 scoped_ptr<PrerenderContents> prerender_contents( | 510 scoped_ptr<PrerenderContents> prerender_contents( |
510 GetEntryButNotSpecifiedTC(url, tab_contents)); | 511 GetEntryButNotSpecifiedTC(url, tab_contents)); |
511 if (prerender_contents.get() == NULL) | 512 if (prerender_contents.get() == NULL) |
512 return false; | 513 return false; |
513 | 514 |
514 // If we are just in the control group (which can be detected by noticing | 515 // If we are just in the control group (which can be detected by noticing |
515 // that prerendering hasn't even started yet), record that |tab_contents| now | 516 // that prerendering hasn't even started yet), record that |tab_contents| now |
516 // would be showing a prerendered contents, but otherwise, don't do anything. | 517 // would be showing a prerendered contents, but otherwise, don't do anything. |
517 if (!prerender_contents->prerendering_has_started()) { | 518 if (!prerender_contents->prerendering_has_started()) { |
518 MarkTabContentsAsWouldBePrerendered(tab_contents); | 519 MarkTabContentsAsWouldBePrerendered(tab_contents); |
(...skipping 27 matching lines...) Expand all Loading... |
546 DCHECK(old_tab_contents); | 547 DCHECK(old_tab_contents); |
547 | 548 |
548 MarkTabContentsAsPrerendered(new_tab_contents->tab_contents()); | 549 MarkTabContentsAsPrerendered(new_tab_contents->tab_contents()); |
549 | 550 |
550 // Merge the browsing history. | 551 // Merge the browsing history. |
551 new_tab_contents->controller().CopyStateFromAndPrune( | 552 new_tab_contents->controller().CopyStateFromAndPrune( |
552 &old_tab_contents->controller(), | 553 &old_tab_contents->controller(), |
553 false); | 554 false); |
554 old_tab_contents->delegate()->SwapTabContents(old_tab_contents, | 555 old_tab_contents->delegate()->SwapTabContents(old_tab_contents, |
555 new_tab_contents); | 556 new_tab_contents); |
556 | |
557 // See if we have any pending prerender requests for this routing id and start | 557 // See if we have any pending prerender requests for this routing id and start |
558 // the preload if we do. | 558 // the preload if we do. |
559 std::pair<int, int> child_route_pair = std::make_pair(child_id, route_id); | 559 std::pair<int, int> child_route_pair = std::make_pair(child_id, route_id); |
560 PendingPrerenderList::iterator pending_it = | 560 PendingPrerenderList::iterator pending_it = |
561 pending_prerender_list_.find(child_route_pair); | 561 pending_prerender_list_.find(child_route_pair); |
562 if (pending_it != pending_prerender_list_.end()) { | 562 if (pending_it != pending_prerender_list_.end()) { |
563 for (std::vector<PendingContentsData>::iterator content_it = | 563 for (std::vector<PendingContentsData>::iterator content_it = |
564 pending_it->second.begin(); | 564 pending_it->second.begin(); |
565 content_it != pending_it->second.end(); ++content_it) { | 565 content_it != pending_it->second.end(); ++content_it) { |
566 AddPreload(pending_it->first, content_it->url_, content_it->referrer_); | 566 AddPreload(pending_it->first, content_it->url_, content_it->referrer_); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 return prerendered_tab_contents_set_.count(tab_contents) > 0; | 912 return prerendered_tab_contents_set_.count(tab_contents) > 0; |
913 } | 913 } |
914 | 914 |
915 bool PrerenderManager::WouldTabContentsBePrerendered( | 915 bool PrerenderManager::WouldTabContentsBePrerendered( |
916 TabContents* tab_contents) const { | 916 TabContents* tab_contents) const { |
917 DCHECK(CalledOnValidThread()); | 917 DCHECK(CalledOnValidThread()); |
918 return would_be_prerendered_tab_contents_set_.count(tab_contents) > 0; | 918 return would_be_prerendered_tab_contents_set_.count(tab_contents) > 0; |
919 } | 919 } |
920 | 920 |
921 } // namespace prerender | 921 } // namespace prerender |
OLD | NEW |