| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 // First, try to find prerender data with the correct session storage | 314 // First, try to find prerender data with the correct session storage |
| 315 // namespace. | 315 // namespace. |
| 316 // TODO(ajwong): This doesn't handle isolated apps correctly. | 316 // TODO(ajwong): This doesn't handle isolated apps correctly. |
| 317 PrerenderData* prerender_data = FindPrerenderData( | 317 PrerenderData* prerender_data = FindPrerenderData( |
| 318 url, | 318 url, |
| 319 web_contents->GetController().GetDefaultSessionStorageNamespace()); | 319 web_contents->GetController().GetDefaultSessionStorageNamespace()); |
| 320 if (!prerender_data) | 320 if (!prerender_data) |
| 321 return false; | 321 return false; |
| 322 DCHECK(prerender_data->contents()); | 322 DCHECK(prerender_data->contents()); |
| 323 | 323 |
| 324 if (prerender_data->contents()->prerender_mode() != FULL_PRERENDER) |
| 325 return false; |
| 326 |
| 324 std::unique_ptr<WebContents> new_web_contents = SwapInternal( | 327 std::unique_ptr<WebContents> new_web_contents = SwapInternal( |
| 325 url, web_contents, prerender_data, params->should_replace_current_entry); | 328 url, web_contents, prerender_data, params->should_replace_current_entry); |
| 326 if (!new_web_contents) | 329 if (!new_web_contents) |
| 327 return false; | 330 return false; |
| 328 | 331 |
| 329 // Record the new target_contents for the callers. | 332 // Record the new target_contents for the callers. |
| 330 params->target_contents = new_web_contents.release(); | 333 params->target_contents = new_web_contents.release(); |
| 331 return true; | 334 return true; |
| 332 } | 335 } |
| 333 | 336 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 case PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP: | 568 case PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP: |
| 566 return "_Enabled"; | 569 return "_Enabled"; |
| 567 case PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP: | 570 case PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP: |
| 568 return "_Control"; | 571 return "_Control"; |
| 569 case PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP: | 572 case PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP: |
| 570 return "_Multi"; | 573 return "_Multi"; |
| 571 case PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP: | 574 case PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP: |
| 572 return "_15MinTTL"; | 575 return "_15MinTTL"; |
| 573 case PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP: | 576 case PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP: |
| 574 return "_NoUse"; | 577 return "_NoUse"; |
| 578 case PRERENDER_MODE_NOSTATE_PREFETCH: |
| 579 return "_NoStatePrefetch"; |
| 575 case PRERENDER_MODE_MAX: | 580 case PRERENDER_MODE_MAX: |
| 576 default: | 581 default: |
| 577 NOTREACHED() << "Invalid PrerenderManager mode."; | 582 NOTREACHED() << "Invalid PrerenderManager mode."; |
| 578 break; | 583 break; |
| 579 } | 584 } |
| 580 return ""; | 585 return ""; |
| 581 } | 586 } |
| 582 | 587 |
| 583 // static | 588 // static |
| 584 bool PrerenderManager::IsPrerenderingPossible() { | 589 bool PrerenderManager::IsPrerenderingPossible() { |
| 585 return GetMode() != PRERENDER_MODE_DISABLED; | 590 return GetMode() != PRERENDER_MODE_DISABLED; |
| 586 } | 591 } |
| 587 | 592 |
| 588 // static | 593 // static |
| 589 bool PrerenderManager::ActuallyPrerendering() { | 594 bool PrerenderManager::ActuallyPrerendering() { |
| 590 return IsPrerenderingPossible() && !IsControlGroup(); | 595 return IsPrerenderingPossible() && !IsControlGroup(); |
| 591 } | 596 } |
| 592 | 597 |
| 593 // static | 598 // static |
| 594 bool PrerenderManager::IsControlGroup() { | 599 bool PrerenderManager::IsControlGroup() { |
| 595 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; | 600 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; |
| 596 } | 601 } |
| 597 | 602 |
| 598 // static | 603 // static |
| 599 bool PrerenderManager::IsNoUseGroup() { | 604 bool PrerenderManager::IsNoUseGroup() { |
| 600 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; | 605 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; |
| 601 } | 606 } |
| 602 | 607 |
| 608 // static |
| 609 bool PrerenderManager::IsNoStatePrefetch() { |
| 610 return GetMode() == PRERENDER_MODE_NOSTATE_PREFETCH; |
| 611 } |
| 612 |
| 603 bool PrerenderManager::IsWebContentsPrerendering( | 613 bool PrerenderManager::IsWebContentsPrerendering( |
| 604 const WebContents* web_contents, | 614 const WebContents* web_contents, |
| 605 Origin* origin) const { | 615 Origin* origin) const { |
| 606 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 616 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 607 PrerenderContents* prerender_contents = GetPrerenderContents(web_contents); | 617 PrerenderContents* prerender_contents = GetPrerenderContents(web_contents); |
| 608 if (!prerender_contents) | 618 if (!prerender_contents) |
| 609 return false; | 619 return false; |
| 610 | 620 |
| 611 if (origin) | 621 if (origin) |
| 612 *origin = prerender_contents->origin(); | 622 *origin = prerender_contents->origin(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 int route_id) const { | 680 int route_id) const { |
| 671 WebContents* web_contents = tab_util::GetWebContentsByID(child_id, route_id); | 681 WebContents* web_contents = tab_util::GetWebContentsByID(child_id, route_id); |
| 672 return web_contents ? GetPrerenderContents(web_contents) : nullptr; | 682 return web_contents ? GetPrerenderContents(web_contents) : nullptr; |
| 673 } | 683 } |
| 674 | 684 |
| 675 std::vector<WebContents*> PrerenderManager::GetAllPrerenderingContents() const { | 685 std::vector<WebContents*> PrerenderManager::GetAllPrerenderingContents() const { |
| 676 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 686 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 677 std::vector<WebContents*> result; | 687 std::vector<WebContents*> result; |
| 678 | 688 |
| 679 for (const auto& prerender : active_prerenders_) { | 689 for (const auto& prerender : active_prerenders_) { |
| 680 if (WebContents* contents = prerender->contents()->prerender_contents()) | 690 WebContents* contents = prerender->contents()->prerender_contents(); |
| 691 if (contents && |
| 692 prerender->contents()->prerender_mode() == FULL_PRERENDER) { |
| 681 result.push_back(contents); | 693 result.push_back(contents); |
| 694 } |
| 682 } | 695 } |
| 683 | 696 |
| 684 return result; | 697 return result; |
| 685 } | 698 } |
| 686 | 699 |
| 687 bool PrerenderManager::HasRecentlyBeenNavigatedTo(Origin origin, | 700 bool PrerenderManager::HasRecentlyBeenNavigatedTo(Origin origin, |
| 688 const GURL& url) { | 701 const GURL& url) { |
| 689 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 702 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 690 | 703 |
| 691 CleanUpOldNavigations(); | 704 CleanUpOldNavigations(); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 // by a navigation and is unlikely to be the same site. | 942 // by a navigation and is unlikely to be the same site. |
| 930 RecordFinalStatusWithoutCreatingPrerenderContents( | 943 RecordFinalStatusWithoutCreatingPrerenderContents( |
| 931 url, origin, FINAL_STATUS_RATE_LIMIT_EXCEEDED); | 944 url, origin, FINAL_STATUS_RATE_LIMIT_EXCEEDED); |
| 932 return nullptr; | 945 return nullptr; |
| 933 } | 946 } |
| 934 | 947 |
| 935 std::unique_ptr<PrerenderContents> prerender_contents = | 948 std::unique_ptr<PrerenderContents> prerender_contents = |
| 936 CreatePrerenderContents(url, referrer, origin); | 949 CreatePrerenderContents(url, referrer, origin); |
| 937 DCHECK(prerender_contents); | 950 DCHECK(prerender_contents); |
| 938 PrerenderContents* prerender_contents_ptr = prerender_contents.get(); | 951 PrerenderContents* prerender_contents_ptr = prerender_contents.get(); |
| 952 if (IsNoStatePrefetch()) |
| 953 prerender_contents_ptr->SetPrerenderMode(PREFETCH_ONLY); |
| 939 active_prerenders_.push_back( | 954 active_prerenders_.push_back( |
| 940 base::MakeUnique<PrerenderData>(this, std::move(prerender_contents), | 955 base::MakeUnique<PrerenderData>(this, std::move(prerender_contents), |
| 941 GetExpiryTimeForNewPrerender(origin))); | 956 GetExpiryTimeForNewPrerender(origin))); |
| 942 if (!prerender_contents_ptr->Init()) { | 957 if (!prerender_contents_ptr->Init()) { |
| 943 DCHECK(active_prerenders_.end() == | 958 DCHECK(active_prerenders_.end() == |
| 944 FindIteratorForPrerenderContents(prerender_contents_ptr)); | 959 FindIteratorForPrerenderContents(prerender_contents_ptr)); |
| 945 return nullptr; | 960 return nullptr; |
| 946 } | 961 } |
| 947 | 962 |
| 948 histograms_->RecordPrerenderStarted(origin); | 963 histograms_->RecordPrerenderStarted(origin); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 DCHECK_EQ(1u, erased); | 1306 DCHECK_EQ(1u, erased); |
| 1292 } | 1307 } |
| 1293 | 1308 |
| 1294 void PrerenderManager::SetPrerenderContentsFactoryForTest( | 1309 void PrerenderManager::SetPrerenderContentsFactoryForTest( |
| 1295 PrerenderContents::Factory* prerender_contents_factory) { | 1310 PrerenderContents::Factory* prerender_contents_factory) { |
| 1296 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1311 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1297 prerender_contents_factory_.reset(prerender_contents_factory); | 1312 prerender_contents_factory_.reset(prerender_contents_factory); |
| 1298 } | 1313 } |
| 1299 | 1314 |
| 1300 } // namespace prerender | 1315 } // namespace prerender |
| OLD | NEW |