[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef COMPONENTS_USER_PREFS_USER_PREFS_H_ | ||||
6 | #define COMPONENTS_USER_PREFS_USER_PREFS_H_ | ||||
7 | |||||
dcheng | 40f88368 | 2015-07-25 05:22:49 | [diff] [blame] | 8 | #include "base/basictypes.h" |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 9 | #include "base/supports_user_data.h" |
dcheng | 40f88368 | 2015-07-25 05:22:49 | [diff] [blame] | 10 | #include "components/user_prefs/user_prefs_export.h" |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 11 | |
12 | class PrefService; | ||||
13 | |||||
[email protected] | c7141feb | 2013-06-11 13:00:16 | [diff] [blame] | 14 | namespace user_prefs { |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 15 | |
droger | 3b2d62d | 2015-04-16 08:04:32 | [diff] [blame] | 16 | // Components may use preferences associated with a given user. These hang off |
17 | // of base::SupportsUserData and can be retrieved using UserPrefs::Get(). | ||||
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 18 | // |
droger | 3b2d62d | 2015-04-16 08:04:32 | [diff] [blame] | 19 | // It is up to the embedder to create and own the PrefService and attach it to |
20 | // base::SupportsUserData using the UserPrefs::Set() function. | ||||
dcheng | 40f88368 | 2015-07-25 05:22:49 | [diff] [blame] | 21 | class USER_PREFS_EXPORT UserPrefs : public base::SupportsUserData::Data { |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 22 | public: |
droger | 3b2d62d | 2015-04-16 08:04:32 | [diff] [blame] | 23 | // Retrieves the PrefService for a given context, or null if none is attached. |
24 | static PrefService* Get(base::SupportsUserData* context); | ||||
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 25 | |
26 | // Hangs the specified |prefs| off of |context|. Should be called | ||||
droger | 3b2d62d | 2015-04-16 08:04:32 | [diff] [blame] | 27 | // only once per context. |
28 | static void Set(base::SupportsUserData* context, PrefService* prefs); | ||||
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 29 | |
30 | private: | ||||
[email protected] | 5a64e82 | 2013-03-08 14:12:50 | [diff] [blame] | 31 | explicit UserPrefs(PrefService* prefs); |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 32 | ~UserPrefs() override; |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 33 | |
34 | // Non-owning; owned by embedder. | ||||
35 | PrefService* prefs_; | ||||
36 | |||||
37 | DISALLOW_COPY_AND_ASSIGN(UserPrefs); | ||||
38 | }; | ||||
39 | |||||
[email protected] | c7141feb | 2013-06-11 13:00:16 | [diff] [blame] | 40 | } // namespace user_prefs |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 41 | |
42 | #endif // COMPONENTS_USER_PREFS_USER_PREFS_H_ |