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

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: 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), schema_registry_(schema_registry) {
bartfab (slow) 2014/06/20 17:03:46 Style guide nit: Each initialization on its own li
Joao da Silva 2014/06/20 22:28:19 Done.
25 if (account.type == DeviceLocalAccount::TYPE_KIOSK_APP) {
26 // This is easy: just add a component for the app id.
bartfab (slow) 2014/06/20 17:03:46 Nit: s/just/Just/
Joao da Silva 2014/06/20 22:28:19 Done.
27 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, account.kiosk_app_id);
28 schema_registry_->RegisterComponent(ns, Schema());
29 } else if (account.type == DeviceLocalAccount::TYPE_PUBLIC_SESSION) {
30 // For public sessions, track the value of the ExtensionInstallForcelist
31 // policy.
32 store_->AddObserver(this);
33 UpdateFromStore();
34 } else {
35 NOTREACHED();
36 }
37
38 schema_registry_->SetReady(POLICY_DOMAIN_EXTENSIONS);
39 }
40
41 DeviceLocalAccountExtensionTracker::~DeviceLocalAccountExtensionTracker() {
42 store_->RemoveObserver(this);
43 }
44
45 void DeviceLocalAccountExtensionTracker::OnStoreLoaded(
46 CloudPolicyStore* store) {
47 UpdateFromStore();
48 }
49
50 void DeviceLocalAccountExtensionTracker::OnStoreError(CloudPolicyStore* store) {
51 UpdateFromStore();
52 }
53
54 void DeviceLocalAccountExtensionTracker::UpdateFromStore() {
55 const policy::PolicyMap& policy_map = store_->policy_map();
56
57 extensions::ExtensionInstallForcelistPolicyHandler policy_handler;
58 if (!policy_handler.CheckPolicySettings(policy_map, NULL))
59 return;
60
61 PrefValueMap pref_value_map;
62 policy_handler.ApplyPolicySettings(policy_map, &pref_value_map);
63
64 const base::Value* value = NULL;
65 const base::DictionaryValue* dict = NULL;
66 if (!pref_value_map.GetValue(extensions::pref_names::kInstallForceList,
67 &value) ||
68 !value->GetAsDictionary(&dict)) {
69 return;
70 }
71
72 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
73 LOG(ERROR)
bartfab (slow) 2014/06/20 17:03:45 Nit: Remove.
Joao da Silva 2014/06/20 22:28:19 Doh, done.
74 << "------- adding a schema from the store policy for extension: "
75 << it.key();
76 PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, it.key());
77 schema_registry_->RegisterComponent(ns, Schema());
78 }
79
80 // Removing an extension from a public session at runtime can happen but is
81 // a rare event. In that case we leave the extension ID in the SchemaRegistry,
82 // and it will be purged on the next restart.
83 }
84
85 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698