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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.cc
diff --git a/chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.cc b/chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..447c9564e6f1d9524f64ed1a832cce5cf494a7a3
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.cc
@@ -0,0 +1,114 @@
+// Copyright 2013 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/extensions/device_local_account_external_policy_loader.h"
+
+#include "base/callback.h"
+#include "base/logging.h"
+#include "base/prefs/pref_value_map.h"
+#include "base/values.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/policy/configuration_policy_handler.h"
+#include "chrome/browser/policy/policy_map.h"
+#include "net/url_request/url_request_context_getter.h"
+
+namespace chromeos {
+
+namespace {
+
+// A dummy pref name under which policy::ExtensionInstallForcelistPolicyHandler
+// can store the parsed list of force-installed extensions.
+char kExtensionInstallForcelist[] = "forcelist";
Joao da Silva 2013/10/17 14:57:54 const char
bartfab (slow) 2013/10/18 12:58:39 Done.
+
+}
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.
+
+DeviceLocalAccountExternalPolicyLoader::
+ DeviceLocalAccountExternalPolicyLoader(policy::CloudPolicyStore* store,
+ const base::FilePath& cache_dir)
+ : store_(store),
+ cache_dir_(cache_dir) {
+}
+
+DeviceLocalAccountExternalPolicyLoader::
+ ~DeviceLocalAccountExternalPolicyLoader() {
+ DCHECK(!external_cache_);
+}
+
+bool DeviceLocalAccountExternalPolicyLoader::IsCacheRunning() const {
+ return external_cache_;
+}
+
+void DeviceLocalAccountExternalPolicyLoader::StartCache(
+ const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner) {
+ DCHECK(!external_cache_);
+ store_->AddObserver(this);
+ external_cache_.reset(new ExternalCache(
+ cache_dir_,
+ g_browser_process->system_request_context(),
+ cache_task_runner,
+ this,
+ true,
+ 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
+
+ if (store_->is_initialized())
+ UpdateExtensionListFromStore();
+}
+
+void DeviceLocalAccountExternalPolicyLoader::StopCache(
+ const base::Closure& callback) {
+ if (external_cache_) {
+ external_cache_->Shutdown(callback);
+ external_cache_.reset();
+ store_->RemoveObserver(this);
+ }
+
+ base::DictionaryValue empty_prefs;
+ OnExtensionListsUpdated(&empty_prefs);
+}
+
+void DeviceLocalAccountExternalPolicyLoader::StartLoading() {
+ if (prefs_)
+ LoadFinished();
+}
+
+void DeviceLocalAccountExternalPolicyLoader::OnStoreLoaded(
+ policy::CloudPolicyStore* store) {
+ DCHECK(external_cache_);
+ DCHECK_EQ(store_, store);
+ UpdateExtensionListFromStore();
+}
+
+void DeviceLocalAccountExternalPolicyLoader::OnStoreError(
+ policy::CloudPolicyStore* store) {
+ DCHECK(external_cache_);
+ DCHECK_EQ(store_, store);
+}
+
+void DeviceLocalAccountExternalPolicyLoader::OnExtensionListsUpdated(
+ const base::DictionaryValue* prefs) {
+ DCHECK(external_cache_ || prefs->empty());
+ prefs_.reset(prefs->DeepCopy());
+ LoadFinished();
+}
+
+void DeviceLocalAccountExternalPolicyLoader::UpdateExtensionListFromStore() {
+ scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue);
+ const policy::PolicyMap& policy_map = store_->policy_map();
+ policy::ExtensionInstallForcelistPolicyHandler
+ 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
+ if (policy_handler.CheckPolicySettings(policy_map, NULL)) {
+ PrefValueMap pref_value_map;
+ policy_handler.ApplyPolicySettings(policy_map, &pref_value_map);
+ const base::Value* value = NULL; // Not owned.
+ 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.
+ if (pref_value_map.GetValue(kExtensionInstallForcelist, &value) &&
+ value->GetAsDictionary(&dict)) {
+ prefs.reset(dict->DeepCopy());
+ }
+ }
+
+ external_cache_->UpdateExtensionsList(prefs.Pass());
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698