OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/sync/sync_setup_flow.h" | 5 #include "chrome/browser/sync/sync_setup_flow.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 namespace { | 28 namespace { |
29 | 29 |
30 // Helper function to disable password sync. | 30 // Helper function to disable password sync. |
31 void DisablePasswordSync(ProfileSyncService* service) { | 31 void DisablePasswordSync(ProfileSyncService* service) { |
32 syncable::ModelTypeSet types; | 32 syncable::ModelTypeSet types; |
33 service->GetPreferredDataTypes(&types); | 33 service->GetPreferredDataTypes(&types); |
34 types.erase(syncable::PASSWORDS); | 34 types.erase(syncable::PASSWORDS); |
35 service->OnUserChoseDatatypes(false, types); | 35 service->OnUserChoseDatatypes(false, types); |
36 } | 36 } |
37 | 37 |
| 38 // Fills |args| for the enter passphrase screen. |
| 39 void GetArgsForEnterPassphrase(bool tried_creating_explicit_passphrase, |
| 40 bool tried_setting_explicit_passphrase, |
| 41 DictionaryValue* args) { |
| 42 args->SetBoolean("show_passphrase", true); |
| 43 args->SetBoolean("passphrase_creation_rejected", |
| 44 tried_creating_explicit_passphrase); |
| 45 args->SetBoolean("passphrase_setting_rejected", |
| 46 tried_setting_explicit_passphrase); |
| 47 } |
| 48 |
| 49 // Returns the next step for the non-fatal error case. |
| 50 SyncSetupWizard::State GetStepForNonFatalError(ProfileSyncService* service) { |
| 51 if (service->IsPassphraseRequired() && service->IsUsingSecondaryPassphrase()) |
| 52 return SyncSetupWizard::ENTER_PASSPHRASE; |
| 53 |
| 54 const GoogleServiceAuthError& error = service->GetAuthError(); |
| 55 if (error.state() == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
| 56 error.state() == GoogleServiceAuthError::CAPTCHA_REQUIRED || |
| 57 error.state() == GoogleServiceAuthError::ACCOUNT_DELETED || |
| 58 error.state() == GoogleServiceAuthError::ACCOUNT_DISABLED || |
| 59 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) |
| 60 return SyncSetupWizard::GAIA_LOGIN; |
| 61 |
| 62 NOTREACHED(); |
| 63 return SyncSetupWizard::FATAL_ERROR; |
| 64 } |
| 65 |
38 } // namespace | 66 } // namespace |
39 | 67 |
40 SyncConfiguration::SyncConfiguration() | 68 SyncConfiguration::SyncConfiguration() |
41 : sync_everything(false), | 69 : sync_everything(false), |
42 use_secondary_passphrase(false) { | 70 use_secondary_passphrase(false) { |
43 } | 71 } |
44 | 72 |
45 SyncConfiguration::~SyncConfiguration() {} | 73 SyncConfiguration::~SyncConfiguration() {} |
46 | 74 |
47 SyncSetupFlow::~SyncSetupFlow() { | 75 SyncSetupFlow::~SyncSetupFlow() { |
48 flow_handler_->SetFlow(NULL); | 76 flow_handler_->SetFlow(NULL); |
49 } | 77 } |
50 | 78 |
51 // static | 79 // static |
52 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, | 80 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, |
53 SyncSetupFlowContainer* container, | 81 SyncSetupFlowContainer* container, |
54 SyncSetupWizard::State start, | 82 SyncSetupWizard::State start, |
55 SyncSetupWizard::State end) { | 83 SyncSetupWizard::State end) { |
| 84 if (start == SyncSetupWizard::NONFATAL_ERROR) |
| 85 start = GetStepForNonFatalError(service); |
| 86 |
56 DictionaryValue args; | 87 DictionaryValue args; |
57 if (start == SyncSetupWizard::GAIA_LOGIN) | 88 if (start == SyncSetupWizard::GAIA_LOGIN) |
58 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); | 89 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); |
59 else if (start == SyncSetupWizard::CONFIGURE) | 90 else if (start == SyncSetupWizard::CONFIGURE) |
60 SyncSetupFlow::GetArgsForConfigure(service, &args); | 91 SyncSetupFlow::GetArgsForConfigure(service, &args); |
61 else if (start == SyncSetupWizard::ENTER_PASSPHRASE) | 92 else if (start == SyncSetupWizard::ENTER_PASSPHRASE) |
62 SyncSetupFlow::GetArgsForEnterPassphrase(false, false, &args); | 93 GetArgsForEnterPassphrase(false, false, &args); |
63 | 94 |
64 std::string json_args; | 95 std::string json_args; |
65 base::JSONWriter::Write(&args, false, &json_args); | 96 base::JSONWriter::Write(&args, false, &json_args); |
66 | 97 |
67 return new SyncSetupFlow(start, end, json_args, container, service); | 98 return new SyncSetupFlow(start, end, json_args, container, service); |
68 } | 99 } |
69 | 100 |
70 // static | 101 // static |
71 void SyncSetupFlow::GetArgsForGaiaLogin(const ProfileSyncService* service, | 102 void SyncSetupFlow::GetArgsForGaiaLogin(const ProfileSyncService* service, |
72 DictionaryValue* args) { | 103 DictionaryValue* args) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 syncable::ModelTypeSet encrypted_types; | 170 syncable::ModelTypeSet encrypted_types; |
140 service->GetEncryptedDataTypes(&encrypted_types); | 171 service->GetEncryptedDataTypes(&encrypted_types); |
141 bool encrypt_all = | 172 bool encrypt_all = |
142 encrypted_types.upper_bound(syncable::PASSWORDS) != encrypted_types.end(); | 173 encrypted_types.upper_bound(syncable::PASSWORDS) != encrypted_types.end(); |
143 args->SetBoolean("encryptAllData", encrypt_all); | 174 args->SetBoolean("encryptAllData", encrypt_all); |
144 | 175 |
145 // Load the parameters for the encryption tab. | 176 // Load the parameters for the encryption tab. |
146 args->SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); | 177 args->SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); |
147 } | 178 } |
148 | 179 |
149 // static | |
150 void SyncSetupFlow::GetArgsForEnterPassphrase( | |
151 bool tried_creating_explicit_passphrase, | |
152 bool tried_setting_explicit_passphrase, | |
153 DictionaryValue* args) { | |
154 args->SetBoolean("show_passphrase", true); | |
155 args->SetBoolean("passphrase_creation_rejected", | |
156 tried_creating_explicit_passphrase); | |
157 args->SetBoolean("passphrase_setting_rejected", | |
158 tried_setting_explicit_passphrase); | |
159 } | |
160 | |
161 void SyncSetupFlow::AttachSyncSetupHandler(SyncSetupFlowHandler* handler) { | 180 void SyncSetupFlow::AttachSyncSetupHandler(SyncSetupFlowHandler* handler) { |
162 flow_handler_ = handler; | 181 flow_handler_ = handler; |
| 182 handler->SetFlow(this); |
163 ActivateState(current_state_); | 183 ActivateState(current_state_); |
164 } | 184 } |
165 | 185 |
166 void SyncSetupFlow::Advance(SyncSetupWizard::State advance_state) { | 186 void SyncSetupFlow::Advance(SyncSetupWizard::State advance_state) { |
167 if (!ShouldAdvance(advance_state)) { | 187 if (!ShouldAdvance(advance_state)) { |
168 LOG(WARNING) << "Invalid state change from " | 188 LOG(WARNING) << "Invalid state change from " |
169 << current_state_ << " to " << advance_state; | 189 << current_state_ << " to " << advance_state; |
170 return; | 190 return; |
171 } | 191 } |
172 | 192 |
173 ActivateState(advance_state); | 193 ActivateState(advance_state); |
174 } | 194 } |
175 | 195 |
176 void SyncSetupFlow::Focus() { | 196 void SyncSetupFlow::Focus() { |
177 // TODO(jhawkins): Implement this. | 197 // TODO(jhawkins): Implement this. |
178 } | 198 } |
179 | 199 |
180 // A callback to notify the delegate that the dialog closed. | 200 // A callback to notify the delegate that the dialog closed. |
181 void SyncSetupFlow::OnDialogClosed(const std::string& json_retval) { | 201 void SyncSetupFlow::OnDialogClosed(const std::string& json_retval) { |
182 DCHECK(json_retval.empty()); | 202 DCHECK(json_retval.empty()); |
183 container_->set_flow(NULL); // Sever ties from the wizard. | 203 container_->set_flow(NULL); // Sever ties from the wizard. |
184 if (current_state_ == SyncSetupWizard::DONE) { | 204 if (current_state_ == SyncSetupWizard::DONE) |
185 service_->SetSyncSetupCompleted(); | 205 service_->SetSyncSetupCompleted(); |
186 } | |
187 | 206 |
188 // Record the state at which the user cancelled the signon dialog. | 207 // Record the state at which the user cancelled the signon dialog. |
189 switch (current_state_) { | 208 switch (current_state_) { |
190 case SyncSetupWizard::GAIA_LOGIN: | 209 case SyncSetupWizard::GAIA_LOGIN: |
191 ProfileSyncService::SyncEvent( | 210 ProfileSyncService::SyncEvent( |
192 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); | 211 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); |
193 break; | 212 break; |
194 case SyncSetupWizard::GAIA_SUCCESS: | 213 case SyncSetupWizard::GAIA_SUCCESS: |
195 ProfileSyncService::SyncEvent( | 214 ProfileSyncService::SyncEvent( |
196 ProfileSyncService::CANCEL_DURING_SIGNON); | 215 ProfileSyncService::CANCEL_DURING_SIGNON); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 case SyncSetupWizard::GAIA_SUCCESS: | 315 case SyncSetupWizard::GAIA_SUCCESS: |
297 return current_state_ == SyncSetupWizard::GAIA_LOGIN; | 316 return current_state_ == SyncSetupWizard::GAIA_LOGIN; |
298 case SyncSetupWizard::SYNC_EVERYTHING: | 317 case SyncSetupWizard::SYNC_EVERYTHING: |
299 case SyncSetupWizard::CONFIGURE: | 318 case SyncSetupWizard::CONFIGURE: |
300 return current_state_ == SyncSetupWizard::GAIA_SUCCESS; | 319 return current_state_ == SyncSetupWizard::GAIA_SUCCESS; |
301 case SyncSetupWizard::ENTER_PASSPHRASE: | 320 case SyncSetupWizard::ENTER_PASSPHRASE: |
302 return current_state_ == SyncSetupWizard::SYNC_EVERYTHING || | 321 return current_state_ == SyncSetupWizard::SYNC_EVERYTHING || |
303 current_state_ == SyncSetupWizard::CONFIGURE || | 322 current_state_ == SyncSetupWizard::CONFIGURE || |
304 current_state_ == SyncSetupWizard::SETTING_UP; | 323 current_state_ == SyncSetupWizard::SETTING_UP; |
305 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: | 324 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: |
306 DCHECK(current_state_ != SyncSetupWizard::GAIA_LOGIN && | 325 return (current_state_ != SyncSetupWizard::GAIA_LOGIN && |
307 current_state_ != SyncSetupWizard::GAIA_SUCCESS); | 326 current_state_ != SyncSetupWizard::GAIA_SUCCESS); |
308 return true; | |
309 case SyncSetupWizard::SETTING_UP: | 327 case SyncSetupWizard::SETTING_UP: |
310 return current_state_ == SyncSetupWizard::SYNC_EVERYTHING || | 328 return current_state_ == SyncSetupWizard::SYNC_EVERYTHING || |
311 current_state_ == SyncSetupWizard::CONFIGURE || | 329 current_state_ == SyncSetupWizard::CONFIGURE || |
312 current_state_ == SyncSetupWizard::ENTER_PASSPHRASE; | 330 current_state_ == SyncSetupWizard::ENTER_PASSPHRASE; |
| 331 case SyncSetupWizard::NONFATAL_ERROR: |
313 case SyncSetupWizard::FATAL_ERROR: | 332 case SyncSetupWizard::FATAL_ERROR: |
314 return true; // You can always hit the panic button. | 333 return true; // You can always hit the panic button. |
315 case SyncSetupWizard::DONE: | 334 case SyncSetupWizard::DONE: |
316 return current_state_ == SyncSetupWizard::SETTING_UP || | 335 return current_state_ == SyncSetupWizard::SETTING_UP || |
317 current_state_ == SyncSetupWizard::ENTER_PASSPHRASE; | 336 current_state_ == SyncSetupWizard::ENTER_PASSPHRASE; |
318 default: | 337 default: |
319 NOTREACHED() << "Unhandled State: " << state; | 338 NOTREACHED() << "Unhandled State: " << state; |
320 return false; | 339 return false; |
321 } | 340 } |
322 } | 341 } |
323 | 342 |
324 void SyncSetupFlow::ActivateState(SyncSetupWizard::State state) { | 343 void SyncSetupFlow::ActivateState(SyncSetupWizard::State state) { |
| 344 if (state == SyncSetupWizard::NONFATAL_ERROR) |
| 345 state = GetStepForNonFatalError(service_); |
| 346 |
| 347 current_state_ = state; |
| 348 |
325 switch (state) { | 349 switch (state) { |
326 case SyncSetupWizard::GAIA_LOGIN: { | 350 case SyncSetupWizard::GAIA_LOGIN: { |
327 DictionaryValue args; | 351 DictionaryValue args; |
328 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); | 352 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); |
329 flow_handler_->ShowGaiaLogin(args); | 353 flow_handler_->ShowGaiaLogin(args); |
330 break; | 354 break; |
331 } | 355 } |
332 case SyncSetupWizard::GAIA_SUCCESS: | 356 case SyncSetupWizard::GAIA_SUCCESS: |
333 if (end_state_ == SyncSetupWizard::GAIA_SUCCESS) { | 357 if (end_state_ == SyncSetupWizard::GAIA_SUCCESS) { |
334 flow_handler_->ShowGaiaSuccessAndClose(); | 358 flow_handler_->ShowGaiaSuccessAndClose(); |
335 break; | 359 break; |
336 } | 360 } |
337 state = SyncSetupWizard::SYNC_EVERYTHING; | 361 current_state_ = SyncSetupWizard::SYNC_EVERYTHING; |
338 // Fall through. | 362 // Fall through. |
339 case SyncSetupWizard::SYNC_EVERYTHING: { | 363 case SyncSetupWizard::SYNC_EVERYTHING: { |
340 DictionaryValue args; | 364 DictionaryValue args; |
341 SyncSetupFlow::GetArgsForConfigure(service_, &args); | 365 SyncSetupFlow::GetArgsForConfigure(service_, &args); |
342 args.SetBoolean("showSyncEverythingPage", true); | 366 args.SetBoolean("showSyncEverythingPage", true); |
343 flow_handler_->ShowConfigure(args); | 367 flow_handler_->ShowConfigure(args); |
344 break; | 368 break; |
345 } | 369 } |
346 case SyncSetupWizard::CONFIGURE: { | 370 case SyncSetupWizard::CONFIGURE: { |
347 DictionaryValue args; | 371 DictionaryValue args; |
348 SyncSetupFlow::GetArgsForConfigure(service_, &args); | 372 SyncSetupFlow::GetArgsForConfigure(service_, &args); |
349 flow_handler_->ShowConfigure(args); | 373 flow_handler_->ShowConfigure(args); |
350 break; | 374 break; |
351 } | 375 } |
352 case SyncSetupWizard::ENTER_PASSPHRASE: { | 376 case SyncSetupWizard::ENTER_PASSPHRASE: { |
353 DictionaryValue args; | 377 DictionaryValue args; |
354 SyncSetupFlow::GetArgsForConfigure(service_, &args); | 378 SyncSetupFlow::GetArgsForConfigure(service_, &args); |
355 SyncSetupFlow::GetArgsForEnterPassphrase( | 379 GetArgsForEnterPassphrase(tried_creating_explicit_passphrase_, |
356 tried_creating_explicit_passphrase_, | 380 tried_setting_explicit_passphrase_, |
357 tried_setting_explicit_passphrase_, | 381 &args); |
358 &args); | |
359 flow_handler_->ShowPassphraseEntry(args); | 382 flow_handler_->ShowPassphraseEntry(args); |
360 break; | 383 break; |
361 } | 384 } |
362 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: { | 385 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: { |
363 DictionaryValue args; | 386 DictionaryValue args; |
364 SyncSetupFlow::GetArgsForConfigure(service_, &args); | 387 SyncSetupFlow::GetArgsForConfigure(service_, &args); |
365 args.SetBoolean("was_aborted", true); | 388 args.SetBoolean("was_aborted", true); |
366 flow_handler_->ShowConfigure(args); | 389 flow_handler_->ShowConfigure(args); |
367 break; | 390 break; |
368 } | 391 } |
(...skipping 10 matching lines...) Expand all Loading... |
379 flow_handler_->ShowGaiaLogin(args); | 402 flow_handler_->ShowGaiaLogin(args); |
380 break; | 403 break; |
381 } | 404 } |
382 case SyncSetupWizard::DONE: | 405 case SyncSetupWizard::DONE: |
383 flow_handler_->ShowSetupDone( | 406 flow_handler_->ShowSetupDone( |
384 UTF16ToWide(service_->GetAuthenticatedUsername())); | 407 UTF16ToWide(service_->GetAuthenticatedUsername())); |
385 break; | 408 break; |
386 default: | 409 default: |
387 NOTREACHED() << "Invalid advance state: " << state; | 410 NOTREACHED() << "Invalid advance state: " << state; |
388 } | 411 } |
389 current_state_ = state; | |
390 } | 412 } |
OLD | NEW |