manage_profile_handler.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
1// Copyright (c) 2012 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_MANAGE_PROFILE_HANDLER_H_
6#define CHROME_BROWSER_UI_WEBUI_OPTIONS_MANAGE_PROFILE_HANDLER_H_
7
8#include <string>
9
10#include "base/memory/weak_ptr.h"
11#include "base/prefs/pref_change_registrar.h"
12#include "chrome/browser/sync/profile_sync_service_observer.h"
13#include "chrome/browser/ui/webui/options/options_ui.h"
14
15namespace base {
16class StringValue;
17}
18
19namespace options {
20
21// Chrome personal stuff profiles manage overlay UI handler.
22class ManageProfileHandler : public OptionsPageUIHandler,
23                             public ProfileSyncServiceObserver {
24 public:
25  ManageProfileHandler();
26  virtual ~ManageProfileHandler();
27
28  // OptionsPageUIHandler:
29  virtual void GetLocalizedValues(
30      base::DictionaryValue* localized_strings) OVERRIDE;
31  virtual void InitializeHandler() OVERRIDE;
32  virtual void InitializePage() OVERRIDE;
33
34  // WebUIMessageHandler:
35  virtual void RegisterMessages() OVERRIDE;
36
37  // content::NotificationObserver:
38  virtual void Observe(int type,
39                       const content::NotificationSource& source,
40                       const content::NotificationDetails& details) OVERRIDE;
41
42  // ProfileSyncServiceObserver:
43  virtual void OnStateChanged() OVERRIDE;
44
45 private:
46  // Callback for the "requestDefaultProfileIcons" message.
47  // Sends the array of default profile icon URLs to WebUI.
48  // |args| is of the form: [ {string} iconURL ]
49  void RequestDefaultProfileIcons(const base::ListValue* args);
50
51  // Callback for the "requestNewProfileDefaults" message.
52  // Sends an object to WebUI of the form:
53  //   { "name": profileName, "iconURL": iconURL }
54  void RequestNewProfileDefaults(const base::ListValue* args);
55
56  // Send all profile icons to the overlay.
57  // |iconGrid| is the name of the grid to populate with icons (i.e.
58  // "create-profile-icon-grid" or "manage-profile-icon-grid").
59  void SendProfileIcons(const base::StringValue& icon_grid);
60
61  // Sends an object to WebUI of the form:
62  //   profileNames = {
63  //     "Profile Name 1": true,
64  //     "Profile Name 2": true,
65  //     ...
66  //   };
67  // This is used to detect duplicate profile names.
68  void SendProfileNames();
69
70  // Callback for the "setProfileIconAndName" message. Sets the name and icon
71  // of a given profile.
72  // |args| is of the form: [
73  //   /*string*/ profileFilePath,
74  //   /*string*/ newProfileIconURL
75  //   /*string*/ newProfileName,
76  // ]
77  void SetProfileIconAndName(const base::ListValue* args);
78
79#if defined(ENABLE_SETTINGS_APP)
80  // Callback for the "switchAppListProfile" message. Asks the
81  // app_list_controller to change the profile registered for the AppList.
82  // |args| is of the form: [ {string} profileFilePath ]
83  void SwitchAppListProfile(const base::ListValue* args);
84#endif
85
86  // Callback for the 'profileIconSelectionChanged' message. Used to update the
87  // name in the manager profile dialog based on the selected icon.
88  void ProfileIconSelectionChanged(const base::ListValue* args);
89
90  // Callback for the "requestHasProfileShortcuts" message, which is called
91  // when editing an existing profile. Asks the profile shortcut manager whether
92  // the profile has shortcuts and gets the result in |OnHasProfileShortcuts()|.
93  // |args| is of the form: [ {string} profileFilePath ]
94  void RequestHasProfileShortcuts(const base::ListValue* args);
95
96  // Callback for the "RequestCreateProfileUpdate" message.
97  // Sends the email address of the signed-in user, or an empty string if the
98  // user is not signed in. Also sends information about whether managed users
99  // may be created.
100  void RequestCreateProfileUpdate(const base::ListValue* args);
101
102  // When the pref allowing managed-user creation changes, sends the new value
103  // to the UI.
104  void OnCreateManagedUserPrefChange();
105
106  // Callback invoked from the profile manager indicating whether the profile
107  // being edited has any desktop shortcuts.
108  void OnHasProfileShortcuts(bool has_shortcuts);
109
110  // Callback for the "addProfileShortcut" message, which is called when editing
111  // an existing profile and the user clicks the "Add desktop shortcut" button.
112  // Adds a desktop shortcut for the profile.
113  void AddProfileShortcut(const base::ListValue* args);
114
115  // Callback for the "removeProfileShortcut" message, which is called when
116  // editing an existing profile and the user clicks the "Remove desktop
117  // shortcut" button. Removes the desktop shortcut for the profile.
118  void RemoveProfileShortcut(const base::ListValue* args);
119
120  // URL for the current profile's GAIA picture.
121  std::string gaia_picture_url_;
122
123  // Used to observe the preference that allows creating managed users, which
124  // can be changed by policy.
125  PrefChangeRegistrar pref_change_registrar_;
126
127  // For generating weak pointers to itself for callbacks.
128  base::WeakPtrFactory<ManageProfileHandler> weak_factory_;
129
130  DISALLOW_COPY_AND_ASSIGN(ManageProfileHandler);
131};
132
133}  // namespace options
134
135#endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_MANAGE_PROFILE_HANDLER_H_
136