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