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/webui/signin/signin_tracker.cc

Issue 9295044: Start moving signin code out of browser/sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unit test Created 8 years, 10 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 (c) 2012 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/webui/signin/signin_tracker.h"
6
7 #include "chrome/browser/sync/profile_sync_service.h"
8 #include "chrome/browser/sync/profile_sync_service_factory.h"
9 #include "chrome/common/chrome_notification_types.h"
10 #include "content/public/browser/notification_details.h"
11 #include "content/public/browser/notification_source.h"
12
13 SigninTracker::SigninTracker(Profile* profile, Observer* observer)
14 : state_(WAITING_FOR_GAIA_VALIDATION),
15 profile_(profile),
16 observer_(observer),
17 credentials_valid_(false) {
18 DCHECK(observer_);
19 // Register for notifications from the SigninManager.
20 registrar_.Add(this,
21 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
22 content::Source<Profile>(profile_));
23 registrar_.Add(this,
24 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED,
25 content::Source<Profile>(profile_));
26
27 // Also listen for notifications from the various signed in services (only
28 // sync for now).
29 ProfileSyncService* service =
30 ProfileSyncServiceFactory::GetForProfile(profile_);
31 service->AddObserver(this);
32 }
33
34 SigninTracker::~SigninTracker() {
35 ProfileSyncService* service =
36 ProfileSyncServiceFactory::GetForProfile(profile_);
37 service->RemoveObserver(this);
38 }
39
40 void SigninTracker::Observe(int type,
41 const content::NotificationSource& source,
42 const content::NotificationDetails& details) {
43 // We should not get more than one of these notifications.
44 if (state_ != WAITING_FOR_GAIA_VALIDATION) {
45 NOTREACHED() << "Received unexpected signin notification";
46 return;
James Hawkins 2012/02/10 23:08:01 nit: Don't handle DCHECKs (NOTREACHED in this case
Andrew T Wilson (Slow) 2012/02/11 01:50:45 Done.
47 }
48 switch (type) {
49 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL:
50 state_ = SERVICES_INITIALIZING;
51 observer_->GaiaCredentialsValid();
52 break;
53 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED:
54 state_ = WAITING_FOR_GAIA_VALIDATION;
55 observer_->SigninFailed();
56 break;
57 default:
58 NOTREACHED();
59 }
60 }
61
62 // Called when the ProfileSyncService state changes.
63 void SigninTracker::OnStateChanged() {
64 if (state_ != SERVICES_INITIALIZING) {
65 // Ignore service updates until after our GAIA credentials are validated.
66 return;
67 }
68 // Wait until all of our services are logged in. For now this just means sync.
69 // Long term, we should separate out service auth failures from the signin
70 // process, but for the current UI flow we'll validate service signin status
71 // also.
72 // TODO(atwilson): Move the code to wait for app notification oauth tokens out
73 // of ProfileSyncService and over to here.
74 ProfileSyncService* service =
75 ProfileSyncServiceFactory::GetForProfile(profile_);
76 if (service->waiting_for_auth()) {
77 // Still waiting for an auth token to come in so stay in the INITIALIZING
78 // state (we do this to avoid triggering an early signin error in the case
79 // where there's a previous auth error in the sync service that hasn't
80 // been cleared yet).
81 return;
82 }
83
84 if (!AreServicesSignedIn(profile_)) {
85 state_ = WAITING_FOR_GAIA_VALIDATION;
86 observer_->SigninFailed();
87 } else if (service->sync_initialized()) {
88 state_ = SIGNIN_COMPLETE;
89 observer_->SigninSuccess();
90 }
91 }
92
93 // static
94 bool SigninTracker::AreServicesSignedIn(Profile* profile) {
95 ProfileSyncService* service =
96 ProfileSyncServiceFactory::GetForProfile(profile);
97 return (service->AreCredentialsAvailable() &&
98 service->GetAuthError().state() == GoogleServiceAuthError::NONE &&
99 !service->unrecoverable_error_detected());
100 }
101
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698