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

Side by Side Diff: chrome/browser/policy/device_management_backend_impl.cc

Issue 9066005: Remove all old-style DeviceManagementService legacy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 11 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/policy/device_management_backend_impl.h"
6
7 #include "base/bind.h"
8 #include "base/metrics/histogram.h"
9 #include "base/stl_util.h"
10 #include "chrome/browser/policy/device_management_service.h"
11 #include "chrome/browser/policy/enterprise_metrics.h"
12
13 namespace em = enterprise_management;
14
15 namespace policy {
16
17 namespace {
18
19 // CloudPolicyDataStore::DeviceManagement is being phased out; for now we
20 // convert here to support legacy code.
21 DeviceManagementBackend::ErrorCode ConvertStatus(
22 DeviceManagementStatus status) {
23 switch (status) {
24 case DM_STATUS_SUCCESS:
25 NOTREACHED();
26 return DeviceManagementBackend::kErrorRequestFailed;
27 case DM_STATUS_REQUEST_INVALID:
28 return DeviceManagementBackend::kErrorRequestInvalid;
29 case DM_STATUS_REQUEST_FAILED:
30 return DeviceManagementBackend::kErrorRequestFailed;
31 case DM_STATUS_TEMPORARY_UNAVAILABLE:
32 return DeviceManagementBackend::kErrorTemporaryUnavailable;
33 case DM_STATUS_HTTP_STATUS_ERROR:
34 return DeviceManagementBackend::kErrorHttpStatus;
35 case DM_STATUS_RESPONSE_DECODING_ERROR:
36 return DeviceManagementBackend::kErrorResponseDecoding;
37 case DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED:
38 return DeviceManagementBackend::kErrorServiceManagementNotSupported;
39 case DM_STATUS_SERVICE_DEVICE_NOT_FOUND:
40 return DeviceManagementBackend::kErrorServiceDeviceNotFound;
41 case DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID:
42 return DeviceManagementBackend::kErrorServiceManagementTokenInvalid;
43 case DM_STATUS_SERVICE_ACTIVATION_PENDING:
44 return DeviceManagementBackend::kErrorServiceActivationPending;
45 case DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER:
46 return DeviceManagementBackend::kErrorServiceInvalidSerialNumber;
47 case DM_STATUS_SERVICE_DEVICE_ID_CONFLICT:
48 return DeviceManagementBackend::kErrorServiceDeviceIdConflict;
49 case DM_STATUS_SERVICE_POLICY_NOT_FOUND:
50 return DeviceManagementBackend::kErrorServicePolicyNotFound;
51 }
52
53 NOTREACHED();
54 return DeviceManagementBackend::kErrorRequestFailed;
55 }
56
57 // Conversion helper to support legacy code.
58 UserAffiliation ConvertAffiliation(
59 CloudPolicyDataStore::UserAffiliation affiliation) {
60 switch (affiliation) {
61 case CloudPolicyDataStore::USER_AFFILIATION_MANAGED:
62 return USER_AFFILIATION_MANAGED;
63 case CloudPolicyDataStore::USER_AFFILIATION_NONE:
64 return USER_AFFILIATION_NONE;
65 }
66
67 NOTREACHED();
68 return USER_AFFILIATION_NONE;
69 }
70
71 } // namespace
72
73 DeviceManagementBackendImpl::DeviceManagementBackendImpl(
74 DeviceManagementService* service)
75 : service_(service) {
76 }
77
78 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() {
79 STLDeleteElements(&pending_jobs_);
80 }
81
82 void DeviceManagementBackendImpl::ProcessRegisterRequest(
83 const std::string& gaia_auth_token,
84 const std::string& oauth_token,
85 const std::string& device_id,
86 const em::DeviceRegisterRequest& request,
87 DeviceRegisterResponseDelegate* delegate) {
88 UMA_HISTOGRAM_ENUMERATION(kMetricToken, kMetricTokenFetchRequested,
89 kMetricTokenSize);
90 DeviceManagementRequestJob* job =
91 service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION);
92 job->SetGaiaToken(gaia_auth_token);
93 job->SetOAuthToken(oauth_token);
94 job->SetClientID(device_id);
95 job->GetRequest()->mutable_register_request()->CopyFrom(request);
96 job->Start(base::Bind(&DeviceManagementBackendImpl::OnRegistrationDone,
97 base::Unretained(this), job, delegate));
98 pending_jobs_.insert(job);
99 }
100
101 void DeviceManagementBackendImpl::ProcessUnregisterRequest(
102 const std::string& device_management_token,
103 const std::string& device_id,
104 const em::DeviceUnregisterRequest& request,
105 DeviceUnregisterResponseDelegate* delegate) {
106 DeviceManagementRequestJob* job =
107 service_->CreateJob(DeviceManagementRequestJob::TYPE_UNREGISTRATION);
108 job->SetDMToken(device_management_token);
109 job->SetClientID(device_id);
110 job->GetRequest()->mutable_unregister_request();
111 job->Start(base::Bind(&DeviceManagementBackendImpl::OnUnregistrationDone,
112 base::Unretained(this), job, delegate));
113 pending_jobs_.insert(job);
114 }
115
116 void DeviceManagementBackendImpl::ProcessPolicyRequest(
117 const std::string& device_management_token,
118 const std::string& device_id,
119 CloudPolicyDataStore::UserAffiliation affiliation,
120 const em::DevicePolicyRequest& request,
121 const em::DeviceStatusReportRequest* device_status,
122 DevicePolicyResponseDelegate* delegate) {
123 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchRequested,
124 kMetricPolicySize);
125 DeviceManagementRequestJob* job =
126 service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH);
127 job->SetDMToken(device_management_token);
128 job->SetClientID(device_id);
129 job->SetUserAffiliation(ConvertAffiliation(affiliation));
130 job->GetRequest()->mutable_policy_request()->CopyFrom(request);
131 if (device_status) {
132 job->GetRequest()->mutable_device_status_report_request()->CopyFrom(
133 *device_status);
134 }
135 job->Start(base::Bind(&DeviceManagementBackendImpl::OnPolicyFetchDone,
136 base::Unretained(this), job, delegate));
137 pending_jobs_.insert(job);
138 }
139
140 void DeviceManagementBackendImpl::ProcessAutoEnrollmentRequest(
141 const std::string& device_id,
142 const em::DeviceAutoEnrollmentRequest& request,
143 DeviceAutoEnrollmentResponseDelegate* delegate) {
144 DeviceManagementRequestJob* job =
145 service_->CreateJob(DeviceManagementRequestJob::TYPE_AUTO_ENROLLMENT);
146 job->SetClientID(device_id);
147 job->GetRequest()->mutable_auto_enrollment_request()->CopyFrom(request);
148 job->Start(base::Bind(&DeviceManagementBackendImpl::OnAutoEnrollmentDone,
149 base::Unretained(this), job, delegate));
150 pending_jobs_.insert(job);
151 }
152
153 void DeviceManagementBackendImpl::OnRegistrationDone(
154 DeviceManagementRequestJob* job,
155 DeviceRegisterResponseDelegate* delegate,
156 DeviceManagementStatus status,
157 const enterprise_management::DeviceManagementResponse& response) {
158 pending_jobs_.erase(job);
159 if (status == DM_STATUS_SUCCESS)
160 delegate->HandleRegisterResponse(response.register_response());
161 else
162 delegate->OnError(ConvertStatus(status));
163 delete job;
164 }
165
166 void DeviceManagementBackendImpl::OnUnregistrationDone(
167 DeviceManagementRequestJob* job,
168 DeviceUnregisterResponseDelegate* delegate,
169 DeviceManagementStatus status,
170 const enterprise_management::DeviceManagementResponse& response) {
171 pending_jobs_.erase(job);
172 if (status == DM_STATUS_SUCCESS)
173 delegate->HandleUnregisterResponse(response.unregister_response());
174 else
175 delegate->OnError(ConvertStatus(status));
176 delete job;
177 }
178
179 void DeviceManagementBackendImpl::OnPolicyFetchDone(
180 DeviceManagementRequestJob* job,
181 DevicePolicyResponseDelegate* delegate,
182 DeviceManagementStatus status,
183 const enterprise_management::DeviceManagementResponse& response) {
184 pending_jobs_.erase(job);
185 if (status == DM_STATUS_SUCCESS)
186 delegate->HandlePolicyResponse(response.policy_response());
187 else
188 delegate->OnError(ConvertStatus(status));
189 delete job;
190 }
191
192 void DeviceManagementBackendImpl::OnAutoEnrollmentDone(
193 DeviceManagementRequestJob* job,
194 DeviceAutoEnrollmentResponseDelegate* delegate,
195 DeviceManagementStatus status,
196 const enterprise_management::DeviceManagementResponse& response) {
197 pending_jobs_.erase(job);
198 if (status == DM_STATUS_SUCCESS)
199 delegate->HandleAutoEnrollmentResponse(response.auto_enrollment_response());
200 else
201 delegate->OnError(ConvertStatus(status));
202 delete job;
203 }
204
205 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_management_backend_impl.h ('k') | chrome/browser/policy/device_management_backend_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698