summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy
diff options
context:
space:
mode:
authorjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 19:07:04 +0000
committerjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 19:07:04 +0000
commit7dbb215fff67bd1a7fac0f50fd7ade0fd0ba9259 (patch)
tree4211b49c35f5eb86b3b0cb20cd0ac0d9dc6c86a5 /chrome/browser/policy
parent5f1e75dd1547be7f3b311659d9cb3fa724f7b5ed (diff)
downloadchromium_src-7dbb215fff67bd1a7fac0f50fd7ade0fd0ba9259.zip
chromium_src-7dbb215fff67bd1a7fac0f50fd7ade0fd0ba9259.tar.gz
chromium_src-7dbb215fff67bd1a7fac0f50fd7ade0fd0ba9259.tar.bz2
Publish the location of the screensaver extension from the AppPackUpdater.
BUG=chromium-os:25463,chromium-os:23178 TEST=Set the AppPack and ScreenSaver policies. The ScreenSaver extension is downloaded but not installed. Review URL: http://codereview.chromium.org/9753006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/policy')
-rw-r--r--chrome/browser/policy/app_pack_updater.cc42
-rw-r--r--chrome/browser/policy/app_pack_updater.h24
2 files changed, 60 insertions, 6 deletions
diff --git a/chrome/browser/policy/app_pack_updater.cc b/chrome/browser/policy/app_pack_updater.cc
index 7556f3a..f06f0a9 100644
--- a/chrome/browser/policy/app_pack_updater.cc
+++ b/chrome/browser/policy/app_pack_updater.cc
@@ -5,7 +5,6 @@
#include "chrome/browser/policy/app_pack_updater.h"
#include "base/bind.h"
-#include "base/file_path.h"
#include "base/file_util.h"
#include "base/location.h"
#include "base/stl_util.h"
@@ -116,6 +115,16 @@ ExternalExtensionLoader* AppPackUpdater::CreateExternalExtensionLoader() {
return loader;
}
+void AppPackUpdater::SetScreenSaverUpdateCallback(
+ const AppPackUpdater::ScreenSaverUpdateCallback& callback) {
+ screen_saver_update_callback_ = callback;
+ if (!screen_saver_update_callback_.is_null() && !screen_saver_path_.empty()) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(screen_saver_update_callback_, screen_saver_path_));
+ }
+}
+
void AppPackUpdater::Init() {
worker_pool_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken();
chromeos::CrosSettings::Get()->AddSettingsObserver(chromeos::kAppPack, this);
@@ -147,6 +156,7 @@ void AppPackUpdater::LoadPolicy() {
weak_ptr_factory_.GetWeakPtr()))) {
return;
}
+
app_pack_extensions_.clear();
const base::Value* value = settings->GetPref(chromeos::kAppPack);
const base::ListValue* list = NULL;
@@ -173,6 +183,12 @@ void AppPackUpdater::LoadPolicy() {
VLOG(1) << "Refreshed AppPack policy, got " << app_pack_extensions_.size()
<< " entries.";
+ value = settings->GetPref(chromeos::kScreenSaverExtensionId);
+ if (!value || !value->GetAsString(&screen_saver_id_)) {
+ screen_saver_id_.clear();
+ SetScreenSaverPath(FilePath());
+ }
+
CheckCacheNow();
}
@@ -450,12 +466,17 @@ void AppPackUpdater::OnCacheEntryInstalled(const std::string& id,
const std::string& path,
const std::string& version) {
VLOG(1) << "AppPack installed a new extension in the cache: " << path;
- // AppPack +1
- CacheEntry& entry = cached_extensions_[id];
- entry.path = path;
- entry.cached_version = version;
- UpdateExtensionLoader();
+ if (id == screen_saver_id_) {
+ VLOG(1) << "AppPack got the screen saver extension at " << path;
+ SetScreenSaverPath(FilePath(path));
+ } else {
+ // Add to the list of cached extensions.
+ CacheEntry& entry = cached_extensions_[id];
+ entry.path = path;
+ entry.cached_version = version;
+ UpdateExtensionLoader();
+ }
}
void AppPackUpdater::PostBlockingTask(const tracked_objects::Location& location,
@@ -465,4 +486,13 @@ void AppPackUpdater::PostBlockingTask(const tracked_objects::Location& location,
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
}
+void AppPackUpdater::SetScreenSaverPath(const FilePath& path) {
+ // Don't invoke the callback if the path isn't changing.
+ if (path != screen_saver_path_) {
+ screen_saver_path_ = path;
+ if (!screen_saver_update_callback_.is_null())
+ screen_saver_update_callback_.Run(screen_saver_path_);
+ }
+}
+
} // namespace policy
diff --git a/chrome/browser/policy/app_pack_updater.h b/chrome/browser/policy/app_pack_updater.h
index bda82b0..1fedbe9 100644
--- a/chrome/browser/policy/app_pack_updater.h
+++ b/chrome/browser/policy/app_pack_updater.h
@@ -11,7 +11,9 @@
#include <string>
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/compiler_specific.h"
+#include "base/file_path.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/extensions/updater/extension_downloader_delegate.h"
@@ -46,6 +48,9 @@ class AppPackUpdater : public CloudPolicySubsystem::Observer,
public content::NotificationObserver,
public extensions::ExtensionDownloaderDelegate {
public:
+ // Callback to listen for updates to the screensaver extension's path.
+ typedef base::Callback<void(const FilePath&)> ScreenSaverUpdateCallback;
+
// Keys for the entries in the AppPack dictionary policy.
static const char kExtensionId[];
static const char kUpdateUrl[];
@@ -60,6 +65,12 @@ class AppPackUpdater : public CloudPolicySubsystem::Observer,
// owns the returned value.
ExternalExtensionLoader* CreateExternalExtensionLoader();
+ // |callback| will be invoked whenever the screen saver extension's path
+ // changes. It will be invoked "soon" after this call if a valid path already
+ // exists. Subsequent calls will override the previous |callback|. A null
+ // |callback| can be used to remove a previous callback.
+ void SetScreenSaverUpdateCallback(const ScreenSaverUpdateCallback& callback);
+
private:
struct CacheEntry {
std::string path;
@@ -156,6 +167,10 @@ class AppPackUpdater : public CloudPolicySubsystem::Observer,
void PostBlockingTask(const tracked_objects::Location& from_here,
const base::Closure& task);
+ // Sets |screen_saver_path_| and invokes |screen_saver_update_callback_| if
+ // appropriate.
+ void SetScreenSaverPath(const FilePath& path);
+
base::WeakPtrFactory<AppPackUpdater> weak_ptr_factory_;
// Observes updates to the |device_cloud_policy_subsystem_|, to detect
@@ -173,6 +188,15 @@ class AppPackUpdater : public CloudPolicySubsystem::Observer,
// and that have a valid crx in the cache.
CacheEntryMap cached_extensions_;
+ // The extension ID and path of the CRX file of the screen saver extension,
+ // if it is configured by the policy. Otherwise these fields are empty.
+ std::string screen_saver_id_;
+ FilePath screen_saver_path_;
+
+ // Callback to invoke whenever the screen saver's extension path changes.
+ // Can be null.
+ ScreenSaverUpdateCallback screen_saver_update_callback_;
+
// The extension loader wires the AppPackUpdater to the extensions system, and
// makes it install the currently cached extensions.
bool created_extension_loader_;