summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-19 18:16:59 +0000
committerjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-19 18:16:59 +0000
commit6a6dd9d296df1df8599d562eeffde39f01c5546d (patch)
treedb8dadbd9a616c8bdbdc0339408471c51cabb4eb
parentef0e26b190c956599a9df6194a992c6e137bf74a (diff)
downloadchromium_src-6a6dd9d296df1df8599d562eeffde39f01c5546d.zip
chromium_src-6a6dd9d296df1df8599d562eeffde39f01c5546d.tar.gz
chromium_src-6a6dd9d296df1df8599d562eeffde39f01c5546d.tar.bz2
Refactored the policy code to avoid BrowserThread.
The policy code now mostly uses TaskRunners, so that it can move into a component without DEPS layering violations. The remaining classes that use BrowserThread directly are meant to stay in //chrome and instantiate the policy system. Also cleaned up some unused includes and unused arguments. This is a reland of https://codereview.chromium.org/26211008 after fixing the configuration_policy=0 and clang builds. BUG=271392 TBR=dconnelly@chromium.org Review URL: https://codereview.chromium.org/29253002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229605 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc5
-rw-r--r--chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h4
-rw-r--r--chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc4
-rw-r--r--chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.cc8
-rw-r--r--chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h10
-rw-r--r--chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos_unittest.cc9
-rw-r--r--chrome/browser/chromeos/policy/device_local_account_policy_service.cc9
-rw-r--r--chrome/browser/chromeos/policy/device_local_account_policy_service.h7
-rw-r--r--chrome/browser/chromeos/policy/device_local_account_policy_service_unittest.cc3
-rw-r--r--chrome/browser/chromeos/policy/device_local_account_policy_store.cc9
-rw-r--r--chrome/browser/chromeos/policy/device_local_account_policy_store.h10
-rw-r--r--chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc5
-rw-r--r--chrome/browser/chromeos/policy/enrollment_handler_chromeos.h26
-rw-r--r--chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc10
-rw-r--r--chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h11
-rw-r--r--chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.cc30
-rw-r--r--chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h6
-rw-r--r--chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos_unittest.cc9
-rw-r--r--chrome/browser/chromeos/policy/user_policy_disk_cache.cc81
-rw-r--r--chrome/browser/chromeos/policy/user_policy_disk_cache.h12
-rw-r--r--chrome/browser/chromeos/policy/user_policy_token_loader.cc63
-rw-r--r--chrome/browser/chromeos/policy/user_policy_token_loader.h16
-rw-r--r--chrome/browser/chromeos/settings/session_manager_operation.cc10
-rw-r--r--chrome/browser/chromeos/settings/session_manager_operation_unittest.cc3
-rw-r--r--chrome/browser/policy/browser_policy_connector.cc16
-rw-r--r--chrome/browser/policy/cloud/DEPS22
-rw-r--r--chrome/browser/policy/cloud/cloud_policy_manager_browsertest.cc6
-rw-r--r--chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.cc2
-rw-r--r--chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h2
-rw-r--r--chrome/browser/policy/cloud/cloud_policy_validator.cc12
-rw-r--r--chrome/browser/policy/cloud/cloud_policy_validator.h22
-rw-r--r--chrome/browser/policy/cloud/cloud_policy_validator_unittest.cc11
-rw-r--r--chrome/browser/policy/cloud/component_cloud_policy_service_unittest.cc8
-rw-r--r--chrome/browser/policy/cloud/component_cloud_policy_store.cc3
-rw-r--r--chrome/browser/policy/cloud/device_management_service_browsertest.cc4
-rw-r--r--chrome/browser/policy/cloud/mock_user_cloud_policy_store.cc4
-rw-r--r--chrome/browser/policy/cloud/test_request_interceptor.cc49
-rw-r--r--chrome/browser/policy/cloud/test_request_interceptor.h13
-rw-r--r--chrome/browser/policy/cloud/user_cloud_policy_manager_factory.cc16
-rw-r--r--chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h11
-rw-r--r--chrome/browser/policy/cloud/user_cloud_policy_store.cc50
-rw-r--r--chrome/browser/policy/cloud/user_cloud_policy_store.h13
-rw-r--r--chrome/browser/policy/cloud/user_cloud_policy_store_base.cc7
-rw-r--r--chrome/browser/policy/cloud/user_cloud_policy_store_base.h15
-rw-r--r--chrome/browser/policy/cloud/user_cloud_policy_store_unittest.cc29
-rw-r--r--chrome/browser/policy/policy_browsertest.cc4
-rw-r--r--chrome/browser/policy/profile_policy_connector.cc4
-rw-r--r--chrome/browser/policy/profile_policy_connector.h7
-rw-r--r--chrome/browser/policy/profile_policy_connector_factory.cc11
-rw-r--r--chrome/browser/policy/profile_policy_connector_factory.h6
-rw-r--r--chrome/browser/policy/profile_policy_connector_stub.cc4
-rw-r--r--chrome/browser/profiles/profile_impl.cc6
52 files changed, 426 insertions, 291 deletions
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc
index 987d400..beea91d 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc
@@ -82,6 +82,7 @@ bool GetMachineFlag(const std::string& key, bool default_value) {
DeviceCloudPolicyManagerChromeOS::DeviceCloudPolicyManagerChromeOS(
scoped_ptr<DeviceCloudPolicyStoreChromeOS> store,
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
+ const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
EnterpriseInstallAttributes* install_attributes)
: CloudPolicyManager(
PolicyNamespaceKey(dm_protocol::kChromeDevicePolicyType,
@@ -89,6 +90,7 @@ DeviceCloudPolicyManagerChromeOS::DeviceCloudPolicyManagerChromeOS(
store.get(),
task_runner),
device_store_(store.Pass()),
+ background_task_runner_(background_task_runner),
install_attributes_(install_attributes),
device_management_service_(NULL),
local_state_(NULL) {}
@@ -120,7 +122,8 @@ void DeviceCloudPolicyManagerChromeOS::StartEnrollment(
enrollment_handler_.reset(
new EnrollmentHandlerChromeOS(
- device_store_.get(), install_attributes_, CreateClient(), auth_token,
+ device_store_.get(), install_attributes_, CreateClient(),
+ background_task_runner_, auth_token,
install_attributes_->GetDeviceId(), is_auto_enrollment,
GetDeviceRequisition(), allowed_device_modes,
base::Bind(&DeviceCloudPolicyManagerChromeOS::EnrollmentCompleted,
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h
index a79dd03..1208478 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h
@@ -46,9 +46,12 @@ class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager {
typedef base::Callback<void(EnrollmentStatus)> EnrollmentCallback;
// |task_runner| is the runner for policy refresh tasks.
+ // |background_task_runner| is used to execute long-running background tasks
+ // that may involve file I/O.
DeviceCloudPolicyManagerChromeOS(
scoped_ptr<DeviceCloudPolicyStoreChromeOS> store,
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
+ const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
EnterpriseInstallAttributes* install_attributes);
virtual ~DeviceCloudPolicyManagerChromeOS();
@@ -115,6 +118,7 @@ class DeviceCloudPolicyManagerChromeOS : public CloudPolicyManager {
// Points to the same object as the base CloudPolicyManager::store(), but with
// actual device policy specific type.
scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_store_;
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
EnterpriseInstallAttributes* install_attributes_;
DeviceManagementService* device_management_service_;
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc
index 4d03325e..7ee648e 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc
@@ -84,10 +84,12 @@ class DeviceCloudPolicyManagerChromeOSTest
install_attributes_.reset(new EnterpriseInstallAttributes(
chromeos::DBusThreadManager::Get()->GetCryptohomeClient()));
store_ = new DeviceCloudPolicyStoreChromeOS(&device_settings_service_,
- install_attributes_.get());
+ install_attributes_.get(),
+ loop_.message_loop_proxy());
manager_.reset(new DeviceCloudPolicyManagerChromeOS(
make_scoped_ptr(store_),
loop_.message_loop_proxy(),
+ loop_.message_loop_proxy(),
install_attributes_.get()));
chrome::RegisterLocalState(local_state_.registry());
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.cc b/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.cc
index 3b0d634..7f8a547 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.cc
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
#include "base/bind.h"
+#include "base/sequenced_task_runner.h"
#include "chrome/browser/chromeos/policy/device_policy_decoder_chromeos.h"
#include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
#include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h"
@@ -16,9 +17,11 @@ namespace policy {
DeviceCloudPolicyStoreChromeOS::DeviceCloudPolicyStoreChromeOS(
chromeos::DeviceSettingsService* device_settings_service,
- EnterpriseInstallAttributes* install_attributes)
+ EnterpriseInstallAttributes* install_attributes,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner)
: device_settings_service_(device_settings_service),
install_attributes_(install_attributes),
+ background_task_runner_(background_task_runner),
weak_factory_(this) {
device_settings_service_->AddObserver(this);
}
@@ -92,7 +95,8 @@ scoped_ptr<DeviceCloudPolicyValidator>
scoped_ptr<DeviceCloudPolicyValidator> validator(
DeviceCloudPolicyValidator::Create(
scoped_ptr<em::PolicyFetchResponse>(
- new em::PolicyFetchResponse(policy))));
+ new em::PolicyFetchResponse(policy)),
+ background_task_runner_));
validator->ValidateDomain(install_attributes_->GetDomain());
validator->ValidatePolicyType(dm_protocol::kChromeDevicePolicyType);
validator->ValidatePayload();
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h b/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h
index f468a75..6afcd44 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h
@@ -7,12 +7,17 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/policy/device_cloud_policy_validator.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/policy/cloud/cloud_policy_store.h"
+namespace base {
+class SequencedTaskRunner;
+}
+
namespace enterprise_management {
class PolicyFetchResponse;
}
@@ -29,7 +34,8 @@ class DeviceCloudPolicyStoreChromeOS
public:
DeviceCloudPolicyStoreChromeOS(
chromeos::DeviceSettingsService* device_settings_service,
- EnterpriseInstallAttributes* install_attributes);
+ EnterpriseInstallAttributes* install_attributes,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
virtual ~DeviceCloudPolicyStoreChromeOS();
// CloudPolicyStore:
@@ -68,6 +74,8 @@ class DeviceCloudPolicyStoreChromeOS
chromeos::DeviceSettingsService* device_settings_service_;
EnterpriseInstallAttributes* install_attributes_;
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
+
base::WeakPtrFactory<DeviceCloudPolicyStoreChromeOS> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyStoreChromeOS);
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos_unittest.cc b/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos_unittest.cc
index b0347da..5ccd535 100644
--- a/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos_unittest.cc
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos_unittest.cc
@@ -39,7 +39,8 @@ class DeviceCloudPolicyStoreChromeOSTest
install_attributes_(new EnterpriseInstallAttributes(
fake_cryptohome_client_.get())),
store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_,
- install_attributes_.get())) {
+ install_attributes_.get(),
+ loop_.message_loop_proxy())) {
fake_cryptohome_client_->Init(NULL /* no dbus::Bus */);
}
@@ -99,8 +100,10 @@ class DeviceCloudPolicyStoreChromeOSTest
std::string());
install_attributes_.reset(new EnterpriseInstallAttributes(
fake_cryptohome_client_.get()));
- store_.reset(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_,
- install_attributes_.get()));
+ store_.reset(
+ new DeviceCloudPolicyStoreChromeOS(&device_settings_service_,
+ install_attributes_.get(),
+ loop_.message_loop_proxy()));
}
scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_;
diff --git a/chrome/browser/chromeos/policy/device_local_account_policy_service.cc b/chrome/browser/chromeos/policy/device_local_account_policy_service.cc
index 5e59294..825d39c 100644
--- a/chrome/browser/chromeos/policy/device_local_account_policy_service.cc
+++ b/chrome/browser/chromeos/policy/device_local_account_policy_service.cc
@@ -101,13 +101,16 @@ std::string DeviceLocalAccountPolicyBroker::GetDisplayName() const {
DeviceLocalAccountPolicyService::PolicyBrokerWrapper::PolicyBrokerWrapper()
: parent(NULL), broker(NULL) {}
+DeviceLocalAccountPolicyService::PolicyBrokerWrapper::~PolicyBrokerWrapper() {}
+
DeviceLocalAccountPolicyBroker*
DeviceLocalAccountPolicyService::PolicyBrokerWrapper::GetBroker() {
if (!broker) {
scoped_ptr<DeviceLocalAccountPolicyStore> store(
new DeviceLocalAccountPolicyStore(account_id,
parent->session_manager_client_,
- parent->device_settings_service_));
+ parent->device_settings_service_,
+ parent->background_task_runner_));
broker = new DeviceLocalAccountPolicyBroker(
user_id, store.Pass(), base::MessageLoopProxy::current());
broker->core()->store()->AddObserver(parent);
@@ -142,11 +145,13 @@ void DeviceLocalAccountPolicyService::PolicyBrokerWrapper::DeleteBroker() {
DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService(
chromeos::SessionManagerClient* session_manager_client,
chromeos::DeviceSettingsService* device_settings_service,
- chromeos::CrosSettings* cros_settings)
+ chromeos::CrosSettings* cros_settings,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner)
: session_manager_client_(session_manager_client),
device_settings_service_(device_settings_service),
cros_settings_(cros_settings),
device_management_service_(NULL),
+ background_task_runner_(background_task_runner),
cros_settings_callback_factory_(this) {
local_accounts_subscription_ = cros_settings_->AddSettingsObserver(
chromeos::kAccountsPrefDeviceLocalAccounts,
diff --git a/chrome/browser/chromeos/policy/device_local_account_policy_service.h b/chrome/browser/chromeos/policy/device_local_account_policy_service.h
index 02b82f4..73b367e 100644
--- a/chrome/browser/chromeos/policy/device_local_account_policy_service.h
+++ b/chrome/browser/chromeos/policy/device_local_account_policy_service.h
@@ -92,7 +92,8 @@ class DeviceLocalAccountPolicyService : public CloudPolicyStore::Observer {
DeviceLocalAccountPolicyService(
chromeos::SessionManagerClient* session_manager_client,
chromeos::DeviceSettingsService* device_settings_service,
- chromeos::CrosSettings* cros_settings);
+ chromeos::CrosSettings* cros_settings,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
virtual ~DeviceLocalAccountPolicyService();
// Initializes the cloud policy service connection.
@@ -119,6 +120,7 @@ class DeviceLocalAccountPolicyService : public CloudPolicyStore::Observer {
private:
struct PolicyBrokerWrapper {
PolicyBrokerWrapper();
+ ~PolicyBrokerWrapper();
// Return the |broker|, creating it first if necessary.
DeviceLocalAccountPolicyBroker* GetBroker();
@@ -137,6 +139,7 @@ class DeviceLocalAccountPolicyService : public CloudPolicyStore::Observer {
std::string account_id;
DeviceLocalAccountPolicyService* parent;
DeviceLocalAccountPolicyBroker* broker;
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner;
};
typedef std::map<std::string, PolicyBrokerWrapper> PolicyBrokerMap;
@@ -168,6 +171,8 @@ class DeviceLocalAccountPolicyService : public CloudPolicyStore::Observer {
scoped_ptr<chromeos::CrosSettings::ObserverSubscription>
local_accounts_subscription_;
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
+
// Weak pointer factory for cros_settings_->PrepareTrustedValues() callbacks.
base::WeakPtrFactory<DeviceLocalAccountPolicyService>
cros_settings_callback_factory_;
diff --git a/chrome/browser/chromeos/policy/device_local_account_policy_service_unittest.cc b/chrome/browser/chromeos/policy/device_local_account_policy_service_unittest.cc
index 8312db9..8191a7a 100644
--- a/chrome/browser/chromeos/policy/device_local_account_policy_service_unittest.cc
+++ b/chrome/browser/chromeos/policy/device_local_account_policy_service_unittest.cc
@@ -51,7 +51,8 @@ class DeviceLocalAccountPolicyServiceTest
cros_settings_(&device_settings_service_),
service_(&device_settings_test_helper_,
&device_settings_service_,
- &cros_settings_) {}
+ &cros_settings_,
+ loop_.message_loop_proxy()) {}
virtual void SetUp() OVERRIDE {
DeviceSettingsTestBase::SetUp();
diff --git a/chrome/browser/chromeos/policy/device_local_account_policy_store.cc b/chrome/browser/chromeos/policy/device_local_account_policy_store.cc
index 898733a..553d5cf 100644
--- a/chrome/browser/chromeos/policy/device_local_account_policy_store.cc
+++ b/chrome/browser/chromeos/policy/device_local_account_policy_store.cc
@@ -23,8 +23,10 @@ namespace policy {
DeviceLocalAccountPolicyStore::DeviceLocalAccountPolicyStore(
const std::string& account_id,
chromeos::SessionManagerClient* session_manager_client,
- chromeos::DeviceSettingsService* device_settings_service)
- : account_id_(account_id),
+ chromeos::DeviceSettingsService* device_settings_service,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner)
+ : UserCloudPolicyStoreBase(background_task_runner),
+ account_id_(account_id),
session_manager_client_(session_manager_client),
device_settings_service_(device_settings_service),
weak_factory_(this) {}
@@ -169,7 +171,8 @@ void DeviceLocalAccountPolicyStore::Validate(
}
scoped_ptr<UserCloudPolicyValidator> validator(
- UserCloudPolicyValidator::Create(policy_response.Pass()));
+ UserCloudPolicyValidator::Create(policy_response.Pass(),
+ background_task_runner()));
validator->ValidateUsername(account_id_);
validator->ValidatePolicyType(dm_protocol::kChromePublicAccountPolicyType);
validator->ValidateAgainstCurrentPolicy(
diff --git a/chrome/browser/chromeos/policy/device_local_account_policy_store.h b/chrome/browser/chromeos/policy/device_local_account_policy_store.h
index 9036bb6..3af5134 100644
--- a/chrome/browser/chromeos/policy/device_local_account_policy_store.h
+++ b/chrome/browser/chromeos/policy/device_local_account_policy_store.h
@@ -9,12 +9,17 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/policy/cloud/cloud_policy_validator.h"
#include "chrome/browser/policy/cloud/user_cloud_policy_store_base.h"
+namespace base {
+class SequencedTaskRunner;
+}
+
namespace chromeos {
class DeviceSettingsService;
class SessionManagerClient;
@@ -36,7 +41,8 @@ class DeviceLocalAccountPolicyStore
DeviceLocalAccountPolicyStore(
const std::string& account_id,
chromeos::SessionManagerClient* client,
- chromeos::DeviceSettingsService* device_settings_service);
+ chromeos::DeviceSettingsService* device_settings_service,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
virtual ~DeviceLocalAccountPolicyStore();
const std::string& account_id() const { return account_id_; }
@@ -76,6 +82,8 @@ class DeviceLocalAccountPolicyStore
chromeos::SessionManagerClient* session_manager_client_;
chromeos::DeviceSettingsService* device_settings_service_;
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
+
base::WeakPtrFactory<DeviceLocalAccountPolicyStore> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStore);
diff --git a/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc b/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
index c4990df..182b46a 100644
--- a/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
+++ b/chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc
@@ -33,6 +33,7 @@ EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS(
DeviceCloudPolicyStoreChromeOS* store,
EnterpriseInstallAttributes* install_attributes,
scoped_ptr<CloudPolicyClient> client,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner,
const std::string& auth_token,
const std::string& client_id,
bool is_auto_enrollment,
@@ -42,6 +43,7 @@ EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS(
: store_(store),
install_attributes_(install_attributes),
client_(client.Pass()),
+ background_task_runner_(background_task_runner),
auth_token_(auth_token),
client_id_(client_id),
is_auto_enrollment_(is_auto_enrollment),
@@ -94,7 +96,8 @@ void EnrollmentHandlerChromeOS::OnPolicyFetched(CloudPolicyClient* client) {
scoped_ptr<DeviceCloudPolicyValidator> validator(
DeviceCloudPolicyValidator::Create(
scoped_ptr<em::PolicyFetchResponse>(
- new em::PolicyFetchResponse(*policy))));
+ new em::PolicyFetchResponse(*policy)),
+ background_task_runner_));
validator->ValidateTimestamp(base::Time(), base::Time::NowFromSystemTime(),
CloudPolicyValidatorBase::TIMESTAMP_REQUIRED);
diff --git a/chrome/browser/chromeos/policy/enrollment_handler_chromeos.h b/chrome/browser/chromeos/policy/enrollment_handler_chromeos.h
index c470e08..74b0fd1 100644
--- a/chrome/browser/chromeos/policy/enrollment_handler_chromeos.h
+++ b/chrome/browser/chromeos/policy/enrollment_handler_chromeos.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
@@ -18,6 +19,10 @@
#include "chrome/browser/policy/cloud/cloud_policy_store.h"
#include "google_apis/gaia/gaia_oauth_client.h"
+namespace base {
+class SequencedTaskRunner;
+}
+
namespace enterprise_management {
class PolicyFetchResponse;
}
@@ -49,15 +54,17 @@ class EnrollmentHandlerChromeOS : public CloudPolicyClient::Observer,
// are acceptable. If the mode specified by the server is not acceptable,
// enrollment will fail with an EnrollmentStatus indicating
// STATUS_REGISTRATION_BAD_MODE.
- EnrollmentHandlerChromeOS(DeviceCloudPolicyStoreChromeOS* store,
- EnterpriseInstallAttributes* install_attributes,
- scoped_ptr<CloudPolicyClient> client,
- const std::string& auth_token,
- const std::string& client_id,
- bool is_auto_enrollment,
- const std::string& requisition,
- const AllowedDeviceModes& allowed_device_modes,
- const EnrollmentCallback& completion_callback);
+ EnrollmentHandlerChromeOS(
+ DeviceCloudPolicyStoreChromeOS* store,
+ EnterpriseInstallAttributes* install_attributes,
+ scoped_ptr<CloudPolicyClient> client,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner,
+ const std::string& auth_token,
+ const std::string& client_id,
+ bool is_auto_enrollment,
+ const std::string& requisition,
+ const AllowedDeviceModes& allowed_device_modes,
+ const EnrollmentCallback& completion_callback);
virtual ~EnrollmentHandlerChromeOS();
// Starts the enrollment process and reports the result to
@@ -138,6 +145,7 @@ class EnrollmentHandlerChromeOS : public CloudPolicyClient::Observer,
DeviceCloudPolicyStoreChromeOS* store_;
EnterpriseInstallAttributes* install_attributes_;
scoped_ptr<CloudPolicyClient> client_;
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
scoped_ptr<gaia::GaiaOAuthClient> gaia_oauth_client_;
std::string auth_token_;
diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc b/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc
index 4cb9987..a8fdf59 100644
--- a/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc
+++ b/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc
@@ -78,8 +78,10 @@ UserCloudPolicyManagerChromeOS*
scoped_ptr<UserCloudPolicyManagerChromeOS>
UserCloudPolicyManagerFactoryChromeOS::CreateForProfile(
Profile* profile,
- bool force_immediate_load) {
- return GetInstance()->CreateManagerForProfile(profile, force_immediate_load);
+ bool force_immediate_load,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner) {
+ return GetInstance()->CreateManagerForProfile(
+ profile, force_immediate_load, background_task_runner);
}
UserCloudPolicyManagerFactoryChromeOS::UserCloudPolicyManagerFactoryChromeOS()
@@ -102,7 +104,8 @@ UserCloudPolicyManagerChromeOS*
scoped_ptr<UserCloudPolicyManagerChromeOS>
UserCloudPolicyManagerFactoryChromeOS::CreateManagerForProfile(
Profile* profile,
- bool force_immediate_load) {
+ bool force_immediate_load,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner) {
const CommandLine* command_line = CommandLine::ForCurrentProcess();
// Don't initialize cloud policy for the signin profile.
if (chromeos::ProfileHelper::IsSigninProfile(profile))
@@ -156,6 +159,7 @@ scoped_ptr<UserCloudPolicyManagerChromeOS>
new UserCloudPolicyStoreChromeOS(
chromeos::DBusThreadManager::Get()->GetCryptohomeClient(),
chromeos::DBusThreadManager::Get()->GetSessionManagerClient(),
+ background_task_runner,
username, policy_key_dir, token_cache_file, policy_cache_file));
scoped_refptr<base::SequencedTaskRunner> backend_task_runner =
diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h b/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h
index 471bd61..d746067 100644
--- a/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h
+++ b/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h
@@ -8,11 +8,16 @@
#include <map>
#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
#include "components/browser_context_keyed_service/browser_context_keyed_base_factory.h"
class Profile;
+namespace base {
+class SequencedTaskRunner;
+}
+
namespace content {
class BrowserContext;
}
@@ -53,7 +58,8 @@ class UserCloudPolicyManagerFactoryChromeOS
// UserCloudPolicyStore at startup.
static scoped_ptr<UserCloudPolicyManagerChromeOS> CreateForProfile(
Profile* profile,
- bool force_immediate_load);
+ bool force_immediate_load,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
private:
friend struct DefaultSingletonTraits<UserCloudPolicyManagerFactoryChromeOS>;
@@ -65,7 +71,8 @@ class UserCloudPolicyManagerFactoryChromeOS
UserCloudPolicyManagerChromeOS* GetManagerForProfile(Profile* profile);
scoped_ptr<UserCloudPolicyManagerChromeOS> CreateManagerForProfile(
Profile* profile,
- bool force_immediate_load);
+ bool force_immediate_load,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
// BrowserContextKeyedBaseFactory:
virtual void BrowserContextShutdown(
diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.cc b/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.cc
index cce3d66..323baec 100644
--- a/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.cc
+++ b/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.cc
@@ -8,9 +8,10 @@
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/file_util.h"
+#include "base/location.h"
#include "base/logging.h"
-#include "base/memory/ref_counted.h"
#include "base/metrics/histogram.h"
+#include "base/sequenced_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/chromeos/policy/user_policy_disk_cache.h"
@@ -18,7 +19,6 @@
#include "chrome/browser/policy/proto/cloud/device_management_local.pb.h"
#include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/session_manager_client.h"
-#include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "policy/proto/cloud_policy.pb.h"
@@ -59,8 +59,10 @@ class LegacyPolicyCacheLoader : public UserPolicyTokenLoader::Delegate,
CloudPolicyStore::Status,
scoped_ptr<em::PolicyFetchResponse>)> Callback;
- LegacyPolicyCacheLoader(const base::FilePath& token_cache_file,
- const base::FilePath& policy_cache_file);
+ LegacyPolicyCacheLoader(
+ const base::FilePath& token_cache_file,
+ const base::FilePath& policy_cache_file,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
virtual ~LegacyPolicyCacheLoader();
// Starts loading, and reports the result to |callback| when done.
@@ -102,14 +104,17 @@ class LegacyPolicyCacheLoader : public UserPolicyTokenLoader::Delegate,
LegacyPolicyCacheLoader::LegacyPolicyCacheLoader(
const base::FilePath& token_cache_file,
- const base::FilePath& policy_cache_file)
+ const base::FilePath& policy_cache_file,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner)
: weak_factory_(this),
has_policy_(false),
status_(CloudPolicyStore::STATUS_OK) {
token_loader_ = new UserPolicyTokenLoader(weak_factory_.GetWeakPtr(),
- token_cache_file);
+ token_cache_file,
+ background_task_runner);
policy_cache_ = new UserPolicyDiskCache(weak_factory_.GetWeakPtr(),
- policy_cache_file);
+ policy_cache_file,
+ background_task_runner);
}
LegacyPolicyCacheLoader::~LegacyPolicyCacheLoader() {}
@@ -165,18 +170,21 @@ CloudPolicyStore::Status LegacyPolicyCacheLoader::TranslateLoadResult(
UserCloudPolicyStoreChromeOS::UserCloudPolicyStoreChromeOS(
chromeos::CryptohomeClient* cryptohome_client,
chromeos::SessionManagerClient* session_manager_client,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner,
const std::string& username,
const base::FilePath& user_policy_key_dir,
const base::FilePath& legacy_token_cache_file,
const base::FilePath& legacy_policy_cache_file)
- : cryptohome_client_(cryptohome_client),
+ : UserCloudPolicyStoreBase(background_task_runner),
+ cryptohome_client_(cryptohome_client),
session_manager_client_(session_manager_client),
username_(username),
user_policy_key_dir_(user_policy_key_dir),
weak_factory_(this),
legacy_cache_dir_(legacy_token_cache_file.DirName()),
legacy_loader_(new LegacyPolicyCacheLoader(legacy_token_cache_file,
- legacy_policy_cache_file)),
+ legacy_policy_cache_file,
+ background_task_runner)),
legacy_caches_loaded_(false),
policy_key_loaded_(false) {}
@@ -388,7 +396,7 @@ void UserCloudPolicyStoreChromeOS::OnRetrievedPolicyValidated(
// Policy has been loaded successfully. This indicates that new-style policy
// is working, so the legacy cache directory can be removed.
if (!legacy_cache_dir_.empty()) {
- content::BrowserThread::PostBlockingPoolTask(
+ background_task_runner()->PostTask(
FROM_HERE,
base::Bind(&UserCloudPolicyStoreChromeOS::RemoveLegacyCacheDir,
legacy_cache_dir_));
@@ -468,7 +476,7 @@ void UserCloudPolicyStoreChromeOS::RemoveLegacyCacheDir(
void UserCloudPolicyStoreChromeOS::ReloadPolicyKey(
const base::Closure& callback) {
std::vector<uint8>* key = new std::vector<uint8>();
- content::BrowserThread::PostBlockingPoolTaskAndReply(
+ background_task_runner()->PostTaskAndReply(
FROM_HERE,
base::Bind(&UserCloudPolicyStoreChromeOS::LoadPolicyKey,
policy_key_path_,
diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h b/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h
index 913235d..e1939f8 100644
--- a/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h
+++ b/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h
@@ -11,12 +11,17 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/policy/cloud/cloud_policy_validator.h"
#include "chrome/browser/policy/cloud/user_cloud_policy_store_base.h"
#include "chromeos/dbus/dbus_method_call_status.h"
+namespace base {
+class SequencedTaskRunner;
+}
+
namespace chromeos {
class CryptohomeClient;
class SessionManagerClient;
@@ -38,6 +43,7 @@ class UserCloudPolicyStoreChromeOS : public UserCloudPolicyStoreBase {
UserCloudPolicyStoreChromeOS(
chromeos::CryptohomeClient* cryptohome_client,
chromeos::SessionManagerClient* session_manager_client,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner,
const std::string& username,
const base::FilePath& user_policy_key_dir,
const base::FilePath& legacy_token_cache_file,
diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos_unittest.cc b/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos_unittest.cc
index 994d52f..0f5ab74 100644
--- a/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos_unittest.cc
+++ b/chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos_unittest.cc
@@ -19,7 +19,6 @@
#include "chrome/browser/policy/proto/cloud/device_management_local.pb.h"
#include "chromeos/dbus/mock_cryptohome_client.h"
#include "chromeos/dbus/mock_session_manager_client.h"
-#include "content/public/test/test_browser_thread.h"
#include "policy/policy_constants.h"
#include "policy/proto/cloud_policy.pb.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -53,9 +52,7 @@ ACTION_P2(SendSanitizedUsername, call_status, sanitized_username) {
class UserCloudPolicyStoreChromeOSTest : public testing::Test {
protected:
UserCloudPolicyStoreChromeOSTest()
- : loop_(base::MessageLoop::TYPE_UI),
- ui_thread_(content::BrowserThread::UI, &loop_),
- file_thread_(content::BrowserThread::FILE, &loop_) {}
+ : loop_(base::MessageLoop::TYPE_UI) {}
virtual void SetUp() OVERRIDE {
EXPECT_CALL(cryptohome_client_,
@@ -68,6 +65,7 @@ class UserCloudPolicyStoreChromeOSTest : public testing::Test {
ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir());
store_.reset(new UserCloudPolicyStoreChromeOS(&cryptohome_client_,
&session_manager_client_,
+ loop_.message_loop_proxy(),
PolicyBuilder::kFakeUsername,
user_policy_dir(),
token_file(),
@@ -202,7 +200,6 @@ class UserCloudPolicyStoreChromeOSTest : public testing::Test {
void RunUntilIdle() {
loop_.RunUntilIdle();
- content::BrowserThread::GetBlockingPool()->FlushForTesting();
loop_.RunUntilIdle();
}
@@ -231,8 +228,6 @@ class UserCloudPolicyStoreChromeOSTest : public testing::Test {
scoped_ptr<UserCloudPolicyStoreChromeOS> store_;
private:
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_thread_;
base::ScopedTempDir tmp_dir_;
DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStoreChromeOSTest);
diff --git a/chrome/browser/chromeos/policy/user_policy_disk_cache.cc b/chrome/browser/chromeos/policy/user_policy_disk_cache.cc
index e9249cd..d22cddf 100644
--- a/chrome/browser/chromeos/policy/user_policy_disk_cache.cc
+++ b/chrome/browser/chromeos/policy/user_policy_disk_cache.cc
@@ -7,63 +7,47 @@
#include "base/bind.h"
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h"
+#include "base/sequenced_task_runner.h"
#include "chrome/browser/policy/cloud/enterprise_metrics.h"
#include "chrome/browser/policy/proto/cloud/device_management_local.pb.h"
#include "content/public/browser/browser_thread.h"
-using content::BrowserThread;
-
namespace em = enterprise_management;
-namespace {
-
-// Other places can sample on the same UMA counter, so make sure they all do
-// it on the same thread (UI).
-void SampleUMAOnUIThread(policy::MetricPolicy sample) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- UMA_HISTOGRAM_ENUMERATION(policy::kMetricPolicy, sample,
- policy::kMetricPolicySize);
-}
-
-void SampleUMA(policy::MetricPolicy sample) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&SampleUMAOnUIThread, sample));
-}
-
-} // namespace
-
namespace policy {
UserPolicyDiskCache::Delegate::~Delegate() {}
UserPolicyDiskCache::UserPolicyDiskCache(
const base::WeakPtr<Delegate>& delegate,
- const base::FilePath& backing_file_path)
+ const base::FilePath& backing_file_path,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner)
: delegate_(delegate),
- backing_file_path_(backing_file_path) {}
+ backing_file_path_(backing_file_path),
+ origin_task_runner_(base::MessageLoopProxy::current()),
+ background_task_runner_(background_task_runner) {}
void UserPolicyDiskCache::Load() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- bool ret = BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&UserPolicyDiskCache::LoadOnFileThread, this));
+ DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
+ bool ret = background_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&UserPolicyDiskCache::LoadOnFileThread, this));
DCHECK(ret);
}
void UserPolicyDiskCache::Store(
const em::CachedCloudPolicyResponse& policy) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
+ DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
+ background_task_runner_->PostTask(
+ FROM_HERE,
base::Bind(&UserPolicyDiskCache::StoreOnFileThread, this, policy));
}
UserPolicyDiskCache::~UserPolicyDiskCache() {}
void UserPolicyDiskCache::LoadOnFileThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ DCHECK(background_task_runner_->RunsTasksOnCurrentThread());
em::CachedCloudPolicyResponse cached_response;
if (!base::PathExists(backing_file_path_)) {
@@ -94,26 +78,31 @@ void UserPolicyDiskCache::LoadOnFileThread() {
void UserPolicyDiskCache::LoadDone(
LoadResult result,
const em::CachedCloudPolicyResponse& policy) {
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&UserPolicyDiskCache::ReportResultOnUIThread, this,
- result, policy));
+ origin_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &UserPolicyDiskCache::ReportResultOnUIThread, this, result, policy));
}
void UserPolicyDiskCache::ReportResultOnUIThread(
LoadResult result,
const em::CachedCloudPolicyResponse& policy) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
switch (result) {
case LOAD_RESULT_NOT_FOUND:
break;
case LOAD_RESULT_READ_ERROR:
case LOAD_RESULT_PARSE_ERROR:
- SampleUMAOnUIThread(kMetricPolicyLoadFailed);
+ UMA_HISTOGRAM_ENUMERATION(policy::kMetricPolicy,
+ kMetricPolicyLoadFailed,
+ policy::kMetricPolicySize);
break;
case LOAD_RESULT_SUCCESS:
- SampleUMAOnUIThread(kMetricPolicyLoadSucceeded);
+ UMA_HISTOGRAM_ENUMERATION(policy::kMetricPolicy,
+ kMetricPolicyLoadSucceeded,
+ policy::kMetricPolicySize);
+ break;
}
if (delegate_.get())
@@ -122,28 +111,36 @@ void UserPolicyDiskCache::ReportResultOnUIThread(
void UserPolicyDiskCache::StoreOnFileThread(
const em::CachedCloudPolicyResponse& policy) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ DCHECK(background_task_runner_->RunsTasksOnCurrentThread());
std::string data;
if (!policy.SerializeToString(&data)) {
LOG(WARNING) << "Failed to serialize policy data";
- SampleUMA(kMetricPolicyStoreFailed);
+ UMA_HISTOGRAM_ENUMERATION(policy::kMetricPolicy,
+ kMetricPolicyStoreFailed,
+ policy::kMetricPolicySize);
return;
}
if (!file_util::CreateDirectory(backing_file_path_.DirName())) {
LOG(WARNING) << "Failed to create directory "
<< backing_file_path_.DirName().value();
- SampleUMA(kMetricPolicyStoreFailed);
+ UMA_HISTOGRAM_ENUMERATION(policy::kMetricPolicy,
+ kMetricPolicyStoreFailed,
+ policy::kMetricPolicySize);
return;
}
int size = data.size();
if (file_util::WriteFile(backing_file_path_, data.c_str(), size) != size) {
LOG(WARNING) << "Failed to write " << backing_file_path_.value();
- SampleUMA(kMetricPolicyStoreFailed);
+ UMA_HISTOGRAM_ENUMERATION(policy::kMetricPolicy,
+ kMetricPolicyStoreFailed,
+ policy::kMetricPolicySize);
return;
}
- SampleUMA(kMetricPolicyStoreSucceeded);
+ UMA_HISTOGRAM_ENUMERATION(policy::kMetricPolicy,
+ kMetricPolicyStoreSucceeded,
+ policy::kMetricPolicySize);
}
} // namespace policy
diff --git a/chrome/browser/chromeos/policy/user_policy_disk_cache.h b/chrome/browser/chromeos/policy/user_policy_disk_cache.h
index 2c41688..b22ad90 100644
--- a/chrome/browser/chromeos/policy/user_policy_disk_cache.h
+++ b/chrome/browser/chromeos/policy/user_policy_disk_cache.h
@@ -10,6 +10,10 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
+namespace base {
+class SequencedTaskRunner;
+}
+
namespace enterprise_management {
class CachedCloudPolicyResponse;
}
@@ -43,8 +47,10 @@ class UserPolicyDiskCache
const enterprise_management::CachedCloudPolicyResponse& policy) = 0;
};
- UserPolicyDiskCache(const base::WeakPtr<Delegate>& delegate,
- const base::FilePath& backing_file_path);
+ UserPolicyDiskCache(
+ const base::WeakPtr<Delegate>& delegate,
+ const base::FilePath& backing_file_path,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
// Starts reading the policy cache from disk. Passes the read policy
// information back to the hosting UserPolicyCache after a successful cache
@@ -76,6 +82,8 @@ class UserPolicyDiskCache
base::WeakPtr<Delegate> delegate_;
const base::FilePath backing_file_path_;
+ scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
DISALLOW_COPY_AND_ASSIGN(UserPolicyDiskCache);
};
diff --git a/chrome/browser/chromeos/policy/user_policy_token_loader.cc b/chrome/browser/chromeos/policy/user_policy_token_loader.cc
index 1501e6c..0df0966 100644
--- a/chrome/browser/chromeos/policy/user_policy_token_loader.cc
+++ b/chrome/browser/chromeos/policy/user_policy_token_loader.cc
@@ -6,30 +6,12 @@
#include "base/bind.h"
#include "base/file_util.h"
+#include "base/location.h"
+#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h"
+#include "base/sequenced_task_runner.h"
#include "chrome/browser/policy/cloud/enterprise_metrics.h"
#include "chrome/browser/policy/proto/cloud/device_management_local.pb.h"
-#include "content/public/browser/browser_thread.h"
-
-using content::BrowserThread;
-
-namespace {
-
-// Other places can sample on the same UMA counter, so make sure they all do
-// it on the same thread (UI).
-void SampleUMAOnUIThread(policy::MetricToken sample) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- UMA_HISTOGRAM_ENUMERATION(policy::kMetricToken, sample,
- policy::kMetricTokenSize);
-}
-
-void SampleUMA(policy::MetricToken sample) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&SampleUMAOnUIThread, sample));
-}
-
-} // namespace
namespace policy {
@@ -39,22 +21,25 @@ UserPolicyTokenLoader::Delegate::~Delegate() {}
UserPolicyTokenLoader::UserPolicyTokenLoader(
const base::WeakPtr<Delegate>& delegate,
- const base::FilePath& cache_file)
+ const base::FilePath& cache_file,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner)
: delegate_(delegate),
- cache_file_(cache_file) {}
+ cache_file_(cache_file),
+ origin_task_runner_(base::MessageLoopProxy::current()),
+ background_task_runner_(background_task_runner) {}
void UserPolicyTokenLoader::Load() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&UserPolicyTokenLoader::LoadOnFileThread, this));
+ DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
+ background_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&UserPolicyTokenLoader::LoadOnBackgroundThread, this));
}
UserPolicyTokenLoader::~UserPolicyTokenLoader() {
}
-void UserPolicyTokenLoader::LoadOnFileThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+void UserPolicyTokenLoader::LoadOnBackgroundThread() {
+ DCHECK(background_task_runner_->RunsTasksOnCurrentThread());
std::string device_token;
std::string device_id;
@@ -65,23 +50,27 @@ void UserPolicyTokenLoader::LoadOnFileThread() {
device_credentials.ParseFromArray(data.c_str(), data.size())) {
device_token = device_credentials.device_token();
device_id = device_credentials.device_id();
- SampleUMA(kMetricTokenLoadSucceeded);
+ UMA_HISTOGRAM_ENUMERATION(policy::kMetricToken,
+ kMetricTokenLoadSucceeded,
+ policy::kMetricTokenSize);
} else {
- SampleUMA(kMetricTokenLoadFailed);
+ UMA_HISTOGRAM_ENUMERATION(policy::kMetricToken,
+ kMetricTokenLoadFailed,
+ policy::kMetricTokenSize);
}
}
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&UserPolicyTokenLoader::NotifyOnUIThread,
+ origin_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&UserPolicyTokenLoader::NotifyOnOriginThread,
this,
device_token,
device_id));
}
-void UserPolicyTokenLoader::NotifyOnUIThread(const std::string& token,
- const std::string& device_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+void UserPolicyTokenLoader::NotifyOnOriginThread(const std::string& token,
+ const std::string& device_id) {
+ DCHECK(origin_task_runner_->RunsTasksOnCurrentThread());
if (delegate_.get())
delegate_->OnTokenLoaded(token, device_id);
}
diff --git a/chrome/browser/chromeos/policy/user_policy_token_loader.h b/chrome/browser/chromeos/policy/user_policy_token_loader.h
index f213b00..919e4ae 100644
--- a/chrome/browser/chromeos/policy/user_policy_token_loader.h
+++ b/chrome/browser/chromeos/policy/user_policy_token_loader.h
@@ -12,6 +12,10 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
+namespace base {
+class SequencedTaskRunner;
+}
+
namespace policy {
// Handles disk access and threading details for loading and storing tokens.
@@ -29,8 +33,10 @@ class UserPolicyTokenLoader
const std::string& device_id) = 0;
};
- UserPolicyTokenLoader(const base::WeakPtr<Delegate>& delegate,
- const base::FilePath& cache_file);
+ UserPolicyTokenLoader(
+ const base::WeakPtr<Delegate>& delegate,
+ const base::FilePath& cache_file,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
// Starts loading the disk cache. After the load is finished, the result is
// reported through the delegate.
@@ -40,12 +46,14 @@ class UserPolicyTokenLoader
friend class base::RefCountedThreadSafe<UserPolicyTokenLoader>;
~UserPolicyTokenLoader();
- void LoadOnFileThread();
- void NotifyOnUIThread(const std::string& token,
+ void LoadOnBackgroundThread();
+ void NotifyOnOriginThread(const std::string& token,
const std::string& device_id);
const base::WeakPtr<Delegate> delegate_;
const base::FilePath cache_file_;
+ scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
DISALLOW_COPY_AND_ASSIGN(UserPolicyTokenLoader);
};
diff --git a/chrome/browser/chromeos/settings/session_manager_operation.cc b/chrome/browser/chromeos/settings/session_manager_operation.cc
index b31608d..934c7a2 100644
--- a/chrome/browser/chromeos/settings/session_manager_operation.cc
+++ b/chrome/browser/chromeos/settings/session_manager_operation.cc
@@ -143,8 +143,16 @@ void SessionManagerOperation::ValidateDeviceSettings(
return;
}
+ base::SequencedWorkerPool* pool =
+ content::BrowserThread::GetBlockingPool();
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner =
+ pool->GetSequencedTaskRunnerWithShutdownBehavior(
+ pool->GetSequenceToken(),
+ base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
+
policy::DeviceCloudPolicyValidator* validator =
- policy::DeviceCloudPolicyValidator::Create(policy.Pass());
+ policy::DeviceCloudPolicyValidator::Create(policy.Pass(),
+ background_task_runner);
// Policy auto-generated by session manager doesn't include a timestamp, so we
// need to allow missing timestamps.
diff --git a/chrome/browser/chromeos/settings/session_manager_operation_unittest.cc b/chrome/browser/chromeos/settings/session_manager_operation_unittest.cc
index 98d2f4e..1023aa0 100644
--- a/chrome/browser/chromeos/settings/session_manager_operation_unittest.cc
+++ b/chrome/browser/chromeos/settings/session_manager_operation_unittest.cc
@@ -252,7 +252,8 @@ TEST_F(SessionManagerOperationTest, SignAndStoreSettings) {
policy_response->ParseFromString(
device_settings_test_helper_.policy_blob()));
policy::DeviceCloudPolicyValidator* validator =
- policy::DeviceCloudPolicyValidator::Create(policy_response.Pass());
+ policy::DeviceCloudPolicyValidator::Create(
+ policy_response.Pass(), message_loop_.message_loop_proxy());
validator->ValidateUsername(policy_.policy_data().username());
validator->ValidateTimestamp(
before,
diff --git a/chrome/browser/policy/browser_policy_connector.cc b/chrome/browser/policy/browser_policy_connector.cc
index 47c5f15..bc92e58 100644
--- a/chrome/browser/policy/browser_policy_connector.cc
+++ b/chrome/browser/policy/browser_policy_connector.cc
@@ -22,6 +22,7 @@
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/sys_info.h"
+#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/policy/async_policy_provider.h"
#include "chrome/browser/policy/cloud/cloud_policy_client.h"
@@ -99,6 +100,14 @@ const char kDefaultDeviceManagementServerUrl[] =
// Used in BrowserPolicyConnector::SetPolicyProviderForTesting.
ConfigurationPolicyProvider* g_testing_provider = NULL;
+// Helper that returns a new SequencedTaskRunner backed by the blocking pool.
+// Each SequencedTaskRunner returned is independent from the others.
+scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() {
+ base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
+ CHECK(pool);
+ return pool->GetSequencedTaskRunnerWithShutdownBehavior(
+ pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
+}
#if defined(OS_MACOSX) && !defined(OS_IOS)
base::FilePath GetManagedPolicyPath() {
@@ -217,11 +226,13 @@ BrowserPolicyConnector::BrowserPolicyConnector()
scoped_ptr<DeviceCloudPolicyStoreChromeOS> device_cloud_policy_store(
new DeviceCloudPolicyStoreChromeOS(
chromeos::DeviceSettingsService::Get(),
- install_attributes_.get()));
+ install_attributes_.get(),
+ GetBackgroundTaskRunner()));
device_cloud_policy_manager_.reset(
new DeviceCloudPolicyManagerChromeOS(
device_cloud_policy_store.Pass(),
base::MessageLoopProxy::current(),
+ GetBackgroundTaskRunner(),
install_attributes_.get()));
}
#endif
@@ -282,7 +293,8 @@ void BrowserPolicyConnector::Init(
new DeviceLocalAccountPolicyService(
chromeos::DBusThreadManager::Get()->GetSessionManagerClient(),
chromeos::DeviceSettingsService::Get(),
- chromeos::CrosSettings::Get()));
+ chromeos::CrosSettings::Get(),
+ GetBackgroundTaskRunner()));
device_local_account_policy_service_->Connect(
device_management_service_.get());
}
diff --git a/chrome/browser/policy/cloud/DEPS b/chrome/browser/policy/cloud/DEPS
index 6206534..cab579f 100644
--- a/chrome/browser/policy/cloud/DEPS
+++ b/chrome/browser/policy/cloud/DEPS
@@ -49,27 +49,7 @@ specific_include_rules = {
"+chrome/browser/invalidation/fake_invalidation_service.h",
],
- r"cloud_policy_refresh_scheduler\.cc": [
- "+chrome/browser/chrome_notification_types.h",
- "+content/public/browser/notification_details.h",
- ],
-
- r"cloud_policy_validator\.cc": [
- "+content/public/browser/browser_thread.h",
- ],
-
- r"cloud_policy_validator_unittest\.cc": [
- "+content/public/test/test_browser_thread.h",
- ],
-
- r"component_cloud_policy_service_unittest\.cc": [
- "+content/public/browser/browser_thread.h",
- "+content/public/test/test_browser_thread.h",
- ],
-
r"test_request_interceptor\.cc": [
- "+content/public/browser/browser_thread.h",
- "+content/public/test/test_utils.h",
"+content/test/net/url_request_mock_http_job.h",
],
@@ -99,7 +79,6 @@ specific_include_rules = {
"+chrome/browser/profiles/profile.h",
"+chrome/browser/signin/signin_manager.h",
"+chrome/browser/signin/signin_manager_factory.h",
- "+content/public/browser/browser_thread.h",
],
r"user_cloud_policy_store_unittest\.cc": [
@@ -108,6 +87,5 @@ specific_include_rules = {
"+chrome/browser/signin/signin_manager_factory.h",
"+chrome/common/pref_names.h",
"+chrome/test/base/testing_profile.h",
- "+content/public/test/test_browser_thread.h",
],
}
diff --git a/chrome/browser/policy/cloud/cloud_policy_manager_browsertest.cc b/chrome/browser/policy/cloud/cloud_policy_manager_browsertest.cc
index 8c4967c..7e0085c 100644
--- a/chrome/browser/policy/cloud/cloud_policy_manager_browsertest.cc
+++ b/chrome/browser/policy/cloud/cloud_policy_manager_browsertest.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
+#include "content/public/browser/browser_thread.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request_context_getter.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -31,6 +32,7 @@
#include "chrome/browser/signin/signin_manager_factory.h"
#endif
+using content::BrowserThread;
using testing::AnyNumber;
using testing::InvokeWithoutArgs;
using testing::Mock;
@@ -57,7 +59,9 @@ class CloudPolicyManagerTest : public InProcessBrowserTest {
ASSERT_TRUE(PolicyServiceIsEmpty(g_browser_process->policy_service()))
<< "Pre-existing policies in this machine will make this test fail.";
- interceptor_.reset(new TestRequestInterceptor("localhost"));
+ interceptor_.reset(new TestRequestInterceptor(
+ "localhost",
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
BrowserPolicyConnector* connector =
g_browser_process->browser_policy_connector();
diff --git a/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.cc b/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.cc
index d548eab..aaf1c29 100644
--- a/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.cc
+++ b/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.cc
@@ -14,10 +14,8 @@
#include "base/sequenced_task_runner.h"
#include "base/time/default_tick_clock.h"
#include "base/time/tick_clock.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/policy/cloud/cloud_policy_constants.h"
#include "components/policy/core/common/policy_switches.h"
-#include "content/public/browser/notification_details.h"
namespace policy {
diff --git a/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h b/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h
index 675f964..a3d121b 100644
--- a/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h
+++ b/chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h
@@ -37,7 +37,7 @@ class CloudPolicyRefreshScheduler
static const int64 kRefreshDelayMinMs;
static const int64 kRefreshDelayMaxMs;
- // |client|, |store| and |prefs| pointers must stay valid throughout the
+ // |client| and |store| pointers must stay valid throughout the
// lifetime of CloudPolicyRefreshScheduler.
CloudPolicyRefreshScheduler(
CloudPolicyClient* client,
diff --git a/chrome/browser/policy/cloud/cloud_policy_validator.cc b/chrome/browser/policy/cloud/cloud_policy_validator.cc
index b45392e..71649ce 100644
--- a/chrome/browser/policy/cloud/cloud_policy_validator.cc
+++ b/chrome/browser/policy/cloud/cloud_policy_validator.cc
@@ -6,10 +6,10 @@
#include "base/bind_helpers.h"
#include "base/message_loop/message_loop.h"
+#include "base/sequenced_task_runner.h"
#include "base/stl_util.h"
#include "chrome/browser/policy/cloud/cloud_policy_constants.h"
#include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
-#include "content/public/browser/browser_thread.h"
#include "crypto/signature_verifier.h"
#include "google_apis/gaia/gaia_auth_util.h"
@@ -114,7 +114,8 @@ void CloudPolicyValidatorBase::ValidateAgainstCurrentPolicy(
CloudPolicyValidatorBase::CloudPolicyValidatorBase(
scoped_ptr<em::PolicyFetchResponse> policy_response,
- google::protobuf::MessageLite* payload)
+ google::protobuf::MessageLite* payload,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner)
: status_(VALIDATION_OK),
policy_(policy_response.Pass()),
payload_(payload),
@@ -123,12 +124,13 @@ CloudPolicyValidatorBase::CloudPolicyValidatorBase(
timestamp_not_after_(0),
timestamp_option_(TIMESTAMP_REQUIRED),
dm_token_option_(DM_TOKEN_REQUIRED),
- allow_key_rotation_(false) {}
+ allow_key_rotation_(false),
+ background_task_runner_(background_task_runner) {}
void CloudPolicyValidatorBase::PostValidationTask(
const base::Closure& completion_callback) {
- content::BrowserThread::PostTask(
- content::BrowserThread::FILE, FROM_HERE,
+ background_task_runner_->PostTask(
+ FROM_HERE,
base::Bind(&CloudPolicyValidatorBase::PerformValidation,
base::Passed(scoped_ptr<CloudPolicyValidatorBase>(this)),
base::MessageLoop::current()->message_loop_proxy(),
diff --git a/chrome/browser/policy/cloud/cloud_policy_validator.h b/chrome/browser/policy/cloud/cloud_policy_validator.h
index 2635e4a..5b6ed4b 100644
--- a/chrome/browser/policy/cloud/cloud_policy_validator.h
+++ b/chrome/browser/policy/cloud/cloud_policy_validator.h
@@ -13,6 +13,7 @@
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/sequenced_task_runner.h"
#include "base/time/time.h"
#include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h"
#include "policy/proto/cloud_policy.pb.h"
@@ -35,7 +36,7 @@ class PolicyFetchResponse;
namespace policy {
// Helper class that implements the gory details of validating a policy blob.
-// Since signature checks are expensive, validation can happen on the FILE
+// Since signature checks are expensive, validation can happen on a background
// thread. The pattern is to create a validator, configure its behavior through
// the ValidateXYZ() functions, and then call StartValidation(). Alternatively,
// RunValidation() can be used to perform validation on the current thread.
@@ -171,7 +172,8 @@ class CloudPolicyValidatorBase {
// valid for the lifetime of the validator.
CloudPolicyValidatorBase(
scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response,
- google::protobuf::MessageLite* payload);
+ google::protobuf::MessageLite* payload,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
// Posts an asynchronous calls to PerformValidation, which will eventually
// report its result via |completion_callback|.
@@ -237,6 +239,7 @@ class CloudPolicyValidatorBase {
std::string settings_entity_id_;
std::string key_;
bool allow_key_rotation_;
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
DISALLOW_COPY_AND_ASSIGN(CloudPolicyValidatorBase);
};
@@ -252,11 +255,15 @@ class CloudPolicyValidator : public CloudPolicyValidatorBase {
virtual ~CloudPolicyValidator() {}
// Creates a new validator.
+ // |background_task_runner| is optional; if RunValidation() is used directly
+ // and StartValidation() is not used then it can be NULL.
static CloudPolicyValidator<PayloadProto>* Create(
- scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response) {
+ scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner) {
return new CloudPolicyValidator(
policy_response.Pass(),
- scoped_ptr<PayloadProto>(new PayloadProto()));
+ scoped_ptr<PayloadProto>(new PayloadProto()),
+ background_task_runner);
}
scoped_ptr<PayloadProto>& payload() {
@@ -274,8 +281,11 @@ class CloudPolicyValidator : public CloudPolicyValidatorBase {
private:
CloudPolicyValidator(
scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response,
- scoped_ptr<PayloadProto> payload)
- : CloudPolicyValidatorBase(policy_response.Pass(), payload.get()),
+ scoped_ptr<PayloadProto> payload,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner)
+ : CloudPolicyValidatorBase(policy_response.Pass(),
+ payload.get(),
+ background_task_runner),
payload_(payload.Pass()) {}
scoped_ptr<PayloadProto> payload_;
diff --git a/chrome/browser/policy/cloud/cloud_policy_validator_unittest.cc b/chrome/browser/policy/cloud/cloud_policy_validator_unittest.cc
index 1efe9a6..88f9f48 100644
--- a/chrome/browser/policy/cloud/cloud_policy_validator_unittest.cc
+++ b/chrome/browser/policy/cloud/cloud_policy_validator_unittest.cc
@@ -7,11 +7,11 @@
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
+#include "base/message_loop/message_loop_proxy.h"
#include "base/strings/string_util.h"
#include "chrome/browser/policy/cloud/cloud_policy_constants.h"
#include "chrome/browser/policy/cloud/cloud_policy_validator.h"
#include "chrome/browser/policy/cloud/policy_builder.h"
-#include "content/public/test/test_browser_thread.h"
#include "crypto/rsa_private_key.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -39,8 +39,7 @@ class CloudPolicyValidatorTest : public testing::Test {
timestamp_option_(CloudPolicyValidatorBase::TIMESTAMP_REQUIRED),
ignore_missing_dm_token_(CloudPolicyValidatorBase::DM_TOKEN_REQUIRED),
allow_key_rotation_(true),
- existing_dm_token_(PolicyBuilder::kFakeToken),
- file_thread_(content::BrowserThread::FILE, &loop_) {
+ existing_dm_token_(PolicyBuilder::kFakeToken) {
policy_.SetDefaultNewSigningKey();
}
@@ -64,8 +63,8 @@ class CloudPolicyValidatorTest : public testing::Test {
PolicyBuilder::CreateTestSigningKey()->ExportPublicKey(&public_key));
policy_.Build();
- UserCloudPolicyValidator* validator =
- UserCloudPolicyValidator::Create(policy_.GetCopy());
+ UserCloudPolicyValidator* validator = UserCloudPolicyValidator::Create(
+ policy_.GetCopy(), base::MessageLoopProxy::current());
validator->ValidateTimestamp(timestamp_, timestamp_,
timestamp_option_);
validator->ValidateUsername(PolicyBuilder::kFakeUsername);
@@ -103,8 +102,6 @@ class CloudPolicyValidatorTest : public testing::Test {
private:
MOCK_METHOD1(ValidationCompletion, void(UserCloudPolicyValidator* validator));
- content::TestBrowserThread file_thread_;
-
DISALLOW_COPY_AND_ASSIGN(CloudPolicyValidatorTest);
};
diff --git a/chrome/browser/policy/cloud/component_cloud_policy_service_unittest.cc b/chrome/browser/policy/cloud/component_cloud_policy_service_unittest.cc
index deb7724cd..b4fa459e 100644
--- a/chrome/browser/policy/cloud/component_cloud_policy_service_unittest.cc
+++ b/chrome/browser/policy/cloud/component_cloud_policy_service_unittest.cc
@@ -25,8 +25,6 @@
#include "chrome/browser/policy/proto/cloud/chrome_extension_policy.pb.h"
#include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
#include "components/policy/core/common/schema.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/test/test_browser_thread.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_context.h"
@@ -99,9 +97,7 @@ class TestURLRequestContextGetter : public net::URLRequestContextGetter {
class ComponentCloudPolicyServiceTest : public testing::Test {
protected:
- ComponentCloudPolicyServiceTest()
- : ui_thread_(content::BrowserThread::UI, &loop_),
- file_thread_(content::BrowserThread::FILE, &loop_) {}
+ ComponentCloudPolicyServiceTest() {}
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
@@ -200,8 +196,6 @@ class ComponentCloudPolicyServiceTest : public testing::Test {
}
base::MessageLoop loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_thread_;
base::ScopedTempDir temp_dir_;
scoped_refptr<TestURLRequestContextGetter> request_context_;
net::TestURLFetcherFactory fetcher_factory_;
diff --git a/chrome/browser/policy/cloud/component_cloud_policy_store.cc b/chrome/browser/policy/cloud/component_cloud_policy_store.cc
index 334f9d6..e049c3b 100644
--- a/chrome/browser/policy/cloud/component_cloud_policy_store.cc
+++ b/chrome/browser/policy/cloud/component_cloud_policy_store.cc
@@ -261,7 +261,8 @@ bool ComponentCloudPolicyStore::ValidateProto(
return false;
scoped_ptr<ComponentCloudPolicyValidator> validator(
- ComponentCloudPolicyValidator::Create(proto.Pass()));
+ ComponentCloudPolicyValidator::Create(
+ proto.Pass(), scoped_refptr<base::SequencedTaskRunner>()));
validator->ValidateUsername(username_);
validator->ValidateDMToken(dm_token_,
ComponentCloudPolicyValidator::DM_TOKEN_REQUIRED);
diff --git a/chrome/browser/policy/cloud/device_management_service_browsertest.cc b/chrome/browser/policy/cloud/device_management_service_browsertest.cc
index 478629d..1319048 100644
--- a/chrome/browser/policy/cloud/device_management_service_browsertest.cc
+++ b/chrome/browser/policy/cloud/device_management_service_browsertest.cc
@@ -98,7 +98,9 @@ class DeviceManagementServiceIntegrationTest
const em::DeviceManagementResponse&));
std::string InitCannedResponse() {
- interceptor_.reset(new TestRequestInterceptor("localhost"));
+ interceptor_.reset(new TestRequestInterceptor(
+ "localhost",
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
return "http://localhost";
}
diff --git a/chrome/browser/policy/cloud/mock_user_cloud_policy_store.cc b/chrome/browser/policy/cloud/mock_user_cloud_policy_store.cc
index 9c687ec..75b5366 100644
--- a/chrome/browser/policy/cloud/mock_user_cloud_policy_store.cc
+++ b/chrome/browser/policy/cloud/mock_user_cloud_policy_store.cc
@@ -7,7 +7,9 @@
namespace policy {
MockUserCloudPolicyStore::MockUserCloudPolicyStore()
- : UserCloudPolicyStore(NULL, base::FilePath()) {}
+ : UserCloudPolicyStore(NULL,
+ base::FilePath(),
+ scoped_refptr<base::SequencedTaskRunner>()) {}
MockUserCloudPolicyStore::~MockUserCloudPolicyStore() {}
diff --git a/chrome/browser/policy/cloud/test_request_interceptor.cc b/chrome/browser/policy/cloud/test_request_interceptor.cc
index 9e254a4..55492c0 100644
--- a/chrome/browser/policy/cloud/test_request_interceptor.cc
+++ b/chrome/browser/policy/cloud/test_request_interceptor.cc
@@ -10,8 +10,8 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/memory/scoped_ptr.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/test/test_utils.h"
+#include "base/run_loop.h"
+#include "base/sequenced_task_runner.h"
#include "content/test/net/url_request_mock_http_job.h"
#include "net/base/net_errors.h"
#include "net/base/upload_bytes_element_reader.h"
@@ -29,12 +29,6 @@ namespace policy {
namespace {
-// Helper to execute a |task| on IO, and return only after it has completed.
-void PostToIOAndWait(const base::Closure& task) {
- content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, task);
- content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
-}
-
// Helper callback for jobs that should fail with a network |error|.
net::URLRequestJob* ErrorJobCallback(int error,
net::URLRequest* request,
@@ -154,7 +148,8 @@ net::URLRequestJob* RegisterJobCallback(
class TestRequestInterceptor::Delegate
: public net::URLRequestJobFactory::ProtocolHandler {
public:
- explicit Delegate(const std::string& hostname);
+ Delegate(const std::string& hostname,
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner);
virtual ~Delegate();
// ProtocolHandler implementation:
@@ -167,6 +162,7 @@ class TestRequestInterceptor::Delegate
private:
const std::string hostname_;
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
// The queue of pending callbacks. 'mutable' because MaybeCreateJob() is a
// const method; it can't reenter though, because it runs exclusively on
@@ -174,15 +170,17 @@ class TestRequestInterceptor::Delegate
mutable std::queue<JobCallback> pending_job_callbacks_;
};
-TestRequestInterceptor::Delegate::Delegate(const std::string& hostname)
- : hostname_(hostname) {}
+TestRequestInterceptor::Delegate::Delegate(
+ const std::string& hostname,
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner)
+ : hostname_(hostname), io_task_runner_(io_task_runner) {}
TestRequestInterceptor::Delegate::~Delegate() {}
net::URLRequestJob* TestRequestInterceptor::Delegate::MaybeCreateJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const {
- CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ CHECK(io_task_runner_->RunsTasksOnCurrentThread());
if (request->url().host() != hostname_) {
// Reject requests to other servers.
@@ -202,19 +200,21 @@ net::URLRequestJob* TestRequestInterceptor::Delegate::MaybeCreateJob(
void TestRequestInterceptor::Delegate::GetPendingSize(
size_t* pending_size) const {
- CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ CHECK(io_task_runner_->RunsTasksOnCurrentThread());
*pending_size = pending_job_callbacks_.size();
}
void TestRequestInterceptor::Delegate::PushJobCallback(
const JobCallback& callback) {
- CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ CHECK(io_task_runner_->RunsTasksOnCurrentThread());
pending_job_callbacks_.push(callback);
}
-TestRequestInterceptor::TestRequestInterceptor(const std::string& hostname)
- : hostname_(hostname) {
- delegate_ = new Delegate(hostname_);
+TestRequestInterceptor::TestRequestInterceptor(const std::string& hostname,
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner)
+ : hostname_(hostname),
+ io_task_runner_(io_task_runner) {
+ delegate_ = new Delegate(hostname_, io_task_runner_);
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> handler(delegate_);
PostToIOAndWait(
base::Bind(&net::URLRequestFilter::AddHostnameProtocolHandler,
@@ -232,7 +232,7 @@ TestRequestInterceptor::~TestRequestInterceptor() {
"http", hostname_));
}
-size_t TestRequestInterceptor::GetPendingSize() const {
+size_t TestRequestInterceptor::GetPendingSize() {
size_t pending_size = std::numeric_limits<size_t>::max();
PostToIOAndWait(base::Bind(&Delegate::GetPendingSize,
base::Unretained(delegate_),
@@ -270,4 +270,17 @@ TestRequestInterceptor::JobCallback TestRequestInterceptor::FileJob(
return base::Bind(&FileJobCallback, file_path);
}
+void TestRequestInterceptor::PostToIOAndWait(const base::Closure& task) {
+ io_task_runner_->PostTask(FROM_HERE, task);
+ base::RunLoop run_loop;
+ io_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(
+ base::IgnoreResult(&base::MessageLoopProxy::PostTask),
+ base::MessageLoopProxy::current(),
+ FROM_HERE,
+ run_loop.QuitClosure()));
+ run_loop.Run();
+}
+
} // namespace policy
diff --git a/chrome/browser/policy/cloud/test_request_interceptor.h b/chrome/browser/policy/cloud/test_request_interceptor.h
index 7838587..ec22353 100644
--- a/chrome/browser/policy/cloud/test_request_interceptor.h
+++ b/chrome/browser/policy/cloud/test_request_interceptor.h
@@ -9,10 +9,12 @@
#include "base/basictypes.h"
#include "base/callback.h"
+#include "base/memory/ref_counted.h"
#include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
namespace base {
class FilePath;
+class SequencedTaskRunner;
}
namespace net {
@@ -34,11 +36,13 @@ class TestRequestInterceptor {
net::URLRequestJob*(net::URLRequest*, net::NetworkDelegate*)> JobCallback;
// Will intercept request to |hostname| made over HTTP.
- explicit TestRequestInterceptor(const std::string& hostname);
+ TestRequestInterceptor(
+ const std::string& hostname,
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner);
virtual ~TestRequestInterceptor();
// Returns the number of pending callback jobs that haven't been used yet.
- size_t GetPendingSize() const;
+ size_t GetPendingSize();
// Queues |callback| to handle a request to |hostname_|. Each callback is
// used only once, and in the order that they're pushed.
@@ -66,8 +70,13 @@ class TestRequestInterceptor {
private:
class Delegate;
+ // Helper to execute a |task| on IO, and return only after it has completed.
+ void PostToIOAndWait(const base::Closure& task);
+
const std::string hostname_;
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
+
// Owned by URLRequestFilter. This handle is valid on IO and only while the
// interceptor is valid.
Delegate* delegate_;
diff --git a/chrome/browser/policy/cloud/user_cloud_policy_manager_factory.cc b/chrome/browser/policy/cloud/user_cloud_policy_manager_factory.cc
index 0fb0456..0279328 100644
--- a/chrome/browser/policy/cloud/user_cloud_policy_manager_factory.cc
+++ b/chrome/browser/policy/cloud/user_cloud_policy_manager_factory.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
+#include "base/sequenced_task_runner.h"
#include "chrome/browser/policy/cloud/cloud_external_data_manager.h"
#include "chrome/browser/policy/cloud/user_cloud_policy_manager.h"
#include "chrome/browser/policy/cloud/user_cloud_policy_store.h"
@@ -27,9 +28,12 @@ UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetForProfile(
// static
scoped_ptr<UserCloudPolicyManager>
- UserCloudPolicyManagerFactory::CreateForProfile(Profile* profile,
- bool force_immediate_load) {
- return GetInstance()->CreateManagerForProfile(profile, force_immediate_load);
+UserCloudPolicyManagerFactory::CreateForProfile(
+ Profile* profile,
+ bool force_immediate_load,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner) {
+ return GetInstance()->CreateManagerForProfile(
+ profile, force_immediate_load, background_task_runner);
}
UserCloudPolicyManagerFactory::UserCloudPolicyManagerFactory()
@@ -50,8 +54,10 @@ UserCloudPolicyManager* UserCloudPolicyManagerFactory::GetManagerForProfile(
scoped_ptr<UserCloudPolicyManager>
UserCloudPolicyManagerFactory::CreateManagerForProfile(
Profile* profile,
- bool force_immediate_load) {
- scoped_ptr<UserCloudPolicyStore> store(UserCloudPolicyStore::Create(profile));
+ bool force_immediate_load,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner) {
+ scoped_ptr<UserCloudPolicyStore> store(
+ UserCloudPolicyStore::Create(profile, background_task_runner));
if (force_immediate_load)
store->LoadImmediately();
scoped_ptr<UserCloudPolicyManager> manager(
diff --git a/chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h b/chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h
index b1690a9..ec9c251 100644
--- a/chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h
+++ b/chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h
@@ -8,11 +8,16 @@
#include <map>
#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
#include "components/browser_context_keyed_service/browser_context_keyed_base_factory.h"
class Profile;
+namespace base {
+class SequencedTaskRunner;
+}
+
namespace policy {
class UserCloudPolicyManager;
@@ -47,7 +52,8 @@ class UserCloudPolicyManagerFactory : public BrowserContextKeyedBaseFactory {
// UserCloudPolicyStore at startup.
static scoped_ptr<UserCloudPolicyManager> CreateForProfile(
Profile* profile,
- bool force_immediate_load);
+ bool force_immediate_load,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
private:
friend class UserCloudPolicyManager;
@@ -60,7 +66,8 @@ class UserCloudPolicyManagerFactory : public BrowserContextKeyedBaseFactory {
UserCloudPolicyManager* GetManagerForProfile(Profile* profile);
scoped_ptr<UserCloudPolicyManager> CreateManagerForProfile(
Profile* profile,
- bool force_immediate_load);
+ bool force_immediate_load,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
// BrowserContextKeyedBaseFactory:
virtual void BrowserContextShutdown(
diff --git a/chrome/browser/policy/cloud/user_cloud_policy_store.cc b/chrome/browser/policy/cloud/user_cloud_policy_store.cc
index 981e87e..cda8fb7 100644
--- a/chrome/browser/policy/cloud/user_cloud_policy_store.cc
+++ b/chrome/browser/policy/cloud/user_cloud_policy_store.cc
@@ -6,12 +6,13 @@
#include "base/bind.h"
#include "base/file_util.h"
+#include "base/location.h"
+#include "base/task_runner_util.h"
#include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
#include "chrome/browser/policy/proto/cloud/device_management_local.pb.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
-#include "content/public/browser/browser_thread.h"
#include "policy/policy_constants.h"
#include "policy/proto/cloud_policy.pb.h"
@@ -68,11 +69,11 @@ policy::PolicyLoadResult LoadPolicyFromDisk(const base::FilePath& path) {
}
// Stores policy to the backing file (must be called via a task on
-// the FILE thread).
-void StorePolicyToDiskOnFileThread(const base::FilePath& path,
- const em::PolicyFetchResponse& policy) {
+// the background thread).
+void StorePolicyToDiskOnBackgroundThread(
+ const base::FilePath& path,
+ const em::PolicyFetchResponse& policy) {
DVLOG(1) << "Storing policy to " << path.value();
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
std::string data;
if (!policy.SerializeToString(&data)) {
DLOG(WARNING) << "Failed to serialize policy data";
@@ -92,21 +93,25 @@ void StorePolicyToDiskOnFileThread(const base::FilePath& path,
} // namespace
-UserCloudPolicyStore::UserCloudPolicyStore(Profile* profile,
- const base::FilePath& path)
- : weak_factory_(this),
+UserCloudPolicyStore::UserCloudPolicyStore(
+ Profile* profile,
+ const base::FilePath& path,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner)
+ : UserCloudPolicyStoreBase(background_task_runner),
+ weak_factory_(this),
profile_(profile),
- backing_file_path_(path) {
-}
+ backing_file_path_(path) {}
UserCloudPolicyStore::~UserCloudPolicyStore() {}
// static
scoped_ptr<UserCloudPolicyStore> UserCloudPolicyStore::Create(
- Profile* profile) {
+ Profile* profile,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner) {
base::FilePath path =
profile->GetPath().Append(kPolicyDir).Append(kPolicyCacheFile);
- return make_scoped_ptr(new UserCloudPolicyStore(profile, path));
+ return make_scoped_ptr(
+ new UserCloudPolicyStore(profile, path, background_task_runner));
}
void UserCloudPolicyStore::LoadImmediately() {
@@ -120,11 +125,10 @@ void UserCloudPolicyStore::LoadImmediately() {
}
void UserCloudPolicyStore::Clear() {
- content::BrowserThread::PostTask(
- content::BrowserThread::FILE, FROM_HERE,
- base::Bind(base::IgnoreResult(&base::DeleteFile),
- backing_file_path_,
- false));
+ background_task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ base::IgnoreResult(&base::DeleteFile), backing_file_path_, false));
policy_.reset();
policy_map_.Clear();
NotifyStoreLoaded();
@@ -137,8 +141,9 @@ void UserCloudPolicyStore::Load() {
// Start a new Load operation and have us get called back when it is
// complete.
- content::BrowserThread::PostTaskAndReplyWithResult(
- content::BrowserThread::FILE, FROM_HERE,
+ base::PostTaskAndReplyWithResult(
+ background_task_runner(),
+ FROM_HERE,
base::Bind(&LoadPolicyFromDisk, backing_file_path_),
base::Bind(&UserCloudPolicyStore::PolicyLoaded,
weak_factory_.GetWeakPtr(), true));
@@ -146,7 +151,6 @@ void UserCloudPolicyStore::Load() {
void UserCloudPolicyStore::PolicyLoaded(bool validate_in_background,
PolicyLoadResult result) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
switch (result.status) {
case LOAD_RESULT_LOAD_ERROR:
status_ = STATUS_LOAD_ERROR;
@@ -248,9 +252,9 @@ void UserCloudPolicyStore::StorePolicyAfterValidation(
// Persist the validated policy (just fire a task - don't bother getting a
// reply because we can't do anything if it fails).
- content::BrowserThread::PostTask(
- content::BrowserThread::FILE, FROM_HERE,
- base::Bind(&StorePolicyToDiskOnFileThread,
+ background_task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&StorePolicyToDiskOnBackgroundThread,
backing_file_path_, *validator->policy()));
InstallPolicy(validator->policy_data().Pass(), validator->payload().Pass());
status_ = STATUS_OK;
diff --git a/chrome/browser/policy/cloud/user_cloud_policy_store.h b/chrome/browser/policy/cloud/user_cloud_policy_store.h
index 892fc23..b1fcdbe 100644
--- a/chrome/browser/policy/cloud/user_cloud_policy_store.h
+++ b/chrome/browser/policy/cloud/user_cloud_policy_store.h
@@ -15,6 +15,10 @@
class Profile;
+namespace base {
+class SequencedTaskRunner;
+}
+
namespace policy {
// Implements a cloud policy store that is stored in a simple file in the user's
@@ -24,11 +28,16 @@ class UserCloudPolicyStore : public UserCloudPolicyStoreBase {
public:
// Creates a policy store associated with the user signed in to this
// |profile|.
- UserCloudPolicyStore(Profile* profile, const base::FilePath& policy_file);
+ UserCloudPolicyStore(
+ Profile* profile,
+ const base::FilePath& policy_file,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
virtual ~UserCloudPolicyStore();
// Factory method for creating a UserCloudPolicyStore for |profile|.
- static scoped_ptr<UserCloudPolicyStore> Create(Profile* profile);
+ static scoped_ptr<UserCloudPolicyStore> Create(
+ Profile* profile,
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
// Loads policy immediately on the current thread. Virtual for mocks.
virtual void LoadImmediately();
diff --git a/chrome/browser/policy/cloud/user_cloud_policy_store_base.cc b/chrome/browser/policy/cloud/user_cloud_policy_store_base.cc
index 2d097ba..ee1daa6 100644
--- a/chrome/browser/policy/cloud/user_cloud_policy_store_base.cc
+++ b/chrome/browser/policy/cloud/user_cloud_policy_store_base.cc
@@ -17,8 +17,9 @@ void DecodePolicy(const enterprise_management::CloudPolicySettings& policy,
base::WeakPtr<CloudExternalDataManager> external_data_manager,
PolicyMap* policies);
-UserCloudPolicyStoreBase::UserCloudPolicyStoreBase() {
-}
+UserCloudPolicyStoreBase::UserCloudPolicyStoreBase(
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner)
+ : background_task_runner_(background_task_runner) {}
UserCloudPolicyStoreBase::~UserCloudPolicyStoreBase() {
}
@@ -28,7 +29,7 @@ scoped_ptr<UserCloudPolicyValidator> UserCloudPolicyStoreBase::CreateValidator(
CloudPolicyValidatorBase::ValidateTimestampOption timestamp_option) {
// Configure the validator.
UserCloudPolicyValidator* validator =
- UserCloudPolicyValidator::Create(policy.Pass());
+ UserCloudPolicyValidator::Create(policy.Pass(), background_task_runner_);
validator->ValidatePolicyType(GetChromeUserPolicyType());
validator->ValidateAgainstCurrentPolicy(
policy_.get(),
diff --git a/chrome/browser/policy/cloud/user_cloud_policy_store_base.h b/chrome/browser/policy/cloud/user_cloud_policy_store_base.h
index e00a3d2..068002e 100644
--- a/chrome/browser/policy/cloud/user_cloud_policy_store_base.h
+++ b/chrome/browser/policy/cloud/user_cloud_policy_store_base.h
@@ -8,18 +8,24 @@
#include <string>
#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/policy/cloud/cloud_policy_store.h"
#include "chrome/browser/policy/cloud/cloud_policy_validator.h"
+namespace base {
+class SequencedTaskRunner;
+}
+
namespace policy {
// Base class that implements common cross-platform UserCloudPolicyStore
// functionality.
class UserCloudPolicyStoreBase : public CloudPolicyStore {
public:
- UserCloudPolicyStoreBase();
+ explicit UserCloudPolicyStoreBase(
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner);
virtual ~UserCloudPolicyStoreBase();
protected:
@@ -34,7 +40,14 @@ class UserCloudPolicyStoreBase : public CloudPolicyStore {
scoped_ptr<enterprise_management::PolicyData> policy_data,
scoped_ptr<enterprise_management::CloudPolicySettings> payload);
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner() const {
+ return background_task_runner_;
+ }
+
private:
+ // Task runner for background file operations.
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
+
DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStoreBase);
};
diff --git a/chrome/browser/policy/cloud/user_cloud_policy_store_unittest.cc b/chrome/browser/policy/cloud/user_cloud_policy_store_unittest.cc
index e3f378f..2c2876c 100644
--- a/chrome/browser/policy/cloud/user_cloud_policy_store_unittest.cc
+++ b/chrome/browser/policy/cloud/user_cloud_policy_store_unittest.cc
@@ -7,6 +7,7 @@
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/message_loop/message_loop.h"
+#include "base/message_loop/message_loop_proxy.h"
#include "base/prefs/pref_service.h"
#include "base/run_loop.h"
#include "chrome/browser/policy/cloud/mock_cloud_external_data_manager.h"
@@ -17,7 +18,6 @@
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/public/test/test_browser_thread.h"
#include "net/url_request/url_request_context_getter.h"
#include "policy/policy_constants.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -42,8 +42,6 @@ class UserCloudPolicyStoreTest : public testing::Test {
public:
UserCloudPolicyStoreTest()
: loop_(base::MessageLoop::TYPE_UI),
- ui_thread_(content::BrowserThread::UI, &loop_),
- file_thread_(content::BrowserThread::FILE, &loop_),
profile_(new TestingProfile()) {}
virtual void SetUp() OVERRIDE {
@@ -54,7 +52,8 @@ class UserCloudPolicyStoreTest : public testing::Test {
profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
PolicyBuilder::kFakeUsername);
signin->Initialize(profile_.get(), NULL);
- store_.reset(new UserCloudPolicyStore(profile_.get(), policy_file()));
+ store_.reset(new UserCloudPolicyStore(
+ profile_.get(), policy_file(), loop_.message_loop_proxy()));
external_data_manager_.reset(new MockCloudExternalDataManager);
external_data_manager_->SetPolicyStore(store_.get());
store_->AddObserver(&observer_);
@@ -104,8 +103,6 @@ class UserCloudPolicyStoreTest : public testing::Test {
// |ui_thread_| and |file_thread_| share the same MessageLoop |loop_| so
// callers can use RunLoop to manage both virtual threads.
base::MessageLoop loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread file_thread_;
scoped_ptr<TestingProfile> profile_;
base::ScopedTempDir tmp_dir_;
@@ -280,8 +277,8 @@ TEST_F(UserCloudPolicyStoreTest, StoreThenLoad) {
RunUntilIdle();
// Now, make sure the policy can be read back in from a second store.
- scoped_ptr<UserCloudPolicyStore> store2(
- new UserCloudPolicyStore(profile_.get(), policy_file()));
+ scoped_ptr<UserCloudPolicyStore> store2(new UserCloudPolicyStore(
+ profile_.get(), policy_file(), loop_.message_loop_proxy()));
store2->AddObserver(&observer_);
EXPECT_CALL(observer_, OnStoreLoaded(store2.get()));
store2->Load();
@@ -305,8 +302,8 @@ TEST_F(UserCloudPolicyStoreTest, StoreThenLoadImmediately) {
RunUntilIdle();
// Now, make sure the policy can be read back in from a second store.
- scoped_ptr<UserCloudPolicyStore> store2(
- new UserCloudPolicyStore(profile_.get(), policy_file()));
+ scoped_ptr<UserCloudPolicyStore> store2(new UserCloudPolicyStore(
+ profile_.get(), policy_file(), loop_.message_loop_proxy()));
store2->AddObserver(&observer_);
EXPECT_CALL(observer_, OnStoreLoaded(store2.get()));
store2->LoadImmediately(); // Should load without running the message loop.
@@ -345,8 +342,8 @@ TEST_F(UserCloudPolicyStoreTest, LoadValidationError) {
SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
"foobar@foobar.com");
- scoped_ptr<UserCloudPolicyStore> store2(
- new UserCloudPolicyStore(profile_.get(), policy_file()));
+ scoped_ptr<UserCloudPolicyStore> store2(new UserCloudPolicyStore(
+ profile_.get(), policy_file(), loop_.message_loop_proxy()));
store2->AddObserver(&observer_);
ExpectError(store2.get(), CloudPolicyStore::STATUS_VALIDATION_ERROR);
store2->Load();
@@ -358,8 +355,8 @@ TEST_F(UserCloudPolicyStoreTest, LoadValidationError) {
// Sign out - we should be able to load the policy (don't check usernames
// when signed out).
SigninManagerFactory::GetForProfile(profile_.get())->SignOut();
- scoped_ptr<UserCloudPolicyStore> store3(
- new UserCloudPolicyStore(profile_.get(), policy_file()));
+ scoped_ptr<UserCloudPolicyStore> store3(new UserCloudPolicyStore(
+ profile_.get(), policy_file(), loop_.message_loop_proxy()));
store3->AddObserver(&observer_);
EXPECT_CALL(observer_, OnStoreLoaded(store3.get()));
store3->Load();
@@ -373,8 +370,8 @@ TEST_F(UserCloudPolicyStoreTest, LoadValidationError) {
SigninManagerFactory::GetForProfile(profile_.get()));
signin->set_auth_in_progress("foobar@foobar.com");
- scoped_ptr<UserCloudPolicyStore> store4(
- new UserCloudPolicyStore(profile_.get(), policy_file()));
+ scoped_ptr<UserCloudPolicyStore> store4(new UserCloudPolicyStore(
+ profile_.get(), policy_file(), loop_.message_loop_proxy()));
store4->AddObserver(&observer_);
ExpectError(store4.get(), CloudPolicyStore::STATUS_VALIDATION_ERROR);
store4->Load();
diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc
index 5a35f6e..0eaf66c 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -1520,7 +1520,9 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallForcelist) {
base::FilePath test_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_path));
- TestRequestInterceptor interceptor("update.extension");
+ TestRequestInterceptor interceptor(
+ "update.extension",
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
interceptor.PushJobCallback(
TestRequestInterceptor::FileJob(
test_path.Append(kTestExtensionsDir).Append(kGood2CrxManifestName)));
diff --git a/chrome/browser/policy/profile_policy_connector.cc b/chrome/browser/policy/profile_policy_connector.cc
index b2ebe37..fae3b36 100644
--- a/chrome/browser/policy/profile_policy_connector.cc
+++ b/chrome/browser/policy/profile_policy_connector.cc
@@ -44,9 +44,7 @@ ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile)
ProfilePolicyConnector::~ProfilePolicyConnector() {}
-void ProfilePolicyConnector::Init(
- bool force_immediate_load,
- base::SequencedTaskRunner* sequenced_task_runner) {
+void ProfilePolicyConnector::Init(bool force_immediate_load) {
BrowserPolicyConnector* connector =
g_browser_process->browser_policy_connector();
// |providers| contains a list of the policy providers available for the
diff --git a/chrome/browser/policy/profile_policy_connector.h b/chrome/browser/policy/profile_policy_connector.h
index 26af539..d7c4c26 100644
--- a/chrome/browser/policy/profile_policy_connector.h
+++ b/chrome/browser/policy/profile_policy_connector.h
@@ -21,10 +21,6 @@
class Profile;
-namespace base {
-class SequencedTaskRunner;
-}
-
namespace net {
class CertTrustAnchorProvider;
}
@@ -49,8 +45,7 @@ class ProfilePolicyConnector : public BrowserContextKeyedService {
virtual ~ProfilePolicyConnector();
// If |force_immediate_load| then disk caches will be loaded synchronously.
- void Init(bool force_immediate_load,
- base::SequencedTaskRunner* sequenced_task_runner);
+ void Init(bool force_immediate_load);
void InitForTesting(scoped_ptr<PolicyService> service);
diff --git a/chrome/browser/policy/profile_policy_connector_factory.cc b/chrome/browser/policy/profile_policy_connector_factory.cc
index 9d05260..e8b7bc3 100644
--- a/chrome/browser/policy/profile_policy_connector_factory.cc
+++ b/chrome/browser/policy/profile_policy_connector_factory.cc
@@ -37,10 +37,8 @@ ProfilePolicyConnector* ProfilePolicyConnectorFactory::GetForProfile(
scoped_ptr<ProfilePolicyConnector>
ProfilePolicyConnectorFactory::CreateForProfile(
Profile* profile,
- bool force_immediate_load,
- base::SequencedTaskRunner* sequenced_task_runner) {
- return GetInstance()->CreateForProfileInternal(
- profile, force_immediate_load, sequenced_task_runner);
+ bool force_immediate_load) {
+ return GetInstance()->CreateForProfileInternal(profile, force_immediate_load);
}
void ProfilePolicyConnectorFactory::SetServiceForTesting(
@@ -81,11 +79,10 @@ ProfilePolicyConnector*
scoped_ptr<ProfilePolicyConnector>
ProfilePolicyConnectorFactory::CreateForProfileInternal(
Profile* profile,
- bool force_immediate_load,
- base::SequencedTaskRunner* sequenced_task_runner) {
+ bool force_immediate_load) {
DCHECK(connectors_.find(profile) == connectors_.end());
ProfilePolicyConnector* connector = new ProfilePolicyConnector(profile);
- connector->Init(force_immediate_load, sequenced_task_runner);
+ connector->Init(force_immediate_load);
connectors_[profile] = connector;
return scoped_ptr<ProfilePolicyConnector>(connector);
}
diff --git a/chrome/browser/policy/profile_policy_connector_factory.h b/chrome/browser/policy/profile_policy_connector_factory.h
index a44fdee..8371408 100644
--- a/chrome/browser/policy/profile_policy_connector_factory.h
+++ b/chrome/browser/policy/profile_policy_connector_factory.h
@@ -46,8 +46,7 @@ class ProfilePolicyConnectorFactory : public BrowserContextKeyedBaseFactory {
// startup.
static scoped_ptr<ProfilePolicyConnector> CreateForProfile(
Profile* profile,
- bool force_immediate_load,
- base::SequencedTaskRunner* sequenced_task_runner);
+ bool force_immediate_load);
// Overrides the |connector| for the given |profile|; use only in tests.
// Once this class becomes a proper PKS then it can reuse the testing
@@ -65,8 +64,7 @@ class ProfilePolicyConnectorFactory : public BrowserContextKeyedBaseFactory {
scoped_ptr<ProfilePolicyConnector> CreateForProfileInternal(
Profile* profile,
- bool force_immediate_load,
- base::SequencedTaskRunner* sequenced_task_runner);
+ bool force_immediate_load);
// BrowserContextKeyedBaseFactory:
virtual void BrowserContextShutdown(
diff --git a/chrome/browser/policy/profile_policy_connector_stub.cc b/chrome/browser/policy/profile_policy_connector_stub.cc
index 6c03942..49747c8 100644
--- a/chrome/browser/policy/profile_policy_connector_stub.cc
+++ b/chrome/browser/policy/profile_policy_connector_stub.cc
@@ -12,9 +12,7 @@ ProfilePolicyConnector::ProfilePolicyConnector(Profile* profile) {}
ProfilePolicyConnector::~ProfilePolicyConnector() {}
-void ProfilePolicyConnector::Init(
- bool force_immediate_load,
- base::SequencedTaskRunner* sequenced_task_runner) {
+void ProfilePolicyConnector::Init(bool force_immediate_load) {
policy_service_.reset(new PolicyServiceStub());
}
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index baf2557..22abce1 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -408,16 +408,16 @@ ProfileImpl::ProfileImpl(
#if defined(OS_CHROMEOS)
cloud_policy_manager_ =
policy::UserCloudPolicyManagerFactoryChromeOS::CreateForProfile(
- this, force_immediate_policy_load);
+ this, force_immediate_policy_load, sequenced_task_runner);
#else
cloud_policy_manager_ =
policy::UserCloudPolicyManagerFactory::CreateForProfile(
- this, force_immediate_policy_load);
+ this, force_immediate_policy_load, sequenced_task_runner);
#endif
#endif
profile_policy_connector_ =
policy::ProfilePolicyConnectorFactory::CreateForProfile(
- this, force_immediate_policy_load, sequenced_task_runner);
+ this, force_immediate_policy_load);
DCHECK(create_mode == CREATE_MODE_ASYNCHRONOUS ||
create_mode == CREATE_MODE_SYNCHRONOUS);