| 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 #ifndef CHROME_BROWSER_PREFS_PREF_NOTIFIER_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_NOTIFIER_H_ |
| 6 #define CHROME_BROWSER_PREFS_PREF_NOTIFIER_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_NOTIFIER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // preference) change. | 25 // preference) change. |
| 26 class PrefNotifier : public NonThreadSafe, | 26 class PrefNotifier : public NonThreadSafe, |
| 27 public NotificationObserver { | 27 public NotificationObserver { |
| 28 public: | 28 public: |
| 29 // PrefStores must be listed here in order from highest to lowest priority. | 29 // PrefStores must be listed here in order from highest to lowest priority. |
| 30 // MANAGED contains all managed (policy) preference values. | 30 // MANAGED contains all managed (policy) preference values. |
| 31 // EXTENSION contains preference values set by extensions. | 31 // EXTENSION contains preference values set by extensions. |
| 32 // COMMAND_LINE contains preference values set by command-line switches. | 32 // COMMAND_LINE contains preference values set by command-line switches. |
| 33 // USER contains all user-set preference values. | 33 // USER contains all user-set preference values. |
| 34 // RECOMMENDED contains all recommended (policy) preference values. | 34 // RECOMMENDED contains all recommended (policy) preference values. |
| 35 // DEFAULT contains all application default preference values. |
| 35 // This enum is kept in pref_notifier.h rather than pref_value_store.h in | 36 // This enum is kept in pref_notifier.h rather than pref_value_store.h in |
| 36 // order to minimize additional headers needed by the *PrefStore files. | 37 // order to minimize additional headers needed by the *PrefStore files. |
| 37 enum PrefStoreType { | 38 enum PrefStoreType { |
| 38 // INVALID_STORE is not associated with an actual PrefStore but used as | 39 // INVALID_STORE is not associated with an actual PrefStore but used as |
| 39 // an invalid marker, e.g. as a return value. | 40 // an invalid marker, e.g. as a return value. |
| 40 INVALID_STORE = -1, | 41 INVALID_STORE = -1, |
| 41 MANAGED_STORE = 0, | 42 MANAGED_STORE = 0, |
| 42 EXTENSION_STORE, | 43 EXTENSION_STORE, |
| 43 COMMAND_LINE_STORE, | 44 COMMAND_LINE_STORE, |
| 44 USER_STORE, | 45 USER_STORE, |
| 45 RECOMMENDED_STORE, | 46 RECOMMENDED_STORE, |
| 46 PREF_STORE_TYPE_MAX = RECOMMENDED_STORE | 47 DEFAULT_STORE, |
| 48 PREF_STORE_TYPE_MAX = DEFAULT_STORE |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 // The |service| with which this notifier is associated will be sent as the | 51 // The |service| with which this notifier is associated will be sent as the |
| 50 // source of any notifications. | 52 // source of any notifications. |
| 51 PrefNotifier(PrefService* service, PrefValueStore* value_store); | 53 PrefNotifier(PrefService* service, PrefValueStore* value_store); |
| 52 | 54 |
| 53 virtual ~PrefNotifier(); | 55 virtual ~PrefNotifier(); |
| 54 | 56 |
| 55 // For the given pref_name, fire any observer of the pref if |old_value| is | 57 // For the given pref_name, fire any observer of the pref if the effective |
| 56 // different from the current value, or if the store controlling the value | 58 // value of the pref or the store controlling its value has changed, been |
| 57 // has changed. | 59 // added, or been removed (but not if it's re-setting the same value it had |
| 58 // TODO(pamg): Currently notifies in some cases when it shouldn't. See | 60 // already). |new_store| should be the PrefStoreType of the store reporting |
| 59 // comments for PrefHasChanged() in pref_value_store.h. | 61 // the change. |
| 60 void OnPreferenceSet(const char* pref_name, | 62 void OnPreferenceSet(const char* pref_name, |
| 61 PrefNotifier::PrefStoreType new_store, | 63 PrefNotifier::PrefStoreType new_store); |
| 62 const Value* old_value); | |
| 63 | 64 |
| 64 // Convenience method to be called when a preference is set in the | 65 // Convenience method to be called when a preference is set in the |
| 65 // USER_STORE. See OnPreferenceSet(). | 66 // USER_STORE. See OnPreferenceSet(). |
| 66 void OnUserPreferenceSet(const char* pref_name, const Value* old_value); | 67 void OnUserPreferenceSet(const char* pref_name); |
| 67 | 68 |
| 68 // For the given pref_name, fire any observer of the pref. Virtual so it can | 69 // For the given pref_name, fire any observer of the pref. Virtual so it can |
| 69 // be mocked for unit testing. | 70 // be mocked for unit testing. |
| 70 virtual void FireObservers(const char* path); | 71 virtual void FireObservers(const char* path); |
| 71 | 72 |
| 72 // If the pref at the given path changes, we call the observer's Observe | 73 // If the pref at the given path changes, we call the observer's Observe |
| 73 // method with NOTIFY_PREF_CHANGED. | 74 // method with NOTIFY_PREF_CHANGED. |
| 74 void AddPrefObserver(const char* path, NotificationObserver* obs); | 75 void AddPrefObserver(const char* path, NotificationObserver* obs); |
| 75 void RemovePrefObserver(const char* path, NotificationObserver* obs); | 76 void RemovePrefObserver(const char* path, NotificationObserver* obs); |
| 76 | 77 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 103 | 104 |
| 104 // NotificationObserver methods: | 105 // NotificationObserver methods: |
| 105 virtual void Observe(NotificationType type, | 106 virtual void Observe(NotificationType type, |
| 106 const NotificationSource& source, | 107 const NotificationSource& source, |
| 107 const NotificationDetails& details); | 108 const NotificationDetails& details); |
| 108 | 109 |
| 109 DISALLOW_COPY_AND_ASSIGN(PrefNotifier); | 110 DISALLOW_COPY_AND_ASSIGN(PrefNotifier); |
| 110 }; | 111 }; |
| 111 | 112 |
| 112 #endif // CHROME_BROWSER_PREFS_PREF_NOTIFIER_H_ | 113 #endif // CHROME_BROWSER_PREFS_PREF_NOTIFIER_H_ |
| OLD | NEW |