Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_field_trial.cc
blob1420d45f19135ff8c7db7f1d07766ac357cfcacc
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"
7 #include <string>
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"
15 namespace prerender {
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
29 // means enable.
30 mode = PrerenderManager::PRERENDER_MODE_ENABLED;
31 } else {
32 mode = PrerenderManager::PRERENDER_MODE_DISABLED;
33 LOG(ERROR) << "Invalid --prerender option received on command line: "
34 << switch_value;
35 LOG(ERROR) << "Disabling prerendering!";
39 PrerenderManager::SetMode(mode);
42 bool IsOmniboxEnabled(Profile* profile) {
43 if (!profile)
44 return false;
46 if (!PrerenderManager::IsPrerenderingPossible())
47 return false;
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)
57 return true;
59 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueDisabled)
60 return false;
62 DCHECK_EQ(switches::kPrerenderFromOmniboxSwitchValueAuto, switch_value);
65 return (base::FieldTrialList::FindFullName("PrerenderFromOmnibox") !=
66 "OmniboxPrerenderDisabled");
69 } // namespace prerender