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

Unified Diff: chrome/browser/managed_mode/managed_user_shared_settings_service.h

Issue 123293003: Add ManagedUserSharedSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/managed_mode/managed_user_shared_settings_service.h
diff --git a/chrome/browser/managed_mode/managed_user_shared_settings_service.h b/chrome/browser/managed_mode/managed_user_shared_settings_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..fef8bd9125a2987ba654e1b47dff20844bdcd493
--- /dev/null
+++ b/chrome/browser/managed_mode/managed_user_shared_settings_service.h
@@ -0,0 +1,103 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SHARED_SETTINGS_SERVICE_H_
+#define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SHARED_SETTINGS_SERVICE_H_
+
+#include "base/callback.h"
+#include "base/callback_list.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/managed_mode/managed_users.h"
+#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
+#include "sync/api/syncable_service.h"
+
+class PrefService;
+
+namespace base {
+class DictionaryValue;
+class Value;
+}
+
+namespace user_prefs {
+class PrefRegistrySyncable;
+}
+
+// ManagedUserSharedSettingsService syncs settings (as key-value pairs) that can
+// be modified both by a supervised user and their manager.
+// A supervised user can only modify their own settings, whereas a manager can
+// modify settings for all their supervised users.
+class ManagedUserSharedSettingsService : public BrowserContextKeyedService,
+ public syncer::SyncableService {
+ public:
+ typedef base::Callback<void(const std::string& /* mu_id */,
Pam (message me for reviews) 2014/01/08 10:30:40 A comment saying that this is called with settings
Bernhard Bauer 2014/01/08 11:42:04 Done.
+ const std::string& /* key */)> Callback;
+ typedef base::CallbackList<void(const std::string& /* mu_id */,
+ const std::string& /* key */)> CallbackList;
+
+ // Public for testing. Use |ManagedUserSyncServiceFactory::GetForProfile(...)|
+ // to get an instance of this service.
Pam (message me for reviews) 2014/01/08 10:30:40 It's not clear from this comment whether the secon
Bernhard Bauer 2014/01/08 11:42:04 Done.
+ explicit ManagedUserSharedSettingsService(PrefService* prefs);
+ virtual ~ManagedUserSharedSettingsService();
+
+ // Returns the value for the given |key| and the supervised user identified by
+ // |mu_id|. If either the supervised user or the key does not exist, NULL is
+ // returned. Note that a supervised user will only see settings for their own
+ // |mu_id|.
Pam (message me for reviews) 2014/01/08 10:30:40 For complete clarity, something like Returns the
Bernhard Bauer 2014/01/08 11:42:04 Well, the "must be their own" part isn't entirely
+ const base::Value* GetValue(const std::string& mu_id, const std::string& key);
+
+ // Sets the value for the given |key| and the supervised user identified by
+ // |mu_id|. If the profile that owns this service belongs to a supervised
+ // user, |mu_id| must be their own.
+ void SetValue(const std::string& mu_id,
+ const std::string& key,
+ const base::Value& value);
+
+ // Subscribes to changes in the synced settings. The callback will be notified
+ // whenever any setting for any supervised user is changed via Sync (but not
+ // for local changes). Subscribers should filter the settings and users they
+ // are interested in with the |mu_id| and |key| parameters to the callback.
+ scoped_ptr<CallbackList::Subscription> Subscribe(const Callback& cb);
+
+ static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
+
+ // Public for testing.
+ void SetValueInternal(const std::string& mu_id,
Pam (message me for reviews) 2014/01/08 10:30:40 I remember seeing some announcement about naming p
Bernhard Bauer 2014/01/08 11:42:04 There is indeed such a presubmit check, but it is
Pam (message me for reviews) 2014/01/08 12:19:28 Agreed. I reviewed the .h before the .cc and didn'
+ const std::string& key,
+ const base::Value& value,
+ bool acknowledged);
+
+ // Public for testing.
+ static syncer::SyncData CreateSyncDataForSetting(const std::string& mu_id,
+ const std::string& key,
+ const base::Value& value,
+ bool acknowledged);
+
+ // BrowserContextKeyedService implementation:
+ virtual void Shutdown() OVERRIDE;
+
+ // SyncableService implementation:
+ virtual syncer::SyncMergeResult MergeDataAndStartSyncing(
+ syncer::ModelType type,
+ const syncer::SyncDataList& initial_sync_data,
+ scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
+ scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE;
+ virtual void StopSyncing(syncer::ModelType type) OVERRIDE;
+ virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
+ OVERRIDE;
+ virtual syncer::SyncError ProcessSyncChanges(
+ const tracked_objects::Location& from_here,
+ const syncer::SyncChangeList& change_list) OVERRIDE;
+
+ private:
+ friend class ManagedUserSharedSettingsUpdate;
+
+ scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
+ scoped_ptr<syncer::SyncErrorFactory> error_handler_;
+
+ CallbackList callbacks_;
+
+ PrefService* prefs_;
+};
+
+#endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SHARED_SETTINGS_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698