supervised_user_shared_settings_update.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
14e579922ada4e19618710878c32543322f86c9c8Anders Carlsson// Copyright 2014 The Chromium Authors. All rights reserved.
24e579922ada4e19618710878c32543322f86c9c8Anders Carlsson// Use of this source code is governed by a BSD-style license that can be
34e579922ada4e19618710878c32543322f86c9c8Anders Carlsson// found in the LICENSE file.
44e579922ada4e19618710878c32543322f86c9c8Anders Carlsson
54e579922ada4e19618710878c32543322f86c9c8Anders Carlsson#ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_UPDATE_H_
64e579922ada4e19618710878c32543322f86c9c8Anders Carlsson#define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_UPDATE_H_
74e579922ada4e19618710878c32543322f86c9c8Anders Carlsson
84e579922ada4e19618710878c32543322f86c9c8Anders Carlsson#include <string>
94e579922ada4e19618710878c32543322f86c9c8Anders Carlsson
104e579922ada4e19618710878c32543322f86c9c8Anders Carlsson#include "base/callback.h"
114e579922ada4e19618710878c32543322f86c9c8Anders Carlsson#include "base/callback_list.h"
124e579922ada4e19618710878c32543322f86c9c8Anders Carlsson#include "base/memory/scoped_ptr.h"
134e579922ada4e19618710878c32543322f86c9c8Anders Carlsson
144e579922ada4e19618710878c32543322f86c9c8Anders Carlssonnamespace base {
154e579922ada4e19618710878c32543322f86c9c8Anders Carlssonclass Value;
16}
17
18class SupervisedUserSharedSettingsService;
19
20// Lets clients of SupervisedUserSharedSettingsService change settings and wait
21// for the Sync server to acknowledge the change. The callback passed in the
22// constructor will be called with a true success value after the Sync server
23// has flipped the acknowledgement flag for the setting. If another client
24// changes the value in the mean time, the callback will be run with a false
25// success value. If the object is destroyed before that, the callback will not
26// be run. Note that any changes made to the setting will not be undone when
27// destroying the object, even if the update was not successful or was canceled.
28class SupervisedUserSharedSettingsUpdate {
29 public:
30  SupervisedUserSharedSettingsUpdate(
31      SupervisedUserSharedSettingsService* service,
32      const std::string& su_id,
33      const std::string& key,
34      scoped_ptr<base::Value> value,
35      const base::Callback<void(bool)>& success_callback);
36  ~SupervisedUserSharedSettingsUpdate();
37
38 private:
39  typedef base::CallbackList<void(const std::string&, const std::string&)>
40      CallbackList;
41
42  void OnSettingChanged(const std::string& su_id,
43                        const std::string& key);
44
45  SupervisedUserSharedSettingsService* service_;
46  std::string su_id_;
47  std::string key_;
48  scoped_ptr<base::Value> value_;
49  base::Callback<void(bool)> callback_;
50  scoped_ptr<CallbackList::Subscription> subscription_;
51};
52
53#endif  // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_UPDATE_H_
54