| OLD | NEW | 
|    1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |    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 |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 // This provides a way to access the application's current preferences. |    5 // This provides a way to access the application's current preferences. | 
|    6  |    6  | 
|    7 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |    7 #ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 
|    8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |    8 #define CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 
|    9 #pragma once |    9 #pragma once | 
|   10  |   10  | 
|   11 #include <set> |   11 #include <set> | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|   35  public: |   35  public: | 
|   36   // A helper class to store all the information associated with a preference. |   36   // A helper class to store all the information associated with a preference. | 
|   37   class Preference { |   37   class Preference { | 
|   38    public: |   38    public: | 
|   39  |   39  | 
|   40     // The type of the preference is determined by the type with which it is |   40     // The type of the preference is determined by the type with which it is | 
|   41     // registered. This type needs to be a boolean, integer, real, string, |   41     // registered. This type needs to be a boolean, integer, real, string, | 
|   42     // dictionary (a branch), or list.  You shouldn't need to construct this on |   42     // dictionary (a branch), or list.  You shouldn't need to construct this on | 
|   43     // your own; use the PrefService::Register*Pref methods instead. |   43     // your own; use the PrefService::Register*Pref methods instead. | 
|   44     Preference(const PrefService* service, |   44     Preference(const PrefService* service, | 
|   45                const char* name); |   45                const char* name, | 
 |   46                Value::ValueType type); | 
|   46     ~Preference() {} |   47     ~Preference() {} | 
|   47  |   48  | 
|   48     // Returns the name of the Preference (i.e., the key, e.g., |   49     // Returns the name of the Preference (i.e., the key, e.g., | 
|   49     // browser.window_placement). |   50     // browser.window_placement). | 
|   50     const std::string name() const { return name_; } |   51     const std::string name() const { return name_; } | 
|   51  |   52  | 
|   52     // Returns the registered type of the preference. |   53     // Returns the registered type of the preference. | 
|   53     Value::ValueType GetType() const; |   54     Value::ValueType GetType() const; | 
|   54  |   55  | 
|   55     // Returns the value of the Preference, falling back to the registered |   56     // Returns the value of the Preference, falling back to the registered | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
|   85     // Returns true if the user can change the Preference value, which is the |   86     // Returns true if the user can change the Preference value, which is the | 
|   86     // case if no higher-priority source than the user store controls the |   87     // case if no higher-priority source than the user store controls the | 
|   87     // Preference. |   88     // Preference. | 
|   88     bool IsUserModifiable() const; |   89     bool IsUserModifiable() const; | 
|   89  |   90  | 
|   90    private: |   91    private: | 
|   91     friend class PrefService; |   92     friend class PrefService; | 
|   92  |   93  | 
|   93     std::string name_; |   94     std::string name_; | 
|   94  |   95  | 
 |   96     Value::ValueType type_; | 
 |   97  | 
|   95     // Reference to the PrefService in which this pref was created. |   98     // Reference to the PrefService in which this pref was created. | 
|   96     const PrefService* pref_service_; |   99     const PrefService* pref_service_; | 
|   97  |  100  | 
|   98     DISALLOW_COPY_AND_ASSIGN(Preference); |  101     DISALLOW_COPY_AND_ASSIGN(Preference); | 
|   99   }; |  102   }; | 
|  100  |  103  | 
|  101   // Factory method that creates a new instance of a PrefService with the |  104   // Factory method that creates a new instance of a PrefService with the | 
|  102   // applicable PrefStores. The |pref_filename| points to the user preference |  105   // applicable PrefStores. The |pref_filename| points to the user preference | 
|  103   // file. The |profile| is the one to which these preferences apply; it may be |  106   // file. The |profile| is the one to which these preferences apply; it may be | 
|  104   // NULL if we're dealing with the local state. This is the usual way to create |  107   // NULL if we're dealing with the local state. This is the usual way to create | 
|  105   // a new PrefService. |extension_pref_store| is used as the source for |  108   // a new PrefService. |extension_pref_store| is used as the source for | 
|  106   // extension-controlled preferences and may be NULL. The PrefService takes |  109   // extension-controlled preferences and may be NULL. The PrefService takes | 
|  107   // ownership of |extension_pref_store|. |  110   // ownership of |extension_pref_store|. | 
|  108   static PrefService* CreatePrefService(const FilePath& pref_filename, |  111   static PrefService* CreatePrefService(const FilePath& pref_filename, | 
|  109                                         PrefStore* extension_pref_store, |  112                                         PrefStore* extension_pref_store, | 
|  110                                         Profile* profile); |  113                                         Profile* profile); | 
|  111  |  114  | 
 |  115   // Creates an incognito copy of the pref service that shares most pref stores | 
 |  116   // but uses a fresh non-persistent overlay for the user pref store and an | 
 |  117   // individual extension pref store (to cache the effective extension prefs for | 
 |  118   // incognito windows). | 
 |  119   PrefService* CreateIncognitoPrefService(PrefStore* incognito_extension_prefs); | 
 |  120  | 
|  112   virtual ~PrefService(); |  121   virtual ~PrefService(); | 
|  113  |  122  | 
|  114   // Reloads the data from file. This should only be called when the importer |  123   // Reloads the data from file. This should only be called when the importer | 
|  115   // is running during first run, and the main process may not change pref |  124   // is running during first run, and the main process may not change pref | 
|  116   // values while the importer process is running. Returns true on success. |  125   // values while the importer process is running. Returns true on success. | 
|  117   bool ReloadPersistentPrefs(); |  126   bool ReloadPersistentPrefs(); | 
|  118  |  127  | 
|  119   // Returns true if the preference for the given preference name is available |  128   // Returns true if the preference for the given preference name is available | 
|  120   // and is managed. |  129   // and is managed. | 
|  121   bool IsManagedPreference(const char* pref_name) const; |  130   bool IsManagedPreference(const char* pref_name) const; | 
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  223  |  232  | 
|  224  protected: |  233  protected: | 
|  225   // Construct a new pref service, specifying the pref sources as explicit |  234   // Construct a new pref service, specifying the pref sources as explicit | 
|  226   // PrefStore pointers. This constructor is what CreatePrefService() ends up |  235   // PrefStore pointers. This constructor is what CreatePrefService() ends up | 
|  227   // calling. It's also used for unit tests. |  236   // calling. It's also used for unit tests. | 
|  228   PrefService(PrefStore* managed_platform_prefs, |  237   PrefService(PrefStore* managed_platform_prefs, | 
|  229               PrefStore* device_management_prefs, |  238               PrefStore* device_management_prefs, | 
|  230               PrefStore* extension_prefs, |  239               PrefStore* extension_prefs, | 
|  231               PrefStore* command_line_prefs, |  240               PrefStore* command_line_prefs, | 
|  232               PersistentPrefStore* user_prefs, |  241               PersistentPrefStore* user_prefs, | 
|  233               PrefStore* recommended_prefs); |  242               PrefStore* recommended_prefs, | 
 |  243               DefaultPrefStore* default_store, | 
 |  244               bool init_from_storage); | 
|  234  |  245  | 
|  235   // The PrefNotifier handles registering and notifying preference observers. |  246   // The PrefNotifier handles registering and notifying preference observers. | 
|  236   // It is created and owned by this PrefService. Subclasses may access it for |  247   // It is created and owned by this PrefService. Subclasses may access it for | 
|  237   // unit testing. |  248   // unit testing. | 
|  238   scoped_ptr<PrefNotifierImpl> pref_notifier_; |  249   scoped_ptr<PrefNotifierImpl> pref_notifier_; | 
|  239  |  250  | 
|  240  private: |  251  private: | 
|  241   friend class PrefServiceMockBuilder; |  252   friend class PrefServiceMockBuilder; | 
|  242  |  253  | 
|  243   // Registration of pref change observers must be done using the |  254   // Registration of pref change observers must be done using the | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
|  265   void SetUserPrefValue(const char* path, Value* new_value); |  276   void SetUserPrefValue(const char* path, Value* new_value); | 
|  266  |  277  | 
|  267   // Load preferences from storage, attempting to diagnose and handle errors. |  278   // Load preferences from storage, attempting to diagnose and handle errors. | 
|  268   // This should only be called from the constructor. |  279   // This should only be called from the constructor. | 
|  269   void InitFromStorage(); |  280   void InitFromStorage(); | 
|  270  |  281  | 
|  271   // The PrefValueStore provides prioritized preference values. It is created |  282   // The PrefValueStore provides prioritized preference values. It is created | 
|  272   // and owned by this PrefService. Subclasses may access it for unit testing. |  283   // and owned by this PrefService. Subclasses may access it for unit testing. | 
|  273   scoped_refptr<PrefValueStore> pref_value_store_; |  284   scoped_refptr<PrefValueStore> pref_value_store_; | 
|  274  |  285  | 
|  275   // The persistent pref store used for actual user data. |  286   // Pref Stores and profile that we passed to the PrefValueStore. | 
|  276   PersistentPrefStore* user_pref_store_; |  287   scoped_refptr<PrefStore> managed_platform_prefs_; | 
 |  288   scoped_refptr<PrefStore> device_management_prefs_; | 
 |  289   scoped_refptr<PrefStore> extension_prefs_; | 
 |  290   scoped_refptr<PrefStore> command_line_prefs_; | 
 |  291   scoped_refptr<PrefStore> recommended_prefs_; | 
 |  292   scoped_refptr<PersistentPrefStore> user_pref_store_; | 
 |  293   scoped_refptr<DefaultPrefStore> default_store_; | 
 |  294   Profile* profile_; | 
|  277  |  295  | 
|  278   // Points to the default pref store we passed to the PrefValueStore. |  296   // Local cache of registered Preference objects. The default_store_ | 
|  279   DefaultPrefStore* default_store_; |  297   // is authoritative with respect to what the types and default values | 
|  280  |  298   // of registered preferences are. | 
|  281   // A set of all the registered Preference objects. |  299   mutable PreferenceSet prefs_; | 
|  282   PreferenceSet prefs_; |  | 
|  283  |  300  | 
|  284   DISALLOW_COPY_AND_ASSIGN(PrefService); |  301   DISALLOW_COPY_AND_ASSIGN(PrefService); | 
|  285 }; |  302 }; | 
|  286  |  303  | 
|  287 #endif  // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ |  304 #endif  // CHROME_BROWSER_PREFS_PREF_SERVICE_H_ | 
| OLD | NEW |