Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / supervised_user_import_handler.h
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.
4
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_SUPERVISED_USER_IMPORT_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_SUPERVISED_USER_IMPORT_HANDLER_H_
7
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"
14
15 namespace base {
16 class DictionaryValue;
17 class ListValue;
18 }
19
20 namespace options {
21
22 // Handler for the 'import existing supervised user' dialog.
23 class SupervisedUserImportHandler : public OptionsPageUIHandler,
24                                     public SupervisedUserSyncServiceObserver,
25                                     public SigninErrorController::Observer {
26  public:
27   typedef base::CallbackList<void(const std::string&, const std::string&)>
28       CallbackList;
29
30   SupervisedUserImportHandler();
31   ~SupervisedUserImportHandler() override;
32
33   // OptionsPageUIHandler implementation.
34   void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
35   void InitializeHandler() override;
36
37   // WebUIMessageHandler implementation.
38   void RegisterMessages() override;
39
40   // SupervisedUserSyncServiceObserver implementation.
41   void OnSupervisedUserAcknowledged(
42       const std::string& supervised_user_id) override {}
43   void OnSupervisedUsersSyncingStopped() override {}
44   void OnSupervisedUsersChanged() override;
45
46   // SigninErrorController::Observer implementation.
47   void OnErrorChanged() override;
48
49  private:
50   // Clears the cached list of supervised users and fetches the new list of
51   // supervised users.
52   void FetchSupervisedUsers();
53
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);
59
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
67   //   }
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);
71
72   // Sends messages to the JS side to clear supervised users and show an error
73   // bubble.
74   void ClearSupervisedUsersAndShowError();
75
76   bool IsAccountConnected() const;
77   bool HasAuthError() const;
78
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);
83
84   scoped_ptr<CallbackList::Subscription> subscription_;
85
86   ScopedObserver<SigninErrorController, SupervisedUserImportHandler> observer_;
87
88   base::WeakPtrFactory<SupervisedUserImportHandler> weak_ptr_factory_;
89
90   DISALLOW_COPY_AND_ASSIGN(SupervisedUserImportHandler);
91 };
92
93 }  // namespace options
94
95 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_SUPERVISED_USER_IMPORT_HANDLER_H_