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

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

Issue 5178005: Rework the device management backend implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/device_management_policy_provider.cc
diff --git a/chrome/browser/policy/device_management_policy_provider.cc b/chrome/browser/policy/device_management_policy_provider.cc
index babc5a41b544a0d3cc73daec7a26d27b97c7b1e4..31c9ec07f9fc526d7770ed72f8bdc827a7ece4cd 100644
--- a/chrome/browser/policy/device_management_policy_provider.cc
+++ b/chrome/browser/policy/device_management_policy_provider.cc
@@ -11,7 +11,6 @@
#include "base/time.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/policy/device_management_backend.h"
-#include "chrome/browser/policy/device_management_backend_impl.h"
#include "chrome/browser/policy/device_management_policy_cache.h"
#include "chrome/browser/policy/device_token_fetcher.h"
#include "chrome/common/chrome_paths.h"
@@ -19,16 +18,12 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
-namespace {
+namespace policy {
const char kChromePolicyScope[] = "cros/device";
const char kChromeDevicePolicySettingKey[] = "chrome-policy";
const int64 kPolicyRefreshRateInMinutes = 3 * 60; // 3 hours
-} // namespace
-
-namespace policy {
-
// Ensures that the portion of the policy provider implementation that requires
// the IOThread is deferred until the IOThread is fully initialized. The policy
// provider posts this task on the UI thread during its constructor, thereby
@@ -56,25 +51,16 @@ class DeviceManagementPolicyProvider::InitializeAfterIOThreadExistsTask
DeviceManagementPolicyProvider::DeviceManagementPolicyProvider(
const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list,
DeviceManagementBackend* backend,
+ TokenService* token_service,
const FilePath& storage_dir)
: ConfigurationPolicyProvider(policy_list),
backend_(backend),
+ token_service_(token_service),
storage_dir_(GetOrCreateDeviceManagementDir(storage_dir)),
policy_request_pending_(false) {
Initialize();
}
-DeviceManagementPolicyProvider::DeviceManagementPolicyProvider(
- const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list)
- : ConfigurationPolicyProvider(policy_list),
- policy_request_pending_(false) {
- FilePath user_dir;
- if (!PathService::Get(chrome::DIR_USER_DATA, &user_dir))
- NOTREACHED();
- storage_dir_ = GetOrCreateDeviceManagementDir(user_dir);
- Initialize();
-}
-
DeviceManagementPolicyProvider::~DeviceManagementPolicyProvider() {}
bool DeviceManagementPolicyProvider::Provide(
@@ -88,11 +74,11 @@ void DeviceManagementPolicyProvider::Observe(
NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- if ((type == NotificationType::DEVICE_TOKEN_AVAILABLE) &&
- (token_fetcher_.get() == Source<DeviceTokenFetcher>(source).ptr())) {
- if (!policy_request_pending_) {
- if (IsPolicyStale())
- SendPolicyRequest();
+ if (type == NotificationType::DEVICE_TOKEN_AVAILABLE) {
+ if (token_fetcher_.get() == Source<DeviceTokenFetcher>(source).ptr() &&
+ !policy_request_pending_ &&
+ IsPolicyStale()) {
+ SendPolicyRequest();
}
} else {
NOTREACHED();
@@ -114,12 +100,10 @@ void DeviceManagementPolicyProvider::OnError(
// TODO(danno): do something sensible in the error case, perhaps retry later?
}
-DeviceManagementBackend* DeviceManagementPolicyProvider::GetBackend() {
- if (!backend_.get()) {
- backend_.reset(new DeviceManagementBackendImpl(
- GetDeviceManagementURL()));
- }
- return backend_.get();
+void DeviceManagementPolicyProvider::Shutdown() {
+ token_service_ = NULL;
+ if (token_fetcher_)
+ token_fetcher_->Shutdown();
}
void DeviceManagementPolicyProvider::Initialize() {
@@ -141,8 +125,11 @@ void DeviceManagementPolicyProvider::Initialize() {
void DeviceManagementPolicyProvider::InitializeAfterIOThreadExists() {
const FilePath token_path = storage_dir_.Append(
FILE_PATH_LITERAL("Token"));
- token_fetcher_ = new DeviceTokenFetcher(GetBackend(), token_path);
- token_fetcher_->StartFetching();
+ if (token_service_) {
+ token_fetcher_ =
+ new DeviceTokenFetcher(backend_.get(), token_service_, token_path);
+ token_fetcher_->StartFetching();
+ }
}
void DeviceManagementPolicyProvider::SendPolicyRequest() {
@@ -152,9 +139,8 @@ void DeviceManagementPolicyProvider::SendPolicyRequest() {
em::DevicePolicySettingRequest* setting =
policy_request.add_setting_request();
setting->set_key(kChromeDevicePolicySettingKey);
- GetBackend()->ProcessPolicyRequest(token_fetcher_->GetDeviceToken(),
- policy_request,
- this);
+ backend_->ProcessPolicyRequest(token_fetcher_->GetDeviceToken(),
+ policy_request, this);
policy_request_pending_ = true;
}
}

Powered by Google App Engine
This is Rietveld 408576698