summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy
diff options
context:
space:
mode:
authormnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-03 14:28:08 +0000
committermnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-03 14:28:08 +0000
commit43dbf8ca2ed73a191703ffd4da3c1252f56adc56 (patch)
tree97989127c917a0aeba009674d192ccdf1e8339ba /chrome/browser/policy
parent79d67b103160a70d92255750b8bc403aa06818b3 (diff)
downloadchromium_src-43dbf8ca2ed73a191703ffd4da3c1252f56adc56.zip
chromium_src-43dbf8ca2ed73a191703ffd4da3c1252f56adc56.tar.gz
chromium_src-43dbf8ca2ed73a191703ffd4da3c1252f56adc56.tar.bz2
Convert DeviceTokenFetcher and CloudPolicyController response callbacks.
BUG=chromium:108928 TEST=Compiles and passes tests. Review URL: http://codereview.chromium.org/9064006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116133 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/policy')
-rw-r--r--chrome/browser/policy/browser_policy_connector.cc12
-rw-r--r--chrome/browser/policy/browser_policy_connector.h9
-rw-r--r--chrome/browser/policy/cloud_policy_controller.cc117
-rw-r--r--chrome/browser/policy/cloud_policy_controller.h25
-rw-r--r--chrome/browser/policy/cloud_policy_controller_unittest.cc119
-rw-r--r--chrome/browser/policy/cloud_policy_data_store.cc12
-rw-r--r--chrome/browser/policy/cloud_policy_data_store.h7
-rw-r--r--chrome/browser/policy/device_token_fetcher.cc146
-rw-r--r--chrome/browser/policy/device_token_fetcher.h30
-rw-r--r--chrome/browser/policy/device_token_fetcher_unittest.cc50
-rw-r--r--chrome/browser/policy/mock_device_management_backend.h1
-rw-r--r--chrome/browser/policy/proto/device_management_constants.cc15
-rw-r--r--chrome/browser/policy/proto/device_management_constants.h18
13 files changed, 287 insertions, 274 deletions
diff --git a/chrome/browser/policy/browser_policy_connector.cc b/chrome/browser/policy/browser_policy_connector.cc
index 0ff2466..8e2c3ce9 100644
--- a/chrome/browser/policy/browser_policy_connector.cc
+++ b/chrome/browser/policy/browser_policy_connector.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.
@@ -10,10 +10,10 @@
#include "base/path_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/gaia/token_service.h"
+#include "chrome/browser/policy/cloud_policy_data_store.h"
#include "chrome/browser/policy/cloud_policy_provider.h"
#include "chrome/browser/policy/cloud_policy_provider_impl.h"
#include "chrome/browser/policy/cloud_policy_subsystem.h"
-#include "chrome/browser/policy/configuration_policy_pref_store.h"
#include "chrome/browser/policy/configuration_policy_provider.h"
#include "chrome/browser/policy/network_configuration_updater.h"
#include "chrome/browser/policy/user_policy_cache.h"
@@ -343,19 +343,19 @@ const ConfigurationPolicyHandlerList*
return &handler_list_;
}
-CloudPolicyDataStore::UserAffiliation
- BrowserPolicyConnector::GetUserAffiliation(const std::string& user_name) {
+UserAffiliation BrowserPolicyConnector::GetUserAffiliation(
+ const std::string& user_name) {
#if defined(OS_CHROMEOS)
if (install_attributes_.get()) {
size_t pos = user_name.find('@');
if (pos != std::string::npos &&
user_name.substr(pos + 1) == install_attributes_->GetDomain()) {
- return CloudPolicyDataStore::USER_AFFILIATION_MANAGED;
+ return USER_AFFILIATION_MANAGED;
}
}
#endif
- return CloudPolicyDataStore::USER_AFFILIATION_NONE;
+ return USER_AFFILIATION_NONE;
}
void BrowserPolicyConnector::Observe(
diff --git a/chrome/browser/policy/browser_policy_connector.h b/chrome/browser/policy/browser_policy_connector.h
index 64763f0..66cc0c9 100644
--- a/chrome/browser/policy/browser_policy_connector.h
+++ b/chrome/browser/policy/browser_policy_connector.h
@@ -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.
@@ -11,17 +11,17 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "chrome/browser/policy/cloud_policy_data_store.h"
+#include "chrome/browser/policy/cloud_policy_constants.h"
#include "chrome/browser/policy/configuration_policy_handler_list.h"
#include "chrome/browser/policy/enterprise_install_attributes.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-class TestingBrowserProcess;
class TokenService;
namespace policy {
+class CloudPolicyDataStore;
class CloudPolicyProvider;
class CloudPolicySubsystem;
class ConfigurationPolicyProvider;
@@ -123,8 +123,7 @@ class BrowserPolicyConnector : public content::NotificationObserver {
// Works out the user affiliation by checking the given |user_name| against
// the installation attributes.
- policy::CloudPolicyDataStore::UserAffiliation GetUserAffiliation(
- const std::string& user_name);
+ UserAffiliation GetUserAffiliation(const std::string& user_name);
private:
// content::NotificationObserver method overrides:
diff --git a/chrome/browser/policy/cloud_policy_controller.cc b/chrome/browser/policy/cloud_policy_controller.cc
index 3d3d8cc..6f58a6d 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;
diff --git a/chrome/browser/policy/cloud_policy_controller.h b/chrome/browser/policy/cloud_policy_controller.h
index d3388c0..d7c971b 100644
--- a/chrome/browser/policy/cloud_policy_controller.h
+++ b/chrome/browser/policy/cloud_policy_controller.h
@@ -8,23 +8,26 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/policy/cloud_policy_constants.h"
#include "chrome/browser/policy/cloud_policy_data_store.h"
-#include "chrome/browser/policy/device_management_backend.h"
+
+namespace enterprise_management {
+class DeviceManagementResponse;
+}
namespace policy {
class CloudPolicyCacheBase;
class DelayedWorkScheduler;
+class DeviceManagementRequestJob;
class DeviceManagementService;
class DeviceTokenFetcher;
class PolicyNotifier;
// Coordinates the actions of DeviceTokenFetcher, CloudPolicyDataStore,
-// DeviceManagementBackend, and CloudPolicyCache: calls their methods and
-// listens to their callbacks/notifications.
-class CloudPolicyController
- : public DeviceManagementBackend::DevicePolicyResponseDelegate,
- public CloudPolicyDataStore::Observer {
+// and CloudPolicyCache: calls their methods and listens to their
+// callbacks/notifications.
+class CloudPolicyController : public CloudPolicyDataStore::Observer {
public:
// All parameters are weak pointers.
CloudPolicyController(DeviceManagementService* service,
@@ -47,10 +50,10 @@ class CloudPolicyController
// a fetch was attempted.
void RefreshPolicies();
- // DevicePolicyResponseDelegate implementation:
- virtual void HandlePolicyResponse(
- const enterprise_management::DevicePolicyResponse& response) OVERRIDE;
- virtual void OnError(DeviceManagementBackend::ErrorCode code) OVERRIDE;
+ // Policy request response handler.
+ void OnPolicyFetchCompleted(
+ DeviceManagementStatus status,
+ const enterprise_management::DeviceManagementResponse& response);
// CloudPolicyDataStore::Observer implementation:
virtual void OnDeviceTokenChanged() OVERRIDE;
@@ -120,7 +123,7 @@ class CloudPolicyController
CloudPolicyCacheBase* cache_;
CloudPolicyDataStore* data_store_;
DeviceTokenFetcher* token_fetcher_;
- scoped_ptr<DeviceManagementBackend> backend_;
+ scoped_ptr<DeviceManagementRequestJob> request_job_;
ControllerState state_;
PolicyNotifier* notifier_;
diff --git a/chrome/browser/policy/cloud_policy_controller_unittest.cc b/chrome/browser/policy/cloud_policy_controller_unittest.cc
index 12d2fe7f..6295b2c 100644
--- a/chrome/browser/policy/cloud_policy_controller_unittest.cc
+++ b/chrome/browser/policy/cloud_policy_controller_unittest.cc
@@ -10,9 +10,10 @@
#include "chrome/browser/policy/cloud_policy_data_store.h"
#include "chrome/browser/policy/device_token_fetcher.h"
#include "chrome/browser/policy/logging_work_scheduler.h"
-#include "chrome/browser/policy/mock_device_management_backend.h"
-#include "chrome/browser/policy/mock_device_management_service_old.h"
+#include "chrome/browser/policy/mock_device_management_service.h"
#include "chrome/browser/policy/policy_notifier.h"
+#include "chrome/browser/policy/proto/cloud_policy.pb.h"
+#include "chrome/browser/policy/proto/device_management_backend.pb.h"
#include "chrome/browser/policy/user_policy_cache.h"
#include "content/test/test_browser_thread.h"
#include "policy/policy_constants.h"
@@ -24,7 +25,9 @@ namespace em = enterprise_management;
namespace policy {
using ::testing::AnyNumber;
+using ::testing::DoAll;
using ::testing::InSequence;
+using ::testing::InvokeWithoutArgs;
using ::testing::_;
using content::BrowserThread;
@@ -46,7 +49,24 @@ class CloudPolicyControllerTest : public testing::Test {
public:
CloudPolicyControllerTest()
: ui_thread_(BrowserThread::UI, &loop_),
- file_thread_(BrowserThread::FILE, &loop_) {}
+ file_thread_(BrowserThread::FILE, &loop_) {
+ em::PolicyData signed_response;
+ em::CloudPolicySettings settings;
+ em::DisableSpdyProto* spdy_proto = settings.mutable_disablespdy();
+ spdy_proto->set_disablespdy(true);
+ spdy_proto->mutable_policy_options()->set_mode(
+ em::PolicyOptions::MANDATORY);
+ EXPECT_TRUE(
+ settings.SerializeToString(signed_response.mutable_policy_value()));
+ base::TimeDelta timestamp =
+ base::Time::NowFromSystemTime() - base::Time::UnixEpoch();
+ signed_response.set_timestamp(timestamp.InMilliseconds());
+ std::string serialized_signed_response;
+ EXPECT_TRUE(signed_response.SerializeToString(&serialized_signed_response));
+ em::PolicyFetchResponse* fetch_response =
+ spdy_policy_response_.mutable_policy_response()->add_response();
+ fetch_response->set_policy_data(serialized_signed_response);
+ }
virtual ~CloudPolicyControllerTest() {}
@@ -56,9 +76,7 @@ class CloudPolicyControllerTest : public testing::Test {
temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"),
false /* wait_for_policy_fetch */));
token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get()));
- EXPECT_CALL(service_, CreateBackend())
- .Times(AnyNumber())
- .WillRepeatedly(MockDeviceManagementServiceProxyBackend(&backend_));
+ EXPECT_CALL(service_, StartJob(_)).Times(AnyNumber());
data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
}
@@ -92,20 +110,16 @@ class CloudPolicyControllerTest : public testing::Test {
ASSERT_TRUE(Value::Equals(&expected, policy_map->Get(kPolicyDisableSpdy)));
}
- void StopMessageLoop() {
- loop_.QuitNow();
- }
-
protected:
scoped_ptr<CloudPolicyCacheBase> cache_;
scoped_ptr<CloudPolicyController> controller_;
scoped_ptr<MockDeviceTokenFetcher> token_fetcher_;
scoped_ptr<CloudPolicyDataStore> data_store_;
- MockDeviceManagementBackend backend_;
- MockDeviceManagementServiceOld service_;
+ MockDeviceManagementService service_;
PolicyNotifier notifier_;
ScopedTempDir temp_user_data_dir_;
MessageLoop loop_;
+ em::DeviceManagementResponse spdy_policy_response_;
private:
content::TestBrowserThread ui_thread_;
@@ -119,9 +133,10 @@ class CloudPolicyControllerTest : public testing::Test {
TEST_F(CloudPolicyControllerTest, StartupWithDeviceToken) {
data_store_->SetupForTesting("fake_device_token", "device_id", "", "",
true);
- EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll(
- InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop),
- MockDeviceManagementBackendSucceedSpdyCloudPolicy()));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
+ service_.SucceedJob(spdy_policy_response_)));
CreateNewController();
loop_.RunAllPending();
ExpectHasSpdyPolicy();
@@ -155,13 +170,13 @@ TEST_F(CloudPolicyControllerTest, RefreshAfterSuccessfulPolicy) {
"auth_token", true);
{
InSequence s;
- EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendSucceedSpdyCloudPolicy());
- EXPECT_CALL(backend_,
- ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll(
- InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop),
- MockDeviceManagementBackendFailPolicy(
- DeviceManagementBackend::kErrorRequestFailed)));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(service_.SucceedJob(spdy_policy_response_));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
+ service_.FailJob(DM_STATUS_REQUEST_FAILED)));
}
CreateNewController();
loop_.RunAllPending();
@@ -175,14 +190,13 @@ TEST_F(CloudPolicyControllerTest, RefreshAfterError) {
"auth_token", true);
{
InSequence s;
- EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendFailPolicy(
- DeviceManagementBackend::kErrorRequestFailed));
- EXPECT_CALL(backend_,
- ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll(
- InvokeWithoutArgs(this,
- &CloudPolicyControllerTest::StopMessageLoop),
- MockDeviceManagementBackendSucceedSpdyCloudPolicy()));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
+ service_.SucceedJob(spdy_policy_response_)));
}
CreateNewController();
loop_.RunAllPending();
@@ -194,9 +208,9 @@ TEST_F(CloudPolicyControllerTest, RefreshAfterError) {
TEST_F(CloudPolicyControllerTest, InvalidToken) {
data_store_->SetupForTesting("device_token", "device_id",
"standup@ten.am", "auth", true);
- EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendFailPolicy(
- DeviceManagementBackend::kErrorServiceManagementTokenInvalid));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID));
EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1);
CreateNewController();
loop_.RunAllPending();
@@ -207,9 +221,9 @@ TEST_F(CloudPolicyControllerTest, InvalidToken) {
TEST_F(CloudPolicyControllerTest, DeviceNotFound) {
data_store_->SetupForTesting("device_token", "device_id",
"me@you.com", "auth", true);
- EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendFailPolicy(
- DeviceManagementBackend::kErrorServiceDeviceNotFound));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(service_.FailJob(DM_STATUS_SERVICE_DEVICE_NOT_FOUND));
EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1);
CreateNewController();
loop_.RunAllPending();
@@ -220,9 +234,9 @@ TEST_F(CloudPolicyControllerTest, DeviceNotFound) {
TEST_F(CloudPolicyControllerTest, DeviceIdConflict) {
data_store_->SetupForTesting("device_token", "device_id",
"me@you.com", "auth", true);
- EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendFailPolicy(
- DeviceManagementBackend::kErrorServiceDeviceIdConflict));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(service_.FailJob(DM_STATUS_SERVICE_DEVICE_ID_CONFLICT));
EXPECT_CALL(*token_fetcher_.get(), FetchToken()).Times(1);
CreateNewController();
loop_.RunAllPending();
@@ -234,9 +248,9 @@ TEST_F(CloudPolicyControllerTest, DeviceIdConflict) {
TEST_F(CloudPolicyControllerTest, NoLongerManaged) {
data_store_->SetupForTesting("device_token", "device_id",
"who@what.com", "auth", true);
- EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendFailPolicy(
- DeviceManagementBackend::kErrorServiceManagementNotSupported));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED));
EXPECT_CALL(*token_fetcher_.get(), SetUnmanagedState()).Times(1);
CreateNewController();
loop_.RunAllPending();
@@ -248,9 +262,9 @@ TEST_F(CloudPolicyControllerTest, NoLongerManaged) {
TEST_F(CloudPolicyControllerTest, InvalidSerialNumber) {
data_store_->SetupForTesting("device_token", "device_id",
"who@what.com", "auth", true);
- EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendFailPolicy(
- DeviceManagementBackend::kErrorServiceInvalidSerialNumber));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(service_.FailJob(DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER));
EXPECT_CALL(*token_fetcher_.get(), SetSerialNumberInvalidState()).Times(1);
CreateNewController();
loop_.RunAllPending();
@@ -308,9 +322,10 @@ TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetch) {
CreateNewWaitingCache();
data_store_->SetupForTesting("device_token", "device_id",
"user@enterprise.com", "auth", true);
- EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll(
- InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop),
- MockDeviceManagementBackendSucceedSpdyCloudPolicy()));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
+ service_.SucceedJob(spdy_policy_response_)));
CreateNewController();
loop_.RunAllPending();
EXPECT_TRUE(cache_->IsReady());
@@ -321,10 +336,10 @@ TEST_F(CloudPolicyControllerTest, SetFetchingDoneAfterPolicyFetchFails) {
CreateNewWaitingCache();
data_store_->SetupForTesting("device_token", "device_id",
"user@enterprise.com", "auth", true);
- EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _, _, _)).WillOnce(DoAll(
- InvokeWithoutArgs(this, &CloudPolicyControllerTest::StopMessageLoop),
- MockDeviceManagementBackendFailPolicy(
- DeviceManagementBackend::kErrorRequestFailed)));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
+ .WillOnce(DoAll(InvokeWithoutArgs(&loop_, &MessageLoop::QuitNow),
+ service_.FailJob(DM_STATUS_REQUEST_FAILED)));
CreateNewController();
loop_.RunAllPending();
EXPECT_TRUE(cache_->IsReady());
diff --git a/chrome/browser/policy/cloud_policy_data_store.cc b/chrome/browser/policy/cloud_policy_data_store.cc
index 9fb0a50..061e4cd 100644
--- a/chrome/browser/policy/cloud_policy_data_store.cc
+++ b/chrome/browser/policy/cloud_policy_data_store.cc
@@ -7,7 +7,6 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chrome/browser/policy/proto/device_management_backend.pb.h"
-#include "chrome/browser/policy/proto/device_management_constants.h"
namespace em = enterprise_management;
@@ -18,19 +17,19 @@ CloudPolicyDataStore::~CloudPolicyDataStore() {}
// static
CloudPolicyDataStore* CloudPolicyDataStore::CreateForUserPolicies() {
return new CloudPolicyDataStore(em::DeviceRegisterRequest::USER,
- kChromeUserPolicyType);
+ dm_protocol::kChromeUserPolicyType);
}
// static
CloudPolicyDataStore* CloudPolicyDataStore::CreateForDevicePolicies() {
return new CloudPolicyDataStore(em::DeviceRegisterRequest::DEVICE,
- kChromeDevicePolicyType);
+ dm_protocol::kChromeDevicePolicyType);
}
CloudPolicyDataStore::CloudPolicyDataStore(
const em::DeviceRegisterRequest_Type policy_register_type,
const std::string& policy_type)
- : user_affiliation_(USER_AFFILIATION_NONE),
+ : user_affiliation_(policy::USER_AFFILIATION_NONE),
policy_register_type_(policy_register_type),
policy_type_(policy_type),
token_cache_loaded_(false) {}
@@ -103,7 +102,7 @@ void CloudPolicyDataStore::set_user_name(const std::string& user_name) {
}
void CloudPolicyDataStore::set_user_affiliation(
- UserAffiliation user_affiliation) {
+ policy::UserAffiliation user_affiliation) {
user_affiliation_ = user_affiliation;
}
@@ -148,8 +147,7 @@ const std::string& CloudPolicyDataStore::user_name() const {
return user_name_;
}
-CloudPolicyDataStore::UserAffiliation
- CloudPolicyDataStore::user_affiliation() const {
+policy::UserAffiliation CloudPolicyDataStore::user_affiliation() const {
return user_affiliation_;
}
diff --git a/chrome/browser/policy/cloud_policy_data_store.h b/chrome/browser/policy/cloud_policy_data_store.h
index 0b4e05a..47942a9 100644
--- a/chrome/browser/policy/cloud_policy_data_store.h
+++ b/chrome/browser/policy/cloud_policy_data_store.h
@@ -10,6 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
+#include "chrome/browser/policy/cloud_policy_constants.h"
#include "chrome/browser/policy/proto/device_management_backend.pb.h"
#if defined(OS_CHROMEOS)
@@ -82,7 +83,7 @@ class CloudPolicyDataStore {
void set_machine_id(const std::string& machine_id);
void set_machine_model(const std::string& machine_model);
void set_user_name(const std::string& user_name);
- void set_user_affiliation(UserAffiliation user_affiliation);
+ void set_user_affiliation(policy::UserAffiliation user_affiliation);
#if defined(OS_CHROMEOS)
void set_device_status_collector(DeviceStatusCollector* collector);
@@ -101,7 +102,7 @@ class CloudPolicyDataStore {
const std::string& policy_type() const;
bool token_cache_loaded() const;
const std::string& user_name() const;
- UserAffiliation user_affiliation() const;
+ policy::UserAffiliation user_affiliation() const;
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
@@ -121,7 +122,7 @@ class CloudPolicyDataStore {
// Data necessary for constructing policy requests.
std::string device_token_;
- UserAffiliation user_affiliation_;
+ policy::UserAffiliation user_affiliation_;
// Constants that won't change over the life-time of a cloud policy
// subsystem.
diff --git a/chrome/browser/policy/device_token_fetcher.cc b/chrome/browser/policy/device_token_fetcher.cc
index 540c4df..95942b6 100644
--- a/chrome/browser/policy/device_token_fetcher.cc
+++ b/chrome/browser/policy/device_token_fetcher.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.
@@ -10,12 +10,12 @@
#include "base/metrics/histogram.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_data_store.h"
#include "chrome/browser/policy/delayed_work_scheduler.h"
#include "chrome/browser/policy/device_management_service.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/browser/policy/proto/device_management_local.pb.h"
namespace {
@@ -63,27 +63,6 @@ void DeviceTokenFetcher::FetchToken() {
FetchTokenInternal();
}
-void DeviceTokenFetcher::FetchTokenInternal() {
- DCHECK(state_ != STATE_TOKEN_AVAILABLE);
- if (!data_store_->has_auth_token() || data_store_->device_id().empty()) {
- // Maybe this device is unmanaged, just exit. The CloudPolicyController
- // will call FetchToken() again if something changes.
- return;
- }
- // Construct a new backend, which will discard any previous requests.
- backend_.reset(service_->CreateBackend());
- em::DeviceRegisterRequest request;
- request.set_type(data_store_->policy_register_type());
- if (!data_store_->machine_id().empty())
- request.set_machine_id(data_store_->machine_id());
- if (!data_store_->machine_model().empty())
- request.set_machine_model(data_store_->machine_model());
- backend_->ProcessRegisterRequest(data_store_->gaia_token(),
- data_store_->oauth_token(),
- data_store_->device_id(),
- request, this);
-}
-
void DeviceTokenFetcher::SetUnmanagedState() {
// The call to |cache_->SetUnmanaged()| has to happen first because it sets
// the timestamp that |SetState()| needs to determine the correct refresh
@@ -100,45 +79,95 @@ void DeviceTokenFetcher::Reset() {
SetState(STATE_INACTIVE);
}
-void DeviceTokenFetcher::HandleRegisterResponse(
- const em::DeviceRegisterResponse& response) {
- if (response.has_device_management_token()) {
- UMA_HISTOGRAM_ENUMERATION(kMetricToken, kMetricTokenFetchOK,
- kMetricTokenSize);
- data_store_->SetDeviceToken(response.device_management_token(), false);
- SetState(STATE_TOKEN_AVAILABLE);
- } else {
- NOTREACHED();
- UMA_HISTOGRAM_ENUMERATION(kMetricToken, kMetricTokenFetchBadResponse,
- kMetricTokenSize);
- SetState(STATE_ERROR);
+void DeviceTokenFetcher::Initialize(DeviceManagementService* service,
+ CloudPolicyCacheBase* cache,
+ CloudPolicyDataStore* data_store,
+ PolicyNotifier* notifier,
+ DelayedWorkScheduler* scheduler) {
+ service_ = service;
+ cache_ = cache;
+ notifier_ = notifier;
+ data_store_ = data_store;
+ effective_token_fetch_error_delay_ms_ = kTokenFetchErrorDelayMilliseconds;
+ state_ = STATE_INACTIVE;
+ scheduler_.reset(scheduler);
+
+ if (cache_->is_unmanaged())
+ SetState(STATE_UNMANAGED);
+}
+
+void DeviceTokenFetcher::FetchTokenInternal() {
+ DCHECK(state_ != STATE_TOKEN_AVAILABLE);
+ if (!data_store_->has_auth_token() || data_store_->device_id().empty()) {
+ // Maybe this device is unmanaged, just exit. The CloudPolicyController
+ // will call FetchToken() again if something changes.
+ return;
}
+ // Reinitialize |request_job_|, discarding any previous requests.
+ request_job_.reset(
+ service_->CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION));
+ request_job_->SetGaiaToken(data_store_->gaia_token());
+ request_job_->SetOAuthToken(data_store_->oauth_token());
+ request_job_->SetClientID(data_store_->device_id());
+ em::DeviceRegisterRequest* request =
+ request_job_->GetRequest()->mutable_register_request();
+ request->set_type(data_store_->policy_register_type());
+ if (!data_store_->machine_id().empty())
+ request->set_machine_id(data_store_->machine_id());
+ if (!data_store_->machine_model().empty())
+ request->set_machine_model(data_store_->machine_model());
+ request_job_->Start(base::Bind(&DeviceTokenFetcher::OnTokenFetchCompleted,
+ base::Unretained(this)));
}
-void DeviceTokenFetcher::OnError(DeviceManagementBackend::ErrorCode code) {
- switch (code) {
- case DeviceManagementBackend::kErrorServiceManagementNotSupported:
+void DeviceTokenFetcher::OnTokenFetchCompleted(
+ DeviceManagementStatus status,
+ const em::DeviceManagementResponse& response) {
+ if (status == DM_STATUS_SUCCESS && !response.has_register_response()) {
+ // Handled below.
+ status = DM_STATUS_RESPONSE_DECODING_ERROR;
+ }
+
+ switch (status) {
+ case DM_STATUS_SUCCESS: {
+ const em::DeviceRegisterResponse& register_response =
+ response.register_response();
+ if (register_response.has_device_management_token()) {
+ UMA_HISTOGRAM_ENUMERATION(kMetricToken, kMetricTokenFetchOK,
+ kMetricTokenSize);
+ data_store_->SetDeviceToken(register_response.device_management_token(),
+ false);
+ SetState(STATE_TOKEN_AVAILABLE);
+ } else {
+ NOTREACHED();
+ UMA_HISTOGRAM_ENUMERATION(kMetricToken, kMetricTokenFetchBadResponse,
+ kMetricTokenSize);
+ SetState(STATE_ERROR);
+ }
+ return;
+ }
+ case DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED:
SetUnmanagedState();
return;
- case DeviceManagementBackend::kErrorRequestFailed:
- case DeviceManagementBackend::kErrorTemporaryUnavailable:
- case DeviceManagementBackend::kErrorServiceDeviceNotFound:
- case DeviceManagementBackend::kErrorServiceDeviceIdConflict:
+ case DM_STATUS_REQUEST_FAILED:
+ case DM_STATUS_TEMPORARY_UNAVAILABLE:
+ case DM_STATUS_SERVICE_DEVICE_NOT_FOUND:
+ case DM_STATUS_SERVICE_DEVICE_ID_CONFLICT:
SetState(STATE_TEMPORARY_ERROR);
return;
- case DeviceManagementBackend::kErrorServiceManagementTokenInvalid:
+ case DM_STATUS_SERVICE_MANAGEMENT_TOKEN_INVALID:
// Most probably the GAIA auth cookie has expired. We can not do anything
// until the user logs-in again.
SetState(STATE_BAD_AUTH);
return;
- case DeviceManagementBackend::kErrorServiceInvalidSerialNumber:
+ case DM_STATUS_SERVICE_INVALID_SERIAL_NUMBER:
SetSerialNumberInvalidState();
return;
- case DeviceManagementBackend::kErrorRequestInvalid:
- case DeviceManagementBackend::kErrorHttpStatus:
- case DeviceManagementBackend::kErrorResponseDecoding:
- case DeviceManagementBackend::kErrorServiceActivationPending:
- case DeviceManagementBackend::kErrorServicePolicyNotFound:
+ case DM_STATUS_REQUEST_INVALID:
+ case DM_STATUS_HTTP_STATUS_ERROR:
+ case DM_STATUS_RESPONSE_DECODING_ERROR:
+ case DM_STATUS_SERVICE_ACTIVATION_PENDING:
+ case DM_STATUS_SERVICE_POLICY_NOT_FOUND:
SetState(STATE_ERROR);
return;
}
@@ -146,29 +175,12 @@ void DeviceTokenFetcher::OnError(DeviceManagementBackend::ErrorCode code) {
SetState(STATE_ERROR);
}
-void DeviceTokenFetcher::Initialize(DeviceManagementService* service,
- CloudPolicyCacheBase* cache,
- CloudPolicyDataStore* data_store,
- PolicyNotifier* notifier,
- DelayedWorkScheduler* scheduler) {
- service_ = service;
- cache_ = cache;
- notifier_ = notifier;
- data_store_ = data_store;
- effective_token_fetch_error_delay_ms_ = kTokenFetchErrorDelayMilliseconds;
- state_ = STATE_INACTIVE;
- scheduler_.reset(scheduler);
-
- if (cache_->is_unmanaged())
- SetState(STATE_UNMANAGED);
-}
-
void DeviceTokenFetcher::SetState(FetcherState state) {
state_ = state;
if (state_ != STATE_TEMPORARY_ERROR)
effective_token_fetch_error_delay_ms_ = kTokenFetchErrorDelayMilliseconds;
- backend_.reset(); // Stop any pending requests.
+ request_job_.reset(); // Stop any pending requests.
base::Time delayed_work_at;
switch (state_) {
diff --git a/chrome/browser/policy/device_token_fetcher.h b/chrome/browser/policy/device_token_fetcher.h
index 398ddfe..cb80a88 100644
--- a/chrome/browser/policy/device_token_fetcher.h
+++ b/chrome/browser/policy/device_token_fetcher.h
@@ -6,15 +6,20 @@
#define CHROME_BROWSER_POLICY_DEVICE_TOKEN_FETCHER_H_
#pragma once
+#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/policy/device_management_backend.h"
-#include "chrome/browser/policy/proto/device_management_backend.pb.h"
+#include "chrome/browser/policy/cloud_policy_constants.h"
+
+namespace enterprise_management {
+class DeviceManagementResponse;
+}
namespace policy {
class CloudPolicyCacheBase;
class CloudPolicyDataStore;
class DelayedWorkScheduler;
+class DeviceManagementRequestJob;
class DeviceManagementService;
class PolicyNotifier;
@@ -23,8 +28,7 @@ class PolicyNotifier;
// requested, otherwise from the device management server. An instance of the
// fetcher is shared as a singleton by all users of the device management token
// to ensure they all get the same token.
-class DeviceTokenFetcher
- : public DeviceManagementBackend::DeviceRegisterResponseDelegate {
+class DeviceTokenFetcher {
public:
// |service| is used to talk to the device management service and |cache| is
// used to persist whether the device is unmanaged.
@@ -51,11 +55,6 @@ class DeviceTokenFetcher
// Cancels any pending work on this fetcher and resets it to inactive state.
void Reset();
- // DeviceManagementBackend::DeviceRegisterResponseDelegate method overrides:
- virtual void HandleRegisterResponse(
- const enterprise_management::DeviceRegisterResponse& response) OVERRIDE;
- virtual void OnError(DeviceManagementBackend::ErrorCode code) OVERRIDE;
-
private:
friend class DeviceTokenFetcherTest;
@@ -90,20 +89,25 @@ class DeviceTokenFetcher
PolicyNotifier* notifier,
DelayedWorkScheduler* scheduler);
- // Moves the fetcher into a new state.
- void SetState(FetcherState state);
-
// Resets |backend_|, then uses |auth_token_| and |device_id_| to perform
// an actual token fetch.
void FetchTokenInternal();
+ // Handles token fetch request completion.
+ void OnTokenFetchCompleted(
+ DeviceManagementStatus status,
+ const enterprise_management::DeviceManagementResponse& response);
+
+ // Moves the fetcher into a new state.
+ void SetState(FetcherState state);
+
// DelayedWorkScheduler::Client:
virtual void DoWork();
// Service and backend. A new backend is created whenever the fetcher gets
// reset.
DeviceManagementService* service_; // weak
- scoped_ptr<DeviceManagementBackend> backend_;
+ scoped_ptr<DeviceManagementRequestJob> request_job_;
// Reference to the cache. Used to persist and read unmanaged state.
CloudPolicyCacheBase* cache_;
diff --git a/chrome/browser/policy/device_token_fetcher_unittest.cc b/chrome/browser/policy/device_token_fetcher_unittest.cc
index 4e8a6a6..029d8d4 100644
--- a/chrome/browser/policy/device_token_fetcher_unittest.cc
+++ b/chrome/browser/policy/device_token_fetcher_unittest.cc
@@ -9,8 +9,7 @@
#include "chrome/browser/policy/cloud_policy_data_store.h"
#include "chrome/browser/policy/logging_work_scheduler.h"
#include "chrome/browser/policy/mock_cloud_policy_data_store.h"
-#include "chrome/browser/policy/mock_device_management_backend.h"
-#include "chrome/browser/policy/mock_device_management_service_old.h"
+#include "chrome/browser/policy/mock_device_management_service.h"
#include "chrome/browser/policy/policy_notifier.h"
#include "chrome/browser/policy/user_policy_cache.h"
#include "content/test/test_browser_thread.h"
@@ -34,15 +33,15 @@ class DeviceTokenFetcherTest : public testing::Test {
: ui_thread_(BrowserThread::UI, &loop_),
file_thread_(BrowserThread::FILE, &loop_) {
EXPECT_TRUE(temp_user_data_dir_.CreateUniqueTempDir());
+ successful_registration_response_.mutable_register_response()->
+ set_device_management_token("fake_token");
}
virtual void SetUp() {
cache_.reset(new UserPolicyCache(
temp_user_data_dir_.path().AppendASCII("DeviceTokenFetcherTest"),
false /* wait_for_policy_fetch */));
- EXPECT_CALL(service_, CreateBackend())
- .Times(AnyNumber())
- .WillRepeatedly(MockDeviceManagementServiceProxyBackend(&backend_));
+ EXPECT_CALL(service_, StartJob(_)).Times(AnyNumber());
data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
data_store_->AddObserver(&observer_);
}
@@ -71,13 +70,13 @@ class DeviceTokenFetcherTest : public testing::Test {
}
MessageLoop loop_;
- MockDeviceManagementBackend backend_;
- MockDeviceManagementServiceOld service_;
+ MockDeviceManagementService service_;
scoped_ptr<CloudPolicyCacheBase> cache_;
scoped_ptr<CloudPolicyDataStore> data_store_;
MockCloudPolicyDataStoreObserver observer_;
PolicyNotifier notifier_;
ScopedTempDir temp_user_data_dir_;
+ em::DeviceManagementResponse successful_registration_response_;
private:
content::TestBrowserThread ui_thread_;
@@ -86,8 +85,9 @@ class DeviceTokenFetcherTest : public testing::Test {
TEST_F(DeviceTokenFetcherTest, FetchToken) {
testing::InSequence s;
- EXPECT_CALL(backend_, ProcessRegisterRequest(_, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendSucceedRegister());
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
+ .WillOnce(service_.SucceedJob(successful_registration_response_));
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_);
EXPECT_CALL(observer_, OnDeviceTokenChanged());
@@ -99,8 +99,11 @@ TEST_F(DeviceTokenFetcherTest, FetchToken) {
EXPECT_NE("", token);
// Calling FetchToken() again should result in a new token being fetched.
- EXPECT_CALL(backend_, ProcessRegisterRequest(_, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendSucceedRegister());
+ successful_registration_response_.mutable_register_response()->
+ set_device_management_token("new_fake_token");
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
+ .WillOnce(service_.SucceedJob(successful_registration_response_));
EXPECT_CALL(observer_, OnDeviceTokenChanged());
FetchToken(&fetcher);
loop_.RunAllPending();
@@ -112,10 +115,10 @@ TEST_F(DeviceTokenFetcherTest, FetchToken) {
TEST_F(DeviceTokenFetcherTest, RetryOnError) {
testing::InSequence s;
- EXPECT_CALL(backend_, ProcessRegisterRequest(_, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendFailRegister(
- DeviceManagementBackend::kErrorRequestFailed)).WillOnce(
- MockDeviceManagementBackendSucceedRegister());
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
+ .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED))
+ .WillOnce(service_.SucceedJob(successful_registration_response_));
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_, new DummyWorkScheduler);
EXPECT_CALL(observer_, OnDeviceTokenChanged());
@@ -126,9 +129,9 @@ TEST_F(DeviceTokenFetcherTest, RetryOnError) {
}
TEST_F(DeviceTokenFetcherTest, UnmanagedDevice) {
- EXPECT_CALL(backend_, ProcessRegisterRequest(_, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendFailRegister(
- DeviceManagementBackend::kErrorServiceManagementNotSupported));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
+ .WillOnce(service_.FailJob(DM_STATUS_SERVICE_MANAGEMENT_NOT_SUPPORTED));
EXPECT_FALSE(cache_->is_unmanaged());
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_);
@@ -149,8 +152,9 @@ TEST_F(DeviceTokenFetcherTest, DontSetFetchingDone) {
TEST_F(DeviceTokenFetcherTest, DontSetFetchingDoneWithoutPolicyFetch) {
CreateNewWaitingCache();
- EXPECT_CALL(backend_, ProcessRegisterRequest(_, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendSucceedRegister());
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
+ .WillOnce(service_.SucceedJob(successful_registration_response_));
EXPECT_CALL(observer_, OnDeviceTokenChanged());
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_);
@@ -172,9 +176,9 @@ TEST_F(DeviceTokenFetcherTest, SetFetchingDoneWhenUnmanaged) {
TEST_F(DeviceTokenFetcherTest, SetFetchingDoneOnFailures) {
CreateNewWaitingCache();
- EXPECT_CALL(backend_, ProcessRegisterRequest(_, _, _, _, _)).WillOnce(
- MockDeviceManagementBackendFailRegister(
- DeviceManagementBackend::kErrorRequestFailed));
+ EXPECT_CALL(service_,
+ CreateJob(DeviceManagementRequestJob::TYPE_REGISTRATION))
+ .WillOnce(service_.FailJob(DM_STATUS_REQUEST_FAILED));
DeviceTokenFetcher fetcher(&service_, cache_.get(), data_store_.get(),
&notifier_);
FetchToken(&fetcher);
diff --git a/chrome/browser/policy/mock_device_management_backend.h b/chrome/browser/policy/mock_device_management_backend.h
index 9054c89..6888d6a0 100644
--- a/chrome/browser/policy/mock_device_management_backend.h
+++ b/chrome/browser/policy/mock_device_management_backend.h
@@ -12,7 +12,6 @@
#include "chrome/browser/policy/device_management_backend.h"
#include "chrome/browser/policy/proto/cloud_policy.pb.h"
#include "chrome/browser/policy/proto/device_management_backend.pb.h"
-#include "chrome/browser/policy/proto/device_management_constants.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/chrome/browser/policy/proto/device_management_constants.cc b/chrome/browser/policy/proto/device_management_constants.cc
deleted file mode 100644
index ec7c32e..0000000
--- a/chrome/browser/policy/proto/device_management_constants.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "chrome/browser/policy/proto/device_management_constants.h"
-
-namespace policy {
-
-const char kChromePolicyScope[] = "chromeos/device";
-const char kChromeDevicePolicySettingKey[] = "chrome-policy";
-
-const char kChromeDevicePolicyType[] = "google/chromeos/device";
-const char kChromeUserPolicyType[] = "google/chromeos/user";
-
-} // namespace policy
diff --git a/chrome/browser/policy/proto/device_management_constants.h b/chrome/browser/policy/proto/device_management_constants.h
deleted file mode 100644
index 207c17b..0000000
--- a/chrome/browser/policy/proto/device_management_constants.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef CHROME_BROWSER_POLICY_PROTO_DEVICE_MANAGEMENT_CONSTANTS_H_
-#define CHROME_BROWSER_POLICY_PROTO_DEVICE_MANAGEMENT_CONSTANTS_H_
-
-namespace policy {
-
-extern const char kChromePolicyScope[];
-extern const char kChromeDevicePolicySettingKey[];
-
-extern const char kChromeDevicePolicyType[];
-extern const char kChromeUserPolicyType[];
-
-} // namespace policy
-
-#endif // CHROME_BROWSER_POLICY_PROTO_DEVICE_MANAGEMENT_CONSTANTS_H_