55dbd9c3444381521971fad8634a503447453007
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / managed_user_import_handler.h
1 // Copyright 2013 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_MANAGED_USER_IMPORT_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_MANAGED_USER_IMPORT_HANDLER_H_
7
8 #include "base/callback_list.h"
9 #include "base/memory/weak_ptr.h"
10 #include "chrome/browser/managed_mode/managed_user_sync_service_observer.h"
11 #include "chrome/browser/ui/webui/options/options_ui.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14
15 namespace base {
16 class DictionaryValue;
17 class ListValue;
18 }
19
20 namespace options {
21
22 // Handler for the 'import existing managed user' dialog.
23 class ManagedUserImportHandler : public OptionsPageUIHandler,
24                                  public content::NotificationObserver,
25                                  public ManagedUserSyncServiceObserver {
26  public:
27   typedef base::CallbackList<void(const std::string&, const std::string&)>
28       CallbackList;
29
30   ManagedUserImportHandler();
31   virtual ~ManagedUserImportHandler();
32
33   // OptionsPageUIHandler implementation.
34   virtual void GetLocalizedValues(
35       base::DictionaryValue* localized_strings) OVERRIDE;
36   virtual void InitializeHandler() OVERRIDE;
37
38   // WebUIMessageHandler implementation.
39   virtual void RegisterMessages() OVERRIDE;
40
41   // content::NotificationObserver implementation.
42   virtual void Observe(int type,
43                        const content::NotificationSource& source,
44                        const content::NotificationDetails& details) OVERRIDE;
45
46   // ManagedUserSyncServiceObserver implementation.
47   virtual void OnManagedUserAcknowledged(const std::string& managed_user_id)
48       OVERRIDE {}
49   virtual void OnManagedUsersSyncingStopped() OVERRIDE {}
50   virtual void OnManagedUsersChanged() OVERRIDE;
51
52  private:
53   // Clears the cached list of managed users and fetches the new list of managed
54   // users.
55   void FetchManagedUsers();
56
57   // Callback for the "requestManagedUserImportUpdate" message.
58   // Checks the sign-in status of the custodian and accordingly
59   // sends an update to the WebUI. The update can be to show/hide
60   // an error bubble and update/clear the managed user list.
61   void RequestManagedUserImportUpdate(const base::ListValue* args);
62
63   // Sends an array of managed users to WebUI. Each entry is of the form:
64   //   managedProfile = {
65   //     id: "Managed User ID",
66   //     name: "Managed User Name",
67   //     iconURL: "chrome://path/to/icon/image",
68   //     onCurrentDevice: true or false,
69   //     needAvatar: true or false
70   //   }
71   // The array holds all existing managed users attached to the
72   // custodian's profile which initiated the request.
73   void SendExistingManagedUsers(const base::DictionaryValue* dict);
74
75   // Sends messages to the JS side to clear managed users and show an error
76   // bubble.
77   void ClearManagedUsersAndShowError();
78
79   bool IsAccountConnected() const;
80   bool HasAuthError() const;
81
82   // Called when a managed user shared setting is changed. If the avatar was
83   // changed, FetchManagedUsers() is called.
84   void OnSharedSettingChanged(const std::string& managed_user_id,
85                               const std::string& key);
86
87   scoped_ptr<CallbackList::Subscription> subscription_;
88
89   base::WeakPtrFactory<ManagedUserImportHandler> weak_ptr_factory_;
90
91   DISALLOW_COPY_AND_ASSIGN(ManagedUserImportHandler);
92 };
93
94 }  // namespace options
95
96 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_MANAGED_USER_IMPORT_HANDLER_H_