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/policy/cloud/user_policy_signin_service.h" | 5 #include "chrome/browser/policy/cloud/user_policy_signin_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 : UserPolicySigninServiceBase(profile, | 32 : UserPolicySigninServiceBase(profile, |
33 local_state, | 33 local_state, |
34 device_management_service), | 34 device_management_service), |
35 oauth2_token_service_(token_service) { | 35 oauth2_token_service_(token_service) { |
36 if (profile->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin)) | 36 if (profile->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin)) |
37 return; | 37 return; |
38 | 38 |
39 // ProfileOAuth2TokenService should not yet have loaded its tokens since this | 39 // ProfileOAuth2TokenService should not yet have loaded its tokens since this |
40 // happens in the background after PKS initialization - so this service | 40 // happens in the background after PKS initialization - so this service |
41 // should always be created before the oauth token is available. | 41 // should always be created before the oauth token is available. |
42 DCHECK(!oauth2_token_service_->RefreshTokenIsAvailable()); | 42 DCHECK(!oauth2_token_service_->RefreshTokenIsAvailable( |
| 43 oauth2_token_service_->GetPrimaryAccountId())); |
43 | 44 |
44 // Listen for an OAuth token to become available so we can register a client | 45 // Listen for an OAuth token to become available so we can register a client |
45 // if for some reason the client is not already registered (for example, if | 46 // if for some reason the client is not already registered (for example, if |
46 // the policy load failed during initial signin). | 47 // the policy load failed during initial signin). |
47 oauth2_token_service_->AddObserver(this); | 48 oauth2_token_service_->AddObserver(this); |
48 } | 49 } |
49 | 50 |
50 UserPolicySigninService::~UserPolicySigninService() { | 51 UserPolicySigninService::~UserPolicySigninService() { |
51 } | 52 } |
52 | 53 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 CloudPolicyService* service) { | 139 CloudPolicyService* service) { |
139 UserCloudPolicyManager* manager = GetManager(); | 140 UserCloudPolicyManager* manager = GetManager(); |
140 DCHECK_EQ(service, manager->core()->service()); | 141 DCHECK_EQ(service, manager->core()->service()); |
141 DCHECK(service->IsInitializationComplete()); | 142 DCHECK(service->IsInitializationComplete()); |
142 // The service is now initialized - if the client is not yet registered, then | 143 // The service is now initialized - if the client is not yet registered, then |
143 // it means that there is no cached policy and so we need to initiate a new | 144 // it means that there is no cached policy and so we need to initiate a new |
144 // client registration. | 145 // client registration. |
145 DVLOG_IF(1, manager->IsClientRegistered()) | 146 DVLOG_IF(1, manager->IsClientRegistered()) |
146 << "Client already registered - not fetching DMToken"; | 147 << "Client already registered - not fetching DMToken"; |
147 if (!manager->IsClientRegistered()) { | 148 if (!manager->IsClientRegistered()) { |
148 if (!oauth2_token_service_->RefreshTokenIsAvailable()) { | 149 if (!oauth2_token_service_->RefreshTokenIsAvailable( |
| 150 oauth2_token_service_->GetPrimaryAccountId())) { |
149 // No token yet - this class listens for OnRefreshTokenAvailable() | 151 // No token yet - this class listens for OnRefreshTokenAvailable() |
150 // and will re-attempt registration once the token is available. | 152 // and will re-attempt registration once the token is available. |
151 DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download"; | 153 DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download"; |
152 return; | 154 return; |
153 } | 155 } |
154 RegisterCloudPolicyService(); | 156 RegisterCloudPolicyService(); |
155 } | 157 } |
156 // If client is registered now, prohibit signout. | 158 // If client is registered now, prohibit signout. |
157 ProhibitSignoutIfNeeded(); | 159 ProhibitSignoutIfNeeded(); |
158 } | 160 } |
(...skipping 25 matching lines...) Expand all Loading... |
184 } | 186 } |
185 | 187 |
186 void UserPolicySigninService::ProhibitSignoutIfNeeded() { | 188 void UserPolicySigninService::ProhibitSignoutIfNeeded() { |
187 if (GetManager()->IsClientRegistered()) { | 189 if (GetManager()->IsClientRegistered()) { |
188 DVLOG(1) << "User is registered for policy - prohibiting signout"; | 190 DVLOG(1) << "User is registered for policy - prohibiting signout"; |
189 GetSigninManager()->ProhibitSignout(true); | 191 GetSigninManager()->ProhibitSignout(true); |
190 } | 192 } |
191 } | 193 } |
192 | 194 |
193 } // namespace policy | 195 } // namespace policy |
OLD | NEW |