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

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

Issue 6310012: Allow policy refresh rate to be configured through policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test. 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/profile_policy_context.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/profile_policy_context.cc
diff --git a/chrome/browser/policy/profile_policy_context.cc b/chrome/browser/policy/profile_policy_context.cc
index c2215295c47701692a1865dda193742f90e3378f..7adffd3e8c562d46b44e42967003df0bc8ebee5c 100644
--- a/chrome/browser/policy/profile_policy_context.cc
+++ b/chrome/browser/policy/profile_policy_context.cc
@@ -7,8 +7,20 @@
#include "chrome/browser/policy/device_management_policy_provider.h"
#include "chrome/browser/policy/device_management_service.h"
#include "chrome/browser/policy/profile_policy_context.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/notification_details.h"
+#include "chrome/common/notification_source.h"
+#include "chrome/common/pref_names.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 {
@@ -34,6 +46,10 @@ ProfilePolicyContext::~ProfilePolicyContext() {
void ProfilePolicyContext::Initialize() {
if (device_management_service_.get())
device_management_service_->Initialize(profile_->GetRequestContext());
+
+ policy_refresh_rate_.Init(prefs::kPolicyRefreshRate, profile_->GetPrefs(),
+ this);
+ UpdatePolicyRefreshRate();
}
void ProfilePolicyContext::Shutdown() {
@@ -46,4 +62,32 @@ ProfilePolicyContext::GetDeviceManagementPolicyProvider() {
return device_management_policy_provider_.get();
}
+// static
+void ProfilePolicyContext::RegisterUserPrefs(PrefService* user_prefs) {
+ user_prefs->RegisterIntegerPref(prefs::kPolicyRefreshRate,
+ kDefaultPolicyRefreshRateInMilliseconds);
+}
+
+void ProfilePolicyContext::UpdatePolicyRefreshRate() {
+ if (device_management_policy_provider_.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);
+ device_management_policy_provider_->SetRefreshRate(refresh_rate);
+ }
+}
+
+void ProfilePolicyContext::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::PREF_CHANGED &&
+ prefs::kPolicyRefreshRate == *(Details<std::string>(details).ptr()) &&
+ profile_->GetPrefs() == Source<PrefService>(source).ptr()) {
+ UpdatePolicyRefreshRate();
+ } else {
+ NOTREACHED();
+ }
+}
+
} // namespace policy
« no previous file with comments | « chrome/browser/policy/profile_policy_context.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698