summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-01 15:47:41 +0000
committercbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-01 15:47:41 +0000
commitd75695a9cc2493f72c1cdaddcb5a9adef76ce2fc (patch)
tree7e252ebaaf386642d6fcec2d809c000644ab0ca9
parent16b48b4b64a48e442f19ac418c91bb4287befe01 (diff)
downloadchromium_src-d75695a9cc2493f72c1cdaddcb5a9adef76ce2fc.zip
chromium_src-d75695a9cc2493f72c1cdaddcb5a9adef76ce2fc.tar.gz
chromium_src-d75695a9cc2493f72c1cdaddcb5a9adef76ce2fc.tar.bz2
Move prerender and prefetch logic out into chrome/browser/prerender.
This makes no logic changes. BUG=None TEST=None Review URL: http://codereview.chromium.org/6596040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76376 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_main.cc80
-rw-r--r--chrome/browser/browser_main.h4
-rw-r--r--chrome/browser/prerender/prerender_field_trial.cc88
-rw-r--r--chrome/browser/prerender/prerender_field_trial.h19
-rw-r--r--chrome/chrome_browser.gypi2
5 files changed, 111 insertions, 82 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index feafe55..1622bfa 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -55,7 +55,7 @@
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/pref_value_store.h"
-#include "chrome/browser/prerender/prerender_manager.h"
+#include "chrome/browser/prerender/prerender_field_trial.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
#include "chrome/browser/printing/print_dialog_cloud.h"
#include "chrome/browser/process_singleton.h"
@@ -233,7 +233,7 @@ void BrowserMainParts::SetupFieldTrials() {
ConnectionFieldTrial();
SocketTimeoutFieldTrial();
ProxyConnectionsFieldTrial();
- PrefetchAndPrerenderFieldTrial();
+ prerender::ConfigurePrefetchAndPrerender(parsed_command_line());
SpdyFieldTrial();
ConnectBackupJobsFieldTrial();
SSLFalseStartFieldTrial();
@@ -457,82 +457,6 @@ void BrowserMainParts::SSLFalseStartFieldTrial() {
net::SSLConfigService::DisableFalseStart();
}
-// Parse the --prerender= command line switch, which controls both prerendering
-// and prefetching. If the switch is unset, or is set to "auto", then the user
-// is assigned to a field trial.
-void BrowserMainParts::PrefetchAndPrerenderFieldTrial() {
- enum PrerenderOption {
- PRERENDER_OPTION_AUTO,
- PRERENDER_OPTION_DISABLED,
- PRERENDER_OPTION_ENABLED,
- PRERENDER_OPTION_PREFETCH_ONLY,
- };
-
- PrerenderOption prerender_option = PRERENDER_OPTION_AUTO;
- if (parsed_command_line().HasSwitch(switches::kPrerender)) {
- const std::string switch_value =
- parsed_command_line().GetSwitchValueASCII(switches::kPrerender);
-
- if (switch_value == switches::kPrerenderSwitchValueAuto) {
- prerender_option = PRERENDER_OPTION_AUTO;
- } else if (switch_value == switches::kPrerenderSwitchValueDisabled) {
- prerender_option = PRERENDER_OPTION_DISABLED;
- } else if (switch_value.empty() ||
- switch_value == switches::kPrerenderSwitchValueEnabled) {
- // The empty string means the option was provided with no value, and that
- // means enable.
- prerender_option = PRERENDER_OPTION_ENABLED;
- } else if (switch_value == switches::kPrerenderSwitchValuePrefetchOnly) {
- prerender_option = PRERENDER_OPTION_PREFETCH_ONLY;
- } else {
- prerender_option = PRERENDER_OPTION_DISABLED;
- LOG(ERROR) << "Invalid --prerender option received on command line: "
- << switch_value;
- LOG(ERROR) << "Disabling prerendering!";
- }
- }
-
- switch (prerender_option) {
- case PRERENDER_OPTION_AUTO: {
- const base::FieldTrial::Probability kPrefetchDivisor = 1000;
- const base::FieldTrial::Probability kYesPrefetchProbability = 500;
- scoped_refptr<base::FieldTrial> trial(
- new base::FieldTrial("Prefetch", kPrefetchDivisor,
- "ContentPrefetchDisabled", 2011, 6, 30));
- const int kNoPrefetchGroup = trial->kDefaultGroupNumber;
- trial->AppendGroup("ContentPrefetchEnabled", kYesPrefetchProbability);
- const int kTrialGroup = trial->group();
- ResourceDispatcherHost::set_is_prefetch_enabled(
- kTrialGroup != kNoPrefetchGroup);
-
- // There is currently no prerendering field trial.
- prerender::PrerenderManager::SetMode(
- prerender::PrerenderManager::PRERENDER_MODE_DISABLED);
- break;
- }
- case PRERENDER_OPTION_DISABLED:
- ResourceDispatcherHost::set_is_prefetch_enabled(false);
- prerender::PrerenderManager::SetMode(
- prerender::PrerenderManager::PRERENDER_MODE_DISABLED);
- break;
- case PRERENDER_OPTION_ENABLED:
- ResourceDispatcherHost::set_is_prefetch_enabled(true);
- prerender::PrerenderManager::SetMode(
- prerender::PrerenderManager::PRERENDER_MODE_ENABLED);
- break;
- case PRERENDER_OPTION_PREFETCH_ONLY:
- ResourceDispatcherHost::set_is_prefetch_enabled(true);
- prerender::PrerenderManager::SetMode(
- prerender::PrerenderManager::PRERENDER_MODE_DISABLED);
- break;
- default:
- NOTREACHED();
- }
-
- UMA_HISTOGRAM_ENUMERATION("Prerender.Sessions",
- prerender::PrerenderManager::GetMode(),
- prerender::PrerenderManager::PRERENDER_MODE_MAX);
-}
// If neither --enable-connect-backup-jobs or --disable-connect-backup-jobs is
// specified, run an A/B test for automatically establishing backup TCP
diff --git a/chrome/browser/browser_main.h b/chrome/browser/browser_main.h
index 81c8c3b..96c10f1 100644
--- a/chrome/browser/browser_main.h
+++ b/chrome/browser/browser_main.h
@@ -118,10 +118,6 @@ class BrowserMainParts {
// A/B test for spdy when --use-spdy not set.
void SpdyFieldTrial();
- // A/B test for prefetching with --(enable|disable)-prefetch not set,
- // some histograms tracking prerender sessions.
- void PrefetchAndPrerenderFieldTrial();
-
// A/B test for automatically establishing a backup TCP connection when a
// specified timeout value is reached.
void ConnectBackupJobsFieldTrial();
diff --git a/chrome/browser/prerender/prerender_field_trial.cc b/chrome/browser/prerender/prerender_field_trial.cc
new file mode 100644
index 0000000..29e6e0a
--- /dev/null
+++ b/chrome/browser/prerender/prerender_field_trial.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/prerender/prerender_field_trial.h"
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/metrics/field_trial.h"
+#include "base/metrics/histogram.h"
+#include "content/browser/renderer_host/resource_dispatcher_host.h"
+#include "chrome/browser/prerender/prerender_manager.h"
+#include "chrome/common/chrome_switches.h"
+
+
+namespace prerender {
+
+void ConfigurePrefetchAndPrerender(const CommandLine& command_line) {
+ enum PrerenderOption {
+ PRERENDER_OPTION_AUTO,
+ PRERENDER_OPTION_DISABLED,
+ PRERENDER_OPTION_ENABLED,
+ PRERENDER_OPTION_PREFETCH_ONLY,
+ };
+
+ PrerenderOption prerender_option = PRERENDER_OPTION_AUTO;
+ if (command_line.HasSwitch(switches::kPrerender)) {
+ const std::string switch_value =
+ command_line.GetSwitchValueASCII(switches::kPrerender);
+
+ if (switch_value == switches::kPrerenderSwitchValueAuto) {
+ prerender_option = PRERENDER_OPTION_AUTO;
+ } else if (switch_value == switches::kPrerenderSwitchValueDisabled) {
+ prerender_option = PRERENDER_OPTION_DISABLED;
+ } else if (switch_value.empty() ||
+ switch_value == switches::kPrerenderSwitchValueEnabled) {
+ // The empty string means the option was provided with no value, and that
+ // means enable.
+ prerender_option = PRERENDER_OPTION_ENABLED;
+ } else if (switch_value == switches::kPrerenderSwitchValuePrefetchOnly) {
+ prerender_option = PRERENDER_OPTION_PREFETCH_ONLY;
+ } else {
+ prerender_option = PRERENDER_OPTION_DISABLED;
+ LOG(ERROR) << "Invalid --prerender option received on command line: "
+ << switch_value;
+ LOG(ERROR) << "Disabling prerendering!";
+ }
+ }
+
+ switch (prerender_option) {
+ case PRERENDER_OPTION_AUTO: {
+ const base::FieldTrial::Probability kPrefetchDivisor = 1000;
+ const base::FieldTrial::Probability kYesPrefetchProbability = 500;
+ scoped_refptr<base::FieldTrial> trial(
+ new base::FieldTrial("Prefetch", kPrefetchDivisor,
+ "ContentPrefetchDisabled", 2011, 6, 30));
+ const int kNoPrefetchGroup = trial->kDefaultGroupNumber;
+ trial->AppendGroup("ContentPrefetchEnabled", kYesPrefetchProbability);
+ const int kTrialGroup = trial->group();
+ ResourceDispatcherHost::set_is_prefetch_enabled(
+ kTrialGroup != kNoPrefetchGroup);
+
+ // There is currently no prerendering field trial.
+ PrerenderManager::SetMode(PrerenderManager::PRERENDER_MODE_DISABLED);
+ break;
+ }
+ case PRERENDER_OPTION_DISABLED:
+ ResourceDispatcherHost::set_is_prefetch_enabled(false);
+ PrerenderManager::SetMode(PrerenderManager::PRERENDER_MODE_DISABLED);
+ break;
+ case PRERENDER_OPTION_ENABLED:
+ ResourceDispatcherHost::set_is_prefetch_enabled(true);
+ PrerenderManager::SetMode(PrerenderManager::PRERENDER_MODE_ENABLED);
+ break;
+ case PRERENDER_OPTION_PREFETCH_ONLY:
+ ResourceDispatcherHost::set_is_prefetch_enabled(true);
+ PrerenderManager::SetMode(PrerenderManager::PRERENDER_MODE_DISABLED);
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ UMA_HISTOGRAM_ENUMERATION("Prerender.Sessions",
+ PrerenderManager::GetMode(),
+ PrerenderManager::PRERENDER_MODE_MAX);
+}
+
+} // namespace prerender
diff --git a/chrome/browser/prerender/prerender_field_trial.h b/chrome/browser/prerender/prerender_field_trial.h
new file mode 100644
index 0000000..b7543ae6
--- /dev/null
+++ b/chrome/browser/prerender/prerender_field_trial.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PRERENDER_PRERENDER_FIELD_TRIAL_H_
+#define CHROME_BROWSER_PRERENDER_PRERENDER_FIELD_TRIAL_H_
+
+class CommandLine;
+
+namespace prerender {
+
+// Parse the --prerender= command line switch, which controls both prerendering
+// and prefetching. If the switch is unset, or is set to "auto", then the user
+// is assigned to a field trial.
+void ConfigurePrefetchAndPrerender(const CommandLine& command_line);
+
+} // namespace prerender
+
+#endif // CHROME_BROWSER_PRERENDER_PRERENDER_FIELD_TRIAL_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index a85f57d..479e052 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1601,6 +1601,8 @@
'browser/prefs/value_map_pref_store.h',
'browser/prerender/prerender_contents.cc',
'browser/prerender/prerender_contents.h',
+ 'browser/prerender/prerender_field_trial.cc',
+ 'browser/prerender/prerender_field_trial.h',
'browser/prerender/prerender_final_status.cc',
'browser/prerender/prerender_final_status.h',
'browser/prerender/prerender_manager.cc',