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

Unified Diff: chrome/browser/policy/cloud_policy_controller.cc

Issue 9064006: Convert DeviceTokenFetcher and CloudPolicyController response callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits Created 8 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/cloud_policy_controller.cc
diff --git a/chrome/browser/policy/cloud_policy_controller.cc b/chrome/browser/policy/cloud_policy_controller.cc
index 3d3d8ccdd15022b393e1604521ec417a88984165..6f58a6d4ebb0f3794d5720d40925de102851dae6 100644
--- a/chrome/browser/policy/cloud_policy_controller.cc
+++ b/chrome/browser/policy/cloud_policy_controller.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,13 +14,13 @@
#include "base/string_util.h"
#include "base/time.h"
#include "chrome/browser/policy/cloud_policy_cache_base.h"
+#include "chrome/browser/policy/cloud_policy_constants.h"
#include "chrome/browser/policy/cloud_policy_subsystem.h"
#include "chrome/browser/policy/delayed_work_scheduler.h"
#include "chrome/browser/policy/device_management_service.h"
#include "chrome/browser/policy/device_token_fetcher.h"
#include "chrome/browser/policy/enterprise_metrics.h"
#include "chrome/browser/policy/policy_notifier.h"
-#include "chrome/browser/policy/proto/device_management_constants.h"
#include "chrome/common/guid.h"
namespace {
@@ -123,71 +123,76 @@ void CloudPolicyController::RefreshPolicies() {
}
}
-void CloudPolicyController::HandlePolicyResponse(
- const em::DevicePolicyResponse& response) {
- if (response.response_size() > 0) {
- if (response.response_size() > 1) {
- LOG(WARNING) << "More than one policy in the response of the device "
- << "management server, discarding.";
- }
- if (!response.response(0).has_error_code() ||
- response.response(0).error_code() ==
- DeviceManagementBackend::kPolicyFetchSuccess) {
- cache_->SetPolicy(response.response(0));
- SetState(STATE_POLICY_VALID);
- } else {
- UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadResponse,
- kMetricPolicySize);
- SetState(STATE_POLICY_UNAVAILABLE);
- }
- } else {
- UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadResponse,
- kMetricPolicySize);
- SetState(STATE_POLICY_UNAVAILABLE);
+void CloudPolicyController::OnPolicyFetchCompleted(
+ DeviceManagementStatus status,
+ const em::DeviceManagementResponse& response) {
+ if (status == DM_STATUS_SUCCESS && !response.has_policy_response()) {
+ // Handled below.
+ status = DM_STATUS_RESPONSE_DECODING_ERROR;
}
-}
-void CloudPolicyController::OnError(DeviceManagementBackend::ErrorCode code) {
- switch (code) {
- case DeviceManagementBackend::kErrorServiceDeviceNotFound:
- case DeviceManagementBackend::kErrorServiceDeviceIdConflict:
- case DeviceManagementBackend::kErrorServiceManagementTokenInvalid: {
+ switch (status) {
+ case DM_STATUS_SUCCESS: {
+ const em::DevicePolicyResponse& policy_response(
+ response.policy_response());
+ if (policy_response.response_size() > 0) {
+ if (policy_response.response_size() > 1) {
+ LOG(WARNING) << "More than one policy in the response of the device "
+ << "management server, discarding.";
+ }
+ const em::PolicyFetchResponse& fetch_response(
+ policy_response.response(0));
+ if (!fetch_response.has_error_code() ||
+ fetch_response.error_code() == dm_protocol::POLICY_FETCH_SUCCESS) {
+ cache_->SetPolicy(fetch_response);
+ SetState(STATE_POLICY_VALID);
+ } else {
+ UMA_HISTOGRAM_ENUMERATION(kMetricPolicy,
+ kMetricPolicyFetchBadResponse,
+ kMetricPolicySize);
+ SetState(STATE_POLICY_UNAVAILABLE);
+ }
+ } else {
+ UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchBadResponse,
+ kMetricPolicySize);
+ SetState(STATE_POLICY_UNAVAILABLE);
+ }
+ return;
+ }
+ case DM_STATUS_SERVICE_DEVICE_NOT_FOUND:
+ case DM_STATUS_SERVICE_DEVICE_ID_CONFLICT:
+ case DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID:
LOG(WARNING) << "The device token was either invalid or unknown to the "
<< "device manager, re-registering device.";
// Will retry fetching a token but gracefully backing off.
SetState(STATE_TOKEN_ERROR);
return;
- }
- case DeviceManagementBackend::kErrorServiceInvalidSerialNumber: {
+ case DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER:
VLOG(1) << "The device is no longer enlisted for the domain.";
token_fetcher_->SetSerialNumberInvalidState();
SetState(STATE_TOKEN_ERROR);
return;
- }
- case DeviceManagementBackend::kErrorServiceManagementNotSupported: {
+ case DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED:
VLOG(1) << "The device is no longer managed.";
token_fetcher_->SetUnmanagedState();
SetState(STATE_TOKEN_UNMANAGED);
return;
- }
- case DeviceManagementBackend::kErrorServicePolicyNotFound:
- case DeviceManagementBackend::kErrorRequestInvalid:
- case DeviceManagementBackend::kErrorServiceActivationPending:
- case DeviceManagementBackend::kErrorResponseDecoding:
- case DeviceManagementBackend::kErrorHttpStatus: {
+ case DM_STATUS_SERVICE_POLICY_NOT_FOUND:
+ case DM_STATUS_REQUEST_INVALID:
+ case DM_STATUS_SERVICE_ACTIVATION_PENDING:
+ case DM_STATUS_RESPONSE_DECODING_ERROR:
+ case DM_STATUS_HTTP_STATUS_ERROR:
VLOG(1) << "An error in the communication with the policy server occurred"
<< ", will retry in a few hours.";
SetState(STATE_POLICY_UNAVAILABLE);
return;
- }
- case DeviceManagementBackend::kErrorRequestFailed:
- case DeviceManagementBackend::kErrorTemporaryUnavailable: {
+ case DM_STATUS_REQUEST_FAILED:
+ case DM_STATUS_TEMPORARY_UNAVAILABLE:
VLOG(1) << "A temporary error in the communication with the policy server"
<< " occurred.";
// Will retry last operation but gracefully backing off.
SetState(STATE_POLICY_ERROR);
return;
- }
}
NOTREACHED();
@@ -279,10 +284,16 @@ void CloudPolicyController::FetchToken() {
}
void CloudPolicyController::SendPolicyRequest() {
- backend_.reset(service_->CreateBackend());
DCHECK(!data_store_->device_token().empty());
- em::DevicePolicyRequest policy_request;
- em::PolicyFetchRequest* fetch_request = policy_request.add_request();
+ request_job_.reset(
+ service_->CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH));
+ request_job_->SetDMToken(data_store_->device_token());
+ request_job_->SetClientID(data_store_->device_id());
+ request_job_->SetUserAffiliation(data_store_->user_affiliation());
+
+ em::DeviceManagementRequest* request = request_job_->GetRequest();
+ em::PolicyFetchRequest* fetch_request =
+ request->mutable_policy_request()->add_request();
em::DeviceStatusReportRequest device_status;
fetch_request->set_signature_type(em::PolicyFetchRequest::SHA1_RSA);
fetch_request->set_policy_type(data_store_->policy_type());
@@ -299,14 +310,14 @@ void CloudPolicyController::SendPolicyRequest() {
fetch_request->set_public_key_version(key_version);
#if defined(OS_CHROMEOS)
- if (data_store_->device_status_collector())
- data_store_->device_status_collector()->GetStatus(&device_status);
+ if (data_store_->device_status_collector()) {
+ data_store_->device_status_collector()->GetStatus(
+ request->mutable_device_status_report_request());
+ }
#endif
- backend_->ProcessPolicyRequest(data_store_->device_token(),
- data_store_->device_id(),
- data_store_->user_affiliation(),
- policy_request, &device_status, this);
+ request_job_->Start(base::Bind(&CloudPolicyController::OnPolicyFetchCompleted,
+ base::Unretained(this)));
}
void CloudPolicyController::DoWork() {
@@ -332,7 +343,7 @@ void CloudPolicyController::SetState(
CloudPolicyController::ControllerState new_state) {
state_ = new_state;
- backend_.reset(); // Stop any pending requests.
+ request_job_.reset(); // Stop any pending requests.
base::Time now(base::Time::NowFromSystemTime());
base::Time refresh_at;
« no previous file with comments | « chrome/browser/policy/cloud_policy_controller.h ('k') | chrome/browser/policy/cloud_policy_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698