Index: chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.h |
diff --git a/chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.h b/chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c9abf5d0d8d20d1d661c64ceec69ba073ea6382d |
--- /dev/null |
+++ b/chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.h |
@@ -0,0 +1,78 @@ |
+// 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. |
+ |
+#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_DEVICE_LOCAL_ACCOUNT_EXTERNAL_POLICY_LOADER_H_ |
+#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_DEVICE_LOCAL_ACCOUNT_EXTERNAL_POLICY_LOADER_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/callback_forward.h" |
+#include "base/compiler_specific.h" |
+#include "base/files/file_path.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/sequenced_task_runner.h" |
+#include "chrome/browser/chromeos/extensions/external_cache.h" |
+#include "chrome/browser/extensions/external_loader.h" |
+#include "chrome/browser/policy/cloud/cloud_policy_store.h" |
+ |
+namespace chromeos { |
+ |
+// A specialization of the ExternalLoader that serves external extensions from |
+// the enterprise policy force-install list. This class is used for device-local |
+// accounts in place of the ExternalPolicyLoader. The difference is that while |
+// the ExternalPolicyLoader requires extensions to be downloaded on-the-fly, |
+// this class caches them, allowing for offline installation. |
+class DeviceLocalAccountExternalPolicyLoader |
+ : public extensions::ExternalLoader, |
+ public policy::CloudPolicyStore::Observer, |
+ public ExternalCache::Delegate { |
+ public: |
+ // The list of force-installed extensions will be read from |store| and the |
+ // extensions will be cached in the |cache_dir_|. |
+ DeviceLocalAccountExternalPolicyLoader(policy::CloudPolicyStore* store, |
+ const base::FilePath& cache_dir); |
+ |
+ // While running, the cache requires exclusive write access to the |
+ // |cache_dir_|. |
+ bool IsCacheRunning() const; |
+ |
+ // Start the cache. This method must only be invoked when there are no pending |
+ // write operations to |cache_dir_| on any thread and none will be initiated |
+ // while the cache is running. |
+ void StartCache( |
+ const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner); |
+ |
+ // Stop the cache. The |callback| will be invoked when the cache has shut down |
+ // completely and write access to the |cache_dir_| is permitted again. |
+ void StopCache(const base::Closure& callback); |
+ |
+ // extensions::ExternalLoader: |
+ virtual void StartLoading() OVERRIDE; |
+ |
+ // policy::CloudPolicyStore::Observer: |
+ virtual void OnStoreLoaded(policy::CloudPolicyStore* store) OVERRIDE; |
+ virtual void OnStoreError(policy::CloudPolicyStore* store) OVERRIDE; |
+ |
+ // ExternalCache::Delegate: |
+ virtual void OnExtensionListsUpdated( |
+ const base::DictionaryValue* prefs) OVERRIDE; |
+ |
+ private: |
+ // If the cache was started, it must be stopped before |this| is destroyed. |
+ virtual ~DeviceLocalAccountExternalPolicyLoader(); |
+ |
+ // Pass the current list of force-installed extensions from the |store_| to |
+ // the |external_cache_|. |
+ void UpdateExtensionListFromStore(); |
+ |
+ policy::CloudPolicyStore* store_; |
+ const base::FilePath cache_dir_; |
+ scoped_ptr<ExternalCache> external_cache_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountExternalPolicyLoader); |
+}; |
+ |
+} // namespace chromeos |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_DEVICE_LOCAL_ACCOUNT_EXTERNAL_POLICY_LOADER_H_ |