OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/policy/android_management_client.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" |
| 10 #include "components/policy/core/common/cloud/device_management_service.h" |
| 11 #include "policy/proto/device_management_backend.pb.h" |
| 12 |
| 13 namespace em = enterprise_management; |
| 14 |
| 15 namespace policy { |
| 16 |
| 17 AndroidManagementClient::AndroidManagementClient( |
| 18 DeviceManagementService* service, |
| 19 scoped_refptr<net::URLRequestContextGetter> request_context) |
| 20 : service_(service), request_context_(request_context) {} |
| 21 |
| 22 AndroidManagementClient::~AndroidManagementClient() {} |
| 23 |
| 24 void AndroidManagementClient::CheckAndroidManagement( |
| 25 const std::string& auth_token, |
| 26 const StatusCallback& callback) { |
| 27 DCHECK(service_); |
| 28 DCHECK(!auth_token.empty()); |
| 29 |
| 30 request_job_.reset(service_->CreateJob( |
| 31 DeviceManagementRequestJob::TYPE_ANDROID_MANAGEMENT_CHECK, |
| 32 request_context_.get())); |
| 33 request_job_->SetGaiaToken(auth_token); |
| 34 request_job_->GetRequest()->mutable_check_android_management_request(); |
| 35 |
| 36 request_job_->Start( |
| 37 base::Bind(&AndroidManagementClient::OnAndroidManagementChecked, |
| 38 base::Unretained(this), callback)); |
| 39 } |
| 40 |
| 41 void AndroidManagementClient::OnAndroidManagementChecked( |
| 42 const StatusCallback& callback, |
| 43 DeviceManagementStatus status, |
| 44 int net_error, |
| 45 const em::DeviceManagementResponse& response) { |
| 46 if (status == DM_STATUS_SUCCESS && |
| 47 !response.has_check_android_management_response()) { |
| 48 LOG(WARNING) << "Invalid check android management response."; |
| 49 status = DM_STATUS_RESPONSE_DECODING_ERROR; |
| 50 } |
| 51 |
| 52 Result result; |
| 53 switch (status) { |
| 54 case DM_STATUS_SUCCESS: |
| 55 result = RESULT_UNMANAGED; |
| 56 break; |
| 57 case DM_STATUS_SERVICE_DEVICE_ID_CONFLICT: |
| 58 result = RESULT_MANAGED; |
| 59 break; |
| 60 default: |
| 61 result = RESULT_ERROR; |
| 62 } |
| 63 |
| 64 callback.Run(result); |
| 65 request_job_.reset(); |
| 66 } |
| 67 |
| 68 } // namespace policy |
OLD | NEW |