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

Side by Side Diff: chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.cc

Issue 27548004: Cache force-installed apps/extensions in device-local accounts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 2013 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/extensions/device_local_account_external_polic y_loader.h"
6
7 #include "base/callback.h"
8 #include "base/logging.h"
9 #include "base/prefs/pref_value_map.h"
10 #include "base/values.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/policy/configuration_policy_handler.h"
13 #include "chrome/browser/policy/policy_map.h"
14 #include "net/url_request/url_request_context_getter.h"
15
16 namespace chromeos {
17
18 namespace {
19
20 // A dummy pref name under which policy::ExtensionInstallForcelistPolicyHandler
21 // can store the parsed list of force-installed extensions.
22 char kExtensionInstallForcelist[] = "forcelist";
Joao da Silva 2013/10/17 14:57:54 const char
bartfab (slow) 2013/10/18 12:58:39 Done.
23
24 }
Joao da Silva 2013/10/17 14:57:54 // namespace
bartfab (slow) 2013/10/18 12:58:39 Done.
bartfab (slow) 2013/10/18 12:58:39 Done.
25
26 DeviceLocalAccountExternalPolicyLoader::
27 DeviceLocalAccountExternalPolicyLoader(policy::CloudPolicyStore* store,
28 const base::FilePath& cache_dir)
29 : store_(store),
30 cache_dir_(cache_dir) {
31 }
32
33 DeviceLocalAccountExternalPolicyLoader::
34 ~DeviceLocalAccountExternalPolicyLoader() {
35 DCHECK(!external_cache_);
36 }
37
38 bool DeviceLocalAccountExternalPolicyLoader::IsCacheRunning() const {
39 return external_cache_;
40 }
41
42 void DeviceLocalAccountExternalPolicyLoader::StartCache(
43 const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner) {
44 DCHECK(!external_cache_);
45 store_->AddObserver(this);
46 external_cache_.reset(new ExternalCache(
47 cache_dir_,
48 g_browser_process->system_request_context(),
49 cache_task_runner,
50 this,
51 true,
52 false));
Joao da Silva 2013/10/17 14:57:54 Suggestion: just by looking at this it's not clear
bartfab (slow) 2013/10/18 12:58:39 Done, although I went with a documentation pattern
53
54 if (store_->is_initialized())
55 UpdateExtensionListFromStore();
56 }
57
58 void DeviceLocalAccountExternalPolicyLoader::StopCache(
59 const base::Closure& callback) {
60 if (external_cache_) {
61 external_cache_->Shutdown(callback);
62 external_cache_.reset();
63 store_->RemoveObserver(this);
64 }
65
66 base::DictionaryValue empty_prefs;
67 OnExtensionListsUpdated(&empty_prefs);
68 }
69
70 void DeviceLocalAccountExternalPolicyLoader::StartLoading() {
71 if (prefs_)
72 LoadFinished();
73 }
74
75 void DeviceLocalAccountExternalPolicyLoader::OnStoreLoaded(
76 policy::CloudPolicyStore* store) {
77 DCHECK(external_cache_);
78 DCHECK_EQ(store_, store);
79 UpdateExtensionListFromStore();
80 }
81
82 void DeviceLocalAccountExternalPolicyLoader::OnStoreError(
83 policy::CloudPolicyStore* store) {
84 DCHECK(external_cache_);
85 DCHECK_EQ(store_, store);
86 }
87
88 void DeviceLocalAccountExternalPolicyLoader::OnExtensionListsUpdated(
89 const base::DictionaryValue* prefs) {
90 DCHECK(external_cache_ || prefs->empty());
91 prefs_.reset(prefs->DeepCopy());
92 LoadFinished();
93 }
94
95 void DeviceLocalAccountExternalPolicyLoader::UpdateExtensionListFromStore() {
96 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue);
97 const policy::PolicyMap& policy_map = store_->policy_map();
98 policy::ExtensionInstallForcelistPolicyHandler
99 policy_handler(kExtensionInstallForcelist);
Joao da Silva 2013/10/17 14:57:54 Daniel has recently refactored this class and the
bartfab (slow) 2013/10/18 12:58:39 At least for now, the class still takes a pref nam
100 if (policy_handler.CheckPolicySettings(policy_map, NULL)) {
101 PrefValueMap pref_value_map;
102 policy_handler.ApplyPolicySettings(policy_map, &pref_value_map);
103 const base::Value* value = NULL; // Not owned.
104 const base::DictionaryValue* dict = NULL; // Not owned.
Joao da Silva 2013/10/17 14:57:54 Same comment re // not owned comment
bartfab (slow) 2013/10/18 12:58:39 Done.
105 if (pref_value_map.GetValue(kExtensionInstallForcelist, &value) &&
106 value->GetAsDictionary(&dict)) {
107 prefs.reset(dict->DeepCopy());
108 }
109 }
110
111 external_cache_->UpdateExtensionsList(prefs.Pass());
112 }
113
114 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698