Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / supervised_user_import_handler.h
blob46e93a26a1f2cb2c832b5dba7992daec768e9d79
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 <string>
10 #include "base/callback_list.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/scoped_observer.h"
13 #include "base/strings/string16.h"
14 #include "chrome/browser/profiles/profile_info_cache_observer.h"
15 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_observer.h"
16 #include "chrome/browser/ui/webui/options/options_ui.h"
17 #include "components/signin/core/browser/signin_error_controller.h"
19 namespace base {
20 class DictionaryValue;
21 class ListValue;
24 class ProfileInfoCache;
25 class SupervisedUserSyncService;
27 namespace options {
29 // Handler for the 'import existing supervised user' dialog.
30 class SupervisedUserImportHandler : public OptionsPageUIHandler,
31 public ProfileInfoCacheObserver,
32 public SupervisedUserSyncServiceObserver,
33 public SigninErrorController::Observer {
34 public:
35 typedef base::CallbackList<void(const std::string&, const std::string&)>
36 CallbackList;
38 SupervisedUserImportHandler();
39 ~SupervisedUserImportHandler() override;
41 private:
42 // OptionsPageUIHandler implementation.
43 void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
44 void InitializeHandler() override;
46 // WebUIMessageHandler implementation.
47 void RegisterMessages() override;
49 // ProfileInfoCacheObserver implementation.
50 void OnProfileAdded(const base::FilePath& profile_path) override;
51 void OnProfileWillBeRemoved(const base::FilePath& profile_path) override;
52 void OnProfileWasRemoved(const base::FilePath& profile_path,
53 const base::string16& profile_name) override;
54 void OnProfileIsOmittedChanged(const base::FilePath& profile_path) override;
56 // SupervisedUserSyncServiceObserver implementation.
57 void OnSupervisedUserAcknowledged(
58 const std::string& supervised_user_id) override {}
59 void OnSupervisedUsersSyncingStopped() override {}
60 void OnSupervisedUsersChanged() override;
62 // SigninErrorController::Observer implementation.
63 void OnErrorChanged() override;
65 // Clears the cached list of supervised users and fetches the new list of
66 // supervised users.
67 void FetchSupervisedUsers();
69 // Callback for the "requestSupervisedUserImportUpdate" message.
70 // Checks the sign-in status of the custodian and accordingly
71 // sends an update to the WebUI. The update can be to show/hide
72 // an error bubble and update/clear the supervised user list.
73 void RequestSupervisedUserImportUpdate(const base::ListValue* args);
75 // Sends an array of supervised users to WebUI. Each entry is of the form:
76 // supervisedProfile = {
77 // id: "Supervised User ID",
78 // name: "Supervised User Name",
79 // iconURL: "chrome://path/to/icon/image",
80 // onCurrentDevice: true or false,
81 // needAvatar: true or false
82 // }
83 // The array holds all existing supervised users attached to the
84 // custodian's profile which initiated the request.
85 void SendExistingSupervisedUsers(const base::DictionaryValue* dict);
87 // Sends messages to the JS side to clear supervised users and show an error
88 // bubble.
89 void ClearSupervisedUsersAndShowError();
91 bool IsAccountConnected() const;
92 bool HasAuthError() const;
94 // Called when a supervised user shared setting is changed. If the avatar was
95 // changed, FetchSupervisedUsers() is called.
96 void OnSharedSettingChanged(const std::string& supervised_user_id,
97 const std::string& key);
99 scoped_ptr<CallbackList::Subscription> subscription_;
101 ScopedObserver<ProfileInfoCache, SupervisedUserImportHandler>
102 profile_observer_;
103 ScopedObserver<SigninErrorController, SupervisedUserImportHandler>
104 signin_error_observer_;
105 ScopedObserver<SupervisedUserSyncService, SupervisedUserImportHandler>
106 supervised_user_sync_service_observer_;
108 bool removed_profile_is_supervised_;
110 base::WeakPtrFactory<SupervisedUserImportHandler> weak_ptr_factory_;
112 DISALLOW_COPY_AND_ASSIGN(SupervisedUserImportHandler);
115 } // namespace options
117 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_SUPERVISED_USER_IMPORT_HANDLER_H_