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

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

Issue 6312121: Add initial device policy infrastructure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix race condition and tests. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/policy/cloud_policy_context.h ('k') | chrome/browser/policy/cloud_policy_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/cloud_policy_context.cc
diff --git a/chrome/browser/policy/cloud_policy_context.cc b/chrome/browser/policy/cloud_policy_context.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7c624e96ba74e93f87b29ccc70b5e741ab6bd0b6
--- /dev/null
+++ b/chrome/browser/policy/cloud_policy_context.cc
@@ -0,0 +1,118 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "chrome/browser/policy/cloud_policy_cache.h"
+#include "chrome/browser/policy/cloud_policy_client.h"
+#include "chrome/browser/policy/cloud_policy_context.h"
+#include "chrome/browser/policy/cloud_policy_controller.h"
+#include "chrome/browser/policy/configuration_policy_provider.h"
+#include "chrome/browser/policy/device_management_service.h"
+#include "chrome/browser/policy/device_token_fetcher.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/notification_details.h"
+#include "chrome/common/notification_source.h"
+#include "chrome/common/notification_type.h"
+
+namespace {
+
+// Refresh rate sanity interval bounds.
+const int64 kPolicyRefreshRateMinMs = 30 * 60 * 1000; // 30 minutes
+const int64 kPolicyRefreshRateMaxMs = 24 * 60 * 60 * 1000; // 1 day
+
+}
+
+namespace policy {
+
+CloudPolicyContext::CloudPolicyContext(const FilePath& policy_cache_file,
+ CloudPolicyController* controller)
+ : prefs_(NULL) {
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switches::kDeviceManagementUrl)) {
+ device_management_service_.reset(new DeviceManagementService(
+ command_line->GetSwitchValueASCII(switches::kDeviceManagementUrl)));
+ cloud_policy_cache_.reset(new CloudPolicyCache(policy_cache_file));
+ cloud_policy_cache_->LoadFromFile();
+
+ device_token_fetcher_.reset(
+ new DeviceTokenFetcher(device_management_service_.get(),
+ cloud_policy_cache_.get()));
+
+ cloud_policy_client_.reset(
+ new CloudPolicyClient(cloud_policy_cache_.get(),
+ device_management_service_->CreateBackend(),
+ device_token_fetcher_.get(),
+ controller));
+ }
+}
+
+CloudPolicyContext::~CloudPolicyContext() {
+ DCHECK(!prefs_);
+ cloud_policy_client_.reset();
+ device_token_fetcher_.reset();
+ cloud_policy_cache_.reset();
+ device_management_service_.reset();
+}
+
+void CloudPolicyContext::Initialize(PrefService* prefs,
+ const char* refresh_rate_pref_name,
+ URLRequestContextGetter* request_context) {
+ DCHECK(!prefs_);
+ prefs_ = prefs;
+
+ if (device_management_service_.get())
+ device_management_service_->Initialize(request_context);
+
+ policy_refresh_rate_.Init(refresh_rate_pref_name, prefs_, this);
+ UpdatePolicyRefreshRate();
+}
+
+void CloudPolicyContext::Shutdown() {
+ if (device_management_service_.get())
+ device_management_service_->Shutdown();
+ cloud_policy_client_.reset();
+ cloud_policy_cache_.reset();
+ policy_refresh_rate_.Destroy();
+ prefs_ = NULL;
+}
+
+ConfigurationPolicyProvider* CloudPolicyContext::GetManagedPolicyProvider() {
+ if (cloud_policy_cache_.get())
+ return cloud_policy_cache_->GetManagedPolicyProvider();
+
+ return NULL;
+}
+
+ConfigurationPolicyProvider*
+ CloudPolicyContext::GetRecommendedPolicyProvider() {
+ if (cloud_policy_cache_.get())
+ return cloud_policy_cache_->GetRecommendedPolicyProvider();
+
+ return NULL;
+}
+
+void CloudPolicyContext::UpdatePolicyRefreshRate() {
+ if (cloud_policy_client_.get()) {
+ // Clamp to sane values.
+ int64 refresh_rate = policy_refresh_rate_.GetValue();
+ refresh_rate = std::max(kPolicyRefreshRateMinMs, refresh_rate);
+ refresh_rate = std::min(kPolicyRefreshRateMaxMs, refresh_rate);
+ cloud_policy_client_->SetRefreshRate(refresh_rate);
+ }
+}
+
+void CloudPolicyContext::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::PREF_CHANGED &&
+ policy_refresh_rate_.GetPrefName()
+ == *(Details<std::string>(details).ptr()) &&
+ prefs_ == Source<PrefService>(source).ptr()) {
+ UpdatePolicyRefreshRate();
+ } else {
+ NOTREACHED();
+ }
+}
+
+} // namespace policy
« no previous file with comments | « chrome/browser/policy/cloud_policy_context.h ('k') | chrome/browser/policy/cloud_policy_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698