Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/profiles/profile_window.h" | 11 #include "chrome/browser/profiles/profile_window.h" |
| 12 #include "chrome/browser/ui/host_desktop.h" | 12 #include "chrome/browser/ui/host_desktop.h" |
| 13 #include "chrome/browser/ui/webui/options/options_ui.h" | 13 #include "chrome/browser/ui/webui/options/options_ui.h" |
| 14 #include "google_apis/gaia/google_service_auth_error.h" | 14 #include "google_apis/gaia/google_service_auth_error.h" |
| 15 | 15 |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 class DictionaryValue; | 18 class DictionaryValue; |
| 19 class ListValue; | 19 class ListValue; |
| 20 } | 20 } |
| 21 | 21 |
| 22 #if defined(ENABLE_MANAGED_USERS) | |
| 22 class SupervisedUserRegistrationUtility; | 23 class SupervisedUserRegistrationUtility; |
| 24 #endif | |
| 23 | 25 |
| 24 namespace options { | 26 namespace options { |
| 25 | 27 |
| 26 // Handler for the 'create profile' overlay. | 28 // Handler for the 'create profile' overlay. |
| 27 class CreateProfileHandler: public OptionsPageUIHandler { | 29 class CreateProfileHandler: public OptionsPageUIHandler { |
| 28 public: | 30 public: |
| 29 CreateProfileHandler(); | 31 CreateProfileHandler(); |
| 30 virtual ~CreateProfileHandler(); | 32 virtual ~CreateProfileHandler(); |
| 31 | 33 |
| 32 // OptionsPageUIHandler implementation. | 34 // OptionsPageUIHandler implementation. |
| 33 virtual void GetLocalizedValues( | 35 virtual void GetLocalizedValues( |
| 34 base::DictionaryValue* localized_strings) OVERRIDE; | 36 base::DictionaryValue* localized_strings) OVERRIDE; |
| 35 | 37 |
| 36 // WebUIMessageHandler implementation. | 38 // WebUIMessageHandler implementation. |
| 37 virtual void RegisterMessages() OVERRIDE; | 39 virtual void RegisterMessages() OVERRIDE; |
| 38 | 40 |
| 39 private: | 41 private: |
| 40 // Represents the final profile creation status. It is used to map | 42 // Represents the final profile creation status. It is used to map |
| 41 // the status to the javascript method to be called. | 43 // the status to the javascript method to be called. |
| 42 enum ProfileCreationStatus { | 44 enum ProfileCreationStatus { |
| 43 PROFILE_CREATION_SUCCESS, | 45 PROFILE_CREATION_SUCCESS, |
| 44 PROFILE_CREATION_ERROR, | 46 PROFILE_CREATION_ERROR, |
| 45 }; | 47 }; |
| 46 | 48 |
| 47 // Represents errors that could occur during a profile creation. | |
| 48 // It is used to map error types to messages that will be displayed | |
| 49 // to the user. | |
| 50 enum ProfileCreationErrorType { | |
| 51 REMOTE_ERROR, | |
| 52 LOCAL_ERROR, | |
| 53 SIGNIN_ERROR | |
| 54 }; | |
| 55 | |
| 56 // Represents the type of the in progress profile creation operation. | 49 // Represents the type of the in progress profile creation operation. |
| 57 // It is used to map the type of the profile creation operation to the | 50 // It is used to map the type of the profile creation operation to the |
| 58 // correct UMA metric name. | 51 // correct UMA metric name. |
| 59 enum ProfileCreationOperationType { | 52 enum ProfileCreationOperationType { |
| 53 #if defined(ENABLE_MANAGED_USERS) | |
| 60 SUPERVISED_PROFILE_CREATION, | 54 SUPERVISED_PROFILE_CREATION, |
| 61 SUPERVISED_PROFILE_IMPORT, | 55 SUPERVISED_PROFILE_IMPORT, |
| 56 #endif | |
| 62 NON_SUPERVISED_PROFILE_CREATION, | 57 NON_SUPERVISED_PROFILE_CREATION, |
| 63 NO_CREATION_IN_PROGRESS | 58 NO_CREATION_IN_PROGRESS |
| 64 }; | 59 }; |
| 65 | 60 |
| 66 // Asynchronously creates and initializes a new profile. | 61 // Asynchronously creates and initializes a new profile. |
| 67 // The arguments are as follows: | 62 // The arguments are as follows: |
| 68 // 0: name (string) | 63 // 0: name (string) |
| 69 // 1: icon (string) | 64 // 1: icon (string) |
| 70 // 2: a flag stating whether we should create a profile desktop shortcut | 65 // 2: a flag stating whether we should create a profile desktop shortcut |
| 71 // (optional, boolean) | 66 // (optional, boolean) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 83 chrome::HostDesktopType desktop_type, | 78 chrome::HostDesktopType desktop_type, |
| 84 const std::string& supervised_user_id, | 79 const std::string& supervised_user_id, |
| 85 Profile* profile, | 80 Profile* profile, |
| 86 Profile::CreateStatus status); | 81 Profile::CreateStatus status); |
| 87 | 82 |
| 88 void HandleProfileCreationSuccess(bool create_shortcut, | 83 void HandleProfileCreationSuccess(bool create_shortcut, |
| 89 chrome::HostDesktopType desktop_type, | 84 chrome::HostDesktopType desktop_type, |
| 90 const std::string& supervised_user_id, | 85 const std::string& supervised_user_id, |
| 91 Profile* profile); | 86 Profile* profile); |
| 92 | 87 |
| 93 // After a new supervised-user profile has been created, registers the user | |
| 94 // with the management server. | |
| 95 void RegisterSupervisedUser(bool create_shortcut, | |
| 96 chrome::HostDesktopType desktop_type, | |
| 97 const std::string& managed_user_id, | |
| 98 Profile* new_profile); | |
| 99 | |
| 100 // Called back with the result of the supervised user registration. | |
| 101 void OnSupervisedUserRegistered(bool create_shortcut, | |
| 102 chrome::HostDesktopType desktop_type, | |
| 103 Profile* profile, | |
| 104 const GoogleServiceAuthError& error); | |
| 105 | |
| 106 // Creates desktop shortcut and updates the UI to indicate success | 88 // Creates desktop shortcut and updates the UI to indicate success |
| 107 // when creating a profile. | 89 // when creating a profile. |
| 108 void CreateShortcutAndShowSuccess(bool create_shortcut, | 90 void CreateShortcutAndShowSuccess(bool create_shortcut, |
| 109 chrome::HostDesktopType desktop_type, | 91 chrome::HostDesktopType desktop_type, |
| 110 Profile* profile); | 92 Profile* profile); |
| 111 | 93 |
| 112 // Updates the UI to show an error when creating a profile. | 94 // Updates the UI to show an error when creating a profile. |
| 113 void ShowProfileCreationError(Profile* profile, const base::string16& error); | 95 void ShowProfileCreationError(Profile* profile, const base::string16& error); |
| 114 | 96 |
| 115 // Updates the UI to show a non-fatal warning when creating a profile. | 97 // Updates the UI to show a non-fatal warning when creating a profile. |
| 116 void ShowProfileCreationWarning(const base::string16& warning); | 98 void ShowProfileCreationWarning(const base::string16& warning); |
| 117 | 99 |
| 100 // Records UMA histograms relevant to profile creation. | |
| 101 void RecordProfileCreationMetrics(Profile::CreateStatus status); | |
| 102 | |
| 103 base::string16 GetProfileCreationErrorMessageLocal() const; | |
| 104 #if defined(ENABLE_MANAGED_USERS) | |
| 105 // The following error messages only apply to supervised profiles. | |
| 106 base::string16 GetProfileCreationErrorMessageRemote() const; | |
| 107 base::string16 GetProfileCreationErrorMessageSignin() const; | |
| 108 #endif | |
| 109 | |
| 110 std::string GetJavascriptMethodName(ProfileCreationStatus status) const; | |
| 111 | |
| 112 // Used to allow cancelling a profile creation (particularly a supervised-user | |
| 113 // registration) in progress. Set when profile creation is begun, and | |
| 114 // cleared when all the callbacks have been run and creation is complete. | |
| 115 base::FilePath profile_path_being_created_; | |
| 116 | |
| 117 // Used to track how long profile creation takes. | |
| 118 base::TimeTicks profile_creation_start_time_; | |
| 119 | |
| 120 // Indicates the type of the in progress profile creation operation. | |
| 121 // The value is only relevant while we are creating/importing a profile. | |
| 122 ProfileCreationOperationType profile_creation_type_; | |
| 123 | |
| 124 #if defined(ENABLE_MANAGED_USERS) | |
|
James Hawkins
2014/08/05 08:50:48
This is still a ton of code that is only for ENABL
| |
| 125 // Extracts the supervised user ID from the args passed into CreateProfile, | |
| 126 // sets |profile_creation_type_| if necessary, and returns true if the | |
| 127 // supervised user id specified in |args| are valid. | |
| 128 bool ProcessSupervisedCreateProfileArgs(const base::ListValue* args, | |
| 129 std::string* supervised_user_id); | |
| 130 | |
| 118 // Cancels creation of a supervised-user profile currently in progress, as | 131 // Cancels creation of a supervised-user profile currently in progress, as |
| 119 // indicated by profile_path_being_created_, removing the object and files | 132 // indicated by profile_path_being_created_, removing the object and files |
| 120 // and canceling supervised-user registration. This is the handler for the | 133 // and canceling supervised-user registration. This is the handler for the |
| 121 // "cancelCreateProfile" message. |args| is not used. | 134 // "cancelCreateProfile" message. |args| is not used. |
| 122 void HandleCancelProfileCreation(const base::ListValue* args); | 135 void HandleCancelProfileCreation(const base::ListValue* args); |
| 123 | 136 |
| 124 // Internal implementation. This may safely be called whether profile creation | 137 // Internal implementation. This may safely be called whether profile creation |
| 125 // or registration is in progress or not. |user_initiated| should be true if | 138 // or registration is in progress or not. |user_initiated| should be true if |
| 126 // the cancellation was deliberately requested by the user, and false if it | 139 // the cancellation was deliberately requested by the user, and false if it |
| 127 // was caused implicitly, e.g. by shutting down the browser. | 140 // was caused implicitly, e.g. by shutting down the browser. |
| 128 void CancelProfileRegistration(bool user_initiated); | 141 void CancelProfileRegistration(bool user_initiated); |
| 129 | 142 |
| 130 // Records UMA histograms relevant to profile creation. | 143 // After a new supervised-user profile has been created, registers the user |
| 131 void RecordProfileCreationMetrics(Profile::CreateStatus status); | 144 // with the management server. |
| 145 void RegisterSupervisedUser(bool create_shortcut, | |
| 146 chrome::HostDesktopType desktop_type, | |
| 147 const std::string& managed_user_id, | |
| 148 Profile* new_profile); | |
| 149 | |
| 150 // Called back with the result of the supervised user registration. | |
| 151 void OnSupervisedUserRegistered(bool create_shortcut, | |
| 152 chrome::HostDesktopType desktop_type, | |
| 153 Profile* profile, | |
| 154 const GoogleServiceAuthError& error); | |
| 132 | 155 |
| 133 // Records UMA histograms relevant to supervised user profiles | 156 // Records UMA histograms relevant to supervised user profiles |
| 134 // creation and registration. | 157 // creation and registration. |
| 135 void RecordSupervisedProfileCreationMetrics( | 158 void RecordSupervisedProfileCreationMetrics( |
| 136 GoogleServiceAuthError::State error_state); | 159 GoogleServiceAuthError::State error_state); |
| 137 | 160 |
| 138 base::string16 GetProfileCreationErrorMessage( | |
| 139 ProfileCreationErrorType error) const; | |
| 140 std::string GetJavascriptMethodName(ProfileCreationStatus status) const; | |
| 141 | |
| 142 bool IsValidExistingSupervisedUserId( | 161 bool IsValidExistingSupervisedUserId( |
| 143 const std::string& existing_supervised_user_id) const; | 162 const std::string& existing_supervised_user_id) const; |
| 144 | 163 |
| 145 // Used to allow cancelling a profile creation (particularly a supervised-user | |
| 146 // registration) in progress. Set when profile creation is begun, and | |
| 147 // cleared when all the callbacks have been run and creation is complete. | |
| 148 base::FilePath profile_path_being_created_; | |
| 149 | |
| 150 // Used to track how long profile creation takes. | |
| 151 base::TimeTicks profile_creation_start_time_; | |
| 152 | |
| 153 scoped_ptr<SupervisedUserRegistrationUtility> | 164 scoped_ptr<SupervisedUserRegistrationUtility> |
| 154 supervised_user_registration_utility_; | 165 supervised_user_registration_utility_; |
| 155 | 166 #endif |
| 156 // Indicates the type of the in progress profile creation operation. | |
| 157 // The value is only relevant while we are creating/importing a profile. | |
| 158 ProfileCreationOperationType profile_creation_type_; | |
| 159 | 167 |
| 160 base::WeakPtrFactory<CreateProfileHandler> weak_ptr_factory_; | 168 base::WeakPtrFactory<CreateProfileHandler> weak_ptr_factory_; |
| 161 | 169 |
| 162 DISALLOW_COPY_AND_ASSIGN(CreateProfileHandler); | 170 DISALLOW_COPY_AND_ASSIGN(CreateProfileHandler); |
| 163 }; | 171 }; |
| 164 | 172 |
| 165 } // namespace options | 173 } // namespace options |
| 166 | 174 |
| 167 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ | 175 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ |
| OLD | NEW |