| OLD | NEW | 
|    1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |    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 |    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_PREF_SERVICE_H_ |    7 #ifndef CHROME_BROWSER_PREF_SERVICE_H_ | 
|    8 #define CHROME_BROWSER_PREF_SERVICE_H_ |    8 #define CHROME_BROWSER_PREF_SERVICE_H_ | 
|    9 #pragma once |    9 #pragma once | 
|   10  |   10  | 
|   11 #include <set> |   11 #include <set> | 
 |   12 #include <string> | 
 |   13 #include <vector> | 
|   12  |   14  | 
|   13 #include "base/file_path.h" |   15 #include "base/file_path.h" | 
|   14 #include "base/hash_tables.h" |   16 #include "base/hash_tables.h" | 
|   15 #include "base/non_thread_safe.h" |   17 #include "base/non_thread_safe.h" | 
|   16 #include "base/observer_list.h" |   18 #include "base/observer_list.h" | 
 |   19 #include "base/ref_counted.h" | 
|   17 #include "base/scoped_ptr.h" |   20 #include "base/scoped_ptr.h" | 
|   18 #include "base/values.h" |   21 #include "base/values.h" | 
|   19 #include "chrome/browser/pref_value_store.h" |   22 #include "chrome/browser/pref_value_store.h" | 
 |   23 #include "chrome/common/notification_observer.h" | 
 |   24 #include "chrome/common/notification_registrar.h" | 
|   20 #include "chrome/common/pref_store.h" |   25 #include "chrome/common/pref_store.h" | 
|   21  |   26  | 
|   22 class NotificationObserver; |   27 class NotificationDetails; | 
 |   28 class NotificationSource; | 
 |   29 class NotificationType; | 
|   23 class Preference; |   30 class Preference; | 
|   24 class Profile; |   31 class Profile; | 
|   25 class ScopedPrefUpdate; |   32 class ScopedPrefUpdate; | 
|   26  |   33  | 
|   27 class PrefService : public NonThreadSafe { |   34 class PrefService : public NonThreadSafe, | 
 |   35                     public NotificationObserver { | 
|   28  public: |   36  public: | 
|   29  |   37  | 
|   30   // A helper class to store all the information associated with a preference. |   38   // A helper class to store all the information associated with a preference. | 
|   31   class Preference { |   39   class Preference { | 
|   32    public: |   40    public: | 
|   33  |   41  | 
|   34     // The type of the preference is determined by the type of |default_value|. |   42     // The type of the preference is determined by the type of |default_value|. | 
|   35     // Therefore, the type needs to be a boolean, integer, real, string, |   43     // Therefore, the type needs to be a boolean, integer, real, string, | 
|   36     // dictionary (a branch), or list.  You shouldn't need to construct this on |   44     // dictionary (a branch), or list.  You shouldn't need to construct this on | 
|   37     // your own, use the PrefService::Register*Pref methods instead. |   45     // your own, use the PrefService::Register*Pref methods instead. | 
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  247   // deleting the returned object. |  255   // deleting the returned object. | 
|  248   Value* GetPrefCopy(const wchar_t* pref_name); |  256   Value* GetPrefCopy(const wchar_t* pref_name); | 
|  249  |  257  | 
|  250   // Load from disk.  Returns a non-zero error code on failure. |  258   // Load from disk.  Returns a non-zero error code on failure. | 
|  251   PrefStore::PrefReadError LoadPersistentPrefs(); |  259   PrefStore::PrefReadError LoadPersistentPrefs(); | 
|  252  |  260  | 
|  253   // Load preferences from storage, attempting to diagnose and handle errors. |  261   // Load preferences from storage, attempting to diagnose and handle errors. | 
|  254   // This should only be called from the constructor. |  262   // This should only be called from the constructor. | 
|  255   void InitFromStorage(); |  263   void InitFromStorage(); | 
|  256  |  264  | 
 |  265   // NotificationObserver methods: | 
 |  266   virtual void Observe(NotificationType type, | 
 |  267                        const NotificationSource& source, | 
 |  268                        const NotificationDetails& details); | 
 |  269  | 
 |  270   // Called after a policy refresh to notify relevant preference observers. | 
 |  271   // |changed_prefs_paths| is the vector of preference paths changed by the | 
 |  272   // policy update. It is passed by value and not reference because | 
 |  273   // this method is called asynchronously as a callback from another thread. | 
 |  274   // Copying the vector guarantees that the vector's lifecycle spans the | 
 |  275   // method's invocation. | 
 |  276   void FireObserversForRefreshedManagedPrefs( | 
 |  277       std::vector<std::string> changed_prefs_paths); | 
 |  278  | 
|  257   // The value of a Preference can be: |  279   // The value of a Preference can be: | 
|  258   // managed, user defined, recommended or default. |  280   // managed, user defined, recommended or default. | 
|  259   // The PrefValueStore manages enforced, user defined and recommended values |  281   // The PrefValueStore manages enforced, user defined and recommended values | 
|  260   // for Preferences. It returns the value of a Preference with the |  282   // for Preferences. It returns the value of a Preference with the | 
|  261   // highest priority, and allows to set user defined values for preferences |  283   // highest priority, and allows to set user defined values for preferences | 
|  262   // that are not managed. |  284   // that are not managed. | 
|  263   scoped_ptr<PrefValueStore> pref_value_store_; |  285   scoped_refptr<PrefValueStore> pref_value_store_; | 
 |  286  | 
 |  287   NotificationRegistrar registrar_; | 
|  264  |  288  | 
|  265   // A set of all the registered Preference objects. |  289   // A set of all the registered Preference objects. | 
|  266   PreferenceSet prefs_; |  290   PreferenceSet prefs_; | 
|  267  |  291  | 
|  268   // A map from pref names to a list of observers.  Observers get fired in the |  292   // A map from pref names to a list of observers.  Observers get fired in the | 
|  269   // order they are added. |  293   // order they are added. | 
|  270   typedef ObserverList<NotificationObserver> NotificationObserverList; |  294   typedef ObserverList<NotificationObserver> NotificationObserverList; | 
|  271   typedef base::hash_map<std::wstring, NotificationObserverList*> |  295   typedef base::hash_map<std::wstring, NotificationObserverList*> | 
|  272       PrefObserverMap; |  296       PrefObserverMap; | 
|  273   PrefObserverMap pref_observers_; |  297   PrefObserverMap pref_observers_; | 
|  274  |  298  | 
|  275   friend class ScopedPrefUpdate; |  299   friend class ScopedPrefUpdate; | 
|  276  |  300  | 
|  277   DISALLOW_COPY_AND_ASSIGN(PrefService); |  301   DISALLOW_COPY_AND_ASSIGN(PrefService); | 
|  278 }; |  302 }; | 
|  279  |  303  | 
|  280 #endif  // CHROME_BROWSER_PREF_SERVICE_H_ |  304 #endif  // CHROME_BROWSER_PREF_SERVICE_H_ | 
| OLD | NEW |