OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/chromeos/policy/user_cloud_policy_token_forwarder.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder.h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 8 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
9 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 9 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 10 #include "chrome/browser/signin/signin_manager.h" |
10 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 11 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
11 #include "content/public/browser/notification_source.h" | 12 #include "content/public/browser/notification_source.h" |
12 #include "google_apis/gaia/gaia_constants.h" | 13 #include "google_apis/gaia/gaia_constants.h" |
13 #include "google_apis/gaia/gaia_urls.h" | 14 #include "google_apis/gaia/gaia_urls.h" |
14 | 15 |
15 namespace policy { | 16 namespace policy { |
16 | 17 |
17 UserCloudPolicyTokenForwarder::UserCloudPolicyTokenForwarder( | 18 UserCloudPolicyTokenForwarder::UserCloudPolicyTokenForwarder( |
18 UserCloudPolicyManagerChromeOS* manager, | 19 UserCloudPolicyManagerChromeOS* manager, |
19 ProfileOAuth2TokenService* token_service) | 20 ProfileOAuth2TokenService* token_service, |
| 21 SigninManagerBase* signin_manager) |
20 : OAuth2TokenService::Consumer("policy_token_forwarder"), | 22 : OAuth2TokenService::Consumer("policy_token_forwarder"), |
21 manager_(manager), | 23 manager_(manager), |
22 token_service_(token_service) { | 24 token_service_(token_service), |
| 25 signin_manager_(signin_manager) { |
23 // Start by waiting for the CloudPolicyService to be initialized, so that | 26 // Start by waiting for the CloudPolicyService to be initialized, so that |
24 // we can check if it already has a DMToken or not. | 27 // we can check if it already has a DMToken or not. |
25 if (manager_->core()->service()->IsInitializationComplete()) { | 28 if (manager_->core()->service()->IsInitializationComplete()) { |
26 Initialize(); | 29 Initialize(); |
27 } else { | 30 } else { |
28 manager_->core()->service()->AddObserver(this); | 31 manager_->core()->service()->AddObserver(this); |
29 } | 32 } |
30 } | 33 } |
31 | 34 |
32 UserCloudPolicyTokenForwarder::~UserCloudPolicyTokenForwarder() {} | 35 UserCloudPolicyTokenForwarder::~UserCloudPolicyTokenForwarder() {} |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 CloudPolicyService* service) { | 75 CloudPolicyService* service) { |
73 Initialize(); | 76 Initialize(); |
74 } | 77 } |
75 | 78 |
76 void UserCloudPolicyTokenForwarder::Initialize() { | 79 void UserCloudPolicyTokenForwarder::Initialize() { |
77 // TODO(mnissler): Once a better way to reconfirm whether a user is on the | 80 // TODO(mnissler): Once a better way to reconfirm whether a user is on the |
78 // login whitelist is available, there is no reason to fetch the OAuth2 token | 81 // login whitelist is available, there is no reason to fetch the OAuth2 token |
79 // here if the client is already registered, so check and bail out here. | 82 // here if the client is already registered, so check and bail out here. |
80 | 83 |
81 if (token_service_->RefreshTokenIsAvailable( | 84 if (token_service_->RefreshTokenIsAvailable( |
82 token_service_->GetPrimaryAccountId())) | 85 signin_manager_->GetAuthenticatedAccountId())) |
83 RequestAccessToken(); | 86 RequestAccessToken(); |
84 else | 87 else |
85 token_service_->AddObserver(this); | 88 token_service_->AddObserver(this); |
86 } | 89 } |
87 | 90 |
88 void UserCloudPolicyTokenForwarder::RequestAccessToken() { | 91 void UserCloudPolicyTokenForwarder::RequestAccessToken() { |
89 OAuth2TokenService::ScopeSet scopes; | 92 OAuth2TokenService::ScopeSet scopes; |
90 scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth); | 93 scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth); |
91 scopes.insert(GaiaUrls::GetInstance()->oauth_wrap_bridge_user_info_scope()); | 94 scopes.insert(GaiaUrls::GetInstance()->oauth_wrap_bridge_user_info_scope()); |
92 request_ = token_service_->StartRequest( | 95 request_ = token_service_->StartRequest( |
93 token_service_->GetPrimaryAccountId(), scopes, this); | 96 signin_manager_->GetAuthenticatedAccountId(), scopes, this); |
94 } | 97 } |
95 | 98 |
96 } // namespace policy | 99 } // namespace policy |
OLD | NEW |