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

Unified Diff: chrome/browser/chromeos/policy/device_local_account_extension_tracker.cc

Issue 337053005: Precache policy-for-extensions for device-local accounts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed ios tests Created 6 years, 6 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
Index: chrome/browser/chromeos/policy/device_local_account_extension_tracker.cc
diff --git a/chrome/browser/chromeos/policy/device_local_account_extension_tracker.cc b/chrome/browser/chromeos/policy/device_local_account_extension_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cc8cd124a6045137ac9055a64ea6549a58668c96
--- /dev/null
+++ b/chrome/browser/chromeos/policy/device_local_account_extension_tracker.cc
@@ -0,0 +1,83 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/policy/device_local_account_extension_tracker.h"
+
+#include "base/logging.h"
+#include "base/prefs/pref_value_map.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/policy/device_local_account.h"
+#include "chrome/browser/extensions/policy_handlers.h"
+#include "components/policy/core/common/policy_map.h"
+#include "components/policy/core/common/policy_namespace.h"
+#include "components/policy/core/common/schema.h"
+#include "components/policy/core/common/schema_registry.h"
+#include "extensions/browser/pref_names.h"
+
+namespace policy {
+
+DeviceLocalAccountExtensionTracker::DeviceLocalAccountExtensionTracker(
+ const DeviceLocalAccount& account,
+ CloudPolicyStore* store,
+ SchemaRegistry* schema_registry)
+ : store_(store),
+ schema_registry_(schema_registry) {
+ if (account.type == DeviceLocalAccount::TYPE_KIOSK_APP) {
+ // This is easy: Just add a component for the app id.
+ PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, account.kiosk_app_id);
+ schema_registry_->RegisterComponent(ns, Schema());
+ } else if (account.type == DeviceLocalAccount::TYPE_PUBLIC_SESSION) {
+ // For public sessions, track the value of the ExtensionInstallForcelist
+ // policy.
+ store_->AddObserver(this);
+ UpdateFromStore();
+ } else {
+ NOTREACHED();
+ }
+
+ schema_registry_->SetReady(POLICY_DOMAIN_EXTENSIONS);
+}
+
+DeviceLocalAccountExtensionTracker::~DeviceLocalAccountExtensionTracker() {
+ store_->RemoveObserver(this);
+}
+
+void DeviceLocalAccountExtensionTracker::OnStoreLoaded(
+ CloudPolicyStore* store) {
+ UpdateFromStore();
+}
+
+void DeviceLocalAccountExtensionTracker::OnStoreError(CloudPolicyStore* store) {
+ UpdateFromStore();
+}
+
+void DeviceLocalAccountExtensionTracker::UpdateFromStore() {
+ const policy::PolicyMap& policy_map = store_->policy_map();
+
+ extensions::ExtensionInstallForcelistPolicyHandler policy_handler;
+ if (!policy_handler.CheckPolicySettings(policy_map, NULL))
+ return;
+
+ PrefValueMap pref_value_map;
+ policy_handler.ApplyPolicySettings(policy_map, &pref_value_map);
+
+ const base::Value* value = NULL;
+ const base::DictionaryValue* dict = NULL;
+ if (!pref_value_map.GetValue(extensions::pref_names::kInstallForceList,
+ &value) ||
+ !value->GetAsDictionary(&dict)) {
+ return;
+ }
+
+ for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
+ PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, it.key());
+ schema_registry_->RegisterComponent(ns, Schema());
+ }
+
+ // Removing an extension from a public session at runtime can happen but is
+ // a rare event. In that case we leave the extension ID in the SchemaRegistry,
+ // and it will be purged on the next restart.
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698