OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MANAGED_MODE_MANAGED_USER_SHARED_SETTINGS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_SERVICE_H
_ |
6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SHARED_SETTINGS_SERVICE_H_ | 6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_SERVICE_H
_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/callback_list.h" | 9 #include "base/callback_list.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/browser/managed_mode/managed_users.h" | 11 #include "chrome/browser/supervised_user/supervised_users.h" |
12 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
13 #include "sync/api/syncable_service.h" | 13 #include "sync/api/syncable_service.h" |
14 | 14 |
15 class PrefService; | 15 class PrefService; |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class DictionaryValue; | 18 class DictionaryValue; |
19 class Value; | 19 class Value; |
20 } | 20 } |
21 | 21 |
22 namespace user_prefs { | 22 namespace user_prefs { |
23 class PrefRegistrySyncable; | 23 class PrefRegistrySyncable; |
24 } | 24 } |
25 | 25 |
26 // ManagedUserSharedSettingsService syncs settings (as key-value pairs) that can | 26 // SupervisedUserSharedSettingsService syncs settings (as key-value pairs) that |
27 // be modified both by a supervised user and their manager. | 27 // can be modified both by a supervised user and their manager. |
28 // A supervised user can only modify their own settings, whereas a manager can | 28 // A supervised user can only modify their own settings, whereas a manager can |
29 // modify settings for all their supervised users. | 29 // modify settings for all their supervised users. |
30 // | 30 // |
31 // The shared settings are stored in the user preferences in a multi-level | 31 // The shared settings are stored in the user preferences in a multi-level |
32 // dictionary. The first level is the MU ID, the second level is the key for the | 32 // dictionary. The first level is the SU ID (called "managed user ID" on the |
33 // setting, and the third level is a dictionary with a "value" key for the value | 33 // server for historic reasons), the second level is the key for the setting, |
34 // and an "acknowledged" flag, which is used to wait for the Sync server to | 34 // and the third level is a dictionary with a "value" key for the value and an |
35 // acknowledge that it has seen a setting change (see | 35 // "acknowledged" flag, which is used to wait for the Sync server to acknowledge |
36 // ManagedUserSharedSettingsUpdate for how to use this). | 36 // that it has seen a setting change (see SupervisedUserSharedSettingsUpdate for |
37 class ManagedUserSharedSettingsService : public KeyedService, | 37 // how to use this). |
38 public syncer::SyncableService { | 38 class SupervisedUserSharedSettingsService : public KeyedService, |
| 39 public syncer::SyncableService { |
39 public: | 40 public: |
40 // Called whenever a setting changes (see Subscribe() below). | 41 // Called whenever a setting changes (see Subscribe() below). |
41 typedef base::Callback<void(const std::string& /* mu_id */, | 42 typedef base::Callback<void(const std::string& /* su_id */, |
42 const std::string& /* key */)> ChangeCallback; | 43 const std::string& /* key */)> ChangeCallback; |
43 typedef base::CallbackList< | 44 typedef base::CallbackList< |
44 void(const std::string& /* mu_id */, const std::string& /* key */)> | 45 void(const std::string& /* su_id */, const std::string& /* key */)> |
45 ChangeCallbackList; | 46 ChangeCallbackList; |
46 | 47 |
47 // This constructor is public only for testing. Use | 48 // This constructor is public only for testing. Use |
48 // |ManagedUserSyncServiceFactory::GetForProfile(...)| instead to get an | 49 // |SupervisedUserSharedSettingsServiceFactory::GetForProfile(...)| instead to |
49 // instance of this service in production code. | 50 // get an instance of this service in production code. |
50 explicit ManagedUserSharedSettingsService(PrefService* prefs); | 51 explicit SupervisedUserSharedSettingsService(PrefService* prefs); |
51 virtual ~ManagedUserSharedSettingsService(); | 52 virtual ~SupervisedUserSharedSettingsService(); |
52 | 53 |
53 // Returns the value for the given |key| and the supervised user identified by | 54 // Returns the value for the given |key| and the supervised user identified by |
54 // |mu_id|. If either the supervised user or the key does not exist, NULL is | 55 // |su_id|. If either the supervised user or the key does not exist, NULL is |
55 // returned. Note that if the profile that owns this service belongs to a | 56 // returned. Note that if the profile that owns this service belongs to a |
56 // supervised user, callers will only see settings for their own |mu_id|, i.e. | 57 // supervised user, callers will only see settings for their own |su_id|, i.e. |
57 // a non-matching |mu_id| is treated as non-existent. | 58 // a non-matching |su_id| is treated as non-existent. |
58 const base::Value* GetValue(const std::string& mu_id, const std::string& key); | 59 const base::Value* GetValue(const std::string& su_id, const std::string& key); |
59 | 60 |
60 // Sets the value for the given |key| and the supervised user identified by | 61 // Sets the value for the given |key| and the supervised user identified by |
61 // |mu_id|. If the profile that owns this service belongs to a supervised | 62 // |su_id|. If the profile that owns this service belongs to a supervised |
62 // user, |mu_id| must be their own. | 63 // user, |su_id| must be their own. |
63 void SetValue(const std::string& mu_id, | 64 void SetValue(const std::string& su_id, |
64 const std::string& key, | 65 const std::string& key, |
65 const base::Value& value); | 66 const base::Value& value); |
66 | 67 |
67 // Subscribes to changes in the synced settings. The callback will be notified | 68 // Subscribes to changes in the synced settings. The callback will be notified |
68 // whenever any setting for any supervised user is changed via Sync (but not | 69 // whenever any setting for any supervised user is changed via Sync (but not |
69 // for local changes). Subscribers should filter the settings and users they | 70 // for local changes). Subscribers should filter the settings and users they |
70 // are interested in with the |mu_id| and |key| parameters to the callback. | 71 // are interested in with the |su_id| and |key| parameters to the callback. |
71 scoped_ptr<ChangeCallbackList::Subscription> Subscribe( | 72 scoped_ptr<ChangeCallbackList::Subscription> Subscribe( |
72 const ChangeCallback& cb); | 73 const ChangeCallback& cb); |
73 | 74 |
74 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 75 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
75 | 76 |
76 // Public for testing. | 77 // Public for testing. |
77 void SetValueInternal(const std::string& mu_id, | 78 void SetValueInternal(const std::string& su_id, |
78 const std::string& key, | 79 const std::string& key, |
79 const base::Value& value, | 80 const base::Value& value, |
80 bool acknowledged); | 81 bool acknowledged); |
81 | 82 |
82 // Public for testing. | 83 // Public for testing. |
83 static syncer::SyncData CreateSyncDataForSetting(const std::string& mu_id, | 84 static syncer::SyncData CreateSyncDataForSetting(const std::string& su_id, |
84 const std::string& key, | 85 const std::string& key, |
85 const base::Value& value, | 86 const base::Value& value, |
86 bool acknowledged); | 87 bool acknowledged); |
87 | 88 |
88 // KeyedService implementation: | 89 // KeyedService implementation: |
89 virtual void Shutdown() OVERRIDE; | 90 virtual void Shutdown() OVERRIDE; |
90 | 91 |
91 // SyncableService implementation: | 92 // SyncableService implementation: |
92 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 93 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
93 syncer::ModelType type, | 94 syncer::ModelType type, |
94 const syncer::SyncDataList& initial_sync_data, | 95 const syncer::SyncDataList& initial_sync_data, |
95 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | 96 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
96 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; | 97 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
97 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | 98 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
98 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const | 99 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const |
99 OVERRIDE; | 100 OVERRIDE; |
100 virtual syncer::SyncError ProcessSyncChanges( | 101 virtual syncer::SyncError ProcessSyncChanges( |
101 const tracked_objects::Location& from_here, | 102 const tracked_objects::Location& from_here, |
102 const syncer::SyncChangeList& change_list) OVERRIDE; | 103 const syncer::SyncChangeList& change_list) OVERRIDE; |
103 | 104 |
104 private: | 105 private: |
105 friend class ManagedUserSharedSettingsUpdate; | |
106 | |
107 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 106 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
108 scoped_ptr<syncer::SyncErrorFactory> error_handler_; | 107 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
109 | 108 |
110 ChangeCallbackList callbacks_; | 109 ChangeCallbackList callbacks_; |
111 | 110 |
112 PrefService* prefs_; | 111 PrefService* prefs_; |
113 }; | 112 }; |
114 | 113 |
115 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SHARED_SETTINGS_SERVICE_H_ | 114 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_SERVIC
E_H_ |
OLD | NEW |