OLD | NEW |
(Empty) | |
| 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 CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SHARED_SETTINGS_SERVICE_H_ |
| 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SHARED_SETTINGS_SERVICE_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/callback_list.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/managed_mode/managed_users.h" |
| 12 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 13 #include "sync/api/syncable_service.h" |
| 14 |
| 15 class PrefService; |
| 16 |
| 17 namespace base { |
| 18 class DictionaryValue; |
| 19 class Value; |
| 20 } |
| 21 |
| 22 namespace user_prefs { |
| 23 class PrefRegistrySyncable; |
| 24 } |
| 25 |
| 26 // ManagedUserSharedSettingsService syncs settings (as key-value pairs) that can |
| 27 // be modified both by a supervised user and their manager. |
| 28 // A supervised user can only modify their own settings, whereas a manager can |
| 29 // modify settings for all their supervised users. |
| 30 // |
| 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 |
| 33 // setting, and the third level is a dictionary with a "value" key for the value |
| 34 // and an "acknowledged" flag, which is used to wait for the Sync server to |
| 35 // acknowledge that it has seen a setting change (see |
| 36 // ManagedUserSharedSettingsUpdate for how to use this). |
| 37 class ManagedUserSharedSettingsService : public BrowserContextKeyedService, |
| 38 public syncer::SyncableService { |
| 39 public: |
| 40 // Called whenever a setting changes (see Subscribe() below). |
| 41 typedef base::Callback<void(const std::string& /* mu_id */, |
| 42 const std::string& /* key */)> ChangeCallback; |
| 43 typedef base::CallbackList< |
| 44 void(const std::string& /* mu_id */, const std::string& /* key */)> |
| 45 ChangeCallbackList; |
| 46 |
| 47 // This constructor is public only for testing. Use |
| 48 // |ManagedUserSyncServiceFactory::GetForProfile(...)| instead to get an |
| 49 // instance of this service in production code. |
| 50 explicit ManagedUserSharedSettingsService(PrefService* prefs); |
| 51 virtual ~ManagedUserSharedSettingsService(); |
| 52 |
| 53 // 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 // 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 // a non-matching |mu_id| is treated as non-existent. |
| 58 const base::Value* GetValue(const std::string& mu_id, const std::string& key); |
| 59 |
| 60 // 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 // user, |mu_id| must be their own. |
| 63 void SetValue(const std::string& mu_id, |
| 64 const std::string& key, |
| 65 const base::Value& value); |
| 66 |
| 67 // 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 // 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 scoped_ptr<ChangeCallbackList::Subscription> Subscribe( |
| 72 const ChangeCallback& cb); |
| 73 |
| 74 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 75 |
| 76 // Public for testing. |
| 77 void SetValueInternal(const std::string& mu_id, |
| 78 const std::string& key, |
| 79 const base::Value& value, |
| 80 bool acknowledged); |
| 81 |
| 82 // Public for testing. |
| 83 static syncer::SyncData CreateSyncDataForSetting(const std::string& mu_id, |
| 84 const std::string& key, |
| 85 const base::Value& value, |
| 86 bool acknowledged); |
| 87 |
| 88 // BrowserContextKeyedService implementation: |
| 89 virtual void Shutdown() OVERRIDE; |
| 90 |
| 91 // SyncableService implementation: |
| 92 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
| 93 syncer::ModelType type, |
| 94 const syncer::SyncDataList& initial_sync_data, |
| 95 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 96 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
| 97 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
| 98 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const |
| 99 OVERRIDE; |
| 100 virtual syncer::SyncError ProcessSyncChanges( |
| 101 const tracked_objects::Location& from_here, |
| 102 const syncer::SyncChangeList& change_list) OVERRIDE; |
| 103 |
| 104 private: |
| 105 friend class ManagedUserSharedSettingsUpdate; |
| 106 |
| 107 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
| 108 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
| 109 |
| 110 ChangeCallbackList callbacks_; |
| 111 |
| 112 PrefService* prefs_; |
| 113 }; |
| 114 |
| 115 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SHARED_SETTINGS_SERVICE_H_ |
OLD | NEW |