Chromium Code Reviews| 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 } | |
|
mmenke
2016/08/22 14:17:58
nit: Remove braces
mattcary
2016/08/23 10:53:56
Done.
| |
| 327 | |
| 324 std::unique_ptr<WebContents> new_web_contents = SwapInternal( | 328 std::unique_ptr<WebContents> new_web_contents = SwapInternal( |
| 325 url, web_contents, prerender_data, params->should_replace_current_entry); | 329 url, web_contents, prerender_data, params->should_replace_current_entry); |
| 326 if (!new_web_contents) | 330 if (!new_web_contents) |
| 327 return false; | 331 return false; |
| 328 | 332 |
| 329 // Record the new target_contents for the callers. | 333 // Record the new target_contents for the callers. |
| 330 params->target_contents = new_web_contents.release(); | 334 params->target_contents = new_web_contents.release(); |
| 331 return true; | 335 return true; |
| 332 } | 336 } |
| 333 | 337 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 case PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP: | 569 case PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP: |
| 566 return "_Enabled"; | 570 return "_Enabled"; |
| 567 case PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP: | 571 case PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP: |
| 568 return "_Control"; | 572 return "_Control"; |
| 569 case PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP: | 573 case PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP: |
| 570 return "_Multi"; | 574 return "_Multi"; |
| 571 case PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP: | 575 case PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP: |
| 572 return "_15MinTTL"; | 576 return "_15MinTTL"; |
| 573 case PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP: | 577 case PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP: |
| 574 return "_NoUse"; | 578 return "_NoUse"; |
| 579 case PRERENDER_MODE_NOSTATE_PREFETCH: | |
| 580 return "_NoStatePrefetch"; | |
|
mmenke
2016/08/22 14:17:58
Need to update histograms.xml for this addition.
mattcary
2016/08/23 10:53:56
Done.
I see that the PrerenderMode histogram in h
mmenke
2016/08/23 14:35:27
Hrm...you're right. I'd say no. Looks like a lot
| |
| 575 case PRERENDER_MODE_MAX: | 581 case PRERENDER_MODE_MAX: |
| 576 default: | 582 default: |
| 577 NOTREACHED() << "Invalid PrerenderManager mode."; | 583 NOTREACHED() << "Invalid PrerenderManager mode."; |
| 578 break; | 584 break; |
| 579 } | 585 } |
| 580 return ""; | 586 return ""; |
| 581 } | 587 } |
| 582 | 588 |
| 583 // static | 589 // static |
| 584 bool PrerenderManager::IsPrerenderingPossible() { | 590 bool PrerenderManager::IsPrerenderingPossible() { |
| 585 return GetMode() != PRERENDER_MODE_DISABLED; | 591 return GetMode() != PRERENDER_MODE_DISABLED; |
| 586 } | 592 } |
| 587 | 593 |
| 588 // static | 594 // static |
| 589 bool PrerenderManager::ActuallyPrerendering() { | 595 bool PrerenderManager::ActuallyPrerendering() { |
| 590 return IsPrerenderingPossible() && !IsControlGroup(); | 596 return IsPrerenderingPossible() && !IsControlGroup(); |
| 591 } | 597 } |
| 592 | 598 |
| 593 // static | 599 // static |
| 594 bool PrerenderManager::IsControlGroup() { | 600 bool PrerenderManager::IsControlGroup() { |
| 595 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; | 601 return GetMode() == PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP; |
| 596 } | 602 } |
| 597 | 603 |
| 598 // static | 604 // static |
| 599 bool PrerenderManager::IsNoUseGroup() { | 605 bool PrerenderManager::IsNoUseGroup() { |
| 600 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; | 606 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; |
| 601 } | 607 } |
| 602 | 608 |
| 609 // static | |
| 610 bool PrerenderManager::IsNoStatePrefetch() { | |
| 611 return GetMode() == PRERENDER_MODE_NOSTATE_PREFETCH; | |
| 612 } | |
| 613 | |
| 603 bool PrerenderManager::IsWebContentsPrerendering( | 614 bool PrerenderManager::IsWebContentsPrerendering( |
| 604 const WebContents* web_contents, | 615 const WebContents* web_contents, |
| 605 Origin* origin) const { | 616 Origin* origin) const { |
| 606 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 617 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 607 PrerenderContents* prerender_contents = GetPrerenderContents(web_contents); | 618 PrerenderContents* prerender_contents = GetPrerenderContents(web_contents); |
| 608 if (!prerender_contents) | 619 if (!prerender_contents) |
| 609 return false; | 620 return false; |
| 610 | 621 |
| 611 if (origin) | 622 if (origin) |
| 612 *origin = prerender_contents->origin(); | 623 *origin = prerender_contents->origin(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 670 int route_id) const { | 681 int route_id) const { |
| 671 WebContents* web_contents = tab_util::GetWebContentsByID(child_id, route_id); | 682 WebContents* web_contents = tab_util::GetWebContentsByID(child_id, route_id); |
| 672 return web_contents ? GetPrerenderContents(web_contents) : nullptr; | 683 return web_contents ? GetPrerenderContents(web_contents) : nullptr; |
| 673 } | 684 } |
| 674 | 685 |
| 675 std::vector<WebContents*> PrerenderManager::GetAllPrerenderingContents() const { | 686 std::vector<WebContents*> PrerenderManager::GetAllPrerenderingContents() const { |
| 676 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 687 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 677 std::vector<WebContents*> result; | 688 std::vector<WebContents*> result; |
| 678 | 689 |
| 679 for (const auto& prerender : active_prerenders_) { | 690 for (const auto& prerender : active_prerenders_) { |
| 680 if (WebContents* contents = prerender->contents()->prerender_contents()) | 691 WebContents* contents = prerender->contents()->prerender_contents(); |
|
mmenke
2016/08/22 14:17:58
So we do create a WebContents in the non-full prer
mattcary
2016/08/23 10:53:56
AFAIK, we will have a WebContents for the prefetch
| |
| 692 if (contents && | |
| 693 prerender->contents()->prerender_mode() == FULL_PRERENDER) { | |
| 681 result.push_back(contents); | 694 result.push_back(contents); |
| 695 } | |
| 682 } | 696 } |
| 683 | 697 |
| 684 return result; | 698 return result; |
| 685 } | 699 } |
| 686 | 700 |
| 687 bool PrerenderManager::HasRecentlyBeenNavigatedTo(Origin origin, | 701 bool PrerenderManager::HasRecentlyBeenNavigatedTo(Origin origin, |
| 688 const GURL& url) { | 702 const GURL& url) { |
| 689 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 703 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 690 | 704 |
| 691 CleanUpOldNavigations(); | 705 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. | 943 // by a navigation and is unlikely to be the same site. |
| 930 RecordFinalStatusWithoutCreatingPrerenderContents( | 944 RecordFinalStatusWithoutCreatingPrerenderContents( |
| 931 url, origin, FINAL_STATUS_RATE_LIMIT_EXCEEDED); | 945 url, origin, FINAL_STATUS_RATE_LIMIT_EXCEEDED); |
| 932 return nullptr; | 946 return nullptr; |
| 933 } | 947 } |
| 934 | 948 |
| 935 std::unique_ptr<PrerenderContents> prerender_contents = | 949 std::unique_ptr<PrerenderContents> prerender_contents = |
| 936 CreatePrerenderContents(url, referrer, origin); | 950 CreatePrerenderContents(url, referrer, origin); |
| 937 DCHECK(prerender_contents); | 951 DCHECK(prerender_contents); |
| 938 PrerenderContents* prerender_contents_ptr = prerender_contents.get(); | 952 PrerenderContents* prerender_contents_ptr = prerender_contents.get(); |
| 953 if (IsNoStatePrefetch()) { | |
| 954 prerender_contents_ptr->SetPrerenderMode(PREFETCH_ONLY); | |
| 955 } | |
|
mmenke
2016/08/22 14:17:58
nit: Remove braces
mattcary
2016/08/23 10:53:56
Done.
| |
| 939 active_prerenders_.push_back( | 956 active_prerenders_.push_back( |
| 940 base::MakeUnique<PrerenderData>(this, std::move(prerender_contents), | 957 base::MakeUnique<PrerenderData>(this, std::move(prerender_contents), |
| 941 GetExpiryTimeForNewPrerender(origin))); | 958 GetExpiryTimeForNewPrerender(origin))); |
| 942 if (!prerender_contents_ptr->Init()) { | 959 if (!prerender_contents_ptr->Init()) { |
| 943 DCHECK(active_prerenders_.end() == | 960 DCHECK(active_prerenders_.end() == |
| 944 FindIteratorForPrerenderContents(prerender_contents_ptr)); | 961 FindIteratorForPrerenderContents(prerender_contents_ptr)); |
| 945 return nullptr; | 962 return nullptr; |
| 946 } | 963 } |
| 947 | 964 |
| 948 histograms_->RecordPrerenderStarted(origin); | 965 histograms_->RecordPrerenderStarted(origin); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1291 DCHECK_EQ(1u, erased); | 1308 DCHECK_EQ(1u, erased); |
| 1292 } | 1309 } |
| 1293 | 1310 |
| 1294 void PrerenderManager::SetPrerenderContentsFactoryForTest( | 1311 void PrerenderManager::SetPrerenderContentsFactoryForTest( |
| 1295 PrerenderContents::Factory* prerender_contents_factory) { | 1312 PrerenderContents::Factory* prerender_contents_factory) { |
| 1296 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1313 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1297 prerender_contents_factory_.reset(prerender_contents_factory); | 1314 prerender_contents_factory_.reset(prerender_contents_factory); |
| 1298 } | 1315 } |
| 1299 | 1316 |
| 1300 } // namespace prerender | 1317 } // namespace prerender |
| OLD | NEW |