| 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" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 NON_SUPERVISED_PROFILE_CREATION, | 62 NON_SUPERVISED_PROFILE_CREATION, |
| 63 NO_CREATION_IN_PROGRESS | 63 NO_CREATION_IN_PROGRESS |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // Asynchronously creates and initializes a new profile. | 66 // Asynchronously creates and initializes a new profile. |
| 67 // The arguments are as follows: | 67 // The arguments are as follows: |
| 68 // 0: name (string) | 68 // 0: name (string) |
| 69 // 1: icon (string) | 69 // 1: icon (string) |
| 70 // 2: a flag stating whether we should create a profile desktop shortcut | 70 // 2: a flag stating whether we should create a profile desktop shortcut |
| 71 // (optional, boolean) | 71 // (optional, boolean) |
| 72 // 3: a flag stating whether the user should be managed (optional, boolean) | 72 // 3: a flag stating whether the user should be supervised |
| 73 // 4: a string representing the managed user ID. | 73 // (optional, boolean) |
| 74 // 4: a string representing the supervised user ID. |
| 74 void CreateProfile(const base::ListValue* args); | 75 void CreateProfile(const base::ListValue* args); |
| 75 | 76 |
| 76 // If a local error occurs during profile creation, then show an appropriate | 77 // If a local error occurs during profile creation, then show an appropriate |
| 77 // error message. However, if profile creation succeeded and the | 78 // error message. However, if profile creation succeeded and the |
| 78 // profile being created/imported is a supervised user profile, | 79 // profile being created/imported is a supervised user profile, |
| 79 // then proceed with the registration step. Otherwise, update the UI | 80 // then proceed with the registration step. Otherwise, update the UI |
| 80 // as the final task after a new profile has been created. | 81 // as the final task after a new profile has been created. |
| 81 void OnProfileCreated(bool create_shortcut, | 82 void OnProfileCreated(bool create_shortcut, |
| 82 chrome::HostDesktopType desktop_type, | 83 chrome::HostDesktopType desktop_type, |
| 83 const std::string& managed_user_id, | 84 const std::string& supervised_user_id, |
| 84 Profile* profile, | 85 Profile* profile, |
| 85 Profile::CreateStatus status); | 86 Profile::CreateStatus status); |
| 86 | 87 |
| 87 void HandleProfileCreationSuccess(bool create_shortcut, | 88 void HandleProfileCreationSuccess(bool create_shortcut, |
| 88 chrome::HostDesktopType desktop_type, | 89 chrome::HostDesktopType desktop_type, |
| 89 const std::string& managed_user_id, | 90 const std::string& supervised_user_id, |
| 90 Profile* profile); | 91 Profile* profile); |
| 91 | 92 |
| 92 // After a new managed-user profile has been created, registers the user with | 93 // After a new supervised-user profile has been created, registers the user |
| 93 // the management server. | 94 // with the management server. |
| 94 void RegisterManagedUser(bool create_shortcut, | 95 void RegisterSupervisedUser(bool create_shortcut, |
| 95 chrome::HostDesktopType desktop_type, | 96 chrome::HostDesktopType desktop_type, |
| 96 const std::string& managed_user_id, | 97 const std::string& managed_user_id, |
| 97 Profile* new_profile); | 98 Profile* new_profile); |
| 98 | 99 |
| 99 // Called back with the result of the managed user registration. | 100 // Called back with the result of the supervised user registration. |
| 100 void OnManagedUserRegistered(bool create_shortcut, | 101 void OnSupervisedUserRegistered(bool create_shortcut, |
| 101 chrome::HostDesktopType desktop_type, | 102 chrome::HostDesktopType desktop_type, |
| 102 Profile* profile, | 103 Profile* profile, |
| 103 const GoogleServiceAuthError& error); | 104 const GoogleServiceAuthError& error); |
| 104 | 105 |
| 105 // Creates desktop shortcut and updates the UI to indicate success | 106 // Creates desktop shortcut and updates the UI to indicate success |
| 106 // when creating a profile. | 107 // when creating a profile. |
| 107 void CreateShortcutAndShowSuccess(bool create_shortcut, | 108 void CreateShortcutAndShowSuccess(bool create_shortcut, |
| 108 chrome::HostDesktopType desktop_type, | 109 chrome::HostDesktopType desktop_type, |
| 109 Profile* profile); | 110 Profile* profile); |
| 110 | 111 |
| 111 // Updates the UI to show an error when creating a profile. | 112 // Updates the UI to show an error when creating a profile. |
| 112 void ShowProfileCreationError(Profile* profile, const base::string16& error); | 113 void ShowProfileCreationError(Profile* profile, const base::string16& error); |
| 113 | 114 |
| 114 // Updates the UI to show a non-fatal warning when creating a profile. | 115 // Updates the UI to show a non-fatal warning when creating a profile. |
| 115 void ShowProfileCreationWarning(const base::string16& warning); | 116 void ShowProfileCreationWarning(const base::string16& warning); |
| 116 | 117 |
| 117 // Cancels creation of a managed-user profile currently in progress, as | 118 // Cancels creation of a supervised-user profile currently in progress, as |
| 118 // indicated by profile_path_being_created_, removing the object and files | 119 // indicated by profile_path_being_created_, removing the object and files |
| 119 // and canceling managed-user registration. This is the handler for the | 120 // and canceling supervised-user registration. This is the handler for the |
| 120 // "cancelCreateProfile" message. |args| is not used. | 121 // "cancelCreateProfile" message. |args| is not used. |
| 121 void HandleCancelProfileCreation(const base::ListValue* args); | 122 void HandleCancelProfileCreation(const base::ListValue* args); |
| 122 | 123 |
| 123 // Internal implementation. This may safely be called whether profile creation | 124 // Internal implementation. This may safely be called whether profile creation |
| 124 // or registration is in progress or not. |user_initiated| should be true if | 125 // or registration is in progress or not. |user_initiated| should be true if |
| 125 // the cancellation was deliberately requested by the user, and false if it | 126 // the cancellation was deliberately requested by the user, and false if it |
| 126 // was caused implicitly, e.g. by shutting down the browser. | 127 // was caused implicitly, e.g. by shutting down the browser. |
| 127 void CancelProfileRegistration(bool user_initiated); | 128 void CancelProfileRegistration(bool user_initiated); |
| 128 | 129 |
| 129 // Records UMA histograms relevant to profile creation. | 130 // Records UMA histograms relevant to profile creation. |
| 130 void RecordProfileCreationMetrics(Profile::CreateStatus status); | 131 void RecordProfileCreationMetrics(Profile::CreateStatus status); |
| 131 | 132 |
| 132 // Records UMA histograms relevant to supervised user profiles | 133 // Records UMA histograms relevant to supervised user profiles |
| 133 // creation and registration. | 134 // creation and registration. |
| 134 void RecordSupervisedProfileCreationMetrics( | 135 void RecordSupervisedProfileCreationMetrics( |
| 135 GoogleServiceAuthError::State error_state); | 136 GoogleServiceAuthError::State error_state); |
| 136 | 137 |
| 137 base::string16 GetProfileCreationErrorMessage( | 138 base::string16 GetProfileCreationErrorMessage( |
| 138 ProfileCreationErrorType error) const; | 139 ProfileCreationErrorType error) const; |
| 139 std::string GetJavascriptMethodName(ProfileCreationStatus status) const; | 140 std::string GetJavascriptMethodName(ProfileCreationStatus status) const; |
| 140 | 141 |
| 141 bool IsValidExistingManagedUserId( | 142 bool IsValidExistingSupervisedUserId( |
| 142 const std::string& existing_managed_user_id) const; | 143 const std::string& existing_supervised_user_id) const; |
| 143 | 144 |
| 144 // Used to allow cancelling a profile creation (particularly a managed-user | 145 // Used to allow cancelling a profile creation (particularly a supervised-user |
| 145 // registration) in progress. Set when profile creation is begun, and | 146 // registration) in progress. Set when profile creation is begun, and |
| 146 // cleared when all the callbacks have been run and creation is complete. | 147 // cleared when all the callbacks have been run and creation is complete. |
| 147 base::FilePath profile_path_being_created_; | 148 base::FilePath profile_path_being_created_; |
| 148 | 149 |
| 149 // Used to track how long profile creation takes. | 150 // Used to track how long profile creation takes. |
| 150 base::TimeTicks profile_creation_start_time_; | 151 base::TimeTicks profile_creation_start_time_; |
| 151 | 152 |
| 152 scoped_ptr<ManagedUserRegistrationUtility> managed_user_registration_utility_; | 153 scoped_ptr<ManagedUserRegistrationUtility> managed_user_registration_utility_; |
| 153 | 154 |
| 154 // Indicates the type of the in progress profile creation operation. | 155 // Indicates the type of the in progress profile creation operation. |
| 155 // The value is only relevant while we are creating/importing a profile. | 156 // The value is only relevant while we are creating/importing a profile. |
| 156 ProfileCreationOperationType profile_creation_type_; | 157 ProfileCreationOperationType profile_creation_type_; |
| 157 | 158 |
| 158 base::WeakPtrFactory<CreateProfileHandler> weak_ptr_factory_; | 159 base::WeakPtrFactory<CreateProfileHandler> weak_ptr_factory_; |
| 159 | 160 |
| 160 DISALLOW_COPY_AND_ASSIGN(CreateProfileHandler); | 161 DISALLOW_COPY_AND_ASSIGN(CreateProfileHandler); |
| 161 }; | 162 }; |
| 162 | 163 |
| 163 } // namespace options | 164 } // namespace options |
| 164 | 165 |
| 165 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ | 166 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ |
| OLD | NEW |