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 ~SupervisedUserImportHandler() override;
33 // OptionsPageUIHandler implementation.
34 void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
35 void InitializeHandler() override;
37 // WebUIMessageHandler implementation.
38 void RegisterMessages() override;
40 // SupervisedUserSyncServiceObserver implementation.
41 void OnSupervisedUserAcknowledged(
42 const std::string& supervised_user_id) override {}
43 void OnSupervisedUsersSyncingStopped() override {}
44 void OnSupervisedUsersChanged() override;
46 // SigninErrorController::Observer implementation.
47 void OnErrorChanged() override;
50 // Clears the cached list of supervised users and fetches the new list of
52 void FetchSupervisedUsers();
54 // Callback for the "requestSupervisedUserImportUpdate" message.
55 // Checks the sign-in status of the custodian and accordingly
56 // sends an update to the WebUI. The update can be to show/hide
57 // an error bubble and update/clear the supervised user list.
58 void RequestSupervisedUserImportUpdate(const base::ListValue* args);
60 // Sends an array of supervised users to WebUI. Each entry is of the form:
61 // supervisedProfile = {
62 // id: "Supervised User ID",
63 // name: "Supervised User Name",
64 // iconURL: "chrome://path/to/icon/image",
65 // onCurrentDevice: true or false,
66 // needAvatar: true or false
68 // The array holds all existing supervised users attached to the
69 // custodian's profile which initiated the request.
70 void SendExistingSupervisedUsers(const base::DictionaryValue* dict);
72 // Sends messages to the JS side to clear supervised users and show an error
74 void ClearSupervisedUsersAndShowError();
76 bool IsAccountConnected() const;
77 bool HasAuthError() const;
79 // Called when a supervised user shared setting is changed. If the avatar was
80 // changed, FetchSupervisedUsers() is called.
81 void OnSharedSettingChanged(const std::string& supervised_user_id,
82 const std::string& key);
84 scoped_ptr<CallbackList::Subscription> subscription_;
86 ScopedObserver<SigninErrorController, SupervisedUserImportHandler> observer_;
88 base::WeakPtrFactory<SupervisedUserImportHandler> weak_ptr_factory_;
90 DISALLOW_COPY_AND_ASSIGN(SupervisedUserImportHandler);
93 } // namespace options
95 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_SUPERVISED_USER_IMPORT_HANDLER_H_