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

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: Add API tests 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..b6ad75d8f69f3dd965e8b557011145bc2817b79d
--- /dev/null
+++ b/chrome/browser/ui/sync/one_click_signin_sync_observer.cc
@@ -0,0 +1,101 @@
+// 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() {
+ 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_)) {
+ // 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 {
+ if (sync_service->FirstSetupInProgress()) {
+ // Sync setup has not completed yet. Wait for it to complete.
+ return;
+ }
+
+ if (sync_service->sync_initialized() &&
+ signin::GetSourceForPromoURL(continue_url_)
+ != signin::SOURCE_SETTINGS) {
+ // TODO(isherman): Redirecting after Sync is set up still has some bugs:
+ // http://crbug.com/355885
+ // Having multiple settings pages open can cause issues.
+ // http://crbug.com/XXXXXX
+ // Selecting anything other than "Sync Everything" when configuring Sync
+ // prevents the redirect.
+ LoadContinueUrl();
+ }
+ }
+
+ 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