Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: chrome/browser/prefs/scoped_user_pref_update.h

Issue 7634018: base: Rename ValueType to something less redundant as _just_ Type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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 // A helper class that assists preferences in firing notifications when lists 5 // A helper class that assists preferences in firing notifications when lists
6 // or dictionaries are changed. 6 // or dictionaries are changed.
7 7
8 #ifndef CHROME_BROWSER_PREFS_SCOPED_USER_PREF_UPDATE_H_ 8 #ifndef CHROME_BROWSER_PREFS_SCOPED_USER_PREF_UPDATE_H_
9 #define CHROME_BROWSER_PREFS_SCOPED_USER_PREF_UPDATE_H_ 9 #define CHROME_BROWSER_PREFS_SCOPED_USER_PREF_UPDATE_H_
10 #pragma once 10 #pragma once
(...skipping 22 matching lines...) Expand all
33 // and getting access to PrefService::GetMutableUserPref and 33 // and getting access to PrefService::GetMutableUserPref and
34 // PrefService::ReportUserPrefChanged. 34 // PrefService::ReportUserPrefChanged.
35 class ScopedUserPrefUpdateBase : public base::NonThreadSafe { 35 class ScopedUserPrefUpdateBase : public base::NonThreadSafe {
36 protected: 36 protected:
37 ScopedUserPrefUpdateBase(PrefService* service, const char* path); 37 ScopedUserPrefUpdateBase(PrefService* service, const char* path);
38 38
39 // Calls Notify(). 39 // Calls Notify().
40 virtual ~ScopedUserPrefUpdateBase(); 40 virtual ~ScopedUserPrefUpdateBase();
41 41
42 // Sets |value_| to |service_|->GetMutableUserPref and returns it. 42 // Sets |value_| to |service_|->GetMutableUserPref and returns it.
43 base::Value* Get(Value::ValueType type); 43 base::Value* Get(base::Value::Type type);
44 44
45 private: 45 private:
46 // If |value_| is not null, triggers a notification of PrefObservers and 46 // If |value_| is not null, triggers a notification of PrefObservers and
47 // resets |value_|. 47 // resets |value_|.
48 virtual void Notify(); 48 virtual void Notify();
49 49
50 // Weak pointer. 50 // Weak pointer.
51 PrefService* service_; 51 PrefService* service_;
52 // Path of the preference being updated. 52 // Path of the preference being updated.
53 std::string path_; 53 std::string path_;
54 // Cache of value from user pref store (set between Get() and Notify() calls). 54 // Cache of value from user pref store (set between Get() and Notify() calls).
55 base::Value* value_; 55 base::Value* value_;
56 56
57 DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdateBase); 57 DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdateBase);
58 }; 58 };
59 59
60 } // namespace subtle 60 } // namespace subtle
61 61
62 // Class to support modifications to DictionaryValues and ListValues while 62 // Class to support modifications to DictionaryValues and ListValues while
63 // guaranteeing that PrefObservers are notified of changed values. 63 // guaranteeing that PrefObservers are notified of changed values.
64 // 64 //
65 // This class may only be used on the UI thread as it requires access to the 65 // This class may only be used on the UI thread as it requires access to the
66 // PrefService. 66 // PrefService.
67 template <typename T, Value::ValueType type_enum_value> 67 template <typename T, base::Value::Type type_enum_value>
68 class ScopedUserPrefUpdate : public subtle::ScopedUserPrefUpdateBase { 68 class ScopedUserPrefUpdate : public subtle::ScopedUserPrefUpdateBase {
69 public: 69 public:
70 ScopedUserPrefUpdate(PrefService* service, const char* path) 70 ScopedUserPrefUpdate(PrefService* service, const char* path)
71 : ScopedUserPrefUpdateBase(service, path) {} 71 : ScopedUserPrefUpdateBase(service, path) {}
72 72
73 // Triggers an update notification if Get() was called. 73 // Triggers an update notification if Get() was called.
74 virtual ~ScopedUserPrefUpdate() {} 74 virtual ~ScopedUserPrefUpdate() {}
75 75
76 // Returns a mutable |T| instance that 76 // Returns a mutable |T| instance that
77 // - is already in the user pref store, or 77 // - is already in the user pref store, or
(...skipping 19 matching lines...) Expand all
97 97
98 private: 98 private:
99 DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdate); 99 DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdate);
100 }; 100 };
101 101
102 typedef ScopedUserPrefUpdate<base::DictionaryValue, Value::TYPE_DICTIONARY> 102 typedef ScopedUserPrefUpdate<base::DictionaryValue, Value::TYPE_DICTIONARY>
103 DictionaryPrefUpdate; 103 DictionaryPrefUpdate;
104 typedef ScopedUserPrefUpdate<base::ListValue, Value::TYPE_LIST> ListPrefUpdate; 104 typedef ScopedUserPrefUpdate<base::ListValue, Value::TYPE_LIST> ListPrefUpdate;
105 105
106 #endif // CHROME_BROWSER_PREFS_SCOPED_USER_PREF_UPDATE_H_ 106 #endif // CHROME_BROWSER_PREFS_SCOPED_USER_PREF_UPDATE_H_
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_value_store.cc ('k') | chrome/browser/prefs/scoped_user_pref_update.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698