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