supervised_user_shared_settings_update.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_UPDATE_H_
6f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_UPDATE_H_
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string>
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/callback.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/callback_list.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace base {
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Value;
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
18f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class SupervisedUserSharedSettingsService;
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
20f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// Lets clients of SupervisedUserSharedSettingsService change settings and wait
21f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// for the Sync server to acknowledge the change. The callback passed in the
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// constructor will be called with a true success value after the Sync server
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// has flipped the acknowledgement flag for the setting. If another client
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// changes the value in the mean time, the callback will be run with a false
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// success value. If the object is destroyed before that, the callback will not
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// be run. Note that any changes made to the setting will not be undone when
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// destroying the object, even if the update was not successful or was canceled.
28f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class SupervisedUserSharedSettingsUpdate {
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
30f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SupervisedUserSharedSettingsUpdate(
31f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      SupervisedUserSharedSettingsService* service,
32f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      const std::string& su_id,
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const std::string& key,
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      scoped_ptr<base::Value> value,
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const base::Callback<void(bool)>& success_callback);
36f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  ~SupervisedUserSharedSettingsUpdate();
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  typedef base::CallbackList<void(const std::string&, const std::string&)>
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      CallbackList;
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
42f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void OnSettingChanged(const std::string& su_id,
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                        const std::string& key);
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
45f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  SupervisedUserSharedSettingsService* service_;
46f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  std::string su_id_;
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string key_;
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<base::Value> value_;
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::Callback<void(bool)> callback_;
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<CallbackList::Subscription> subscription_;
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
53f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#endif  // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_UPDATE_H_
54