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
3 // found in the LICENSE file.
5 #include "chrome/browser/prerender/prerender_field_trial.h"
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "base/metrics/field_trial.h"
12 #include "chrome/browser/prerender/prerender_manager.h"
13 #include "chrome/common/chrome_switches.h"
17 void ConfigurePrerender(const base::CommandLine
& command_line
) {
18 PrerenderManager::PrerenderManagerMode mode
=
19 PrerenderManager::PRERENDER_MODE_ENABLED
;
20 if (command_line
.HasSwitch(switches::kPrerenderMode
)) {
21 const std::string switch_value
=
22 command_line
.GetSwitchValueASCII(switches::kPrerenderMode
);
24 if (switch_value
== switches::kPrerenderModeSwitchValueDisabled
) {
25 mode
= PrerenderManager::PRERENDER_MODE_DISABLED
;
26 } else if (switch_value
.empty() ||
27 switch_value
== switches::kPrerenderModeSwitchValueEnabled
) {
28 // The empty string means the option was provided with no value, and that
30 mode
= PrerenderManager::PRERENDER_MODE_ENABLED
;
32 mode
= PrerenderManager::PRERENDER_MODE_DISABLED
;
33 LOG(ERROR
) << "Invalid --prerender option received on command line: "
35 LOG(ERROR
) << "Disabling prerendering!";
39 PrerenderManager::SetMode(mode
);
42 bool IsOmniboxEnabled(Profile
* profile
) {
46 if (!PrerenderManager::IsPrerenderingPossible())
49 // Override any field trial groups if the user has set a command line flag.
50 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
51 switches::kPrerenderFromOmnibox
)) {
52 const std::string switch_value
=
53 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
54 switches::kPrerenderFromOmnibox
);
56 if (switch_value
== switches::kPrerenderFromOmniboxSwitchValueEnabled
)
59 if (switch_value
== switches::kPrerenderFromOmniboxSwitchValueDisabled
)
62 DCHECK_EQ(switches::kPrerenderFromOmniboxSwitchValueAuto
, switch_value
);
65 return (base::FieldTrialList::FindFullName("PrerenderFromOmnibox") !=
66 "OmniboxPrerenderDisabled");
69 } // namespace prerender