Home | History | Annotate | Download | only in prefs
      1 // Copyright (c) 2011 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/memory/scoped_ptr.h"
     12 #include "base/values.h"
     13 #include "chrome/browser/prefs/value_map_pref_store.h"
     14 
     15 class DictionaryValue;
     16 
     17 // This PrefStore keeps track of preferences set by command-line switches,
     18 // such as proxy settings.
     19 class CommandLinePrefStore : public ValueMapPrefStore {
     20  public:
     21   explicit CommandLinePrefStore(const CommandLine* command_line);
     22   virtual ~CommandLinePrefStore();
     23 
     24  protected:
     25   // Logs a message and returns false if the proxy switches are
     26   // self-contradictory. Protected so it can be used in unit testing.
     27   bool ValidateProxySwitches();
     28 
     29  private:
     30   struct StringSwitchToPreferenceMapEntry {
     31     const char* switch_name;
     32     const char* preference_path;
     33   };
     34 
     35   // |set_value| indicates what the preference should be set to if the switch
     36   // is present.
     37   struct BooleanSwitchToPreferenceMapEntry {
     38     const char* switch_name;
     39     const char* preference_path;
     40     bool set_value;
     41   };
     42   static const BooleanSwitchToPreferenceMapEntry boolean_switch_map_[];
     43 
     44   // Using the string and boolean maps, apply command-line switches to their
     45   // corresponding preferences in this pref store.
     46   void ApplySimpleSwitches();
     47 
     48   // Determines the proxy mode preference from the given proxy switches.
     49   void ApplyProxyMode();
     50 
     51   // Weak reference.
     52   const CommandLine* command_line_;
     53 
     54   static const StringSwitchToPreferenceMapEntry string_switch_map_[];
     55 
     56   DISALLOW_COPY_AND_ASSIGN(CommandLinePrefStore);
     57 };
     58 
     59 #endif  // CHROME_BROWSER_PREFS_COMMAND_LINE_PREF_STORE_H_
     60