OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SYNC_SETUP_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/timer.h" | 10 #include "base/timer.h" |
11 #include "chrome/browser/signin/signin_tracker.h" | 11 #include "chrome/browser/signin/signin_tracker.h" |
12 #include "chrome/browser/ui/webui/options/options_ui.h" | 12 #include "chrome/browser/ui/webui/options/options_ui.h" |
13 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 13 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
15 | 15 |
16 class LoginUIService; | 16 class LoginUIService; |
17 class ProfileManager; | 17 class ProfileManager; |
18 class ProfileSyncService; | 18 class ProfileSyncService; |
19 class SigninManager; | 19 class SigninManagerBase; |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 class WebContents; | 22 class WebContents; |
23 } | 23 } |
24 | 24 |
25 class SyncSetupHandler : public options::OptionsPageUIHandler, | 25 class SyncSetupHandler : public options::OptionsPageUIHandler, |
26 public SigninTracker::Observer, | 26 public SigninTracker::Observer, |
27 public LoginUIService::LoginUI, | 27 public LoginUIService::LoginUI, |
28 public content::WebContentsObserver { | 28 public content::WebContentsObserver { |
29 public: | 29 public: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 // Shows advanced configuration dialog without going through sign in dialog. | 64 // Shows advanced configuration dialog without going through sign in dialog. |
65 // Kicks the sync backend if necessary with showing spinner dialog until it | 65 // Kicks the sync backend if necessary with showing spinner dialog until it |
66 // gets ready. | 66 // gets ready. |
67 void OpenConfigureSync(); | 67 void OpenConfigureSync(); |
68 | 68 |
69 // Terminates the sync setup flow. | 69 // Terminates the sync setup flow. |
70 void CloseSyncSetup(); | 70 void CloseSyncSetup(); |
71 | 71 |
72 protected: | 72 protected: |
73 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, GaiaErrorInitializingSync); | |
74 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, HandleCaptcha); | |
75 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, HandleGaiaAuthFailure); | |
76 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SelectCustomEncryption); | 73 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SelectCustomEncryption); |
77 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SuccessfullySetPassphrase); | 74 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SuccessfullySetPassphrase); |
78 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncEverything); | 75 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncEverything); |
79 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncAllManually); | 76 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncAllManually); |
80 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestPassphraseStillRequired); | 77 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestPassphraseStillRequired); |
81 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncIndividualTypes); | 78 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TestSyncIndividualTypes); |
82 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TurnOnEncryptAll); | 79 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, TurnOnEncryptAll); |
83 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, | 80 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, UnsuccessfullySetPassphrase); |
| 81 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest, |
84 UnrecoverableErrorInitializingSync); | 82 UnrecoverableErrorInitializingSync); |
85 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, UnsuccessfullySetPassphrase); | 83 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest, |
86 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerTest, SubmitAuthWithInvalidUsername); | 84 GaiaErrorInitializingSync); |
| 85 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest, HandleCaptcha); |
| 86 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest, HandleGaiaAuthFailure); |
| 87 FRIEND_TEST_ALL_PREFIXES(SyncSetupHandlerNonCrosTest, |
| 88 SubmitAuthWithInvalidUsername); |
87 | 89 |
88 bool is_configuring_sync() const { return configuring_sync_; } | 90 bool is_configuring_sync() const { return configuring_sync_; } |
89 bool have_signin_tracker() const { return signin_tracker_; } | 91 bool have_signin_tracker() const { return signin_tracker_; } |
90 | 92 |
91 // Subclasses must implement this to show the setup UI that's appropriate | 93 // Subclasses must implement this to show the setup UI that's appropriate |
92 // for the page this is contained in. | 94 // for the page this is contained in. |
93 virtual void ShowSetupUI() = 0; | 95 virtual void ShowSetupUI() = 0; |
94 | 96 |
95 // Overridden by subclasses (like SyncPromoHandler) to log stats about the | 97 // Overridden by subclasses (like SyncPromoHandler) to log stats about the |
96 // user's signin activity. | 98 // user's signin activity. |
(...skipping 13 matching lines...) Expand all Loading... |
110 // Helper routine that gets the ProfileSyncService associated with the parent | 112 // Helper routine that gets the ProfileSyncService associated with the parent |
111 // profile. | 113 // profile. |
112 ProfileSyncService* GetSyncService() const; | 114 ProfileSyncService* GetSyncService() const; |
113 | 115 |
114 // Returns the LoginUIService for the parent profile. | 116 // Returns the LoginUIService for the parent profile. |
115 LoginUIService* GetLoginUIService() const; | 117 LoginUIService* GetLoginUIService() const; |
116 | 118 |
117 private: | 119 private: |
118 // Callbacks from the page. | 120 // Callbacks from the page. |
119 void OnDidClosePage(const base::ListValue* args); | 121 void OnDidClosePage(const base::ListValue* args); |
120 void HandleSubmitAuth(const base::ListValue* args); | |
121 void HandleConfigure(const base::ListValue* args); | 122 void HandleConfigure(const base::ListValue* args); |
122 void HandlePassphraseEntry(const base::ListValue* args); | 123 void HandlePassphraseEntry(const base::ListValue* args); |
123 void HandlePassphraseCancel(const base::ListValue* args); | 124 void HandlePassphraseCancel(const base::ListValue* args); |
124 void HandleAttachHandler(const base::ListValue* args); | 125 void HandleAttachHandler(const base::ListValue* args); |
125 void HandleShowErrorUI(const base::ListValue* args); | 126 void HandleShowErrorUI(const base::ListValue* args); |
126 void HandleShowSetupUI(const base::ListValue* args); | 127 void HandleShowSetupUI(const base::ListValue* args); |
127 void HandleShowSetupUIWithoutLogin(const base::ListValue* args); | 128 void HandleShowSetupUIWithoutLogin(const base::ListValue* args); |
128 void HandleDoSignOutOnAuthError(const base::ListValue* args); | 129 void HandleDoSignOutOnAuthError(const base::ListValue* args); |
129 void HandleStopSyncing(const base::ListValue* args); | 130 void HandleStopSyncing(const base::ListValue* args); |
130 void HandleCloseTimeout(const base::ListValue* args); | 131 void HandleCloseTimeout(const base::ListValue* args); |
| 132 #if !defined(OS_CHROMEOS) |
| 133 void HandleSubmitAuth(const base::ListValue* args); |
| 134 |
| 135 // Initiates a login via the signin manager. |
| 136 void TryLogin(const std::string& username, |
| 137 const std::string& password, |
| 138 const std::string& captcha, |
| 139 const std::string& access_code); |
| 140 #endif |
131 | 141 |
132 // Helper routine that gets the Profile associated with this object (virtual | 142 // Helper routine that gets the Profile associated with this object (virtual |
133 // so tests can override). | 143 // so tests can override). |
134 virtual Profile* GetProfile() const; | 144 virtual Profile* GetProfile() const; |
135 | 145 |
136 // Shows the GAIA login success page then exits. | 146 // Shows the GAIA login success page then exits. |
137 void DisplayGaiaSuccessAndClose(); | 147 void DisplayGaiaSuccessAndClose(); |
138 | 148 |
139 // Displays the GAIA login success page then transitions to sync setup. | 149 // Displays the GAIA login success page then transitions to sync setup. |
140 void DisplayGaiaSuccessAndSettingUp(); | 150 void DisplayGaiaSuccessAndSettingUp(); |
(...skipping 22 matching lines...) Expand all Loading... |
163 // TODO(kochi): better to show some message that the user can understand what | 173 // TODO(kochi): better to show some message that the user can understand what |
164 // is running in the background. | 174 // is running in the background. |
165 void DisplaySpinner(); | 175 void DisplaySpinner(); |
166 | 176 |
167 // Displays an error dialog which shows timeout of starting the sync backend. | 177 // Displays an error dialog which shows timeout of starting the sync backend. |
168 void DisplayTimeout(); | 178 void DisplayTimeout(); |
169 | 179 |
170 // Returns true if this object is the active login object. | 180 // Returns true if this object is the active login object. |
171 bool IsActiveLogin() const; | 181 bool IsActiveLogin() const; |
172 | 182 |
173 // Initiates a login via the signin manager. | |
174 void TryLogin(const std::string& username, | |
175 const std::string& password, | |
176 const std::string& captcha, | |
177 const std::string& access_code); | |
178 | |
179 // If a wizard already exists, focus it and return true. | 183 // If a wizard already exists, focus it and return true. |
180 bool FocusExistingWizardIfPresent(); | 184 bool FocusExistingWizardIfPresent(); |
181 | 185 |
182 // Invokes the javascript call to close the setup overlay. | 186 // Invokes the javascript call to close the setup overlay. |
183 void CloseOverlay(); | 187 void CloseOverlay(); |
184 | 188 |
185 // When using web-flow, closes the Gaia page used to collection user | 189 // When using web-flow, closes the Gaia page used to collection user |
186 // credentials. | 190 // credentials. |
187 void CloseGaiaSigninPage(); | 191 void CloseGaiaSigninPage(); |
188 | 192 |
189 // Returns true if the given login data is valid, false otherwise. If the | 193 // Returns true if the given login data is valid, false otherwise. If the |
190 // login data is not valid then on return |error_message| will be set to a | 194 // login data is not valid then on return |error_message| will be set to a |
191 // localized error message. Note, |error_message| must not be NULL. | 195 // localized error message. Note, |error_message| must not be NULL. |
192 bool IsLoginAuthDataValid(const std::string& username, | 196 bool IsLoginAuthDataValid(const std::string& username, |
193 string16* error_message); | 197 string16* error_message); |
194 | 198 |
195 // Returns the SigninManager for the parent profile. | |
196 SigninManager* GetSignin() const; | |
197 | |
198 // The SigninTracker object used to determine when the user has fully signed | 199 // The SigninTracker object used to determine when the user has fully signed |
199 // in (this requires waiting for various services to initialize and tracking | 200 // in (this requires waiting for various services to initialize and tracking |
200 // errors from multiple sources). Should only be non-null while the login UI | 201 // errors from multiple sources). Should only be non-null while the login UI |
201 // is visible. | 202 // is visible. |
202 scoped_ptr<SigninTracker> signin_tracker_; | 203 scoped_ptr<SigninTracker> signin_tracker_; |
203 | 204 |
204 // Set to true whenever the sync configure UI is visible. This is used to tell | 205 // Set to true whenever the sync configure UI is visible. This is used to tell |
205 // what stage of the setup wizard the user was in and to update the UMA | 206 // what stage of the setup wizard the user was in and to update the UMA |
206 // histograms in the case that the user cancels out. | 207 // histograms in the case that the user cancels out. |
207 bool configuring_sync_; | 208 bool configuring_sync_; |
(...skipping 16 matching lines...) Expand all Loading... |
224 scoped_ptr<base::OneShotTimer<SyncSetupHandler> > backend_start_timer_; | 225 scoped_ptr<base::OneShotTimer<SyncSetupHandler> > backend_start_timer_; |
225 | 226 |
226 // When using web-flow, weak pointer to the tab that holds the Gaia sign in | 227 // When using web-flow, weak pointer to the tab that holds the Gaia sign in |
227 // page. | 228 // page. |
228 content::WebContents* active_gaia_signin_tab_; | 229 content::WebContents* active_gaia_signin_tab_; |
229 | 230 |
230 DISALLOW_COPY_AND_ASSIGN(SyncSetupHandler); | 231 DISALLOW_COPY_AND_ASSIGN(SyncSetupHandler); |
231 }; | 232 }; |
232 | 233 |
233 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ | 234 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER_H_ |
OLD | NEW |