Chromium Code Reviews| Index: chrome/browser/extensions/startup_helper.cc |
| diff --git a/chrome/browser/extensions/startup_helper.cc b/chrome/browser/extensions/startup_helper.cc |
| index b0c90bcc804918565bd00f1f4ccda4aebb86ee64..f535e77358639d9bb63030c3c45def5e86ba2c1a 100644 |
| --- a/chrome/browser/extensions/startup_helper.cc |
| +++ b/chrome/browser/extensions/startup_helper.cc |
| @@ -4,13 +4,19 @@ |
| #include "chrome/browser/extensions/startup_helper.h" |
| +#include "base/bind.h" |
| #include "base/command_line.h" |
| +#include "base/message_loop.h" |
| #include "base/string_util.h" |
| #include "base/stringprintf.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/extensions/webstore_inline_installer.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/chrome_switches.h" |
| +#include "chrome/common/extensions/extension.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "ipc/ipc_message.h" |
| namespace { |
| @@ -76,6 +82,73 @@ bool StartupHelper::UninstallExtension(const CommandLine& cmd_line, |
| extension_id); |
| } |
| +namespace { |
| + |
| +class AppInstallHelper { |
| + public: |
| + AppInstallHelper(); |
| + virtual ~AppInstallHelper(); |
| + bool success() { return success_; } |
| + const std::string& error() { return error_; } |
| + |
| + WebstoreInlineInstaller::Callback Callback(); |
| + void OnAppInstallComplete(bool success, const std::string& error); |
| + |
| + private: |
| + // These hold on to the result of the app install when it is complete. |
| + bool success_; |
| + std::string error_; |
| +}; |
| + |
| +AppInstallHelper::AppInstallHelper() : success_(false) {} |
| + |
| +AppInstallHelper::~AppInstallHelper() {} |
| + |
| +WebstoreInlineInstaller::Callback AppInstallHelper::Callback() { |
| + return base::Bind(&AppInstallHelper::OnAppInstallComplete, |
| + base::Unretained(this)); |
| +} |
| +void AppInstallHelper::OnAppInstallComplete(bool success, |
| + const std::string& error) { |
| + success_ = success; |
| + error_= error; |
| + MessageLoop::current()->Quit(); |
| +} |
| + |
| +} // namespace |
| + |
| +bool StartupHelper::InstallFromWebstore(const CommandLine& cmd_line, |
| + Profile* profile) { |
| + std::string id = cmd_line.GetSwitchValueASCII(switches::kInstallFromWebstore); |
| + if (!Extension::IdIsValid(id)) { |
| + LOG(ERROR) << "Invalid id for " << switches::kInstallFromWebstore |
| + << " : '" << id << "'"; |
| + return false; |
| + } |
| + |
| + // TODO(asargent) - it would be nice not to need a WebContents just to |
| + // use the inline installer. (crbug.com/149039) |
| + scoped_ptr<content::WebContents> web_contents( |
| + content::WebContents::Create(profile, NULL, MSG_ROUTING_NONE, NULL)); |
| + |
| + AppInstallHelper helper; |
| + WebstoreInlineInstaller::Callback callback = |
| + base::Bind(&AppInstallHelper::OnAppInstallComplete, |
| + base::Unretained(&helper)); |
| + scoped_refptr<WebstoreInlineInstaller> installer( |
| + new WebstoreInlineInstaller( |
| + web_contents.get(), |
| + id, |
| + WebstoreInlineInstaller::DO_NOT_REQUIRE_VERIFIED_SITE, |
| + GURL(), |
| + callback)); |
| + installer->set_skip_post_install_ui(true); |
| + installer->BeginInstall(); |
| + |
| + MessageLoop::current()->Run(); |
| + return helper.success(); |
|
Mihai Parparita -not on Chrome
2012/09/16 06:42:38
To aid debugging, log helper.error() if success if
asargent_no_longer_on_chrome
2012/09/17 05:11:45
Done.
|
| +} |
| + |
| StartupHelper::~StartupHelper() { |
| if (pack_job_.get()) |
| pack_job_->ClearClient(); |