summaryrefslogtreecommitdiffstats
path: root/chrome/browser/first_run_win.cc
diff options
context:
space:
mode:
authorcpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-08 18:42:25 +0000
committercpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-08 18:42:25 +0000
commit4576e9f095e767e8b78861e2cdde6d6730ad5267 (patch)
tree69df195ef0855087872358b99ca9025cbf442eb1 /chrome/browser/first_run_win.cc
parent0afa1c4259d103037bbce99a5b52057aaaef4f34 (diff)
downloadchromium_src-4576e9f095e767e8b78861e2cdde6d6730ad5267.zip
chromium_src-4576e9f095e767e8b78861e2cdde6d6730ad5267.tar.gz
chromium_src-4576e9f095e767e8b78861e2cdde6d6730ad5267.tar.bz2
Add support for auto-installing extensions at first run via master prefs
This a even lower impact method, with no new fields added. This is how it works: 1- The extension pared down manifest goes into the master prefs 2- The master prefs become the prefs at first run 3- First run notices an extensions block, an triggers an extensions check 4- The full extension gets updated then BUG=37573 TEST=ut included, also see bug Review URL: http://codereview.chromium.org/669218 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/first_run_win.cc')
-rw-r--r--chrome/browser/first_run_win.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/chrome/browser/first_run_win.cc b/chrome/browser/first_run_win.cc
index faaef63..c57126c 100644
--- a/chrome/browser/first_run_win.cc
+++ b/chrome/browser/first_run_win.cc
@@ -27,8 +27,13 @@
#include "base/string_util.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/notification_registrar.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/browser/extensions/extension_updater.h"
#include "chrome/browser/hang_monitor/hung_window_detector.h"
#include "chrome/browser/importer/importer.h"
#include "chrome/browser/pref_service.h"
@@ -151,6 +156,51 @@ bool WriteEULAtoTempFile(FilePath* eula_path) {
return (file_util::WriteFile(*eula_path, terms.c_str(), terms.size()) > 0);
}
+// Helper class that performs delayed first-run tasks that need more of the
+// chrome infrastructure to be up an running before they can be attempted.
+class FirsRunDelayedTasks : public NotificationObserver {
+ public:
+ enum Tasks {
+ NO_TASK,
+ INSTALL_EXTENSIONS
+ };
+
+ explicit FirsRunDelayedTasks(Tasks task) {
+ if (task == INSTALL_EXTENSIONS) {
+ registrar_.Add(this, NotificationType::EXTENSIONS_READY,
+ NotificationService::AllSources());
+ }
+ registrar_.Add(this, NotificationType::BROWSER_CLOSED,
+ NotificationService::AllSources());
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ // After processing the notification we always delete ourselves.
+ if (type.value == NotificationType::EXTENSIONS_READY)
+ DoExtensionWork(Source<Profile>(source).ptr()->GetExtensionsService());
+ delete this;
+ return;
+ }
+
+ private:
+ // Private ctor forces it to be created only in the heap.
+ ~FirsRunDelayedTasks() {}
+
+ // The extension work is to basically trigger an extension update check.
+ // If the extension specified in the master pref is older than the live
+ // extension it will get updated which is the same as get it installed.
+ void DoExtensionWork(ExtensionsService* service) {
+ if (!service)
+ return;
+ service->updater()->CheckNow();
+ return;
+ }
+
+ NotificationRegistrar registrar_;
+};
+
} // namespace
bool FirstRun::CreateChromeDesktopShortcut() {
@@ -247,6 +297,12 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
if (!file_util::CopyFile(master_prefs, user_prefs))
return true;
+ DictionaryValue* extensions = 0;
+ if (installer_util::HasExtensionsBlock(prefs.get(), &extensions)) {
+ LOG(INFO) << "Extensions block found in master preferences";
+ new FirsRunDelayedTasks(FirsRunDelayedTasks::INSTALL_EXTENSIONS);
+ }
+
// Add a special exception for import_search_engine preference.
// Even though we skip all other import_* preferences below, if
// skip-first-run-ui is not specified, we make exception for this one