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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_MANAGE_PROFILE_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_MANAGE_PROFILE_HANDLER_H_
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 #include "content/public/browser/notification_observer.h"
22 // Chrome personal stuff profiles manage overlay UI handler.
23 class ManageProfileHandler : public OptionsPageUIHandler,
24 public content::NotificationObserver,
25 public ProfileSyncServiceObserver {
27 ManageProfileHandler();
28 ~ManageProfileHandler() override;
30 // OptionsPageUIHandler:
31 void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
32 void InitializeHandler() override;
33 void InitializePage() override;
34 void Uninitialize() override;
36 // WebUIMessageHandler:
37 void RegisterMessages() override;
39 // content::NotificationObserver:
40 void Observe(int type,
41 const content::NotificationSource& source,
42 const content::NotificationDetails& details) override;
44 // ProfileSyncServiceObserver:
45 void OnStateChanged() override;
48 // This function creates signed in user specific strings in loadTimeData.
49 void GenerateSignedinUserSpecificStrings(base::DictionaryValue* dictionary);
51 // Callback for the "requestDefaultProfileIcons" message.
52 // Sends the array of default profile icon URLs and profile names to WebUI.
53 // First item of |args| is the dialog mode, i.e. "create" or "manage".
54 void RequestDefaultProfileIcons(const base::ListValue* args);
56 // Callback for the "requestNewProfileDefaults" message.
57 // Sends an object to WebUI of the form:
58 // { "name": profileName, "iconURL": iconURL }
59 void RequestNewProfileDefaults(const base::ListValue* args);
61 // Send all profile icons and their default names to the overlay.
62 // |mode| is the dialog mode, i.e. "create" or "manage".
63 void SendProfileIconsAndNames(const base::StringValue& mode);
65 // Sends an object to WebUI of the form:
67 // "Profile Name 1": true,
68 // "Profile Name 2": true,
71 // This is used to detect duplicate profile names.
72 void SendExistingProfileNames();
74 // Show disconnect managed profile dialog after generating domain and user
76 void ShowDisconnectManagedProfileDialog(const base::ListValue* args);
78 // Callback for the "setProfileIconAndName" message. Sets the name and icon
79 // of a given profile.
80 // |args| is of the form: [
81 // /*string*/ profileFilePath,
82 // /*string*/ newProfileIconURL
83 // /*string*/ newProfileName,
85 void SetProfileIconAndName(const base::ListValue* args);
87 #if defined(ENABLE_SETTINGS_APP)
88 // Callback for the "switchAppListProfile" message. Asks the
89 // app_list_controller to change the profile registered for the AppList.
90 // |args| is of the form: [ {string} profileFilePath ]
91 void SwitchAppListProfile(const base::ListValue* args);
94 // Callback for the 'profileIconSelectionChanged' message. Used to update the
95 // name in the manager profile dialog based on the selected icon.
96 void ProfileIconSelectionChanged(const base::ListValue* args);
98 // Callback for the "requestHasProfileShortcuts" message, which is called
99 // when editing an existing profile. Asks the profile shortcut manager whether
100 // the profile has shortcuts and gets the result in |OnHasProfileShortcuts()|.
101 // |args| is of the form: [ {string} profileFilePath ]
102 void RequestHasProfileShortcuts(const base::ListValue* args);
104 // Callback for the "RequestCreateProfileUpdate" message.
105 // Sends the email address of the signed-in user, or an empty string if the
106 // user is not signed in. Also sends information about whether supervised
107 // users may be created.
108 void RequestCreateProfileUpdate(const base::ListValue* args);
110 // When the pref allowing supervised-user creation changes, sends the new
112 void OnCreateSupervisedUserPrefChange();
114 // Callback invoked from the profile manager indicating whether the profile
115 // being edited has any desktop shortcuts.
116 void OnHasProfileShortcuts(bool has_shortcuts);
118 // Callback for the "addProfileShortcut" message, which is called when editing
119 // an existing profile and the user clicks the "Add desktop shortcut" button.
120 // Adds a desktop shortcut for the profile.
121 void AddProfileShortcut(const base::ListValue* args);
123 // Callback for the "removeProfileShortcut" message, which is called when
124 // editing an existing profile and the user clicks the "Remove desktop
125 // shortcut" button. Removes the desktop shortcut for the profile.
126 void RemoveProfileShortcut(const base::ListValue* args);
128 // Callback for the "refreshGaiaPicture" message, which is called when the
129 // user is editing an existing profile.
130 void RefreshGaiaPicture(const base::ListValue* args);
132 // URL for the current profile's GAIA picture.
133 std::string gaia_picture_url_;
135 // Used to observe the preference that allows creating supervised users, which
136 // can be changed by policy.
137 PrefChangeRegistrar pref_change_registrar_;
139 // For generating weak pointers to itself for callbacks.
140 base::WeakPtrFactory<ManageProfileHandler> weak_factory_;
142 DISALLOW_COPY_AND_ASSIGN(ManageProfileHandler);
145 } // namespace options
147 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_MANAGE_PROFILE_HANDLER_H_