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

Side by Side Diff: chrome/browser/ui/webui/options/sync_setup_handler.cc

Issue 7093004: Sync: Refactor the ProfileSyncService and sync setup flow to remove use of WebUI from PSS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win fix. Created 9 years, 6 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/ui/webui/options/sync_setup_handler.h" 5 #include "chrome/browser/ui/webui/options/sync_setup_handler.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/google/google_util.h" 10 #include "chrome/browser/google/google_util.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 web_ui_->RegisterMessageCallback("SyncSetupSubmitAuth", 268 web_ui_->RegisterMessageCallback("SyncSetupSubmitAuth",
269 NewCallback(this, &SyncSetupHandler::HandleSubmitAuth)); 269 NewCallback(this, &SyncSetupHandler::HandleSubmitAuth));
270 web_ui_->RegisterMessageCallback("SyncSetupConfigure", 270 web_ui_->RegisterMessageCallback("SyncSetupConfigure",
271 NewCallback(this, &SyncSetupHandler::HandleConfigure)); 271 NewCallback(this, &SyncSetupHandler::HandleConfigure));
272 web_ui_->RegisterMessageCallback("SyncSetupPassphrase", 272 web_ui_->RegisterMessageCallback("SyncSetupPassphrase",
273 NewCallback(this, &SyncSetupHandler::HandlePassphraseEntry)); 273 NewCallback(this, &SyncSetupHandler::HandlePassphraseEntry));
274 web_ui_->RegisterMessageCallback("SyncSetupPassphraseCancel", 274 web_ui_->RegisterMessageCallback("SyncSetupPassphraseCancel",
275 NewCallback(this, &SyncSetupHandler::HandlePassphraseCancel)); 275 NewCallback(this, &SyncSetupHandler::HandlePassphraseCancel));
276 web_ui_->RegisterMessageCallback("SyncSetupAttachHandler", 276 web_ui_->RegisterMessageCallback("SyncSetupAttachHandler",
277 NewCallback(this, &SyncSetupHandler::HandleAttachHandler)); 277 NewCallback(this, &SyncSetupHandler::HandleAttachHandler));
278 web_ui_->RegisterMessageCallback("SyncSetupShowErrorUI",
279 NewCallback(this, &SyncSetupHandler::HandleShowErrorUI));
278 } 280 }
279 281
280 void SyncSetupHandler::ShowGaiaLogin(const DictionaryValue& args) { 282 void SyncSetupHandler::ShowGaiaLogin(const DictionaryValue& args) {
281 StringValue page("login"); 283 StringValue page("login");
282 web_ui_->CallJavascriptFunction( 284 web_ui_->CallJavascriptFunction(
283 "SyncSetupOverlay.showSyncSetupPage", page, args); 285 "SyncSetupOverlay.showSyncSetupPage", page, args);
284 } 286 }
285 287
286 void SyncSetupHandler::ShowGaiaSuccessAndClose() { 288 void SyncSetupHandler::ShowGaiaSuccessAndClose() {
287 web_ui_->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); 289 web_ui_->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose");
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 392
391 DCHECK(flow_); 393 DCHECK(flow_);
392 flow_->OnPassphraseEntry(passphrase); 394 flow_->OnPassphraseEntry(passphrase);
393 } 395 }
394 396
395 void SyncSetupHandler::HandlePassphraseCancel(const ListValue* args) { 397 void SyncSetupHandler::HandlePassphraseCancel(const ListValue* args) {
396 DCHECK(flow_); 398 DCHECK(flow_);
397 flow_->OnPassphraseCancel(); 399 flow_->OnPassphraseCancel();
398 } 400 }
399 401
402 // TODO(jhawkins): Too much logic going on in this method: refactor.
400 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) { 403 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) {
401 DCHECK(web_ui_); 404 DCHECK(web_ui_);
402 405
403 ProfileSyncService* sync_service = 406 ProfileSyncService* sync_service =
404 web_ui_->GetProfile()->GetProfileSyncService(); 407 web_ui_->GetProfile()->GetProfileSyncService();
405 if (!sync_service) { 408 if (!sync_service) {
406 // If there's no sync service, the user tried to manually invoke a syncSetup 409 // If there's no sync service, the user tried to manually invoke a syncSetup
407 // URL, but sync features are disabled. We need to close the overlay for 410 // URL, but sync features are disabled. We need to close the overlay for
408 // this (rare) case. 411 // this (rare) case.
409 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); 412 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay");
410 return; 413 return;
411 } 414 }
412 415
413 if (sync_service->get_wizard().IsVisible()) { 416 SyncSetupWizard::State state;
414 // The wizard and setup flow have been configured, all we need to do is
415 // attach the handler if we haven't already done so.
416 if (!flow_)
417 flow_ = sync_service->get_wizard().AttachSyncSetupHandler(this);
418 return;
419 }
420 417
421 // The user is trying to manually load a syncSetup URL. We should bring up 418 // The user is trying to manually load a syncSetup URL. We should bring up
422 // either a login or a configure flow based on the state of sync. 419 // either a login or a configure flow based on the state of sync.
423 if (sync_service->HasSyncSetupCompleted()) { 420 if (sync_service->HasSyncSetupCompleted())
424 sync_service->ShowConfigure(web_ui_, false); 421 state = SyncSetupWizard::CONFIGURE;
425 } else { 422 else
426 sync_service->ShowLoginDialog(web_ui_); 423 state = SyncSetupWizard::GAIA_LOGIN;
427 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_URL); 424
425 if (!flow_) {
426 sync_service->get_wizard().Step(state);
binji 2011/06/08 20:19:56 This logic seems strange to me. Why do you have to
James Hawkins 2011/06/08 22:33:39 Indeed, though I'd like to change that in a separa
tim (not reviewing) 2011/06/09 14:50:36 But how is this not broken? Shouldn't we just yank
427 flow_ = sync_service->get_wizard().AttachSyncSetupHandler(this);
428 } 428 }
429
430 flow_->Advance(state);
429 } 431 }
430 432
433 void SyncSetupHandler::HandleShowErrorUI(const ListValue* args) {
434 if (!flow_) {
435 ProfileSyncService* service =
436 web_ui_->GetProfile()->GetProfileSyncService();
437 service->get_wizard().Step(SyncSetupWizard::NONFATAL_ERROR);
438 flow_ = service->get_wizard().AttachSyncSetupHandler(this);
439 }
440
441 flow_->Advance(SyncSetupWizard::NONFATAL_ERROR);
442 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698