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) |
72 // 3: a flag stating whether the user should be supervised | 67 // 3: a flag stating whether the user should be supervised |
73 // (optional, boolean) | 68 // (optional, boolean) |
74 // 4: a string representing the supervised user ID. | 69 // 4: a string representing the supervised user ID. |
75 void CreateProfile(const base::ListValue* args); | 70 void CreateProfile(const base::ListValue* args); |
76 | 71 |
72 // Extracts the supervised user ID from the args passed into CreateProfile, | |
73 // and returns true if the supervised user id is valid. | |
74 bool GetSupervisedUserIdFromArgs(const base::ListValue* args, | |
75 std::string& supervised_user_id); | |
Bernhard Bauer
2014/07/21 08:55:15
Outparameters are pointers. You should probably al
mckev
2014/08/05 01:09:14
Done. Changed the method name to be more descript
| |
76 | |
77 // 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 |
78 // error message. However, if profile creation succeeded and the | 78 // error message. However, if profile creation succeeded and the |
79 // profile being created/imported is a supervised user profile, | 79 // profile being created/imported is a supervised user profile, |
80 // then proceed with the registration step. Otherwise, update the UI | 80 // then proceed with the registration step. Otherwise, update the UI |
81 // as the final task after a new profile has been created. | 81 // as the final task after a new profile has been created. |
82 void OnProfileCreated(bool create_shortcut, | 82 void OnProfileCreated(bool create_shortcut, |
83 chrome::HostDesktopType desktop_type, | 83 chrome::HostDesktopType desktop_type, |
84 const std::string& supervised_user_id, | 84 const std::string& supervised_user_id, |
85 Profile* profile, | 85 Profile* profile, |
86 Profile::CreateStatus status); | 86 Profile::CreateStatus status); |
87 | 87 |
88 void HandleProfileCreationSuccess(bool create_shortcut, | 88 void HandleProfileCreationSuccess(bool create_shortcut, |
89 chrome::HostDesktopType desktop_type, | 89 chrome::HostDesktopType desktop_type, |
90 const std::string& supervised_user_id, | 90 const std::string& supervised_user_id, |
91 Profile* profile); | 91 Profile* profile); |
92 | 92 |
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 | 93 // Creates desktop shortcut and updates the UI to indicate success |
107 // when creating a profile. | 94 // when creating a profile. |
108 void CreateShortcutAndShowSuccess(bool create_shortcut, | 95 void CreateShortcutAndShowSuccess(bool create_shortcut, |
109 chrome::HostDesktopType desktop_type, | 96 chrome::HostDesktopType desktop_type, |
110 Profile* profile); | 97 Profile* profile); |
111 | 98 |
112 // Updates the UI to show an error when creating a profile. | 99 // Updates the UI to show an error when creating a profile. |
113 void ShowProfileCreationError(Profile* profile, const base::string16& error); | 100 void ShowProfileCreationError(Profile* profile, const base::string16& error); |
114 | 101 |
115 // 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. |
116 void ShowProfileCreationWarning(const base::string16& warning); | 103 void ShowProfileCreationWarning(const base::string16& warning); |
117 | 104 |
118 // Cancels creation of a supervised-user profile currently in progress, as | 105 // Cancels creation of a supervised-user profile currently in progress, as |
119 // indicated by profile_path_being_created_, removing the object and files | 106 // indicated by profile_path_being_created_, removing the object and files |
120 // and canceling supervised-user registration. This is the handler for the | 107 // and canceling supervised-user registration. This is the handler for the |
121 // "cancelCreateProfile" message. |args| is not used. | 108 // "cancelCreateProfile" message. |args| is not used. |
122 void HandleCancelProfileCreation(const base::ListValue* args); | 109 void HandleCancelProfileCreation(const base::ListValue* args); |
123 | 110 |
124 // Internal implementation. This may safely be called whether profile creation | 111 // Internal implementation. This may safely be called whether profile creation |
125 // or registration is in progress or not. |user_initiated| should be true if | 112 // 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 | 113 // the cancellation was deliberately requested by the user, and false if it |
127 // was caused implicitly, e.g. by shutting down the browser. | 114 // was caused implicitly, e.g. by shutting down the browser. |
128 void CancelProfileRegistration(bool user_initiated); | 115 void CancelProfileRegistration(bool user_initiated); |
129 | 116 |
130 // Records UMA histograms relevant to profile creation. | 117 // Records UMA histograms relevant to profile creation. |
131 void RecordProfileCreationMetrics(Profile::CreateStatus status); | 118 void RecordProfileCreationMetrics(Profile::CreateStatus status); |
132 | 119 |
133 // Records UMA histograms relevant to supervised user profiles | 120 base::string16 GetProfileCreationErrorMessageLocal() const; |
Bernhard Bauer
2014/07/21 08:55:15
I think I would actually prefer to move the superv
mckev
2014/08/05 01:09:14
No problem, done.
| |
134 // creation and registration. | |
135 void RecordSupervisedProfileCreationMetrics( | |
136 GoogleServiceAuthError::State error_state); | |
137 | 121 |
138 base::string16 GetProfileCreationErrorMessage( | |
139 ProfileCreationErrorType error) const; | |
140 std::string GetJavascriptMethodName(ProfileCreationStatus status) const; | 122 std::string GetJavascriptMethodName(ProfileCreationStatus status) const; |
141 | 123 |
142 bool IsValidExistingSupervisedUserId( | |
143 const std::string& existing_supervised_user_id) const; | |
144 | |
145 // Used to allow cancelling a profile creation (particularly a supervised-user | 124 // Used to allow cancelling a profile creation (particularly a supervised-user |
146 // registration) in progress. Set when profile creation is begun, and | 125 // registration) in progress. Set when profile creation is begun, and |
147 // cleared when all the callbacks have been run and creation is complete. | 126 // cleared when all the callbacks have been run and creation is complete. |
148 base::FilePath profile_path_being_created_; | 127 base::FilePath profile_path_being_created_; |
149 | 128 |
150 // Used to track how long profile creation takes. | 129 // Used to track how long profile creation takes. |
151 base::TimeTicks profile_creation_start_time_; | 130 base::TimeTicks profile_creation_start_time_; |
152 | 131 |
153 scoped_ptr<SupervisedUserRegistrationUtility> | |
154 supervised_user_registration_utility_; | |
155 | |
156 // Indicates the type of the in progress profile creation operation. | 132 // Indicates the type of the in progress profile creation operation. |
157 // The value is only relevant while we are creating/importing a profile. | 133 // The value is only relevant while we are creating/importing a profile. |
158 ProfileCreationOperationType profile_creation_type_; | 134 ProfileCreationOperationType profile_creation_type_; |
159 | 135 |
136 #if defined(ENABLE_MANAGED_USERS) | |
137 // After a new supervised-user profile has been created, registers the user | |
138 // with the management server. | |
139 void RegisterSupervisedUser(bool create_shortcut, | |
140 chrome::HostDesktopType desktop_type, | |
141 const std::string& managed_user_id, | |
142 Profile* new_profile); | |
143 | |
144 // Called back with the result of the supervised user registration. | |
145 void OnSupervisedUserRegistered(bool create_shortcut, | |
146 chrome::HostDesktopType desktop_type, | |
147 Profile* profile, | |
148 const GoogleServiceAuthError& error); | |
149 | |
150 // Records UMA histograms relevant to supervised user profiles | |
151 // creation and registration. | |
152 void RecordSupervisedProfileCreationMetrics( | |
153 GoogleServiceAuthError::State error_state); | |
154 | |
155 bool IsValidExistingSupervisedUserId( | |
156 const std::string& existing_supervised_user_id) const; | |
157 | |
158 base::string16 GetProfileCreationErrorMessageRemote() const; | |
159 base::string16 GetProfileCreationErrorMessageSignin() const; | |
160 | |
161 scoped_ptr<SupervisedUserRegistrationUtility> | |
162 supervised_user_registration_utility_; | |
163 #endif | |
164 | |
160 base::WeakPtrFactory<CreateProfileHandler> weak_ptr_factory_; | 165 base::WeakPtrFactory<CreateProfileHandler> weak_ptr_factory_; |
161 | 166 |
162 DISALLOW_COPY_AND_ASSIGN(CreateProfileHandler); | 167 DISALLOW_COPY_AND_ASSIGN(CreateProfileHandler); |
163 }; | 168 }; |
164 | 169 |
165 } // namespace options | 170 } // namespace options |
166 | 171 |
167 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ | 172 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ |
OLD | NEW |