diff options
author | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-16 04:10:38 +0000 |
---|---|---|
committer | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-16 04:10:38 +0000 |
commit | 0688d8dc3ed88977a92675dac4d03520d71afc24 (patch) | |
tree | 24bb368a1554ccb90194db42fc39c8f7246b32ad /chrome/browser/extensions/startup_helper.cc | |
parent | b225e9557f5bca7253d131a9913da4af9cd204e5 (diff) | |
download | chromium_src-0688d8dc3ed88977a92675dac4d03520d71afc24.zip chromium_src-0688d8dc3ed88977a92675dac4d03520d71afc24.tar.gz chromium_src-0688d8dc3ed88977a92675dac4d03520d71afc24.tar.bz2 |
Add a limited install extension from webstore command.
chrome/browser/extensions/startup_helper.*:
Added a method which does an asynchronous install of an
extension. It only handles fixed inputs to limit the
surface area of the feature. The callback for
LimitedInstallFromWebstore and the "2" are there to help
with testing. The core was formed by pulling out common
code from InstallFromWebstore. InstallFromWebstore doesn't
meet the needs because this command is used for apps (not
extensions).
chrome/browser/extensions/webstore_standalone_install_browsertest.cc:
Made CommandLineWebstoreInstall slightly more general
so that it could be used to test the limited install
scenario as well.
chrome/browser/ui/startup/startup_browser_creator.cc:
Handle the command line flag. This location handles flags
passed cross-process when a browser instance is already
running and another instance is started with the flag.
chrome/installer/setup/install_worker.cc:
Added the app command to the registry to allow using the
limited install switch. This re-uses much of the same code
as AddInstallAppCommandWorkItems.
chrome/installer/util/installation_validator.*
The verification for the new registry entry.
chrome/installer/util/installation_validator_unittest.cc:
Testing the verification.
chrome/common/chrome_switches.*:
The command line flag to do the limited install.
chrome/installer/util/util_constants.*:
The registry key value for the app command.
Review URL: https://chromiumcodereview.appspot.com/12226105
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/startup_helper.cc')
-rw-r--r-- | chrome/browser/extensions/startup_helper.cc | 105 |
1 files changed, 83 insertions, 22 deletions
diff --git a/chrome/browser/extensions/startup_helper.cc b/chrome/browser/extensions/startup_helper.cc index fefd492..3df2360 100644 --- a/chrome/browser/extensions/startup_helper.cc +++ b/chrome/browser/extensions/startup_helper.cc @@ -5,6 +5,7 @@ #include "chrome/browser/extensions/startup_helper.h" #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/command_line.h" #include "base/message_loop.h" #include "base/string_util.h" @@ -93,18 +94,30 @@ namespace { class AppInstallHelper { public: + // A callback for when the install process is done. + typedef base::Callback<void()> DoneCallback; + AppInstallHelper(); virtual ~AppInstallHelper(); bool success() { return success_; } const std::string& error() { return error_; } + void BeginInstall(Profile* profile, + const std::string& id, + WebstoreStandaloneInstaller::PromptType prompt_type, + DoneCallback callback); + private: WebstoreStandaloneInstaller::Callback Callback(); void OnAppInstallComplete(bool success, const std::string& error); - private: + DoneCallback done_callback_; + // These hold on to the result of the app install when it is complete. bool success_; std::string error_; + + scoped_ptr<content::WebContents> web_contents_; + scoped_refptr<WebstoreStandaloneInstaller> installer_; }; AppInstallHelper::AppInstallHelper() : success_(false) {} @@ -115,11 +128,44 @@ WebstoreStandaloneInstaller::Callback AppInstallHelper::Callback() { return base::Bind(&AppInstallHelper::OnAppInstallComplete, base::Unretained(this)); } + +void AppInstallHelper::BeginInstall( + Profile* profile, + const std::string& id, + WebstoreStandaloneInstaller::PromptType prompt_type, + DoneCallback done_callback) { + done_callback_ = done_callback; + + // TODO(asargent) - it would be nice not to need a WebContents just to + // use the standalone installer. (crbug.com/149039) + web_contents_.reset(content::WebContents::Create( + content::WebContents::CreateParams(profile))); + + WebstoreStandaloneInstaller::Callback callback = + base::Bind(&AppInstallHelper::OnAppInstallComplete, + base::Unretained(this)); + installer_ = new WebstoreStandaloneInstaller( + web_contents_.get(), + id, + WebstoreStandaloneInstaller::DO_NOT_REQUIRE_VERIFIED_SITE, + prompt_type, + GURL(), + callback); + installer_->set_skip_post_install_ui(true); + installer_->BeginInstall(); +} + void AppInstallHelper::OnAppInstallComplete(bool success, const std::string& error) { success_ = success; error_= error; - MessageLoop::current()->Quit(); + done_callback_.Run(); +} + +void DeleteHelperAndRunCallback(AppInstallHelper* helper, + base::Callback<void()> callback) { + delete helper; + callback.Run(); } } // namespace @@ -133,27 +179,12 @@ bool StartupHelper::InstallFromWebstore(const CommandLine& cmd_line, return false; } - // TODO(asargent) - it would be nice not to need a WebContents just to - // use the standalone installer. (crbug.com/149039) - scoped_ptr<content::WebContents> web_contents(content::WebContents::Create( - content::WebContents::CreateParams(profile))); - AppInstallHelper helper; - WebstoreStandaloneInstaller::Callback callback = - base::Bind(&AppInstallHelper::OnAppInstallComplete, - base::Unretained(&helper)); - scoped_refptr<WebstoreStandaloneInstaller> installer( - new WebstoreStandaloneInstaller( - web_contents.get(), - id, - WebstoreStandaloneInstaller::DO_NOT_REQUIRE_VERIFIED_SITE, - cmd_line.HasSwitch(switches::kForceAppMode) ? - WebstoreStandaloneInstaller::SKIP_PROMPT : - WebstoreStandaloneInstaller::STANDARD_PROMPT , - GURL(), - callback)); - installer->set_skip_post_install_ui(true); - installer->BeginInstall(); + helper.BeginInstall(profile, id, + cmd_line.HasSwitch(switches::kForceAppMode) ? + WebstoreStandaloneInstaller::SKIP_PROMPT : + WebstoreStandaloneInstaller::STANDARD_PROMPT, + MessageLoop::QuitWhenIdleClosure()); MessageLoop::current()->Run(); if (!helper.success()) @@ -161,6 +192,36 @@ bool StartupHelper::InstallFromWebstore(const CommandLine& cmd_line, return helper.success(); } +void StartupHelper::LimitedInstallFromWebstore( + const CommandLine& cmd_line, + Profile* profile, + base::Callback<void()> done_callback) { + std::string id = WebStoreIdFromLimitedInstallCmdLine(cmd_line); + if (!Extension::IdIsValid(id)) { + LOG(ERROR) << "Invalid index for " << switches::kLimitedInstallFromWebstore; + done_callback.Run(); + return; + } + + AppInstallHelper* helper = new AppInstallHelper(); + helper->BeginInstall(profile, id, + WebstoreStandaloneInstaller::STANDARD_PROMPT, + base::Bind(&DeleteHelperAndRunCallback, helper, done_callback)); +} + +std::string StartupHelper::WebStoreIdFromLimitedInstallCmdLine( + const CommandLine& cmd_line) { + std::string index = cmd_line.GetSwitchValueASCII( + switches::kLimitedInstallFromWebstore); + std::string id; + if (index == "1") { + id = "nckgahadagoaajjgafhacjanaoiihapd"; + } else if (index == "2") { + id = "ecglahbcnmdpdciemllbhojghbkagdje"; + } + return id; +} + StartupHelper::~StartupHelper() { if (pack_job_.get()) pack_job_->ClearClient(); |