Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_mobile.h" | 5 #include "chrome/browser/policy/cloud/user_policy_signin_service_mobile.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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 // iOS doesn't create this service with the Profile; instead it's created | 62 // iOS doesn't create this service with the Profile; instead it's created |
| 63 // a little bit later. See UserPolicySigninServiceFactory. | 63 // a little bit later. See UserPolicySigninServiceFactory. |
| 64 InitializeOnProfileReady(profile); | 64 InitializeOnProfileReady(profile); |
| 65 #endif | 65 #endif |
| 66 } | 66 } |
| 67 | 67 |
| 68 UserPolicySigninService::~UserPolicySigninService() {} | 68 UserPolicySigninService::~UserPolicySigninService() {} |
| 69 | 69 |
| 70 void UserPolicySigninService::RegisterForPolicy( | 70 void UserPolicySigninService::RegisterForPolicy( |
| 71 const std::string& username, | 71 const std::string& username, |
| 72 const std::string& accountId, | |
| 72 const PolicyRegistrationCallback& callback) { | 73 const PolicyRegistrationCallback& callback) { |
| 73 RegisterForPolicyInternal(username, "", callback); | 74 RegisterForPolicyInternal(username, accountId, "", callback); |
| 74 } | 75 } |
| 75 | 76 |
| 76 #if !defined(OS_ANDROID) | 77 #if !defined(OS_ANDROID) |
| 77 void UserPolicySigninService::RegisterForPolicyWithAccessToken( | 78 void UserPolicySigninService::RegisterForPolicyWithAccessToken( |
| 78 const std::string& username, | 79 const std::string& username, |
| 79 const std::string& access_token, | 80 const std::string& access_token, |
| 80 const PolicyRegistrationCallback& callback) { | 81 const PolicyRegistrationCallback& callback) { |
| 81 RegisterForPolicyInternal(username, access_token, callback); | 82 RegisterForPolicyInternal(username, "", access_token, callback); |
|
Roger Tawa OOO till Jul 10th
2015/08/12 15:28:47
This won't work on non-android platforms. Since t
gogerald1
2015/08/13 18:12:12
This interface go with access_token, so we no need
| |
| 82 } | 83 } |
| 83 | 84 |
| 84 // static | 85 // static |
| 85 std::vector<std::string> UserPolicySigninService::GetScopes() { | 86 std::vector<std::string> UserPolicySigninService::GetScopes() { |
| 86 return CloudPolicyClientRegistrationHelper::GetScopes(); | 87 return CloudPolicyClientRegistrationHelper::GetScopes(); |
| 87 } | 88 } |
| 88 #endif | 89 #endif |
| 89 | 90 |
| 90 void UserPolicySigninService::RegisterForPolicyInternal( | 91 void UserPolicySigninService::RegisterForPolicyInternal( |
| 91 const std::string& username, | 92 const std::string& username, |
| 93 const std::string& accountId, | |
| 92 const std::string& access_token, | 94 const std::string& access_token, |
| 93 const PolicyRegistrationCallback& callback) { | 95 const PolicyRegistrationCallback& callback) { |
| 94 // Create a new CloudPolicyClient for fetching the DMToken. | 96 // Create a new CloudPolicyClient for fetching the DMToken. |
| 95 scoped_ptr<CloudPolicyClient> policy_client = CreateClientForRegistrationOnly( | 97 scoped_ptr<CloudPolicyClient> policy_client = CreateClientForRegistrationOnly( |
| 96 username); | 98 username); |
| 97 if (!policy_client) { | 99 if (!policy_client) { |
| 98 callback.Run(std::string(), std::string()); | 100 callback.Run(std::string(), std::string()); |
| 99 return; | 101 return; |
| 100 } | 102 } |
| 101 | 103 |
| 102 CancelPendingRegistration(); | 104 CancelPendingRegistration(); |
| 103 | 105 |
| 104 // Fire off the registration process. Callback keeps the CloudPolicyClient | 106 // Fire off the registration process. Callback keeps the CloudPolicyClient |
| 105 // alive for the length of the registration process. | 107 // alive for the length of the registration process. |
| 106 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( | 108 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( |
| 107 policy_client.get(), | 109 policy_client.get(), |
| 108 kCloudPolicyRegistrationType)); | 110 kCloudPolicyRegistrationType)); |
| 109 | 111 |
| 110 if (access_token.empty()) { | 112 if (access_token.empty()) { |
| 111 registration_helper_->StartRegistration( | 113 registration_helper_->StartRegistration( |
| 112 oauth2_token_service_, | 114 oauth2_token_service_, accountId, |
| 113 username, | |
| 114 base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback, | 115 base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback, |
| 115 base::Unretained(this), | 116 base::Unretained(this), base::Passed(&policy_client), |
| 116 base::Passed(&policy_client), | |
| 117 callback)); | 117 callback)); |
| 118 } else { | 118 } else { |
| 119 #if defined(OS_ANDROID) | 119 #if defined(OS_ANDROID) |
| 120 NOTREACHED(); | 120 NOTREACHED(); |
| 121 #else | 121 #else |
| 122 registration_helper_->StartRegistrationWithAccessToken( | 122 registration_helper_->StartRegistrationWithAccessToken( |
| 123 access_token, | 123 access_token, |
| 124 base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback, | 124 base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback, |
| 125 base::Unretained(this), | 125 base::Unretained(this), |
| 126 base::Passed(&policy_client), | 126 base::Passed(&policy_client), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 DCHECK(policy_manager()->core()->client()); | 196 DCHECK(policy_manager()->core()->client()); |
| 197 | 197 |
| 198 // Persist the current time as the last policy registration attempt time. | 198 // Persist the current time as the last policy registration attempt time. |
| 199 profile_prefs_->SetInt64(prefs::kLastPolicyCheckTime, | 199 profile_prefs_->SetInt64(prefs::kLastPolicyCheckTime, |
| 200 base::Time::Now().ToInternalValue()); | 200 base::Time::Now().ToInternalValue()); |
| 201 | 201 |
| 202 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( | 202 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( |
| 203 policy_manager()->core()->client(), | 203 policy_manager()->core()->client(), |
| 204 kCloudPolicyRegistrationType)); | 204 kCloudPolicyRegistrationType)); |
| 205 registration_helper_->StartRegistration( | 205 registration_helper_->StartRegistration( |
| 206 oauth2_token_service_, | 206 oauth2_token_service_, signin_manager()->GetAuthenticatedAccountId(), |
|
Roger Tawa OOO till Jul 10th
2015/08/12 15:28:47
Good catch.
gogerald1
2015/08/13 18:12:12
Done.
| |
| 207 signin_manager()->GetAuthenticatedUsername(), | |
| 208 base::Bind(&UserPolicySigninService::OnRegistrationDone, | 207 base::Bind(&UserPolicySigninService::OnRegistrationDone, |
| 209 base::Unretained(this))); | 208 base::Unretained(this))); |
| 210 } | 209 } |
| 211 | 210 |
| 212 void UserPolicySigninService::CancelPendingRegistration() { | 211 void UserPolicySigninService::CancelPendingRegistration() { |
| 213 weak_factory_.InvalidateWeakPtrs(); | 212 weak_factory_.InvalidateWeakPtrs(); |
| 214 } | 213 } |
| 215 | 214 |
| 216 void UserPolicySigninService::OnRegistrationDone() { | 215 void UserPolicySigninService::OnRegistrationDone() { |
| 217 registration_helper_.reset(); | 216 registration_helper_.reset(); |
| 218 } | 217 } |
| 219 | 218 |
| 220 } // namespace policy | 219 } // namespace policy |
| OLD | NEW |