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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/time/time.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_window.h"
12 #include "chrome/browser/ui/host_desktop.h"
13 #include "chrome/browser/ui/webui/options/options_ui.h"
14 #include "google_apis/gaia/google_service_auth_error.h"
18 class DictionaryValue
;
22 #if defined(ENABLE_MANAGED_USERS)
23 class SupervisedUserRegistrationUtility
;
28 // Handler for the 'create profile' overlay.
29 class CreateProfileHandler
: public OptionsPageUIHandler
{
31 CreateProfileHandler();
32 virtual ~CreateProfileHandler();
34 // OptionsPageUIHandler implementation.
35 virtual void GetLocalizedValues(
36 base::DictionaryValue
* localized_strings
) override
;
38 // WebUIMessageHandler implementation.
39 virtual void RegisterMessages() override
;
42 // Represents the final profile creation status. It is used to map
43 // the status to the javascript method to be called.
44 enum ProfileCreationStatus
{
45 PROFILE_CREATION_SUCCESS
,
46 PROFILE_CREATION_ERROR
,
49 // Represents the type of the in progress profile creation operation.
50 // It is used to map the type of the profile creation operation to the
51 // correct UMA metric name.
52 enum ProfileCreationOperationType
{
53 #if defined(ENABLE_MANAGED_USERS)
54 SUPERVISED_PROFILE_CREATION
,
55 SUPERVISED_PROFILE_IMPORT
,
57 NON_SUPERVISED_PROFILE_CREATION
,
58 NO_CREATION_IN_PROGRESS
61 // Asynchronously creates and initializes a new profile.
62 // The arguments are as follows:
65 // 2: a flag stating whether we should create a profile desktop shortcut
66 // (optional, boolean)
67 // 3: a flag stating whether the user should be supervised
68 // (optional, boolean)
69 // 4: a string representing the supervised user ID.
70 void CreateProfile(const base::ListValue
* args
);
72 // If a local error occurs during profile creation, then show an appropriate
73 // error message. However, if profile creation succeeded and the
74 // profile being created/imported is a supervised user profile,
75 // then proceed with the registration step. Otherwise, update the UI
76 // as the final task after a new profile has been created.
77 void OnProfileCreated(bool create_shortcut
,
78 chrome::HostDesktopType desktop_type
,
79 const std::string
& supervised_user_id
,
81 Profile::CreateStatus status
);
83 void HandleProfileCreationSuccess(bool create_shortcut
,
84 chrome::HostDesktopType desktop_type
,
85 const std::string
& supervised_user_id
,
88 // Creates desktop shortcut and updates the UI to indicate success
89 // when creating a profile.
90 void CreateShortcutAndShowSuccess(bool create_shortcut
,
91 chrome::HostDesktopType desktop_type
,
94 // Updates the UI to show an error when creating a profile.
95 void ShowProfileCreationError(Profile
* profile
, const base::string16
& error
);
97 // Updates the UI to show a non-fatal warning when creating a profile.
98 void ShowProfileCreationWarning(const base::string16
& warning
);
100 // Records UMA histograms relevant to profile creation.
101 void RecordProfileCreationMetrics(Profile::CreateStatus status
);
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;
110 std::string
GetJavascriptMethodName(ProfileCreationStatus status
) const;
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_
;
117 // Used to track how long profile creation takes.
118 base::TimeTicks profile_creation_start_time_
;
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_
;
124 #if defined(ENABLE_MANAGED_USERS)
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
);
131 // Cancels creation of a supervised-user profile currently in progress, as
132 // indicated by profile_path_being_created_, removing the object and files
133 // and canceling supervised-user registration. This is the handler for the
134 // "cancelCreateProfile" message. |args| is not used.
135 void HandleCancelProfileCreation(const base::ListValue
* args
);
137 // Internal implementation. This may safely be called whether profile creation
138 // or registration is in progress or not. |user_initiated| should be true if
139 // the cancellation was deliberately requested by the user, and false if it
140 // was caused implicitly, e.g. by shutting down the browser.
141 void CancelProfileRegistration(bool user_initiated
);
143 // After a new supervised-user profile has been created, registers the user
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
);
150 // Called back with the result of the supervised user registration.
151 void OnSupervisedUserRegistered(bool create_shortcut
,
152 chrome::HostDesktopType desktop_type
,
154 const GoogleServiceAuthError
& error
);
156 // Records UMA histograms relevant to supervised user profiles
157 // creation and registration.
158 void RecordSupervisedProfileCreationMetrics(
159 GoogleServiceAuthError::State error_state
);
161 bool IsValidExistingSupervisedUserId(
162 const std::string
& existing_supervised_user_id
) const;
164 scoped_ptr
<SupervisedUserRegistrationUtility
>
165 supervised_user_registration_utility_
;
168 base::WeakPtrFactory
<CreateProfileHandler
> weak_ptr_factory_
;
170 DISALLOW_COPY_AND_ASSIGN(CreateProfileHandler
);
173 } // namespace options
175 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CREATE_PROFILE_HANDLER_H_