Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5328)

Unified Diff: chrome/browser/extensions/startup_helper.cc

Issue 10907104: Support an --install-from-webstore command line switch (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebased Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/startup_helper.h ('k') | chrome/browser/extensions/tab_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..aabbf715738010d87abb94cece766fbd514f00af 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,75 @@ 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();
+ if (!helper.success())
+ LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error();
+ return helper.success();
+}
+
StartupHelper::~StartupHelper() {
if (pack_job_.get())
pack_job_->ClearClient();
« no previous file with comments | « chrome/browser/extensions/startup_helper.h ('k') | chrome/browser/extensions/tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698