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> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 21 #include "base/metrics/field_trial.h" | |
| 21 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
| 22 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 23 #include "base/sys_info.h" | 24 #include "base/sys_info.h" |
| 24 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
| 25 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 26 #include "base/timer/elapsed_timer.h" | 27 #include "base/timer/elapsed_timer.h" |
| 27 #include "base/values.h" | 28 #include "base/values.h" |
| 28 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
| 29 #include "chrome/browser/net/prediction_options.h" | 30 #include "chrome/browser/net/prediction_options.h" |
| 30 #include "chrome/browser/prerender/prerender_contents.h" | 31 #include "chrome/browser/prerender/prerender_contents.h" |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 // static | 605 // static |
| 605 bool PrerenderManager::IsNoUseGroup() { | 606 bool PrerenderManager::IsNoUseGroup() { |
| 606 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; | 607 return GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP; |
| 607 } | 608 } |
| 608 | 609 |
| 609 // static | 610 // static |
| 610 bool PrerenderManager::IsNoStatePrefetch() { | 611 bool PrerenderManager::IsNoStatePrefetch() { |
| 611 return GetMode() == PRERENDER_MODE_NOSTATE_PREFETCH; | 612 return GetMode() == PRERENDER_MODE_NOSTATE_PREFETCH; |
| 612 } | 613 } |
| 613 | 614 |
| 615 bool PrerenderManager::IsPrerenderSilenceExperiment() { | |
| 616 // The group name should contain expiration time formatted as: | |
| 617 // "ExperimentYes_expires_YYYY-MM-DDTHH:MM:SSZ". | |
| 618 std::string group_name = | |
| 619 base::FieldTrialList::FindFullName("PrerenderSilence"); | |
| 620 const char kExperimentPrefix[] = "ExperimentYes"; | |
| 621 if (!base::StartsWith(group_name, kExperimentPrefix, | |
| 622 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 623 return false; | |
| 624 } | |
| 625 const char kExperimentPrefixWithExpiration[] = "ExperimentYes_expires_"; | |
| 626 if (!base::StartsWith(group_name, kExperimentPrefixWithExpiration, | |
| 627 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 628 // Without expiration day in the group name, behave as a normal experiment, | |
| 629 // i.e. sticky to the Chrome session. | |
| 630 return true; | |
| 631 } | |
| 632 base::Time expiration_time; | |
| 633 if (!base::Time::FromString( | |
| 634 group_name.c_str() + (arraysize(kExperimentPrefixWithExpiration) - 1), | |
| 635 &expiration_time)) { | |
| 636 // Malformed expiration time falls back to normal operation. | |
|
droger
2016/08/25 15:23:24
I guess a DCHECK is not appropriate here, maybe a
pasko
2016/08/25 15:31:40
Good idea, done.
| |
| 637 return false; | |
| 638 } | |
| 639 return GetCurrentTime() < expiration_time; | |
| 640 } | |
| 641 | |
| 614 bool PrerenderManager::IsWebContentsPrerendering( | 642 bool PrerenderManager::IsWebContentsPrerendering( |
| 615 const WebContents* web_contents, | 643 const WebContents* web_contents, |
| 616 Origin* origin) const { | 644 Origin* origin) const { |
| 617 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 645 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 618 PrerenderContents* prerender_contents = GetPrerenderContents(web_contents); | 646 PrerenderContents* prerender_contents = GetPrerenderContents(web_contents); |
| 619 if (!prerender_contents) | 647 if (!prerender_contents) |
| 620 return false; | 648 return false; |
| 621 | 649 |
| 622 if (origin) | 650 if (origin) |
| 623 *origin = prerender_contents->origin(); | 651 *origin = prerender_contents->origin(); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 875 // those prerenders is managed by the offliner. | 903 // those prerenders is managed by the offliner. |
| 876 if (IsLowEndDevice() && origin != ORIGIN_OFFLINE) | 904 if (IsLowEndDevice() && origin != ORIGIN_OFFLINE) |
| 877 return nullptr; | 905 return nullptr; |
| 878 | 906 |
| 879 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || | 907 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || |
| 880 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && | 908 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && |
| 881 IsGoogleSearchResultURL(referrer.url)) { | 909 IsGoogleSearchResultURL(referrer.url)) { |
| 882 origin = ORIGIN_GWS_PRERENDER; | 910 origin = ORIGIN_GWS_PRERENDER; |
| 883 } | 911 } |
| 884 | 912 |
| 913 if (origin != ORIGIN_OFFLINE && IsPrerenderSilenceExperiment()) | |
| 914 return nullptr; | |
| 915 | |
| 885 GURL url = url_arg; | 916 GURL url = url_arg; |
| 886 GURL alias_url; | 917 GURL alias_url; |
| 887 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url)) | 918 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url)) |
| 888 url = alias_url; | 919 url = alias_url; |
| 889 | 920 |
| 890 // From here on, we will record a FinalStatus so we need to register with the | 921 // From here on, we will record a FinalStatus so we need to register with the |
| 891 // histogram tracking. | 922 // histogram tracking. |
| 892 histograms_->RecordPrerender(origin, url_arg); | 923 histograms_->RecordPrerender(origin, url_arg); |
| 893 | 924 |
| 894 if (profile_->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies) && | 925 if (profile_->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies) && |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1307 DCHECK_EQ(1u, erased); | 1338 DCHECK_EQ(1u, erased); |
| 1308 } | 1339 } |
| 1309 | 1340 |
| 1310 void PrerenderManager::SetPrerenderContentsFactoryForTest( | 1341 void PrerenderManager::SetPrerenderContentsFactoryForTest( |
| 1311 PrerenderContents::Factory* prerender_contents_factory) { | 1342 PrerenderContents::Factory* prerender_contents_factory) { |
| 1312 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1343 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1313 prerender_contents_factory_.reset(prerender_contents_factory); | 1344 prerender_contents_factory_.reset(prerender_contents_factory); |
| 1314 } | 1345 } |
| 1315 | 1346 |
| 1316 } // namespace prerender | 1347 } // namespace prerender |
| OLD | NEW |