OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_window.h" | 14 #include "chrome/browser/profiles/profile_window.h" |
15 #include "chrome/browser/ui/webui/options/options_ui.h" | 15 #include "content/public/browser/web_ui_message_handler.h" |
16 #include "google_apis/gaia/google_service_auth_error.h" | 16 #include "google_apis/gaia/google_service_auth_error.h" |
17 | 17 |
18 | |
19 namespace base { | 18 namespace base { |
20 class DictionaryValue; | 19 class DictionaryValue; |
21 class ListValue; | 20 class ListValue; |
22 } | 21 } |
23 | 22 |
24 #if defined(ENABLE_SUPERVISED_USERS) | 23 #if defined(ENABLE_SUPERVISED_USERS) |
25 class SupervisedUserRegistrationUtility; | 24 class SupervisedUserRegistrationUtility; |
26 #endif | 25 #endif |
27 | 26 |
28 namespace options { | 27 // Handler for the 'create profile' page. |
| 28 class SigninCreateProfileHandler : public content::WebUIMessageHandler { |
| 29 public: |
| 30 SigninCreateProfileHandler(); |
| 31 ~SigninCreateProfileHandler() override; |
29 | 32 |
30 // Handler for the 'create profile' overlay. | 33 void GetLocalizedValues(base::DictionaryValue* localized_strings); |
31 class CreateProfileHandler: public OptionsPageUIHandler { | |
32 public: | |
33 CreateProfileHandler(); | |
34 ~CreateProfileHandler() override; | |
35 | 34 |
36 // OptionsPageUIHandler implementation. | 35 private: |
37 void GetLocalizedValues(base::DictionaryValue* localized_strings) override; | |
38 | |
39 // WebUIMessageHandler implementation. | 36 // WebUIMessageHandler implementation. |
40 void RegisterMessages() override; | 37 void RegisterMessages() override; |
41 | |
42 private: | |
43 // Represents the final profile creation status. It is used to map | 38 // Represents the final profile creation status. It is used to map |
44 // the status to the javascript method to be called. | 39 // the status to the javascript method to be called. |
45 enum ProfileCreationStatus { | 40 enum ProfileCreationStatus { |
46 PROFILE_CREATION_SUCCESS, | 41 PROFILE_CREATION_SUCCESS, |
47 PROFILE_CREATION_ERROR, | 42 PROFILE_CREATION_ERROR, |
48 }; | 43 }; |
49 | 44 |
50 // Represents the type of the in progress profile creation operation. | 45 // Represents the type of the in progress profile creation operation. |
51 // It is used to map the type of the profile creation operation to the | 46 // It is used to map the type of the profile creation operation to the |
52 // correct UMA metric name. | 47 // correct UMA metric name. |
53 enum ProfileCreationOperationType { | 48 enum ProfileCreationOperationType { |
54 #if defined(ENABLE_SUPERVISED_USERS) | 49 #if defined(ENABLE_SUPERVISED_USERS) |
55 SUPERVISED_PROFILE_CREATION, | 50 SUPERVISED_PROFILE_CREATION, |
56 SUPERVISED_PROFILE_IMPORT, | 51 SUPERVISED_PROFILE_IMPORT, |
57 #endif | 52 #endif |
58 NON_SUPERVISED_PROFILE_CREATION, | 53 NON_SUPERVISED_PROFILE_CREATION, |
59 NO_CREATION_IN_PROGRESS | 54 NO_CREATION_IN_PROGRESS |
60 }; | 55 }; |
61 | 56 |
| 57 // Callback for the "requestDefaultProfileIcons" message. |
| 58 // Sends the array of default profile icon URLs to WebUI. |
| 59 void RequestDefaultProfileIcons(const base::ListValue* args); |
| 60 |
| 61 // Callback for the "requestSignedInProfiles" message. |
| 62 // Sends the email address of the signed-in user, or an empty string if the |
| 63 // user is not signed in. Also sends information about whether supervised |
| 64 // users may be created. |
| 65 void RequestSignedInProfiles(const base::ListValue* args); |
| 66 |
62 // Asynchronously creates and initializes a new profile. | 67 // Asynchronously creates and initializes a new profile. |
63 // The arguments are as follows: | 68 // The arguments are as follows: |
64 // 0: name (string) | 69 // 0: name (string) |
65 // 1: icon (string) | 70 // 1: icon (string) |
66 // 2: a flag stating whether we should create a profile desktop shortcut | 71 // 2: a flag stating whether we should create a profile desktop shortcut |
67 // (optional, boolean) | 72 // (optional, boolean) |
68 // 3: a flag stating whether the user should be supervised | 73 // 3: a flag stating whether the user should be supervised |
69 // (optional, boolean) | 74 // (optional, boolean) |
70 // 4: a string representing the supervised user ID. | 75 // 4: a string representing the supervised user ID. |
| 76 // 5: a string representing the supervisor profile path. |
71 void CreateProfile(const base::ListValue* args); | 77 void CreateProfile(const base::ListValue* args); |
72 | 78 |
73 // If a local error occurs during profile creation, then show an appropriate | 79 // If a local error occurs during profile creation, then show an appropriate |
74 // error message. However, if profile creation succeeded and the | 80 // error message. However, if profile creation succeeded and the |
75 // profile being created/imported is a supervised user profile, | 81 // profile being created/imported is a supervised user profile, |
76 // then proceed with the registration step. Otherwise, update the UI | 82 // then proceed with the registration step. Otherwise, update the UI |
77 // as the final task after a new profile has been created. | 83 // as the final task after a new profile has been created. |
78 void OnProfileCreated(bool create_shortcut, | 84 void OnProfileCreated(bool create_shortcut, |
79 const std::string& supervised_user_id, | 85 const std::string& supervised_user_id, |
| 86 Profile* supervisor_profile, |
80 Profile* profile, | 87 Profile* profile, |
81 Profile::CreateStatus status); | 88 Profile::CreateStatus status); |
82 | 89 |
83 void HandleProfileCreationSuccess(bool create_shortcut, | 90 void HandleProfileCreationSuccess(bool create_shortcut, |
84 const std::string& supervised_user_id, | 91 const std::string& supervised_user_id, |
| 92 Profile* supervisor_profile, |
85 Profile* profile); | 93 Profile* profile); |
86 | 94 |
87 // Creates desktop shortcut and updates the UI to indicate success | 95 // Creates desktop shortcut and updates the UI to indicate success |
88 // when creating a profile. | 96 // when creating a profile. |
89 void CreateShortcutAndShowSuccess(bool create_shortcut, Profile* profile); | 97 void CreateShortcutAndShowSuccess(bool create_shortcut, Profile* profile); |
90 | 98 |
91 // Updates the UI to show an error when creating a profile. | 99 // Updates the UI to show an error when creating a profile. |
92 void ShowProfileCreationError(Profile* profile, const base::string16& error); | 100 void ShowProfileCreationError(Profile* profile, const base::string16& error); |
93 | 101 |
94 // Updates the UI to show a non-fatal warning when creating a profile. | 102 // Updates the UI to show a non-fatal warning when creating a profile. |
95 void ShowProfileCreationWarning(const base::string16& warning); | 103 void ShowProfileCreationWarning(const base::string16& warning); |
96 | 104 |
97 // Records UMA histograms relevant to profile creation. | 105 // Records UMA histograms relevant to profile creation. |
98 void RecordProfileCreationMetrics(Profile::CreateStatus status); | 106 void RecordProfileCreationMetrics(Profile::CreateStatus status); |
99 | 107 |
100 base::string16 GetProfileCreationErrorMessageLocal() const; | 108 base::string16 GetProfileCreationErrorMessageLocal() const; |
101 #if defined(ENABLE_SUPERVISED_USERS) | 109 #if defined(ENABLE_SUPERVISED_USERS) |
102 // The following error messages only apply to supervised profiles. | 110 // The following error messages only apply to supervised profiles. |
103 base::string16 GetProfileCreationErrorMessageRemote() const; | 111 base::string16 GetProfileCreateErrorMessageRemote() const; |
104 base::string16 GetProfileCreationErrorMessageSignin() const; | 112 base::string16 GetProfileCreateErrorMessageSignin() const; |
105 #endif | 113 #endif |
106 | 114 |
107 std::string GetJavascriptMethodName(ProfileCreationStatus status) const; | 115 std::string GetJavascriptMethodName(ProfileCreationStatus status) const; |
108 | 116 |
109 // Used to allow cancelling a profile creation (particularly a supervised-user | 117 // Used to allow cancelling a profile creation (particularly a supervised-user |
110 // registration) in progress. Set when profile creation is begun, and | 118 // registration) in progress. Set when profile creation is begun, and |
111 // cleared when all the callbacks have been run and creation is complete. | 119 // cleared when all the callbacks have been run and creation is complete. |
112 base::FilePath profile_path_being_created_; | 120 base::FilePath profile_path_being_created_; |
113 | 121 |
114 // Used to track how long profile creation takes. | 122 // Used to track how long profile creation takes. |
115 base::TimeTicks profile_creation_start_time_; | 123 base::TimeTicks profile_creation_start_time_; |
116 | 124 |
117 // Indicates the type of the in progress profile creation operation. | 125 // Indicates the type of the in progress profile creation operation. |
118 // The value is only relevant while we are creating/importing a profile. | 126 // The value is only relevant while we are creating/importing a profile. |
119 ProfileCreationOperationType profile_creation_type_; | 127 ProfileCreationOperationType profile_creation_type_; |
120 | 128 |
| 129 // Asynchronously creates and initializes a new profile. |
| 130 void DoCreateProfile(const base::string16& name, |
| 131 const std::string& icon_url, |
| 132 bool create_shortcut, |
| 133 const std::string& supervised_user_id, |
| 134 Profile* supervisor_profile); |
| 135 |
121 #if defined(ENABLE_SUPERVISED_USERS) | 136 #if defined(ENABLE_SUPERVISED_USERS) |
122 // Extracts the supervised user ID from the args passed into CreateProfile, | 137 // Extracts the supervised user ID and the supervisor user profile path from |
123 // sets |profile_creation_type_| if necessary, and returns true if the | 138 // the args passed into CreateProfile. |
124 // supervised user id specified in |args| are valid. | 139 bool GetSupervisedCreateProfileArgs(const base::ListValue* args, |
125 bool ProcessSupervisedCreateProfileArgs(const base::ListValue* args, | 140 std::string* supervised_user_id, |
126 std::string* supervised_user_id); | 141 base::FilePath* supervisor_profile_path); |
| 142 |
| 143 // Callback that runs once the supervisor profile has been loaded. It sets |
| 144 // |profile_creation_type_| if necessary, and calls |DoCreateProfile| if the |
| 145 // supervised user id specified in |args| is valid. |
| 146 void LoadSupervisorProfileCallback(const base::string16& name, |
| 147 const std::string& icon_url, |
| 148 bool create_shortcut, |
| 149 const std::string& supervised_user_id, |
| 150 Profile* supervisor_profile, |
| 151 Profile::CreateStatus status); |
127 | 152 |
128 // Cancels creation of a supervised-user profile currently in progress, as | 153 // Cancels creation of a supervised-user profile currently in progress, as |
129 // indicated by profile_path_being_created_, removing the object and files | 154 // indicated by profile_path_being_created_, removing the object and files |
130 // and canceling supervised-user registration. This is the handler for the | 155 // and canceling supervised-user registration. This is the handler for the |
131 // "cancelCreateProfile" message. |args| is not used. | 156 // "cancelCreateProfile" message. |args| is not used. |
132 void HandleCancelProfileCreation(const base::ListValue* args); | 157 void HandleCancelProfileCreation(const base::ListValue* args); |
133 | 158 |
134 // Internal implementation. This may safely be called whether profile creation | 159 // Internal implementation. This may safely be called whether profile creation |
135 // or registration is in progress or not. |user_initiated| should be true if | 160 // or registration is in progress or not. |user_initiated| should be true if |
136 // the cancellation was deliberately requested by the user, and false if it | 161 // the cancellation was deliberately requested by the user, and false if it |
137 // was caused implicitly, e.g. by shutting down the browser. | 162 // was caused implicitly, e.g. by shutting down the browser. |
138 void CancelProfileRegistration(bool user_initiated); | 163 void CancelProfileRegistration(bool user_initiated); |
139 | 164 |
140 // After a new supervised-user profile has been created, registers the user | 165 // After a new supervised-user profile has been created, registers the user |
141 // with the management server. | 166 // with the management server. |
142 void RegisterSupervisedUser(bool create_shortcut, | 167 void RegisterSupervisedUser(bool create_shortcut, |
143 const std::string& managed_user_id, | 168 const std::string& managed_user_id, |
| 169 Profile* supervisor_profile, |
144 Profile* new_profile); | 170 Profile* new_profile); |
145 | 171 |
146 // Called back with the result of the supervised user registration. | 172 // Called back with the result of the supervised user registration. |
147 void OnSupervisedUserRegistered(bool create_shortcut, | 173 void OnSupervisedUserRegistered(bool create_shortcut, |
148 Profile* profile, | 174 Profile* profile, |
149 const GoogleServiceAuthError& error); | 175 const GoogleServiceAuthError& error); |
150 | 176 |
151 // Records UMA histograms relevant to supervised user profiles | 177 // Records UMA histograms relevant to supervised user profiles |
152 // creation and registration. | 178 // creation and registration. |
153 void RecordSupervisedProfileCreationMetrics( | 179 void RecordSupervisedProfileCreationMetrics( |
154 GoogleServiceAuthError::State error_state); | 180 GoogleServiceAuthError::State error_state); |
155 | 181 |
156 bool IsValidExistingSupervisedUserId( | 182 void DoCreateProfileIfPossible(const base::string16& name, |
157 const std::string& existing_supervised_user_id) const; | 183 const std::string& icon_url, |
| 184 bool create_shortcut, |
| 185 const std::string& supervised_user_id, |
| 186 Profile* supervisor_profile, |
| 187 const base::DictionaryValue* dict); |
158 | 188 |
159 scoped_ptr<SupervisedUserRegistrationUtility> | 189 scoped_ptr<SupervisedUserRegistrationUtility> |
160 supervised_user_registration_utility_; | 190 supervised_user_registration_utility_; |
161 #endif | 191 #endif |
162 | 192 |
163 base::WeakPtrFactory<CreateProfileHandler> weak_ptr_factory_; | 193 base::WeakPtrFactory<SigninCreateProfileHandler> weak_ptr_factory_; |
164 | 194 |
165 DISALLOW_COPY_AND_ASSIGN(CreateProfileHandler); | 195 DISALLOW_COPY_AND_ASSIGN(SigninCreateProfileHandler); |
166 }; | 196 }; |
167 | 197 |
168 } // namespace options | 198 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_CREATE_PROFILE_HANDLER_H_ |
169 | |
170 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ | |
OLD | NEW |