| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/arc/auth/arc_robot_auth.h" | 5 #include "chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher.h" |
| 6 |
| 7 #include <string> |
| 6 | 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 11 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 10 #include "components/policy/core/common/cloud/device_management_service.h" | 12 #include "components/policy/core/common/cloud/device_management_service.h" |
| 11 #include "google_apis/gaia/gaia_constants.h" | 13 #include "google_apis/gaia/gaia_constants.h" |
| 12 #include "google_apis/gaia/gaia_urls.h" | 14 #include "google_apis/gaia/gaia_urls.h" |
| 13 #include "net/url_request/url_request_context_getter.h" | 15 #include "net/url_request/url_request_context_getter.h" |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 29 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 31 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 30 const policy::DeviceCloudPolicyManagerChromeOS* policy_manager = | 32 const policy::DeviceCloudPolicyManagerChromeOS* policy_manager = |
| 31 connector->GetDeviceCloudPolicyManager(); | 33 connector->GetDeviceCloudPolicyManager(); |
| 32 return policy_manager->core()->client(); | 34 return policy_manager->core()->client(); |
| 33 } | 35 } |
| 34 | 36 |
| 35 } // namespace | 37 } // namespace |
| 36 | 38 |
| 37 namespace arc { | 39 namespace arc { |
| 38 | 40 |
| 39 ArcRobotAuth::ArcRobotAuth() : weak_ptr_factory_(this) {} | 41 ArcRobotAuthCodeFetcher::ArcRobotAuthCodeFetcher() : weak_ptr_factory_(this) {} |
| 40 | 42 |
| 41 ArcRobotAuth::~ArcRobotAuth() = default; | 43 ArcRobotAuthCodeFetcher::~ArcRobotAuthCodeFetcher() = default; |
| 42 | 44 |
| 43 void ArcRobotAuth::FetchRobotAuthCode(const RobotAuthCodeCallback& callback) { | 45 void ArcRobotAuthCodeFetcher::Fetch(const FetchCallback& callback) { |
| 44 DCHECK(!fetch_request_job_); | 46 DCHECK(!fetch_request_job_); |
| 45 const policy::CloudPolicyClient* client = GetCloudPolicyClient(); | 47 const policy::CloudPolicyClient* client = GetCloudPolicyClient(); |
| 46 | 48 |
| 47 policy::DeviceManagementService* service = GetDeviceManagementService(); | 49 policy::DeviceManagementService* service = GetDeviceManagementService(); |
| 48 fetch_request_job_.reset(service->CreateJob( | 50 fetch_request_job_.reset(service->CreateJob( |
| 49 policy::DeviceManagementRequestJob::TYPE_API_AUTH_CODE_FETCH, | 51 policy::DeviceManagementRequestJob::TYPE_API_AUTH_CODE_FETCH, |
| 50 g_browser_process->system_request_context())); | 52 g_browser_process->system_request_context())); |
| 51 | 53 |
| 52 fetch_request_job_->SetDMToken(client->dm_token()); | 54 fetch_request_job_->SetDMToken(client->dm_token()); |
| 53 fetch_request_job_->SetClientID(client->client_id()); | 55 fetch_request_job_->SetClientID(client->client_id()); |
| 54 | 56 |
| 55 enterprise_management::DeviceServiceApiAccessRequest* request = | 57 enterprise_management::DeviceServiceApiAccessRequest* request = |
| 56 fetch_request_job_->GetRequest()->mutable_service_api_access_request(); | 58 fetch_request_job_->GetRequest()->mutable_service_api_access_request(); |
| 57 request->set_oauth2_client_id(kAndoidClientId); | 59 request->set_oauth2_client_id(kAndoidClientId); |
| 58 request->add_auth_scope(GaiaConstants::kAnyApiOAuth2Scope); | 60 request->add_auth_scope(GaiaConstants::kAnyApiOAuth2Scope); |
| 59 | 61 |
| 60 fetch_request_job_->Start( | 62 fetch_request_job_->Start( |
| 61 base::Bind(&ArcRobotAuth::OnFetchRobotAuthCodeCompleted, | 63 base::Bind(&ArcRobotAuthCodeFetcher::OnFetchRobotAuthCodeCompleted, |
| 62 weak_ptr_factory_.GetWeakPtr(), callback)); | 64 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 63 } | 65 } |
| 64 | 66 |
| 65 void ArcRobotAuth::OnFetchRobotAuthCodeCompleted( | 67 void ArcRobotAuthCodeFetcher::OnFetchRobotAuthCodeCompleted( |
| 66 RobotAuthCodeCallback callback, | 68 FetchCallback callback, |
| 67 policy::DeviceManagementStatus status, | 69 policy::DeviceManagementStatus status, |
| 68 int net_error, | 70 int net_error, |
| 69 const enterprise_management::DeviceManagementResponse& response) { | 71 const enterprise_management::DeviceManagementResponse& response) { |
| 70 fetch_request_job_.reset(); | 72 fetch_request_job_.reset(); |
| 71 | 73 |
| 72 if (status == policy::DM_STATUS_SUCCESS && | 74 if (status == policy::DM_STATUS_SUCCESS && |
| 73 (!response.has_service_api_access_response())) { | 75 (!response.has_service_api_access_response())) { |
| 74 LOG(WARNING) << "Invalid service api access response."; | 76 LOG(WARNING) << "Invalid service api access response."; |
| 75 status = policy::DM_STATUS_RESPONSE_DECODING_ERROR; | 77 status = policy::DM_STATUS_RESPONSE_DECODING_ERROR; |
| 76 } | 78 } |
| 77 | 79 |
| 78 if (status != policy::DM_STATUS_SUCCESS) { | 80 if (status != policy::DM_STATUS_SUCCESS) { |
| 79 LOG(ERROR) << "Fetching of robot auth code failed. DM Status: " << status; | 81 LOG(ERROR) << "Fetching of robot auth code failed. DM Status: " << status; |
| 80 callback.Run(std::string()); | 82 callback.Run(std::string()); |
| 81 return; | 83 return; |
| 82 } | 84 } |
| 83 | 85 |
| 84 callback.Run(response.service_api_access_response().auth_code()); | 86 callback.Run(response.service_api_access_response().auth_code()); |
| 85 } | 87 } |
| 86 | 88 |
| 87 } // namespace arc | 89 } // namespace arc |
| OLD | NEW |