Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/browser/sync/sync_setup_flow.cc

Issue 7792093: Moved the handling of the initial passphrase into SyncSetupFlow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reverted unnecessary change to domui code. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 16 matching lines...) Expand all
27 namespace { 27 namespace {
28 28
29 // Helper function to disable password sync. 29 // Helper function to disable password sync.
30 void DisablePasswordSync(ProfileSyncService* service) { 30 void DisablePasswordSync(ProfileSyncService* service) {
31 syncable::ModelTypeSet types; 31 syncable::ModelTypeSet types;
32 service->GetPreferredDataTypes(&types); 32 service->GetPreferredDataTypes(&types);
33 types.erase(syncable::PASSWORDS); 33 types.erase(syncable::PASSWORDS);
34 service->OnUserChoseDatatypes(false, types); 34 service->OnUserChoseDatatypes(false, types);
35 } 35 }
36 36
37 // Fills |args| for the enter passphrase screen.
38 void GetArgsForEnterPassphrase(bool tried_creating_explicit_passphrase,
39 bool tried_setting_explicit_passphrase,
40 DictionaryValue* args) {
41 args->SetBoolean("show_passphrase", true);
42 args->SetBoolean("passphrase_creation_rejected",
43 tried_creating_explicit_passphrase);
44 args->SetBoolean("passphrase_setting_rejected",
45 tried_setting_explicit_passphrase);
46 }
47
48 // Returns the next step for the non-fatal error case. 37 // Returns the next step for the non-fatal error case.
49 SyncSetupWizard::State GetStepForNonFatalError(ProfileSyncService* service) { 38 SyncSetupWizard::State GetStepForNonFatalError(ProfileSyncService* service) {
50 // TODO(sync): Update this error handling to allow different platforms to 39 // TODO(sync): Update this error handling to allow different platforms to
51 // display the error appropriately (http://crbug.com/92722) instead of 40 // display the error appropriately (http://crbug.com/92722) instead of
52 // navigating to a LOGIN state that is not supported on every platform. 41 // navigating to a LOGIN state that is not supported on every platform.
53 if (service->IsPassphraseRequired()) { 42 if (service->IsPassphraseRequired()) {
54 if (service->IsUsingSecondaryPassphrase()) 43 if (service->IsUsingSecondaryPassphrase())
55 return SyncSetupWizard::ENTER_PASSPHRASE; 44 return SyncSetupWizard::ENTER_PASSPHRASE;
56 return SyncSetupWizard::GetLoginState(); 45 return SyncSetupWizard::GetLoginState();
57 } 46 }
(...skipping 24 matching lines...) Expand all
82 flow_handler_->SetFlow(NULL); 71 flow_handler_->SetFlow(NULL);
83 } 72 }
84 73
85 // static 74 // static
86 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, 75 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service,
87 SyncSetupFlowContainer* container, 76 SyncSetupFlowContainer* container,
88 SyncSetupWizard::State start, 77 SyncSetupWizard::State start,
89 SyncSetupWizard::State end) { 78 SyncSetupWizard::State end) {
90 if (start == SyncSetupWizard::NONFATAL_ERROR) 79 if (start == SyncSetupWizard::NONFATAL_ERROR)
91 start = GetStepForNonFatalError(service); 80 start = GetStepForNonFatalError(service);
92 81 return new SyncSetupFlow(start, end, container, service);
93 DictionaryValue args;
94 if (start == SyncSetupWizard::GAIA_LOGIN)
95 SyncSetupFlow::GetArgsForGaiaLogin(service, &args);
96 else if (start == SyncSetupWizard::CONFIGURE)
97 SyncSetupFlow::GetArgsForConfigure(service, &args);
98 else if (start == SyncSetupWizard::ENTER_PASSPHRASE)
99 GetArgsForEnterPassphrase(false, false, &args);
100
101 std::string json_args;
102 base::JSONWriter::Write(&args, false, &json_args);
103
104 return new SyncSetupFlow(start, end, json_args, container, service);
105 } 82 }
106 83
107 // static 84 // static
108 void SyncSetupFlow::GetArgsForGaiaLogin(const ProfileSyncService* service, 85 void SyncSetupFlow::GetArgsForGaiaLogin(const ProfileSyncService* service,
109 DictionaryValue* args) { 86 DictionaryValue* args) {
110 const GoogleServiceAuthError& error = service->GetAuthError(); 87 const GoogleServiceAuthError& error = service->GetAuthError();
111 if (!service->last_attempted_user_email().empty()) { 88 if (!service->last_attempted_user_email().empty()) {
112 args->SetString("user", service->last_attempted_user_email()); 89 args->SetString("user", service->last_attempted_user_email());
113 args->SetInteger("error", error.state()); 90 args->SetInteger("error", error.state());
114 args->SetBoolean("editable_user", true); 91 args->SetBoolean("editable_user", true);
115 } else { 92 } else {
116 string16 user; 93 string16 user;
117 if (!service->cros_user().empty()) 94 if (!service->cros_user().empty())
118 user = UTF8ToUTF16(service->cros_user()); 95 user = UTF8ToUTF16(service->cros_user());
119 else 96 else
120 user = service->GetAuthenticatedUsername(); 97 user = service->GetAuthenticatedUsername();
121 args->SetString("user", user); 98 args->SetString("user", user);
122 args->SetInteger("error", 0); 99 args->SetInteger("error", 0);
123 args->SetBoolean("editable_user", user.empty()); 100 args->SetBoolean("editable_user", user.empty());
124 } 101 }
125 102
126 args->SetString("captchaUrl", error.captcha().image_url.spec()); 103 args->SetString("captchaUrl", error.captcha().image_url.spec());
127 } 104 }
128 105
129 // static
130 void SyncSetupFlow::GetArgsForConfigure(ProfileSyncService* service, 106 void SyncSetupFlow::GetArgsForConfigure(ProfileSyncService* service,
131 DictionaryValue* args) { 107 DictionaryValue* args) {
132 // The SYNC_EVERYTHING case will set this to true. 108 // The SYNC_EVERYTHING case will set this to true.
133 args->SetBoolean("showSyncEverythingPage", false); 109 args->SetBoolean("showSyncEverythingPage", false);
134 110
135 args->SetBoolean("keepEverythingSynced", 111 args->SetBoolean("keepEverythingSynced",
136 service->profile()->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced)); 112 service->profile()->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced));
137 113
138 // Bookmarks, Preferences, and Themes are launched for good, there's no 114 // Bookmarks, Preferences, and Themes are launched for good, there's no
139 // going back now. Check if the other data types are registered though. 115 // going back now. Check if the other data types are registered though.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 syncable::ModelTypeSet encrypted_types; 152 syncable::ModelTypeSet encrypted_types;
177 service->GetEncryptedDataTypes(&encrypted_types); 153 service->GetEncryptedDataTypes(&encrypted_types);
178 bool encrypt_all = 154 bool encrypt_all =
179 encrypted_types.upper_bound(syncable::PASSWORDS) != encrypted_types.end(); 155 encrypted_types.upper_bound(syncable::PASSWORDS) != encrypted_types.end();
180 if (service->HasPendingEncryptedTypes()) 156 if (service->HasPendingEncryptedTypes())
181 encrypt_all = true; 157 encrypt_all = true;
182 args->SetBoolean("encryptAllData", encrypt_all); 158 args->SetBoolean("encryptAllData", encrypt_all);
183 159
184 // Load the parameters for the encryption tab. 160 // Load the parameters for the encryption tab.
185 args->SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); 161 args->SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase());
162
163 // Determine if we need a passphrase or not, and if so, prompt the user.
164 if (service->IsPassphraseRequiredForDecryption() &&
165 (service->IsUsingSecondaryPassphrase() || cached_passphrase_.empty())) {
166 // We need a passphrase, and either it's an explicit passphrase, or we
167 // don't have a cached gaia passphrase, so we have to prompt the user.
168 args->SetBoolean("show_passphrase", true);
169 }
170 args->SetBoolean("passphrase_creation_rejected",
171 tried_creating_explicit_passphrase_);
172 args->SetBoolean("passphrase_setting_rejected",
173 tried_setting_explicit_passphrase_);
186 } 174 }
187 175
188 bool SyncSetupFlow::AttachSyncSetupHandler(SyncSetupFlowHandler* handler) { 176 bool SyncSetupFlow::AttachSyncSetupHandler(SyncSetupFlowHandler* handler) {
189 if (flow_handler_) 177 if (flow_handler_)
190 return false; 178 return false;
191 179
192 flow_handler_ = handler; 180 flow_handler_ = handler;
193 handler->SetFlow(this); 181 handler->SetFlow(this);
194 ActivateState(current_state_); 182 ActivateState(current_state_);
195 return true; 183 return true;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 245 }
258 246
259 service_->OnUserCancelledDialog(); 247 service_->OnUserCancelledDialog();
260 delete this; 248 delete this;
261 } 249 }
262 250
263 void SyncSetupFlow::OnUserSubmittedAuth(const std::string& username, 251 void SyncSetupFlow::OnUserSubmittedAuth(const std::string& username,
264 const std::string& password, 252 const std::string& password,
265 const std::string& captcha, 253 const std::string& captcha,
266 const std::string& access_code) { 254 const std::string& access_code) {
255 cached_passphrase_ = password;
267 service_->OnUserSubmittedAuth(username, password, captcha, access_code); 256 service_->OnUserSubmittedAuth(username, password, captcha, access_code);
268 } 257 }
269 258
270 void SyncSetupFlow::OnUserConfigured(const SyncConfiguration& configuration) { 259 void SyncSetupFlow::OnUserConfigured(const SyncConfiguration& configuration) {
271 // Go to the "loading..." screen. 260 // Go to the "loading..." screen.
272 Advance(SyncSetupWizard::SETTING_UP); 261 Advance(SyncSetupWizard::SETTING_UP);
273 262
274 // Note: encryption will not occur until OnUserChoseDatatypes is called. 263 // Note: encryption will not occur until OnUserChoseDatatypes is called.
275 syncable::ModelTypeSet encrypted_types; 264 syncable::ModelTypeSet encrypted_types;
276 if (configuration.encrypt_all) { 265 if (configuration.encrypt_all) {
277 // Encrypt all registered types. 266 // Encrypt all registered types.
278 service_->GetRegisteredDataTypes(&encrypted_types); 267 service_->GetRegisteredDataTypes(&encrypted_types);
279 } // Else we clear the pending types for encryption. 268 } // Else we clear the pending types for encryption.
280 service_->set_pending_types_for_encryption(encrypted_types); 269 service_->set_pending_types_for_encryption(encrypted_types);
281 270
282 if (!configuration.gaia_passphrase.empty()) { 271 if (!configuration.gaia_passphrase.empty()) {
283 // Caller passed a gaia passphrase. This is illegal if we are currently 272 // Caller passed a gaia passphrase. This is illegal if we are currently
284 // using a secondary passphrase. 273 // using a secondary passphrase.
285 DCHECK(!service_->IsUsingSecondaryPassphrase()); 274 DCHECK(!service_->IsUsingSecondaryPassphrase());
286 service_->SetPassphrase(configuration.gaia_passphrase, false, false); 275 service_->SetPassphrase(configuration.gaia_passphrase, false);
276 } else if (!service_->IsUsingSecondaryPassphrase() &&
277 !cached_passphrase_.empty()) {
278 // Service needs a GAIA passphrase and we have one cached, so try it.
279 service_->SetPassphrase(cached_passphrase_, false);
280 cached_passphrase_.clear();
281 } else {
282 // No gaia passphrase cached or set, so make sure the ProfileSyncService
283 // wasn't expecting one.
284 DCHECK(!service_->IsPassphraseRequiredForDecryption() ||
285 service_->IsUsingSecondaryPassphrase());
287 } 286 }
288 287
289 // It's possible the user has to provide a secondary passphrase even when 288 // It's possible the user has to provide a secondary passphrase even when
290 // they have not set one previously. This occurs when the user has changed 289 // they have not set one previously. This occurs when the user has changed
291 // their gaia password and then sign in to a new machine for the first time. 290 // their gaia password and then sign in to a new machine for the first time.
292 // The new machine will download data encrypted with their old gaia password, 291 // The new machine will download data encrypted with their old gaia password,
293 // which their current gaia password will not be able to decrypt, triggering 292 // which their current gaia password will not be able to decrypt, triggering
294 // a prompt for a passphrase. At this point, the user must enter their old 293 // a prompt for a passphrase. At this point, the user must enter their old
295 // password, which we store as a new secondary passphrase. 294 // password, which we store as a new secondary passphrase.
296 // TODO(zea): eventually use the above gaia_passphrase instead of the 295 // TODO(zea): eventually use the above gaia_passphrase instead of the
297 // secondary passphrase in this case. 296 // secondary passphrase in this case.
298 if (configuration.use_secondary_passphrase) { 297 if (configuration.use_secondary_passphrase) {
299 if (!service_->IsUsingSecondaryPassphrase()) { 298 service_->SetPassphrase(configuration.secondary_passphrase, true);
300 service_->SetPassphrase(configuration.secondary_passphrase, true, true); 299 tried_creating_explicit_passphrase_ = true;
301 tried_creating_explicit_passphrase_ = true;
302 } else {
303 service_->SetPassphrase(configuration.secondary_passphrase, true, false);
304 tried_setting_explicit_passphrase_ = true;
305 }
306 } 300 }
307 301
308 service_->OnUserChoseDatatypes(configuration.sync_everything, 302 service_->OnUserChoseDatatypes(configuration.sync_everything,
309 configuration.data_types); 303 configuration.data_types);
310 } 304 }
311 305
312 void SyncSetupFlow::OnPassphraseEntry(const std::string& passphrase) { 306 void SyncSetupFlow::OnPassphraseEntry(const std::string& passphrase) {
313 Advance(SyncSetupWizard::SETTING_UP); 307 Advance(SyncSetupWizard::SETTING_UP);
314 service_->SetPassphrase(passphrase, true, false); 308 service_->SetPassphrase(passphrase, true);
315 tried_setting_explicit_passphrase_ = true; 309 tried_setting_explicit_passphrase_ = true;
316 } 310 }
317 311
318 void SyncSetupFlow::OnPassphraseCancel() { 312 void SyncSetupFlow::OnPassphraseCancel() {
319 // If the user cancels when being asked for the passphrase, 313 // If the user cancels when being asked for the passphrase,
320 // just disable encrypted sync and continue setting up. 314 // just disable encrypted sync and continue setting up.
321 if (current_state_ == SyncSetupWizard::ENTER_PASSPHRASE) 315 if (current_state_ == SyncSetupWizard::ENTER_PASSPHRASE)
322 DisablePasswordSync(service_); 316 DisablePasswordSync(service_);
323 317
324 Advance(SyncSetupWizard::SETTING_UP); 318 Advance(SyncSetupWizard::SETTING_UP);
325 } 319 }
326 320
327 // Use static Run method to get an instance. 321 // Use static Run method to get an instance.
328 SyncSetupFlow::SyncSetupFlow(SyncSetupWizard::State start_state, 322 SyncSetupFlow::SyncSetupFlow(SyncSetupWizard::State start_state,
329 SyncSetupWizard::State end_state, 323 SyncSetupWizard::State end_state,
330 const std::string& args,
331 SyncSetupFlowContainer* container, 324 SyncSetupFlowContainer* container,
332 ProfileSyncService* service) 325 ProfileSyncService* service)
333 : container_(container), 326 : container_(container),
334 dialog_start_args_(args),
335 current_state_(start_state), 327 current_state_(start_state),
336 end_state_(end_state), 328 end_state_(end_state),
337 login_start_time_(base::TimeTicks::Now()), 329 login_start_time_(base::TimeTicks::Now()),
338 flow_handler_(NULL), 330 flow_handler_(NULL),
339 service_(service), 331 service_(service),
340 tried_creating_explicit_passphrase_(false), 332 tried_creating_explicit_passphrase_(false),
341 tried_setting_explicit_passphrase_(false) { 333 tried_setting_explicit_passphrase_(false) {
342 } 334 }
343 335
344 // Returns true if the flow should advance to |state| based on |current_state_|. 336 // Returns true if the flow should advance to |state| based on |current_state_|.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 407 }
416 case SyncSetupWizard::CONFIGURE: { 408 case SyncSetupWizard::CONFIGURE: {
417 DictionaryValue args; 409 DictionaryValue args;
418 SyncSetupFlow::GetArgsForConfigure(service_, &args); 410 SyncSetupFlow::GetArgsForConfigure(service_, &args);
419 flow_handler_->ShowConfigure(args); 411 flow_handler_->ShowConfigure(args);
420 break; 412 break;
421 } 413 }
422 case SyncSetupWizard::ENTER_PASSPHRASE: { 414 case SyncSetupWizard::ENTER_PASSPHRASE: {
423 DictionaryValue args; 415 DictionaryValue args;
424 SyncSetupFlow::GetArgsForConfigure(service_, &args); 416 SyncSetupFlow::GetArgsForConfigure(service_, &args);
425 GetArgsForEnterPassphrase(tried_creating_explicit_passphrase_, 417 GetArgsForConfigure(service_, &args);
426 tried_setting_explicit_passphrase_, 418 // TODO(atwilson): Remove ShowPassphraseEntry (use ShowConfigure()).
Rick Campbell 2011/09/02 18:31:29 Bug number?
Andrew T Wilson (Slow) 2011/09/02 21:40:46 Done.
427 &args);
428 flow_handler_->ShowPassphraseEntry(args); 419 flow_handler_->ShowPassphraseEntry(args);
429 break; 420 break;
430 } 421 }
431 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: { 422 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: {
432 DictionaryValue args; 423 DictionaryValue args;
433 SyncSetupFlow::GetArgsForConfigure(service_, &args); 424 SyncSetupFlow::GetArgsForConfigure(service_, &args);
434 args.SetBoolean("was_aborted", true); 425 args.SetBoolean("was_aborted", true);
435 flow_handler_->ShowConfigure(args); 426 flow_handler_->ShowConfigure(args);
436 break; 427 break;
437 } 428 }
(...skipping 12 matching lines...) Expand all
450 break; 441 break;
451 } 442 }
452 case SyncSetupWizard::DONE: 443 case SyncSetupWizard::DONE:
453 flow_handler_->ShowSetupDone( 444 flow_handler_->ShowSetupDone(
454 UTF16ToWide(service_->GetAuthenticatedUsername())); 445 UTF16ToWide(service_->GetAuthenticatedUsername()));
455 break; 446 break;
456 default: 447 default:
457 NOTREACHED() << "Invalid advance state: " << state; 448 NOTREACHED() << "Invalid advance state: " << state;
458 } 449 }
459 } 450 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698