OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/policy/device_management_backend_impl.h" | 5 #include "chrome/browser/policy/device_management_backend_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 const char DeviceManagementBackendImpl::kValueRequestUnregister[] = | 27 const char DeviceManagementBackendImpl::kValueRequestUnregister[] = |
28 "unregister"; | 28 "unregister"; |
29 const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy"; | 29 const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy"; |
30 const char DeviceManagementBackendImpl::kValueDeviceType[] = "Chrome OS"; | 30 const char DeviceManagementBackendImpl::kValueDeviceType[] = "Chrome OS"; |
31 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome"; | 31 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome"; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const char kValueAgent[] = "%s enterprise management client version %s (%s)"; | 35 const char kValueAgent[] = "%s enterprise management client version %s (%s)"; |
36 | 36 |
37 const char kPostContentType[] = "application/octet-stream"; | 37 const char kPostContentType[] = "application/protobuf"; |
38 | 38 |
39 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth="; | 39 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth="; |
40 const char kDMTokenAuthHeader[] = "Authorization: GoogleDMToken token="; | 40 const char kDMTokenAuthHeader[] = "Authorization: GoogleDMToken token="; |
41 | 41 |
42 // Helper class for URL query parameter encoding/decoding. | 42 // Helper class for URL query parameter encoding/decoding. |
43 class URLQueryParameters { | 43 class URLQueryParameters { |
44 public: | 44 public: |
45 URLQueryParameters() {} | 45 URLQueryParameters() {} |
46 | 46 |
47 // Add a query parameter. | 47 // Add a query parameter. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 em::DeviceManagementResponse response; | 176 em::DeviceManagementResponse response; |
177 if (!response.ParseFromString(data)) { | 177 if (!response.ParseFromString(data)) { |
178 OnError(DeviceManagementBackend::kErrorResponseDecoding); | 178 OnError(DeviceManagementBackend::kErrorResponseDecoding); |
179 return; | 179 return; |
180 } | 180 } |
181 | 181 |
182 // Check service error code. | 182 // Check service error code. |
183 switch (response.error()) { | 183 switch (response.error()) { |
184 case em::DeviceManagementResponse::SUCCESS: | 184 case em::DeviceManagementResponse::SUCCESS: |
185 break; | 185 OnResponse(response); |
| 186 return; |
186 case em::DeviceManagementResponse::DEVICE_MANAGEMENT_NOT_SUPPORTED: | 187 case em::DeviceManagementResponse::DEVICE_MANAGEMENT_NOT_SUPPORTED: |
187 OnError(DeviceManagementBackend::kErrorServiceManagementNotSupported); | 188 OnError(DeviceManagementBackend::kErrorServiceManagementNotSupported); |
188 return; | 189 return; |
189 case em::DeviceManagementResponse::DEVICE_NOT_FOUND: | 190 case em::DeviceManagementResponse::DEVICE_NOT_FOUND: |
190 OnError(DeviceManagementBackend::kErrorServiceDeviceNotFound); | 191 OnError(DeviceManagementBackend::kErrorServiceDeviceNotFound); |
191 return; | 192 return; |
192 case em::DeviceManagementResponse::DEVICE_MANAGEMENT_TOKEN_INVALID: | 193 case em::DeviceManagementResponse::DEVICE_MANAGEMENT_TOKEN_INVALID: |
193 OnError(DeviceManagementBackend::kErrorServiceManagementTokenInvalid); | 194 OnError(DeviceManagementBackend::kErrorServiceManagementTokenInvalid); |
194 return; | 195 return; |
195 case em::DeviceManagementResponse::ACTIVATION_PENDING: | 196 case em::DeviceManagementResponse::ACTIVATION_PENDING: |
196 OnError(DeviceManagementBackend::kErrorServiceActivationPending); | 197 OnError(DeviceManagementBackend::kErrorServiceActivationPending); |
197 return; | 198 return; |
198 default: | 199 case em::DeviceManagementResponse::POLICY_NOT_FOUND: |
199 // This should be caught by the protobuf decoder. | 200 OnError(DeviceManagementBackend::kErrorServicePolicyNotFound); |
200 NOTREACHED(); | |
201 OnError(DeviceManagementBackend::kErrorResponseDecoding); | |
202 return; | 201 return; |
203 } | 202 } |
204 | 203 |
205 OnResponse(response); | 204 // This should be caught by the protobuf decoder. |
| 205 NOTREACHED(); |
| 206 OnError(DeviceManagementBackend::kErrorResponseDecoding); |
206 } | 207 } |
207 | 208 |
208 GURL DeviceManagementJobBase::GetURL( | 209 GURL DeviceManagementJobBase::GetURL( |
209 const std::string& server_url) { | 210 const std::string& server_url) { |
210 return GURL(server_url + '?' + query_params_.Encode()); | 211 return GURL(server_url + '?' + query_params_.Encode()); |
211 } | 212 } |
212 | 213 |
213 void DeviceManagementJobBase::ConfigureRequest(URLFetcher* fetcher) { | 214 void DeviceManagementJobBase::ConfigureRequest(URLFetcher* fetcher) { |
214 fetcher->set_upload_data(kPostContentType, payload_); | 215 fetcher->set_upload_data(kPostContentType, payload_); |
215 std::string extra_headers; | 216 std::string extra_headers; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 void DeviceManagementBackendImpl::ProcessPolicyRequest( | 402 void DeviceManagementBackendImpl::ProcessPolicyRequest( |
402 const std::string& device_management_token, | 403 const std::string& device_management_token, |
403 const std::string& device_id, | 404 const std::string& device_id, |
404 const em::DevicePolicyRequest& request, | 405 const em::DevicePolicyRequest& request, |
405 DevicePolicyResponseDelegate* delegate) { | 406 DevicePolicyResponseDelegate* delegate) { |
406 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id, | 407 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id, |
407 request, delegate)); | 408 request, delegate)); |
408 } | 409 } |
409 | 410 |
410 } // namespace policy | 411 } // namespace policy |
OLD | NEW |