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; |
163 ActivateState(current_state_); | 182 ActivateState(current_state_); |
164 } | 183 } |
165 | 184 |
166 void SyncSetupFlow::Advance(SyncSetupWizard::State advance_state) { | 185 void SyncSetupFlow::Advance(SyncSetupWizard::State advance_state) { |
167 if (!ShouldAdvance(advance_state)) { | 186 if (!ShouldAdvance(advance_state)) { |
168 LOG(WARNING) << "Invalid state change from " | 187 LOG(WARNING) << "Invalid state change from " |
169 << current_state_ << " to " << advance_state; | 188 << current_state_ << " to " << advance_state; |
170 return; | 189 return; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 DCHECK(current_state_ != SyncSetupWizard::GAIA_LOGIN && |
307 current_state_ != SyncSetupWizard::GAIA_SUCCESS); | 326 current_state_ != SyncSetupWizard::GAIA_SUCCESS); |
308 return true; | 327 return true; |
309 case SyncSetupWizard::SETTING_UP: | 328 case SyncSetupWizard::SETTING_UP: |
310 return current_state_ == SyncSetupWizard::SYNC_EVERYTHING || | 329 return current_state_ == SyncSetupWizard::SYNC_EVERYTHING || |
311 current_state_ == SyncSetupWizard::CONFIGURE || | 330 current_state_ == SyncSetupWizard::CONFIGURE || |
312 current_state_ == SyncSetupWizard::ENTER_PASSPHRASE; | 331 current_state_ == SyncSetupWizard::ENTER_PASSPHRASE; |
| 332 case SyncSetupWizard::NONFATAL_ERROR: |
313 case SyncSetupWizard::FATAL_ERROR: | 333 case SyncSetupWizard::FATAL_ERROR: |
314 return true; // You can always hit the panic button. | 334 return true; // You can always hit the panic button. |
315 case SyncSetupWizard::DONE: | 335 case SyncSetupWizard::DONE: |
316 return current_state_ == SyncSetupWizard::SETTING_UP || | 336 return current_state_ == SyncSetupWizard::SETTING_UP || |
317 current_state_ == SyncSetupWizard::ENTER_PASSPHRASE; | 337 current_state_ == SyncSetupWizard::ENTER_PASSPHRASE; |
318 default: | 338 default: |
319 NOTREACHED() << "Unhandled State: " << state; | 339 NOTREACHED() << "Unhandled State: " << state; |
320 return false; | 340 return false; |
321 } | 341 } |
322 } | 342 } |
323 | 343 |
324 void SyncSetupFlow::ActivateState(SyncSetupWizard::State state) { | 344 void SyncSetupFlow::ActivateState(SyncSetupWizard::State state) { |
| 345 if (state == SyncSetupWizard::NONFATAL_ERROR) |
| 346 state = GetStepForNonFatalError(service_); |
| 347 |
325 switch (state) { | 348 switch (state) { |
326 case SyncSetupWizard::GAIA_LOGIN: { | 349 case SyncSetupWizard::GAIA_LOGIN: { |
327 DictionaryValue args; | 350 DictionaryValue args; |
328 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); | 351 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); |
329 flow_handler_->ShowGaiaLogin(args); | 352 flow_handler_->ShowGaiaLogin(args); |
330 break; | 353 break; |
331 } | 354 } |
332 case SyncSetupWizard::GAIA_SUCCESS: | 355 case SyncSetupWizard::GAIA_SUCCESS: |
333 if (end_state_ == SyncSetupWizard::GAIA_SUCCESS) { | 356 if (end_state_ == SyncSetupWizard::GAIA_SUCCESS) { |
334 flow_handler_->ShowGaiaSuccessAndClose(); | 357 flow_handler_->ShowGaiaSuccessAndClose(); |
(...skipping 10 matching lines...) Expand all Loading... |
345 } | 368 } |
346 case SyncSetupWizard::CONFIGURE: { | 369 case SyncSetupWizard::CONFIGURE: { |
347 DictionaryValue args; | 370 DictionaryValue args; |
348 SyncSetupFlow::GetArgsForConfigure(service_, &args); | 371 SyncSetupFlow::GetArgsForConfigure(service_, &args); |
349 flow_handler_->ShowConfigure(args); | 372 flow_handler_->ShowConfigure(args); |
350 break; | 373 break; |
351 } | 374 } |
352 case SyncSetupWizard::ENTER_PASSPHRASE: { | 375 case SyncSetupWizard::ENTER_PASSPHRASE: { |
353 DictionaryValue args; | 376 DictionaryValue args; |
354 SyncSetupFlow::GetArgsForConfigure(service_, &args); | 377 SyncSetupFlow::GetArgsForConfigure(service_, &args); |
355 SyncSetupFlow::GetArgsForEnterPassphrase( | 378 GetArgsForEnterPassphrase(tried_creating_explicit_passphrase_, |
356 tried_creating_explicit_passphrase_, | 379 tried_setting_explicit_passphrase_, |
357 tried_setting_explicit_passphrase_, | 380 &args); |
358 &args); | |
359 flow_handler_->ShowPassphraseEntry(args); | 381 flow_handler_->ShowPassphraseEntry(args); |
360 break; | 382 break; |
361 } | 383 } |
362 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: { | 384 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: { |
363 DictionaryValue args; | 385 DictionaryValue args; |
364 SyncSetupFlow::GetArgsForConfigure(service_, &args); | 386 SyncSetupFlow::GetArgsForConfigure(service_, &args); |
365 args.SetBoolean("was_aborted", true); | 387 args.SetBoolean("was_aborted", true); |
366 flow_handler_->ShowConfigure(args); | 388 flow_handler_->ShowConfigure(args); |
367 break; | 389 break; |
368 } | 390 } |
(...skipping 12 matching lines...) Expand all Loading... |
381 } | 403 } |
382 case SyncSetupWizard::DONE: | 404 case SyncSetupWizard::DONE: |
383 flow_handler_->ShowSetupDone( | 405 flow_handler_->ShowSetupDone( |
384 UTF16ToWide(service_->GetAuthenticatedUsername())); | 406 UTF16ToWide(service_->GetAuthenticatedUsername())); |
385 break; | 407 break; |
386 default: | 408 default: |
387 NOTREACHED() << "Invalid advance state: " << state; | 409 NOTREACHED() << "Invalid advance state: " << state; |
388 } | 410 } |
389 current_state_ = state; | 411 current_state_ = state; |
390 } | 412 } |
OLD | NEW |