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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/policy/device_local_account_extension_tracker. h"
6
7 #include "base/logging.h"
8 #include "base/prefs/pref_value_map.h"
9 #include "base/values.h"
10 #include "chrome/browser/chromeos/policy/device_local_account.h"
11 #include "chrome/browser/extensions/policy_handlers.h"
12 #include "components/policy/core/common/policy_map.h"
13 #include "components/policy/core/common/policy_namespace.h"
14 #include "components/policy/core/common/schema.h"
15 #include "components/policy/core/common/schema_registry.h"
16 #include "extensions/browser/pref_names.h"
17
18 namespace policy {
19
20 DeviceLocalAccountExtensionTracker::DeviceLocalAccountExtensionTracker(
21 const DeviceLocalAccount& account,
22 CloudPolicyStore* store,
23 SchemaRegistry* schema_registry)
24 : store_(store),
25 schema_registry_(schema_registry) {
26 if (account.type == DeviceLocalAccount::TYPE_KIOSK_APP) {
27 // This is easy: Just add a component for the app id.
28 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, account.kiosk_app_id);
29 schema_registry_->RegisterComponent(ns, Schema());
30 } else if (account.type == DeviceLocalAccount::TYPE_PUBLIC_SESSION) {
31 // For public sessions, track the value of the ExtensionInstallForcelist
32 // policy.
33 store_->AddObserver(this);
34 UpdateFromStore();
35 } else {
36 NOTREACHED();
37 }
38
39 schema_registry_->SetReady(POLICY_DOMAIN_EXTENSIONS);
40 }
41
42 DeviceLocalAccountExtensionTracker::~DeviceLocalAccountExtensionTracker() {
43 store_->RemoveObserver(this);
44 }
45
46 void DeviceLocalAccountExtensionTracker::OnStoreLoaded(
47 CloudPolicyStore* store) {
48 UpdateFromStore();
49 }
50
51 void DeviceLocalAccountExtensionTracker::OnStoreError(CloudPolicyStore* store) {
52 UpdateFromStore();
53 }
54
55 void DeviceLocalAccountExtensionTracker::UpdateFromStore() {
56 const policy::PolicyMap& policy_map = store_->policy_map();
57
58 extensions::ExtensionInstallForcelistPolicyHandler policy_handler;
59 if (!policy_handler.CheckPolicySettings(policy_map, NULL))
60 return;
61
62 PrefValueMap pref_value_map;
63 policy_handler.ApplyPolicySettings(policy_map, &pref_value_map);
64
65 const base::Value* value = NULL;
66 const base::DictionaryValue* dict = NULL;
67 if (!pref_value_map.GetValue(extensions::pref_names::kInstallForceList,
68 &value) ||
69 !value->GetAsDictionary(&dict)) {
70 return;
71 }
72
73 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
74 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, it.key());
75 schema_registry_->RegisterComponent(ns, Schema());
76 }
77
78 // Removing an extension from a public session at runtime can happen but is
79 // a rare event. In that case we leave the extension ID in the SchemaRegistry,
80 // and it will be purged on the next restart.
81 }
82
83 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698