Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: chrome/browser/chromeos/policy/android_management_client.cc

Issue 2446563002: Refactor ArcAndroidManagementChecker. (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/arc/policy/arc_android_management_checker_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 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 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/android_management_client.h" 5 #include "chrome/browser/chromeos/policy/android_management_client.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_helpers.h"
9 #include "base/guid.h" 10 #include "base/guid.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "components/policy/core/common/cloud/device_management_service.h" 12 #include "components/policy/core/common/cloud/device_management_service.h"
12 #include "components/policy/proto/device_management_backend.pb.h" 13 #include "components/policy/proto/device_management_backend.pb.h"
13 #include "google_apis/gaia/gaia_constants.h" 14 #include "google_apis/gaia/gaia_constants.h"
14 #include "google_apis/gaia/google_service_auth_error.h" 15 #include "google_apis/gaia/google_service_auth_error.h"
15 16
16 namespace em = enterprise_management; 17 namespace em = enterprise_management;
17 18
18 namespace policy { 19 namespace policy {
(...skipping 28 matching lines...) Expand all
47 DCHECK_EQ(token_request_.get(), request); 48 DCHECK_EQ(token_request_.get(), request);
48 token_request_.reset(); 49 token_request_.reset();
49 50
50 CheckAndroidManagement(access_token); 51 CheckAndroidManagement(access_token);
51 } 52 }
52 53
53 void AndroidManagementClient::OnGetTokenFailure( 54 void AndroidManagementClient::OnGetTokenFailure(
54 const OAuth2TokenService::Request* request, 55 const OAuth2TokenService::Request* request,
55 const GoogleServiceAuthError& error) { 56 const GoogleServiceAuthError& error) {
56 DCHECK_EQ(token_request_.get(), request); 57 DCHECK_EQ(token_request_.get(), request);
58 DCHECK(!callback_.is_null());
57 token_request_.reset(); 59 token_request_.reset();
58 LOG(ERROR) << "Token request failed: " << error.ToString(); 60 LOG(ERROR) << "Token request failed: " << error.ToString();
59 61
60 callback_.Run(RESULT_ERROR); 62 base::ResetAndReturn(&callback_).Run(RESULT_ERROR);
61 callback_.Reset();
62 } 63 }
63 64
64 void AndroidManagementClient::RequestAccessToken() { 65 void AndroidManagementClient::RequestAccessToken() {
65 DCHECK(!token_request_); 66 DCHECK(!token_request_);
66 // The user must be signed in already. 67 // The user must be signed in already.
67 DCHECK(token_service_->RefreshTokenIsAvailable(account_id_)); 68 DCHECK(token_service_->RefreshTokenIsAvailable(account_id_));
68 69
69 OAuth2TokenService::ScopeSet scopes; 70 OAuth2TokenService::ScopeSet scopes;
70 scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth); 71 scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth);
71 scopes.insert(GaiaConstants::kOAuthWrapBridgeUserInfoScope); 72 scopes.insert(GaiaConstants::kOAuthWrapBridgeUserInfoScope);
(...skipping 11 matching lines...) Expand all
83 84
84 request_job_->Start( 85 request_job_->Start(
85 base::Bind(&AndroidManagementClient::OnAndroidManagementChecked, 86 base::Bind(&AndroidManagementClient::OnAndroidManagementChecked,
86 weak_ptr_factory_.GetWeakPtr())); 87 weak_ptr_factory_.GetWeakPtr()));
87 } 88 }
88 89
89 void AndroidManagementClient::OnAndroidManagementChecked( 90 void AndroidManagementClient::OnAndroidManagementChecked(
90 DeviceManagementStatus status, 91 DeviceManagementStatus status,
91 int net_error, 92 int net_error,
92 const em::DeviceManagementResponse& response) { 93 const em::DeviceManagementResponse& response) {
94 DCHECK(!callback_.is_null());
93 if (status == DM_STATUS_SUCCESS && 95 if (status == DM_STATUS_SUCCESS &&
94 !response.has_check_android_management_response()) { 96 !response.has_check_android_management_response()) {
95 LOG(WARNING) << "Invalid check android management response."; 97 LOG(WARNING) << "Invalid check android management response.";
96 status = DM_STATUS_RESPONSE_DECODING_ERROR; 98 status = DM_STATUS_RESPONSE_DECODING_ERROR;
97 } 99 }
98 100
99 Result result; 101 Result result;
100 switch (status) { 102 switch (status) {
101 case DM_STATUS_SUCCESS: 103 case DM_STATUS_SUCCESS:
102 result = RESULT_UNMANAGED; 104 result = RESULT_UNMANAGED;
103 break; 105 break;
104 case DM_STATUS_SERVICE_DEVICE_ID_CONFLICT: 106 case DM_STATUS_SERVICE_DEVICE_ID_CONFLICT:
105 result = RESULT_MANAGED; 107 result = RESULT_MANAGED;
106 break; 108 break;
107 default: 109 default:
108 result = RESULT_ERROR; 110 result = RESULT_ERROR;
109 } 111 }
110 112
111 request_job_.reset(); 113 request_job_.reset();
112 callback_.Run(result); 114 base::ResetAndReturn(&callback_).Run(result);
113 callback_.Reset();
114 } 115 }
115 116
116 } // namespace policy 117 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/policy/arc_android_management_checker_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698