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 "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 void UserPolicySigninService::OnRefreshTokenAvailable( | 105 void UserPolicySigninService::OnRefreshTokenAvailable( |
106 const std::string& account_id) { | 106 const std::string& account_id) { |
107 // If using a TestingProfile with no UserCloudPolicyManager, skip | 107 // If using a TestingProfile with no UserCloudPolicyManager, skip |
108 // initialization. | 108 // initialization. |
109 if (!GetManager()) { | 109 if (!GetManager()) { |
110 DVLOG(1) << "Skipping initialization for tests due to missing components."; | 110 DVLOG(1) << "Skipping initialization for tests due to missing components."; |
111 return; | 111 return; |
112 } | 112 } |
113 | 113 |
114 std::string username = GetSigninManager()->GetAuthenticatedUsername(); | 114 // Ignore OAuth tokens for any account but the primary one. |
115 // Should not have OAuth tokens if the user isn't signed in. | 115 if (account_id != oauth2_token_service_->GetPrimaryAccountId()) |
116 DCHECK(!username.empty()); | 116 return; |
| 117 |
117 // ProfileOAuth2TokenService now has a refresh token so initialize the | 118 // ProfileOAuth2TokenService now has a refresh token so initialize the |
118 // UserCloudPolicyManager. | 119 // UserCloudPolicyManager. |
119 InitializeForSignedInUser(username); | 120 InitializeForSignedInUser(GetSigninManager()->GetAuthenticatedUsername()); |
120 } | 121 } |
121 | 122 |
122 void UserPolicySigninService::InitializeUserCloudPolicyManager( | 123 void UserPolicySigninService::InitializeUserCloudPolicyManager( |
123 const std::string& username, | 124 const std::string& username, |
124 scoped_ptr<CloudPolicyClient> client) { | 125 scoped_ptr<CloudPolicyClient> client) { |
125 UserPolicySigninServiceBase::InitializeUserCloudPolicyManager(username, | 126 UserPolicySigninServiceBase::InitializeUserCloudPolicyManager(username, |
126 client.Pass()); | 127 client.Pass()); |
127 ProhibitSignoutIfNeeded(); | 128 ProhibitSignoutIfNeeded(); |
128 } | 129 } |
129 | 130 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 187 } |
187 | 188 |
188 void UserPolicySigninService::ProhibitSignoutIfNeeded() { | 189 void UserPolicySigninService::ProhibitSignoutIfNeeded() { |
189 if (GetManager()->IsClientRegistered()) { | 190 if (GetManager()->IsClientRegistered()) { |
190 DVLOG(1) << "User is registered for policy - prohibiting signout"; | 191 DVLOG(1) << "User is registered for policy - prohibiting signout"; |
191 GetSigninManager()->ProhibitSignout(true); | 192 GetSigninManager()->ProhibitSignout(true); |
192 } | 193 } |
193 } | 194 } |
194 | 195 |
195 } // namespace policy | 196 } // namespace policy |
OLD | NEW |