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 return true; | |
mattcary
2016/08/25 13:51:18
Do we really want a malformed experiment option to
droger
2016/08/25 13:56:24
Probably same for line 634 below.
pasko
2016/08/25 14:55:18
I wanted a mere "ExperimentYes" (without a date) t
| |
629 } | |
630 base::Time expiration_time; | |
631 if (!base::Time::FromString( | |
632 group_name.c_str() + (arraysize(kExperimentPrefixWithExpiration) - 1), | |
633 &expiration_time)) { | |
634 return true; | |
635 } | |
636 return GetCurrentTime() < expiration_time; | |
637 } | |
638 | |
614 bool PrerenderManager::IsWebContentsPrerendering( | 639 bool PrerenderManager::IsWebContentsPrerendering( |
615 const WebContents* web_contents, | 640 const WebContents* web_contents, |
616 Origin* origin) const { | 641 Origin* origin) const { |
617 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 642 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
618 PrerenderContents* prerender_contents = GetPrerenderContents(web_contents); | 643 PrerenderContents* prerender_contents = GetPrerenderContents(web_contents); |
619 if (!prerender_contents) | 644 if (!prerender_contents) |
620 return false; | 645 return false; |
621 | 646 |
622 if (origin) | 647 if (origin) |
623 *origin = prerender_contents->origin(); | 648 *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. | 900 // those prerenders is managed by the offliner. |
876 if (IsLowEndDevice() && origin != ORIGIN_OFFLINE) | 901 if (IsLowEndDevice() && origin != ORIGIN_OFFLINE) |
877 return nullptr; | 902 return nullptr; |
878 | 903 |
879 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || | 904 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || |
880 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && | 905 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && |
881 IsGoogleSearchResultURL(referrer.url)) { | 906 IsGoogleSearchResultURL(referrer.url)) { |
882 origin = ORIGIN_GWS_PRERENDER; | 907 origin = ORIGIN_GWS_PRERENDER; |
883 } | 908 } |
884 | 909 |
910 if (origin != ORIGIN_OFFLINE && IsPrerenderSilenceExperiment()) | |
911 return nullptr; | |
912 | |
885 GURL url = url_arg; | 913 GURL url = url_arg; |
886 GURL alias_url; | 914 GURL alias_url; |
887 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url)) | 915 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url)) |
888 url = alias_url; | 916 url = alias_url; |
889 | 917 |
890 // From here on, we will record a FinalStatus so we need to register with the | 918 // From here on, we will record a FinalStatus so we need to register with the |
891 // histogram tracking. | 919 // histogram tracking. |
892 histograms_->RecordPrerender(origin, url_arg); | 920 histograms_->RecordPrerender(origin, url_arg); |
893 | 921 |
894 if (profile_->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies) && | 922 if (profile_->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies) && |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1307 DCHECK_EQ(1u, erased); | 1335 DCHECK_EQ(1u, erased); |
1308 } | 1336 } |
1309 | 1337 |
1310 void PrerenderManager::SetPrerenderContentsFactoryForTest( | 1338 void PrerenderManager::SetPrerenderContentsFactoryForTest( |
1311 PrerenderContents::Factory* prerender_contents_factory) { | 1339 PrerenderContents::Factory* prerender_contents_factory) { |
1312 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1340 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1313 prerender_contents_factory_.reset(prerender_contents_factory); | 1341 prerender_contents_factory_.reset(prerender_contents_factory); |
1314 } | 1342 } |
1315 | 1343 |
1316 } // namespace prerender | 1344 } // namespace prerender |
OLD | NEW |