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. |
(...skipping 17 matching lines...) Expand all Loading... | |
50 enum ProfileCreationErrorType { | 52 enum ProfileCreationErrorType { |
51 REMOTE_ERROR, | 53 REMOTE_ERROR, |
52 LOCAL_ERROR, | 54 LOCAL_ERROR, |
53 SIGNIN_ERROR | 55 SIGNIN_ERROR |
54 }; | 56 }; |
55 | 57 |
56 // Represents the type of the in progress profile creation operation. | 58 // 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 | 59 // It is used to map the type of the profile creation operation to the |
58 // correct UMA metric name. | 60 // correct UMA metric name. |
59 enum ProfileCreationOperationType { | 61 enum ProfileCreationOperationType { |
62 #if defined(ENABLE_MANAGED_USERS) | |
60 SUPERVISED_PROFILE_CREATION, | 63 SUPERVISED_PROFILE_CREATION, |
61 SUPERVISED_PROFILE_IMPORT, | 64 SUPERVISED_PROFILE_IMPORT, |
65 #endif | |
62 NON_SUPERVISED_PROFILE_CREATION, | 66 NON_SUPERVISED_PROFILE_CREATION, |
63 NO_CREATION_IN_PROGRESS | 67 NO_CREATION_IN_PROGRESS |
64 }; | 68 }; |
65 | 69 |
66 // Asynchronously creates and initializes a new profile. | 70 // Asynchronously creates and initializes a new profile. |
67 // The arguments are as follows: | 71 // The arguments are as follows: |
68 // 0: name (string) | 72 // 0: name (string) |
69 // 1: icon (string) | 73 // 1: icon (string) |
70 // 2: a flag stating whether we should create a profile desktop shortcut | 74 // 2: a flag stating whether we should create a profile desktop shortcut |
71 // (optional, boolean) | 75 // (optional, boolean) |
(...skipping 11 matching lines...) Expand all Loading... | |
83 chrome::HostDesktopType desktop_type, | 87 chrome::HostDesktopType desktop_type, |
84 const std::string& supervised_user_id, | 88 const std::string& supervised_user_id, |
85 Profile* profile, | 89 Profile* profile, |
86 Profile::CreateStatus status); | 90 Profile::CreateStatus status); |
87 | 91 |
88 void HandleProfileCreationSuccess(bool create_shortcut, | 92 void HandleProfileCreationSuccess(bool create_shortcut, |
89 chrome::HostDesktopType desktop_type, | 93 chrome::HostDesktopType desktop_type, |
90 const std::string& supervised_user_id, | 94 const std::string& supervised_user_id, |
91 Profile* profile); | 95 Profile* profile); |
92 | 96 |
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 | 97 // Creates desktop shortcut and updates the UI to indicate success |
107 // when creating a profile. | 98 // when creating a profile. |
108 void CreateShortcutAndShowSuccess(bool create_shortcut, | 99 void CreateShortcutAndShowSuccess(bool create_shortcut, |
109 chrome::HostDesktopType desktop_type, | 100 chrome::HostDesktopType desktop_type, |
110 Profile* profile); | 101 Profile* profile); |
111 | 102 |
112 // Updates the UI to show an error when creating a profile. | 103 // Updates the UI to show an error when creating a profile. |
113 void ShowProfileCreationError(Profile* profile, const base::string16& error); | 104 void ShowProfileCreationError(Profile* profile, const base::string16& error); |
114 | 105 |
115 // Updates the UI to show a non-fatal warning when creating a profile. | 106 // Updates the UI to show a non-fatal warning when creating a profile. |
116 void ShowProfileCreationWarning(const base::string16& warning); | 107 void ShowProfileCreationWarning(const base::string16& warning); |
117 | 108 |
118 // Cancels creation of a supervised-user profile currently in progress, as | 109 // Cancels creation of a supervised-user profile currently in progress, as |
119 // indicated by profile_path_being_created_, removing the object and files | 110 // indicated by profile_path_being_created_, removing the object and files |
120 // and canceling supervised-user registration. This is the handler for the | 111 // and canceling supervised-user registration. This is the handler for the |
121 // "cancelCreateProfile" message. |args| is not used. | 112 // "cancelCreateProfile" message. |args| is not used. |
122 void HandleCancelProfileCreation(const base::ListValue* args); | 113 void HandleCancelProfileCreation(const base::ListValue* args); |
123 | 114 |
124 // Internal implementation. This may safely be called whether profile creation | 115 // Internal implementation. This may safely be called whether profile creation |
125 // or registration is in progress or not. |user_initiated| should be true if | 116 // 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 | 117 // the cancellation was deliberately requested by the user, and false if it |
127 // was caused implicitly, e.g. by shutting down the browser. | 118 // was caused implicitly, e.g. by shutting down the browser. |
128 void CancelProfileRegistration(bool user_initiated); | 119 void CancelProfileRegistration(bool user_initiated); |
129 | 120 |
130 // Records UMA histograms relevant to profile creation. | 121 // Records UMA histograms relevant to profile creation. |
131 void RecordProfileCreationMetrics(Profile::CreateStatus status); | 122 void RecordProfileCreationMetrics(Profile::CreateStatus status); |
132 | 123 |
133 // Records UMA histograms relevant to supervised user profiles | |
134 // creation and registration. | |
135 void RecordSupervisedProfileCreationMetrics( | |
136 GoogleServiceAuthError::State error_state); | |
137 | |
138 base::string16 GetProfileCreationErrorMessage( | 124 base::string16 GetProfileCreationErrorMessage( |
139 ProfileCreationErrorType error) const; | 125 ProfileCreationErrorType error) const; |
140 std::string GetJavascriptMethodName(ProfileCreationStatus status) const; | 126 std::string GetJavascriptMethodName(ProfileCreationStatus status) const; |
141 | 127 |
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 | 128 // Used to allow cancelling a profile creation (particularly a supervised-user |
146 // registration) in progress. Set when profile creation is begun, and | 129 // registration) in progress. Set when profile creation is begun, and |
147 // cleared when all the callbacks have been run and creation is complete. | 130 // cleared when all the callbacks have been run and creation is complete. |
148 base::FilePath profile_path_being_created_; | 131 base::FilePath profile_path_being_created_; |
149 | 132 |
150 // Used to track how long profile creation takes. | 133 // Used to track how long profile creation takes. |
151 base::TimeTicks profile_creation_start_time_; | 134 base::TimeTicks profile_creation_start_time_; |
152 | 135 |
153 scoped_ptr<SupervisedUserRegistrationUtility> | |
154 supervised_user_registration_utility_; | |
155 | |
156 // Indicates the type of the in progress profile creation operation. | 136 // Indicates the type of the in progress profile creation operation. |
157 // The value is only relevant while we are creating/importing a profile. | 137 // The value is only relevant while we are creating/importing a profile. |
158 ProfileCreationOperationType profile_creation_type_; | 138 ProfileCreationOperationType profile_creation_type_; |
159 | 139 |
160 base::WeakPtrFactory<CreateProfileHandler> weak_ptr_factory_; | 140 base::WeakPtrFactory<CreateProfileHandler> weak_ptr_factory_; |
Bernhard Bauer
2014/07/14 16:39:06
This should be the last member of the object, to e
mckev
2014/07/14 23:50:03
Good catch - thanks for pointing it out.
| |
161 | 141 |
142 | |
143 #if defined(ENABLE_MANAGED_USERS) | |
144 // After a new supervised-user profile has been created, registers the user | |
145 // with the management server. | |
146 void RegisterSupervisedUser(bool create_shortcut, | |
147 chrome::HostDesktopType desktop_type, | |
148 const std::string& managed_user_id, | |
149 Profile* new_profile); | |
150 | |
151 // Called back with the result of the supervised user registration. | |
152 void OnSupervisedUserRegistered(bool create_shortcut, | |
153 chrome::HostDesktopType desktop_type, | |
154 Profile* profile, | |
155 const GoogleServiceAuthError& error); | |
156 | |
157 // Records UMA histograms relevant to supervised user profiles | |
158 // creation and registration. | |
159 void RecordSupervisedProfileCreationMetrics( | |
160 GoogleServiceAuthError::State error_state); | |
161 | |
162 bool IsValidExistingSupervisedUserId( | |
163 const std::string& existing_supervised_user_id) const; | |
164 | |
165 scoped_ptr<SupervisedUserRegistrationUtility> | |
166 supervised_user_registration_utility_; | |
167 #endif | |
168 | |
162 DISALLOW_COPY_AND_ASSIGN(CreateProfileHandler); | 169 DISALLOW_COPY_AND_ASSIGN(CreateProfileHandler); |
163 }; | 170 }; |
164 | 171 |
165 } // namespace options | 172 } // namespace options |
166 | 173 |
167 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ | 174 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_ |
OLD | NEW |