| 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 24 matching lines...) Expand all Loading... |
| 35 local_state, | 35 local_state, |
| 36 request_context, | 36 request_context, |
| 37 device_management_service), | 37 device_management_service), |
| 38 oauth2_token_service_(token_service) { | 38 oauth2_token_service_(token_service) { |
| 39 if (profile->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin)) | 39 if (profile->GetPrefs()->GetBoolean(prefs::kDisableCloudPolicyOnSignin)) |
| 40 return; | 40 return; |
| 41 | 41 |
| 42 // ProfileOAuth2TokenService should not yet have loaded its tokens since this | 42 // ProfileOAuth2TokenService should not yet have loaded its tokens since this |
| 43 // happens in the background after PKS initialization - so this service | 43 // happens in the background after PKS initialization - so this service |
| 44 // should always be created before the oauth token is available. | 44 // should always be created before the oauth token is available. |
| 45 DCHECK(!oauth2_token_service_->RefreshTokenIsAvailable()); | 45 DCHECK(!oauth2_token_service_->RefreshTokenIsAvailable( |
| 46 oauth2_token_service_->GetPrimaryAccountId())); |
| 46 | 47 |
| 47 // Listen for an OAuth token to become available so we can register a client | 48 // Listen for an OAuth token to become available so we can register a client |
| 48 // if for some reason the client is not already registered (for example, if | 49 // if for some reason the client is not already registered (for example, if |
| 49 // the policy load failed during initial signin). | 50 // the policy load failed during initial signin). |
| 50 oauth2_token_service_->AddObserver(this); | 51 oauth2_token_service_->AddObserver(this); |
| 51 } | 52 } |
| 52 | 53 |
| 53 UserPolicySigninService::~UserPolicySigninService() { | 54 UserPolicySigninService::~UserPolicySigninService() { |
| 54 } | 55 } |
| 55 | 56 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 CloudPolicyService* service) { | 142 CloudPolicyService* service) { |
| 142 UserCloudPolicyManager* manager = GetManager(); | 143 UserCloudPolicyManager* manager = GetManager(); |
| 143 DCHECK_EQ(service, manager->core()->service()); | 144 DCHECK_EQ(service, manager->core()->service()); |
| 144 DCHECK(service->IsInitializationComplete()); | 145 DCHECK(service->IsInitializationComplete()); |
| 145 // The service is now initialized - if the client is not yet registered, then | 146 // The service is now initialized - if the client is not yet registered, then |
| 146 // it means that there is no cached policy and so we need to initiate a new | 147 // it means that there is no cached policy and so we need to initiate a new |
| 147 // client registration. | 148 // client registration. |
| 148 DVLOG_IF(1, manager->IsClientRegistered()) | 149 DVLOG_IF(1, manager->IsClientRegistered()) |
| 149 << "Client already registered - not fetching DMToken"; | 150 << "Client already registered - not fetching DMToken"; |
| 150 if (!manager->IsClientRegistered()) { | 151 if (!manager->IsClientRegistered()) { |
| 151 if (!oauth2_token_service_->RefreshTokenIsAvailable()) { | 152 if (!oauth2_token_service_->RefreshTokenIsAvailable( |
| 153 oauth2_token_service_->GetPrimaryAccountId())) { |
| 152 // No token yet - this class listens for OnRefreshTokenAvailable() | 154 // No token yet - this class listens for OnRefreshTokenAvailable() |
| 153 // and will re-attempt registration once the token is available. | 155 // and will re-attempt registration once the token is available. |
| 154 DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download"; | 156 DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download"; |
| 155 return; | 157 return; |
| 156 } | 158 } |
| 157 RegisterCloudPolicyService(); | 159 RegisterCloudPolicyService(); |
| 158 } | 160 } |
| 159 // If client is registered now, prohibit signout. | 161 // If client is registered now, prohibit signout. |
| 160 ProhibitSignoutIfNeeded(); | 162 ProhibitSignoutIfNeeded(); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void UserPolicySigninService::RegisterCloudPolicyService() { | 165 void UserPolicySigninService::RegisterCloudPolicyService() { |
| 164 DCHECK(!GetManager()->IsClientRegistered()); | 166 DCHECK(!GetManager()->IsClientRegistered()); |
| 165 DVLOG(1) << "Fetching new DM Token"; | 167 DVLOG(1) << "Fetching new DM Token"; |
| 166 // Do nothing if already starting the registration process. | 168 // Do nothing if already starting the registration process. |
| 167 if (registration_helper_) | 169 if (registration_helper_) |
| 168 return; | 170 return; |
| 169 | 171 |
| 170 // Start the process of registering the CloudPolicyClient. Once it completes, | 172 // Start the process of registering the CloudPolicyClient. Once it completes, |
| 171 // policy fetch will automatically happen. | 173 // policy fetch will automatically happen. |
| 172 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( | 174 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( |
| 173 profile()->GetRequestContext(), | 175 profile()->GetRequestContext(), |
| 174 GetManager()->core()->client(), | 176 GetManager()->core()->client(), |
| 175 ShouldForceLoadPolicy(), | 177 ShouldForceLoadPolicy(), |
| 176 enterprise_management::DeviceRegisterRequest::BROWSER)); | 178 enterprise_management::DeviceRegisterRequest::BROWSER)); |
| 177 registration_helper_->StartRegistration( | 179 registration_helper_->StartRegistration( |
| 178 oauth2_token_service_, | 180 oauth2_token_service_, |
| 179 GetSigninManager()->GetAuthenticatedUsername(), | 181 oauth2_token_service_->GetPrimaryAccountId(), |
| 180 base::Bind(&UserPolicySigninService::OnRegistrationComplete, | 182 base::Bind(&UserPolicySigninService::OnRegistrationComplete, |
| 181 base::Unretained(this))); | 183 base::Unretained(this))); |
| 182 } | 184 } |
| 183 | 185 |
| 184 void UserPolicySigninService::OnRegistrationComplete() { | 186 void UserPolicySigninService::OnRegistrationComplete() { |
| 185 ProhibitSignoutIfNeeded(); | 187 ProhibitSignoutIfNeeded(); |
| 186 registration_helper_.reset(); | 188 registration_helper_.reset(); |
| 187 } | 189 } |
| 188 | 190 |
| 189 void UserPolicySigninService::ProhibitSignoutIfNeeded() { | 191 void UserPolicySigninService::ProhibitSignoutIfNeeded() { |
| 190 if (GetManager()->IsClientRegistered()) { | 192 if (GetManager()->IsClientRegistered()) { |
| 191 DVLOG(1) << "User is registered for policy - prohibiting signout"; | 193 DVLOG(1) << "User is registered for policy - prohibiting signout"; |
| 192 GetSigninManager()->ProhibitSignout(true); | 194 GetSigninManager()->ProhibitSignout(true); |
| 193 } | 195 } |
| 194 } | 196 } |
| 195 | 197 |
| 196 } // namespace policy | 198 } // namespace policy |
| OLD | NEW |