OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/signin/signin_tracker.h" | 5 #include "chrome/browser/signin/signin_tracker.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/signin/token_service.h" | 8 #include "chrome/browser/signin/token_service.h" |
9 #include "chrome/browser/signin/token_service_factory.h" | 9 #include "chrome/browser/signin/token_service_factory.h" |
10 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
11 #include "chrome/browser/sync/profile_sync_service_factory.h" | 11 #include "chrome/browser/sync/profile_sync_service_factory.h" |
12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
13 #include "chrome/common/net/gaia/gaia_constants.h" | 13 #include "chrome/common/net/gaia/gaia_constants.h" |
14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
16 | 16 |
17 static const char* kSignedInServices[] = { | 17 static const char* kSignedInServices[] = { |
18 GaiaConstants::kSyncService, | 18 GaiaConstants::kSyncService, |
19 GaiaConstants::kGaiaOAuth2LoginRefreshToken | 19 GaiaConstants::kGaiaOAuth2LoginRefreshToken |
20 }; | 20 }; |
21 static const int kNumSignedInServices = | 21 static const int kNumSignedInServices = |
22 arraysize(kSignedInServices); | 22 arraysize(kSignedInServices); |
23 | 23 |
24 // Helper to check if the given token service is relevant for sync. | 24 // Helper to check if the given token service is relevant for sync. |
25 SigninTracker::SigninTracker(Profile* profile, Observer* observer) | 25 SigninTracker::SigninTracker(Profile* profile, Observer* observer) |
26 : state_(WAITING_FOR_GAIA_VALIDATION), | 26 : state_(WAITING_FOR_GAIA_VALIDATION), |
27 profile_(profile), | 27 profile_(profile), |
28 observer_(observer), | 28 observer_(observer), |
29 credentials_valid_(false) { | 29 credentials_valid_(false) { |
30 Initialize(); | |
31 } | |
32 | |
33 SigninTracker::SigninTracker(Profile* profile, | |
34 Observer* observer, | |
35 LoginState state) | |
36 : state_(state), | |
37 profile_(profile), | |
38 observer_(observer), | |
39 credentials_valid_(false) { | |
40 Initialize(); | |
41 } | |
42 | |
43 SigninTracker::~SigninTracker() { | |
44 ProfileSyncService* service = | |
arv (Not doing code reviews)
2012/04/04 17:04:21
No need for var here
kochi
2012/04/04 17:29:46
Done.
| |
45 ProfileSyncServiceFactory::GetForProfile(profile_); | |
46 service->RemoveObserver(this); | |
47 } | |
48 | |
49 void SigninTracker::Initialize() { | |
30 DCHECK(observer_); | 50 DCHECK(observer_); |
31 // Register for notifications from the SigninManager. | 51 // Register for notifications from the SigninManager. |
32 registrar_.Add(this, | 52 registrar_.Add(this, |
33 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 53 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
34 content::Source<Profile>(profile_)); | 54 content::Source<Profile>(profile_)); |
35 registrar_.Add(this, | 55 registrar_.Add(this, |
36 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | 56 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, |
37 content::Source<Profile>(profile_)); | 57 content::Source<Profile>(profile_)); |
38 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 58 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
39 registrar_.Add(this, | 59 registrar_.Add(this, |
40 chrome::NOTIFICATION_TOKEN_AVAILABLE, | 60 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
41 content::Source<TokenService>(token_service)); | 61 content::Source<TokenService>(token_service)); |
42 registrar_.Add(this, | 62 registrar_.Add(this, |
43 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, | 63 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, |
44 content::Source<TokenService>(token_service)); | 64 content::Source<TokenService>(token_service)); |
45 | 65 |
46 // Also listen for notifications from the various signed in services (only | 66 // Also listen for notifications from the various signed in services (only |
47 // sync for now). | 67 // sync for now). |
48 ProfileSyncService* service = | 68 ProfileSyncService* service = |
49 ProfileSyncServiceFactory::GetForProfile(profile_); | 69 ProfileSyncServiceFactory::GetForProfile(profile_); |
50 service->AddObserver(this); | 70 service->AddObserver(this); |
51 } | |
52 | 71 |
53 SigninTracker::~SigninTracker() { | 72 if (state_ == SERVICES_INITIALIZING) |
54 ProfileSyncService* service = | 73 HandleServiceStateChange(); |
55 ProfileSyncServiceFactory::GetForProfile(profile_); | |
56 service->RemoveObserver(this); | |
57 } | 74 } |
58 | 75 |
59 void SigninTracker::Observe(int type, | 76 void SigninTracker::Observe(int type, |
60 const content::NotificationSource& source, | 77 const content::NotificationSource& source, |
61 const content::NotificationDetails& details) { | 78 const content::NotificationDetails& details) { |
62 // We should not get more than one of these notifications. | 79 // We should not get more than one of these notifications. |
63 switch (type) { | 80 switch (type) { |
64 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: | 81 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: |
65 DCHECK_EQ(state_, WAITING_FOR_GAIA_VALIDATION); | 82 DCHECK_EQ(state_, WAITING_FOR_GAIA_VALIDATION); |
66 state_ = SERVICES_INITIALIZING; | 83 state_ = SERVICES_INITIALIZING; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 // static | 173 // static |
157 bool SigninTracker::AreServicesSignedIn(Profile* profile) { | 174 bool SigninTracker::AreServicesSignedIn(Profile* profile) { |
158 if (!AreServiceTokensLoaded(profile)) | 175 if (!AreServiceTokensLoaded(profile)) |
159 return false; | 176 return false; |
160 ProfileSyncService* service = | 177 ProfileSyncService* service = |
161 ProfileSyncServiceFactory::GetForProfile(profile); | 178 ProfileSyncServiceFactory::GetForProfile(profile); |
162 return (service->AreCredentialsAvailable() && | 179 return (service->AreCredentialsAvailable() && |
163 service->GetAuthError().state() == GoogleServiceAuthError::NONE && | 180 service->GetAuthError().state() == GoogleServiceAuthError::NONE && |
164 !service->unrecoverable_error_detected()); | 181 !service->unrecoverable_error_detected()); |
165 } | 182 } |
166 | |
OLD | NEW |