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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/startup_helper.h ('k') | chrome/browser/extensions/tab_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/startup_helper.h" 5 #include "chrome/browser/extensions/startup_helper.h"
6 6
7 #include "base/bind.h"
7 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop.h"
8 #include "base/string_util.h" 10 #include "base/string_util.h"
9 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/webstore_inline_installer.h"
12 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/extensions/extension.h"
18 #include "content/public/browser/web_contents.h"
19 #include "ipc/ipc_message.h"
14 20
15 namespace { 21 namespace {
16 22
17 void PrintPackExtensionMessage(const std::string& message) { 23 void PrintPackExtensionMessage(const std::string& message) {
18 base::StringPrintf("%s\n", message.c_str()); 24 base::StringPrintf("%s\n", message.c_str());
19 } 25 }
20 26
21 } // namespace 27 } // namespace
22 28
23 namespace extensions { 29 namespace extensions {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 ExtensionService* extension_service = profile->GetExtensionService(); 75 ExtensionService* extension_service = profile->GetExtensionService();
70 if (!extension_service) 76 if (!extension_service)
71 return false; 77 return false;
72 78
73 std::string extension_id = cmd_line.GetSwitchValueASCII( 79 std::string extension_id = cmd_line.GetSwitchValueASCII(
74 switches::kUninstallExtension); 80 switches::kUninstallExtension);
75 return ExtensionService::UninstallExtensionHelper(extension_service, 81 return ExtensionService::UninstallExtensionHelper(extension_service,
76 extension_id); 82 extension_id);
77 } 83 }
78 84
85 namespace {
86
87 class AppInstallHelper {
88 public:
89 AppInstallHelper();
90 virtual ~AppInstallHelper();
91 bool success() { return success_; }
92 const std::string& error() { return error_; }
93
94 WebstoreInlineInstaller::Callback Callback();
95 void OnAppInstallComplete(bool success, const std::string& error);
96
97 private:
98 // These hold on to the result of the app install when it is complete.
99 bool success_;
100 std::string error_;
101 };
102
103 AppInstallHelper::AppInstallHelper() : success_(false) {}
104
105 AppInstallHelper::~AppInstallHelper() {}
106
107 WebstoreInlineInstaller::Callback AppInstallHelper::Callback() {
108 return base::Bind(&AppInstallHelper::OnAppInstallComplete,
109 base::Unretained(this));
110 }
111 void AppInstallHelper::OnAppInstallComplete(bool success,
112 const std::string& error) {
113 success_ = success;
114 error_= error;
115 MessageLoop::current()->Quit();
116 }
117
118 } // namespace
119
120 bool StartupHelper::InstallFromWebstore(const CommandLine& cmd_line,
121 Profile* profile) {
122 std::string id = cmd_line.GetSwitchValueASCII(switches::kInstallFromWebstore);
123 if (!Extension::IdIsValid(id)) {
124 LOG(ERROR) << "Invalid id for " << switches::kInstallFromWebstore
125 << " : '" << id << "'";
126 return false;
127 }
128
129 // TODO(asargent) - it would be nice not to need a WebContents just to
130 // use the inline installer. (crbug.com/149039)
131 scoped_ptr<content::WebContents> web_contents(
132 content::WebContents::Create(profile, NULL, MSG_ROUTING_NONE, NULL));
133
134 AppInstallHelper helper;
135 WebstoreInlineInstaller::Callback callback =
136 base::Bind(&AppInstallHelper::OnAppInstallComplete,
137 base::Unretained(&helper));
138 scoped_refptr<WebstoreInlineInstaller> installer(
139 new WebstoreInlineInstaller(
140 web_contents.get(),
141 id,
142 WebstoreInlineInstaller::DO_NOT_REQUIRE_VERIFIED_SITE,
143 GURL(),
144 callback));
145 installer->set_skip_post_install_ui(true);
146 installer->BeginInstall();
147
148 MessageLoop::current()->Run();
149 if (!helper.success())
150 LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error();
151 return helper.success();
152 }
153
79 StartupHelper::~StartupHelper() { 154 StartupHelper::~StartupHelper() {
80 if (pack_job_.get()) 155 if (pack_job_.get())
81 pack_job_->ClearClient(); 156 pack_job_->ClearClient();
82 } 157 }
83 158
84 } // namespace extensions 159 } // namespace extensions
OLDNEW
« 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