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

Side by Side 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: Tidy up 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h"
6
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/signin/signin_promo.h"
9 #include "chrome/browser/sync/profile_sync_service.h"
10 #include "chrome/browser/sync/profile_sync_service_factory.h"
11 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_delegate.h"
13
14 namespace {
15
16 void CloseTab(content::WebContents* tab) {
17 content::WebContentsDelegate* tab_delegate = tab->GetDelegate();
18 if (tab_delegate)
19 tab_delegate->CloseContents(tab);
20 }
21
22 } // namespace
23
24
25 OneClickSigninSyncObserver::OneClickSigninSyncObserver(
26 content::WebContents* web_contents,
27 const GURL& continue_url)
28 : content::WebContentsObserver(web_contents),
29 continue_url_(continue_url) {
30 DCHECK(!continue_url_.is_empty());
31
32 ProfileSyncService* sync_service = GetSyncService(web_contents);
33 if (sync_service)
34 sync_service->AddObserver(this);
35 else
36 delete this;
37
38 // TODO(isherman): What's the appropriate behavior if there is no sync
39 // service? Never redirect?
Ilya Sherman 2014/03/20 08:41:45 ^^^
guohui 2014/03/21 19:04:15 PSS is null in incognito mode or if sync is disabl
Ilya Sherman 2014/03/22 00:06:28 Done.
40 }
41
42 OneClickSigninSyncObserver::~OneClickSigninSyncObserver() {}
43
44 void OneClickSigninSyncObserver::WebContentsDestroyed(
45 content::WebContents* web_contents) {
46 ProfileSyncService* sync_service = GetSyncService(web_contents);
47 if (sync_service)
48 sync_service->RemoveObserver(this);
49
50 delete this;
51 }
52
53 void OneClickSigninSyncObserver::OnStateChanged() {
54 ProfileSyncService* sync_service = GetSyncService(web_contents());
55
56 // At this point, the sign-in process is complete, and control has been handed
57 // back to the sync engine. Close the gaia sign in tab if the |continue_url_|
58 // contains the |auto_close| parameter. Otherwise, wait for sync setup to
59 // complete and then navigate to the |continue_url_|.
60 if (signin::IsAutoCloseEnabledInURL(continue_url_)) {
61 // Close the Gaia sign-in tab via a task to make sure we aren't in the
62 // middle of any WebUI handler code.
63 base::MessageLoop::current()->PostTask(
64 FROM_HERE,
65 base::Bind(&CloseTab, base::Unretained(web_contents())));
66 } else {
67 if (sync_service->FirstSetupInProgress()) {
68 // Sync setup has not completed yet. Wait for it to complete.
69 return;
70 }
71
72 if (sync_service->sync_initialized() &&
73 signin::GetSourceForPromoURL(continue_url_)
74 != signin::SOURCE_SETTINGS) {
75 // TODO(isherman): I'm seeing this case reached with the following STR:
76 // 0. Open a tab pointed to chrome://settings.
77 // 1. In a new tab, navigate to the Chrome Webstore.
78 // 2. Trigger the private API to sign in to Chrome.
79 // 3. Check the box to "Choose what to syc".
80 // 4. Enter username and password to sign in.
81 // 5. Wait for the current tab to be redirected to
82 // chrome://settings/syncSetup
83 // 6. Close the original chrome://settings tab.
84 // 7. At this point, the current tab will redirect back to the Chrome
85 // Webstore, even though the user hasn't actually configured Sync.
86 // I don't really understand why closing the first chrome://settings tab
87 // triggers an OnStateChanged() call. Interestingly, the behavior is
88 // different from the case where the user clicks "Cancel" in the current
89 // tab that's showing the "Configure sync" dialog. Also, this code
90 // doesn't seem to handle the case where the user opts to choose something
91 // other than "Sync everything". Again, I don't know why -- it works fine
92 // for the "Sync everything" case, and it's unchanged from the
93 // pre-existing OneClickSigninHelper logic. This is admittedly all a pile
94 // of edge-cases, but I'm worried that there might be a lot of these edge
95 // cases that add up to a bad user experience vs. opening a new tab that
96 // houses the "Configure sync" settings dialog. WDYT?
Ilya Sherman 2014/03/20 08:41:45 ^^^
guohui 2014/03/21 19:04:15 these sounds like existing bugs in sync code. I su
Ilya Sherman 2014/03/21 19:30:18 I don't actually know how to trigger a similar flo
guohui 2014/03/21 20:00:21 you can trigger inline sign-in flow from the signi
Ilya Sherman 2014/03/21 23:53:32 I tried triggering the sign-in flow from the wrenc
guohui 2014/03/24 21:31:52 i don't think settings page is always a singleton.
97 web_contents()->GetController().LoadURL(
98 continue_url_,
99 content::Referrer(),
100 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
101 std::string());
102 }
103
104 // TODO(isherman): What's the appropriate behavior if the user presses
105 // "Cancel" after opting to "Choose what to sync"?
Ilya Sherman 2014/03/20 08:41:45 ^^^
guohui 2014/03/21 19:04:15 If user presses 'cancel', Chrome would sign out. I
Ilya Sherman 2014/03/21 19:30:18 Actually, the behavior that I observed was that Ch
guohui 2014/03/24 21:31:52 this is actually a known bug, and roger is working
106 }
107
108 sync_service->RemoveObserver(this);
109 delete this;
110 }
111
112 ProfileSyncService* OneClickSigninSyncObserver::GetSyncService(
113 content::WebContents* web_contents) {
114 Profile* profile =
115 Profile::FromBrowserContext(web_contents->GetBrowserContext());
116 return ProfileSyncServiceFactory::GetForProfile(profile);
117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698