| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 registration_helper_.reset(); | 64 registration_helper_.reset(); |
| 65 | 65 |
| 66 UserPolicySigninServiceBase::PrepareForUserCloudPolicyManagerShutdown(); | 66 UserPolicySigninServiceBase::PrepareForUserCloudPolicyManagerShutdown(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void UserPolicySigninService::Shutdown() { | 69 void UserPolicySigninService::Shutdown() { |
| 70 UserPolicySigninServiceBase::Shutdown(); | 70 UserPolicySigninServiceBase::Shutdown(); |
| 71 oauth2_token_service_->RemoveObserver(this); | 71 oauth2_token_service_->RemoveObserver(this); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void UserPolicySigninService::RegisterForPolicy( | 74 void UserPolicySigninService::RegisterForPolicyWithLoginToken( |
| 75 const std::string& username, | 75 const std::string& username, |
| 76 const std::string& oauth2_refresh_token, | 76 const std::string& oauth2_refresh_token, |
| 77 const PolicyRegistrationCallback& callback) { | 77 const PolicyRegistrationCallback& callback) { |
| 78 DCHECK(!oauth2_refresh_token.empty()); | 78 DCHECK(!oauth2_refresh_token.empty()); |
| 79 | 79 |
| 80 // Create a new CloudPolicyClient for fetching the DMToken. | 80 // Create a new CloudPolicyClient for fetching the DMToken. |
| 81 std::unique_ptr<CloudPolicyClient> policy_client = | 81 std::unique_ptr<CloudPolicyClient> policy_client = |
| 82 CreateClientForRegistrationOnly(username); | 82 CreateClientForRegistrationOnly(username); |
| 83 if (!policy_client) { | 83 if (!policy_client) { |
| 84 callback.Run(std::string(), std::string()); | 84 callback.Run(std::string(), std::string()); |
| 85 return; | 85 return; |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Fire off the registration process. Callback keeps the CloudPolicyClient | 88 // Fire off the registration process. Callback keeps the CloudPolicyClient |
| 89 // alive for the length of the registration process. Use the system | 89 // alive for the length of the registration process. Use the system |
| 90 // request context because the user is not signed in to this profile yet | 90 // request context because the user is not signed in to this profile yet |
| 91 // (we are just doing a test registration to see if policy is supported for | 91 // (we are just doing a test registration to see if policy is supported for |
| 92 // this user). | 92 // this user). |
| 93 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( | 93 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( |
| 94 policy_client.get(), | 94 policy_client.get(), |
| 95 enterprise_management::DeviceRegisterRequest::BROWSER)); | 95 enterprise_management::DeviceRegisterRequest::BROWSER)); |
| 96 registration_helper_->StartRegistrationWithLoginToken( | 96 registration_helper_->StartRegistrationWithLoginToken( |
| 97 oauth2_refresh_token, | 97 oauth2_refresh_token, |
| 98 base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback, | 98 base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback, |
| 99 base::Unretained(this), | 99 base::Unretained(this), |
| 100 base::Passed(&policy_client), | 100 base::Passed(&policy_client), |
| 101 callback)); | 101 callback)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void UserPolicySigninService::RegisterForPolicyWithAccountId( |
| 105 const std::string& username, |
| 106 const std::string& account_id, |
| 107 const PolicyRegistrationCallback& callback) { |
| 108 DCHECK(!account_id.empty()); |
| 109 |
| 110 // Create a new CloudPolicyClient for fetching the DMToken. |
| 111 std::unique_ptr<CloudPolicyClient> policy_client = |
| 112 CreateClientForRegistrationOnly(username); |
| 113 if (!policy_client) { |
| 114 callback.Run(std::string(), std::string()); |
| 115 return; |
| 116 } |
| 117 |
| 118 // Fire off the registration process. Callback keeps the CloudPolicyClient |
| 119 // alive for the length of the registration process. Use the system |
| 120 // request context because the user is not signed in to this profile yet |
| 121 // (we are just doing a test registration to see if policy is supported for |
| 122 // this user). |
| 123 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( |
| 124 policy_client.get(), |
| 125 enterprise_management::DeviceRegisterRequest::BROWSER)); |
| 126 registration_helper_->StartRegistration( |
| 127 oauth2_token_service_, account_id, |
| 128 base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback, |
| 129 base::Unretained(this), base::Passed(&policy_client), |
| 130 callback)); |
| 131 } |
| 132 |
| 104 void UserPolicySigninService::CallPolicyRegistrationCallback( | 133 void UserPolicySigninService::CallPolicyRegistrationCallback( |
| 105 std::unique_ptr<CloudPolicyClient> client, | 134 std::unique_ptr<CloudPolicyClient> client, |
| 106 PolicyRegistrationCallback callback) { | 135 PolicyRegistrationCallback callback) { |
| 107 registration_helper_.reset(); | 136 registration_helper_.reset(); |
| 108 callback.Run(client->dm_token(), client->client_id()); | 137 callback.Run(client->dm_token(), client->client_id()); |
| 109 } | 138 } |
| 110 | 139 |
| 111 void UserPolicySigninService::OnRefreshTokenAvailable( | 140 void UserPolicySigninService::OnRefreshTokenAvailable( |
| 112 const std::string& account_id) { | 141 const std::string& account_id) { |
| 113 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 142 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 228 } |
| 200 | 229 |
| 201 void UserPolicySigninService::ProhibitSignoutIfNeeded() { | 230 void UserPolicySigninService::ProhibitSignoutIfNeeded() { |
| 202 if (policy_manager()->IsClientRegistered()) { | 231 if (policy_manager()->IsClientRegistered()) { |
| 203 DVLOG(1) << "User is registered for policy - prohibiting signout"; | 232 DVLOG(1) << "User is registered for policy - prohibiting signout"; |
| 204 signin_manager()->ProhibitSignout(true); | 233 signin_manager()->ProhibitSignout(true); |
| 205 } | 234 } |
| 206 } | 235 } |
| 207 | 236 |
| 208 } // namespace policy | 237 } // namespace policy |
| OLD | NEW |