command_line_pref_store.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2010 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.
4
5#ifndef CHROME_BROWSER_PREFS_COMMAND_LINE_PREF_STORE_H_
6#define CHROME_BROWSER_PREFS_COMMAND_LINE_PREF_STORE_H_
7#pragma once
8
9#include "base/basictypes.h"
10#include "base/command_line.h"
11#include "base/scoped_ptr.h"
12#include "chrome/common/pref_store.h"
13
14class DictionaryValue;
15
16// This PrefStore keeps track of preferences set by command-line switches,
17// such as proxy settings.
18class CommandLinePrefStore : public PrefStore {
19 public:
20  explicit CommandLinePrefStore(const CommandLine* command_line);
21  virtual ~CommandLinePrefStore() {}
22
23  // PrefStore methods:
24  virtual PrefReadError ReadPrefs();
25  virtual DictionaryValue* prefs() { return prefs_.get(); }
26
27 protected:
28  // Logs a message and returns false if the proxy switches are
29  // self-contradictory. Protected so it can be used in unit testing.
30  bool ValidateProxySwitches();
31
32 private:
33  // Weak reference.
34  const CommandLine* command_line_;
35
36  scoped_ptr<DictionaryValue> prefs_;
37
38  struct StringSwitchToPreferenceMapEntry {
39    const char* switch_name;
40    const char* preference_path;
41  };
42  static const StringSwitchToPreferenceMapEntry string_switch_map_[];
43
44  // |set_value| indicates what the preference should be set to if the switch
45  // is present.
46  struct BooleanSwitchToPreferenceMapEntry {
47    const char* switch_name;
48    const char* preference_path;
49    bool set_value;
50  };
51  static const BooleanSwitchToPreferenceMapEntry boolean_switch_map_[];
52
53  // Using the string and boolean maps, apply command-line switches to their
54  // corresponding preferences in this pref store.
55  void ApplySimpleSwitches();
56
57  DISALLOW_COPY_AND_ASSIGN(CommandLinePrefStore);
58};
59
60#endif  // CHROME_BROWSER_PREFS_COMMAND_LINE_PREF_STORE_H_
61