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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_SUPERVISED_USER_IMPORT_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_SUPERVISED_USER_IMPORT_HANDLER_H_
8 #include "base/callback_list.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/scoped_observer.h"
11 #include "chrome/browser/supervised_user/supervised_user_sync_service_observer.h"
12 #include "chrome/browser/ui/webui/options/options_ui.h"
13 #include "components/signin/core/browser/signin_error_controller.h"
16 class DictionaryValue
;
22 // Handler for the 'import existing supervised user' dialog.
23 class SupervisedUserImportHandler
: public OptionsPageUIHandler
,
24 public SupervisedUserSyncServiceObserver
,
25 public SigninErrorController::Observer
{
27 typedef base::CallbackList
<void(const std::string
&, const std::string
&)>
30 SupervisedUserImportHandler();
31 virtual ~SupervisedUserImportHandler();
33 // OptionsPageUIHandler implementation.
34 virtual void GetLocalizedValues(
35 base::DictionaryValue
* localized_strings
) override
;
36 virtual void InitializeHandler() override
;
38 // WebUIMessageHandler implementation.
39 virtual void RegisterMessages() override
;
41 // SupervisedUserSyncServiceObserver implementation.
42 virtual void OnSupervisedUserAcknowledged(
43 const std::string
& supervised_user_id
) override
{}
44 virtual void OnSupervisedUsersSyncingStopped() override
{}
45 virtual void OnSupervisedUsersChanged() override
;
47 // SigninErrorController::Observer implementation.
48 virtual void OnErrorChanged() override
;
51 // Clears the cached list of supervised users and fetches the new list of
53 void FetchSupervisedUsers();
55 // Callback for the "requestSupervisedUserImportUpdate" message.
56 // Checks the sign-in status of the custodian and accordingly
57 // sends an update to the WebUI. The update can be to show/hide
58 // an error bubble and update/clear the supervised user list.
59 void RequestSupervisedUserImportUpdate(const base::ListValue
* args
);
61 // Sends an array of supervised users to WebUI. Each entry is of the form:
62 // supervisedProfile = {
63 // id: "Supervised User ID",
64 // name: "Supervised User Name",
65 // iconURL: "chrome://path/to/icon/image",
66 // onCurrentDevice: true or false,
67 // needAvatar: true or false
69 // The array holds all existing supervised users attached to the
70 // custodian's profile which initiated the request.
71 void SendExistingSupervisedUsers(const base::DictionaryValue
* dict
);
73 // Sends messages to the JS side to clear supervised users and show an error
75 void ClearSupervisedUsersAndShowError();
77 bool IsAccountConnected() const;
78 bool HasAuthError() const;
80 // Called when a supervised user shared setting is changed. If the avatar was
81 // changed, FetchSupervisedUsers() is called.
82 void OnSharedSettingChanged(const std::string
& supervised_user_id
,
83 const std::string
& key
);
85 scoped_ptr
<CallbackList::Subscription
> subscription_
;
87 ScopedObserver
<SigninErrorController
, SupervisedUserImportHandler
> observer_
;
89 base::WeakPtrFactory
<SupervisedUserImportHandler
> weak_ptr_factory_
;
91 DISALLOW_COPY_AND_ASSIGN(SupervisedUserImportHandler
);
94 } // namespace options
96 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_SUPERVISED_USER_IMPORT_HANDLER_H_