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

Unified Diff: chrome/browser/ui/sync/one_click_signin_sync_observer.cc

Issue 196783002: Export a private webstore API to call into the new inline sign-in flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Redirect to the continue URL when Sync is disabled Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/sync/one_click_signin_sync_observer.cc
diff --git a/chrome/browser/ui/sync/one_click_signin_sync_observer.cc b/chrome/browser/ui/sync/one_click_signin_sync_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f4f97293d4b61afb9bebf77e1ed1af934d9f7b8b
--- /dev/null
+++ b/chrome/browser/ui/sync/one_click_signin_sync_observer.cc
@@ -0,0 +1,126 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/sync/one_click_signin_sync_observer.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/signin/signin_promo.h"
+#include "chrome/browser/sync/profile_sync_service.h"
+#include "chrome/browser/sync/profile_sync_service_factory.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_delegate.h"
+
+namespace {
+
+void CloseTab(content::WebContents* tab) {
+ content::WebContentsDelegate* tab_delegate = tab->GetDelegate();
+ if (tab_delegate)
+ tab_delegate->CloseContents(tab);
+}
+
+} // namespace
+
+
+OneClickSigninSyncObserver::OneClickSigninSyncObserver(
+ content::WebContents* web_contents,
+ const GURL& continue_url)
+ : content::WebContentsObserver(web_contents),
+ continue_url_(continue_url) {
+ DCHECK(!continue_url_.is_empty());
+
+ ProfileSyncService* sync_service = GetSyncService(web_contents);
+ if (sync_service) {
+ sync_service->AddObserver(this);
+ } else {
+ LoadContinueUrl();
+ delete this;
+ }
+}
+
+OneClickSigninSyncObserver::~OneClickSigninSyncObserver() {}
+
+void OneClickSigninSyncObserver::WebContentsDestroyed(
+ content::WebContents* web_contents) {
+ ProfileSyncService* sync_service = GetSyncService(web_contents);
+ if (sync_service)
+ sync_service->RemoveObserver(this);
+
+ delete this;
+}
+
+void OneClickSigninSyncObserver::OnStateChanged() {
+ DLOG(WARNING) << "Reached OneClickSigninSyncObserver::OnStateChanged()";
+ ProfileSyncService* sync_service = GetSyncService(web_contents());
+
+ // At this point, the sign-in process is complete, and control has been handed
+ // back to the sync engine. Close the gaia sign in tab if the |continue_url_|
+ // contains the |auto_close| parameter. Otherwise, wait for sync setup to
+ // complete and then navigate to the |continue_url_|.
+ if (signin::IsAutoCloseEnabledInURL(continue_url_)) {
+ DLOG(WARNING) << "Auto-close is enabled in the continue url.";
+ // Close the Gaia sign-in tab via a task to make sure we aren't in the
+ // middle of any WebUI handler code.
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&CloseTab, base::Unretained(web_contents())));
+ } else {
+ DLOG(WARNING) << "Auto-close is not enabled in the continue url.";
+ if (sync_service->FirstSetupInProgress()) {
+ DLOG(WARNING) << "First setup is still in progress; return early.";
+ // Sync setup has not completed yet. Wait for it to complete.
+ return;
+ }
+
+ if (sync_service->sync_initialized() &&
+ signin::GetSourceForPromoURL(continue_url_)
+ != signin::SOURCE_SETTINGS) {
+ DLOG(WARNING) << "Initialized successfully! Time to redirect to the continue URL.";
guohui 2014/03/24 20:55:58 nits: 80 chars
Ilya Sherman 2014/03/26 08:21:39 I'm not planning to commit these DLOG statements.
+ // TODO(isherman): I'm seeing this case reached with the following STR:
+ // 0. Open a tab pointed to chrome://settings.
+ // 1. In a new tab, navigate to the Chrome Webstore.
+ // 2. Trigger the private API to sign in to Chrome.
+ // 3. Check the box to "Choose what to syc".
+ // 4. Enter username and password to sign in.
+ // 5. Wait for the current tab to be redirected to
+ // chrome://settings/syncSetup
+ // 6. Close the original chrome://settings tab.
+ // 7. At this point, the current tab will redirect back to the Chrome
+ // Webstore, even though the user hasn't actually configured Sync.
+ // I don't really understand why closing the first chrome://settings tab
+ // triggers an OnStateChanged() call. Interestingly, the behavior is
+ // different from the case where the user clicks "Cancel" in the current
+ // tab that's showing the "Configure sync" dialog. Also, this code
+ // doesn't seem to handle the case where the user opts to choose something
+ // other than "Sync everything". Again, I don't know why -- it works fine
+ // for the "Sync everything" case, and it's unchanged from the
+ // pre-existing OneClickSigninHelper logic. This is admittedly all a pile
+ // of edge-cases, but I'm worried that there might be a lot of these edge
+ // cases that add up to a bad user experience vs. opening a new tab that
+ // houses the "Configure sync" settings dialog. WDYT?
+ LoadContinueUrl();
+ }
+
+ // TODO(isherman): What's the appropriate behavior if the user presses
+ // "Cancel" after opting to "Choose what to sync"?
+ }
+
+ DLOG(WARNING) << "Sync setup is done. Removing self as an observer and dying.";
guohui 2014/03/24 20:55:58 nits: 80 chars
+ sync_service->RemoveObserver(this);
+ delete this;
+}
+
+void OneClickSigninSyncObserver::LoadContinueUrl() {
+ web_contents()->GetController().LoadURL(
+ continue_url_,
+ content::Referrer(),
+ content::PAGE_TRANSITION_AUTO_TOPLEVEL,
+ std::string());
+}
+
+ProfileSyncService* OneClickSigninSyncObserver::GetSyncService(
+ content::WebContents* web_contents) {
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents->GetBrowserContext());
+ return ProfileSyncServiceFactory::GetForProfile(profile);
+}

Powered by Google App Engine
This is Rietveld 408576698