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

Side by Side Diff: chrome/browser/apps/ephemeral_app_launcher.cc

Issue 389613006: Prevent duplicate concurrent installs of the same extension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed update of webstore_result Created 6 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/apps/ephemeral_app_launcher.h" 5 #include "chrome/browser/apps/ephemeral_app_launcher.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/extension_install_checker.h" 9 #include "chrome/browser/extensions/extension_install_checker.h"
10 #include "chrome/browser/extensions/extension_install_prompt.h" 10 #include "chrome/browser/extensions/extension_install_prompt.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 if (!extensions::util::IsAppLaunchable(extension->id(), profile())) { 217 if (!extensions::util::IsAppLaunchable(extension->id(), profile())) {
218 *reason = webstore_install::REQUIREMENT_VIOLATIONS; 218 *reason = webstore_install::REQUIREMENT_VIOLATIONS;
219 *error = kRequirementsError; 219 *error = kRequirementsError;
220 return false; 220 return false;
221 } 221 }
222 222
223 return true; 223 return true;
224 } 224 }
225 225
226 void EphemeralAppLauncher::EnableInstalledApp(const Extension* extension) { 226 void EphemeralAppLauncher::EnableInstalledApp(const Extension* extension) {
227 // Check whether an install is already in progress.
228 webstore_install::Result result = webstore_install::UNKNOWN_ERROR;
229 std::string error;
230 if (!EnsureUniqueInstall(&result, &error)) {
231 InvokeCallback(result, error);
232 return;
233 }
234
235 // Keep this object alive until the enable flow is complete. Either
236 // ExtensionEnableFlowFinished() or ExtensionEnableFlowAborted() will be
237 // called.
238 AddRef();
239
227 extension_enable_flow_.reset( 240 extension_enable_flow_.reset(
228 new ExtensionEnableFlow(profile(), extension->id(), this)); 241 new ExtensionEnableFlow(profile(), extension->id(), this));
229 if (web_contents()) 242 if (web_contents())
230 extension_enable_flow_->StartForWebContents(web_contents()); 243 extension_enable_flow_->StartForWebContents(web_contents());
231 else 244 else
232 extension_enable_flow_->StartForNativeWindow(parent_window_); 245 extension_enable_flow_->StartForNativeWindow(parent_window_);
233
234 // Keep this object alive until the enable flow is complete. Either
235 // ExtensionEnableFlowFinished() or ExtensionEnableFlowAborted() will be
236 // called.
237 AddRef();
238 } 246 }
239 247
240 void EphemeralAppLauncher::MaybeLaunchApp() { 248 void EphemeralAppLauncher::MaybeLaunchApp() {
241 webstore_install::Result result = webstore_install::UNKNOWN_ERROR; 249 webstore_install::Result result = webstore_install::UNKNOWN_ERROR;
242 std::string error; 250 std::string error;
243 251
244 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); 252 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
245 const Extension* extension = 253 const Extension* extension =
246 registry->GetExtensionById(id(), ExtensionRegistry::EVERYTHING); 254 registry->GetExtensionById(id(), ExtensionRegistry::EVERYTHING);
247 if (extension) { 255 if (extension) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 chrome::NavigateParams params( 293 chrome::NavigateParams params(
286 displayer.browser(), launch_url, content::PAGE_TRANSITION_AUTO_TOPLEVEL); 294 displayer.browser(), launch_url, content::PAGE_TRANSITION_AUTO_TOPLEVEL);
287 params.disposition = NEW_FOREGROUND_TAB; 295 params.disposition = NEW_FOREGROUND_TAB;
288 chrome::Navigate(&params); 296 chrome::Navigate(&params);
289 return true; 297 return true;
290 } 298 }
291 299
292 void EphemeralAppLauncher::InvokeCallback(webstore_install::Result result, 300 void EphemeralAppLauncher::InvokeCallback(webstore_install::Result result,
293 const std::string& error) { 301 const std::string& error) {
294 if (!launch_callback_.is_null()) { 302 if (!launch_callback_.is_null()) {
295 launch_callback_.Run(result, error); 303 LaunchCallback callback = launch_callback_;
296 launch_callback_.Reset(); 304 launch_callback_.Reset();
305 callback.Run(result, error);
297 } 306 }
298 } 307 }
299 308
300 void EphemeralAppLauncher::AbortLaunch(webstore_install::Result result, 309 void EphemeralAppLauncher::AbortLaunch(webstore_install::Result result,
301 const std::string& error) { 310 const std::string& error) {
302 InvokeCallback(result, error); 311 InvokeCallback(result, error);
303 WebstoreStandaloneInstaller::CompleteInstall(result, error); 312 WebstoreStandaloneInstaller::CompleteInstall(result, error);
304 } 313 }
305 314
306 void EphemeralAppLauncher::CheckEphemeralInstallPermitted() { 315 void EphemeralAppLauncher::CheckEphemeralInstallPermitted() {
(...skipping 25 matching lines...) Expand all
332 if (!install_checker_->requirement_errors().empty()) { 341 if (!install_checker_->requirement_errors().empty()) {
333 AbortLaunch(webstore_install::REQUIREMENT_VIOLATIONS, 342 AbortLaunch(webstore_install::REQUIREMENT_VIOLATIONS,
334 install_checker_->requirement_errors().front()); 343 install_checker_->requirement_errors().front());
335 return; 344 return;
336 } 345 }
337 346
338 // Proceed with the normal install flow. 347 // Proceed with the normal install flow.
339 ProceedWithInstallPrompt(); 348 ProceedWithInstallPrompt();
340 } 349 }
341 350
351 void EphemeralAppLauncher::InitInstallData(
352 extensions::ActiveInstallData* install_data) const {
353 install_data->is_ephemeral = true;
354 }
355
342 bool EphemeralAppLauncher::CheckRequestorAlive() const { 356 bool EphemeralAppLauncher::CheckRequestorAlive() const {
343 return dummy_web_contents_.get() != NULL || web_contents() != NULL; 357 return dummy_web_contents_.get() != NULL || web_contents() != NULL;
344 } 358 }
345 359
346 const GURL& EphemeralAppLauncher::GetRequestorURL() const { 360 const GURL& EphemeralAppLauncher::GetRequestorURL() const {
347 return GURL::EmptyGURL(); 361 return GURL::EmptyGURL();
348 } 362 }
349 363
350 bool EphemeralAppLauncher::ShouldShowPostInstallUI() const { 364 bool EphemeralAppLauncher::ShouldShowPostInstallUI() const {
351 return false; 365 return false;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 WebstoreStandaloneInstaller::CompleteInstall(result, error); 446 WebstoreStandaloneInstaller::CompleteInstall(result, error);
433 } 447 }
434 448
435 void EphemeralAppLauncher::WebContentsDestroyed() { 449 void EphemeralAppLauncher::WebContentsDestroyed() {
436 launch_callback_.Reset(); 450 launch_callback_.Reset();
437 AbortInstall(); 451 AbortInstall();
438 } 452 }
439 453
440 void EphemeralAppLauncher::ExtensionEnableFlowFinished() { 454 void EphemeralAppLauncher::ExtensionEnableFlowFinished() {
441 MaybeLaunchApp(); 455 MaybeLaunchApp();
442 Release(); // Matches the AddRef in EnableInstalledApp(). 456
457 // CompleteInstall will call Release.
458 WebstoreStandaloneInstaller::CompleteInstall(webstore_install::SUCCESS,
459 std::string());
443 } 460 }
444 461
445 void EphemeralAppLauncher::ExtensionEnableFlowAborted(bool user_initiated) { 462 void EphemeralAppLauncher::ExtensionEnableFlowAborted(bool user_initiated) {
446 InvokeCallback(webstore_install::USER_CANCELLED, kUserCancelledError); 463 // CompleteInstall will call Release.
447 Release(); // Matches the AddRef in EnableInstalledApp(). 464 CompleteInstall(webstore_install::USER_CANCELLED, kUserCancelledError);
448 } 465 }
OLDNEW
« no previous file with comments | « chrome/browser/apps/ephemeral_app_launcher.h ('k') | chrome/browser/apps/ephemeral_app_launcher_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698