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

Side by Side Diff: components/prefs/scoped_user_pref_update.h

Issue 2908263002: Replace deprecated base::NonThreadSafe in components/prefs in favor of SequenceChecker. (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « components/prefs/pref_service.cc ('k') | components/prefs/scoped_user_pref_update.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 COMPONENTS_PREFS_SCOPED_USER_PREF_UPDATE_H_ 8 #ifndef COMPONENTS_PREFS_SCOPED_USER_PREF_UPDATE_H_
9 #define COMPONENTS_PREFS_SCOPED_USER_PREF_UPDATE_H_ 9 #define COMPONENTS_PREFS_SCOPED_USER_PREF_UPDATE_H_
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/threading/non_thread_safe.h" 14 #include "base/sequence_checker.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "components/prefs/base_prefs_export.h" 16 #include "components/prefs/base_prefs_export.h"
17 #include "components/prefs/pref_service.h" 17 #include "components/prefs/pref_service.h"
18 18
19 class PrefService; 19 class PrefService;
20 20
21 namespace base { 21 namespace base {
22 class DictionaryValue; 22 class DictionaryValue;
23 class ListValue; 23 class ListValue;
24 } 24 }
25 25
26 namespace subtle { 26 namespace subtle {
27 27
28 // Base class for ScopedUserPrefUpdateTemplate that contains the parts 28 // Base class for ScopedUserPrefUpdateTemplate that contains the parts
29 // that do not depend on ScopedUserPrefUpdateTemplate's template parameter. 29 // that do not depend on ScopedUserPrefUpdateTemplate's template parameter.
30 // 30 //
31 // We need this base class mostly for making it a friend of PrefService 31 // We need this base class mostly for making it a friend of PrefService
32 // and getting access to PrefService::GetMutableUserPref and 32 // and getting access to PrefService::GetMutableUserPref and
33 // PrefService::ReportUserPrefChanged. 33 // PrefService::ReportUserPrefChanged.
34 class COMPONENTS_PREFS_EXPORT ScopedUserPrefUpdateBase 34 class COMPONENTS_PREFS_EXPORT ScopedUserPrefUpdateBase {
35 : public base::NonThreadSafe {
36 protected: 35 protected:
37 ScopedUserPrefUpdateBase(PrefService* service, const std::string& path); 36 ScopedUserPrefUpdateBase(PrefService* service, const std::string& path);
38 37
39 // Calls Notify(). 38 // Calls Notify().
40 ~ScopedUserPrefUpdateBase(); 39 ~ScopedUserPrefUpdateBase();
41 40
42 // Sets |value_| to |service_|->GetMutableUserPref and returns it. 41 // Sets |value_| to |service_|->GetMutableUserPref and returns it.
43 base::Value* GetValueOfType(base::Value::Type type); 42 base::Value* GetValueOfType(base::Value::Type type);
44 43
45 private: 44 private:
46 // If |value_| is not null, triggers a notification of PrefObservers and 45 // If |value_| is not null, triggers a notification of PrefObservers and
47 // resets |value_|. 46 // resets |value_|.
48 void Notify(); 47 void Notify();
49 48
50 // Weak pointer. 49 // Weak pointer.
51 PrefService* service_; 50 PrefService* service_;
52 // Path of the preference being updated. 51 // Path of the preference being updated.
53 std::string path_; 52 std::string path_;
54 // Cache of value from user pref store (set between Get() and Notify() calls). 53 // Cache of value from user pref store (set between Get() and Notify() calls).
55 base::Value* value_; 54 base::Value* value_;
56 55
56 SEQUENCE_CHECKER(sequence_checker_);
57
57 DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdateBase); 58 DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdateBase);
58 }; 59 };
59 60
60 } // namespace subtle 61 } // namespace subtle
61 62
62 // Class to support modifications to DictionaryValues and ListValues while 63 // Class to support modifications to DictionaryValues and ListValues while
63 // guaranteeing that PrefObservers are notified of changed values. 64 // guaranteeing that PrefObservers are notified of changed values.
64 // 65 //
65 // This class may only be used on the UI thread as it requires access to the 66 // This class may only be used on the UI thread as it requires access to the
66 // PrefService. 67 // PrefService.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdate); 101 DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdate);
101 }; 102 };
102 103
103 typedef ScopedUserPrefUpdate<base::DictionaryValue, 104 typedef ScopedUserPrefUpdate<base::DictionaryValue,
104 base::Value::Type::DICTIONARY> 105 base::Value::Type::DICTIONARY>
105 DictionaryPrefUpdate; 106 DictionaryPrefUpdate;
106 typedef ScopedUserPrefUpdate<base::ListValue, base::Value::Type::LIST> 107 typedef ScopedUserPrefUpdate<base::ListValue, base::Value::Type::LIST>
107 ListPrefUpdate; 108 ListPrefUpdate;
108 109
109 #endif // COMPONENTS_PREFS_SCOPED_USER_PREF_UPDATE_H_ 110 #endif // COMPONENTS_PREFS_SCOPED_USER_PREF_UPDATE_H_
OLDNEW
« no previous file with comments | « components/prefs/pref_service.cc ('k') | components/prefs/scoped_user_pref_update.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698