OLD | NEW |
---|---|
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/crx_installer.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
19 #include "base/time.h" | 19 #include "base/time.h" |
20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
21 #include "base/version.h" | 21 #include "base/version.h" |
22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/extensions/app_host_installer.h" | |
23 #include "chrome/browser/extensions/convert_user_script.h" | 24 #include "chrome/browser/extensions/convert_user_script.h" |
24 #include "chrome/browser/extensions/convert_web_app.h" | 25 #include "chrome/browser/extensions/convert_web_app.h" |
25 #include "chrome/browser/extensions/extension_error_reporter.h" | 26 #include "chrome/browser/extensions/extension_error_reporter.h" |
26 #include "chrome/browser/extensions/extension_install_ui.h" | 27 #include "chrome/browser/extensions/extension_install_ui.h" |
27 #include "chrome/browser/extensions/extension_service.h" | 28 #include "chrome/browser/extensions/extension_service.h" |
28 #include "chrome/browser/extensions/extension_system.h" | 29 #include "chrome/browser/extensions/extension_system.h" |
29 #include "chrome/browser/extensions/permissions_updater.h" | 30 #include "chrome/browser/extensions/permissions_updater.h" |
30 #include "chrome/browser/extensions/requirements_checker.h" | 31 #include "chrome/browser/extensions/requirements_checker.h" |
31 #include "chrome/browser/extensions/webstore_installer.h" | 32 #include "chrome/browser/extensions/webstore_installer.h" |
32 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 | 457 |
457 current_version_ = | 458 current_version_ = |
458 frontend_weak_->extension_prefs()->GetVersionString(extension_->id()); | 459 frontend_weak_->extension_prefs()->GetVersionString(extension_->id()); |
459 | 460 |
460 if (client_ && (!allow_silent_install_ || !approved_)) { | 461 if (client_ && (!allow_silent_install_ || !approved_)) { |
461 AddRef(); // Balanced in Proceed() and Abort(). | 462 AddRef(); // Balanced in Proceed() and Abort(). |
462 client_->ConfirmInstall(this, extension_.get(), show_dialog_callback_); | 463 client_->ConfirmInstall(this, extension_.get(), show_dialog_callback_); |
463 } else { | 464 } else { |
464 if (!BrowserThread::PostTask( | 465 if (!BrowserThread::PostTask( |
465 BrowserThread::FILE, FROM_HERE, | 466 BrowserThread::FILE, FROM_HERE, |
466 base::Bind(&CrxInstaller::CompleteInstall, this))) | 467 base::Bind(&CrxInstaller::BeginInstall, this))) |
467 NOTREACHED(); | 468 NOTREACHED(); |
468 } | 469 } |
469 return; | 470 return; |
470 } | 471 } |
471 | 472 |
472 void CrxInstaller::InstallUIProceed() { | 473 void CrxInstaller::InstallUIProceed() { |
473 if (!BrowserThread::PostTask( | 474 if (!BrowserThread::PostTask( |
474 BrowserThread::FILE, FROM_HERE, | 475 BrowserThread::FILE, FROM_HERE, |
475 base::Bind(&CrxInstaller::CompleteInstall, this))) | 476 base::Bind(&CrxInstaller::BeginInstall, this))) |
476 NOTREACHED(); | 477 NOTREACHED(); |
477 | 478 |
478 Release(); // balanced in ConfirmInstall(). | 479 Release(); // balanced in ConfirmInstall(). |
479 } | 480 } |
480 | 481 |
481 void CrxInstaller::InstallUIAbort(bool user_initiated) { | 482 void CrxInstaller::InstallUIAbort(bool user_initiated) { |
482 std::string histogram_name = user_initiated ? | 483 std::string histogram_name = user_initiated ? |
483 "Extensions.Permissions_InstallCancel" : | 484 "Extensions.Permissions_InstallCancel" : |
484 "Extensions.Permissions_InstallAbort"; | 485 "Extensions.Permissions_InstallAbort"; |
485 ExtensionService::RecordPermissionMessagesHistogram( | 486 ExtensionService::RecordPermissionMessagesHistogram( |
486 extension_, histogram_name.c_str()); | 487 extension_, histogram_name.c_str()); |
487 | 488 |
488 // Kill the theme loading bubble. | 489 // Kill the theme loading bubble. |
489 content::NotificationService* service = | 490 content::NotificationService* service = |
490 content::NotificationService::current(); | 491 content::NotificationService::current(); |
491 service->Notify(chrome::NOTIFICATION_NO_THEME_DETECTED, | 492 service->Notify(chrome::NOTIFICATION_NO_THEME_DETECTED, |
492 content::Source<CrxInstaller>(this), | 493 content::Source<CrxInstaller>(this), |
493 content::NotificationService::NoDetails()); | 494 content::NotificationService::NoDetails()); |
494 | 495 |
495 NotifyCrxInstallComplete(NULL); | 496 NotifyCrxInstallComplete(NULL); |
496 | 497 |
497 Release(); // balanced in ConfirmInstall(). | 498 Release(); // balanced in ConfirmInstall(). |
498 | 499 |
499 // We're done. Since we don't post any more tasks to ourself, our ref count | 500 // We're done. Since we don't post any more tasks to ourself, our ref count |
500 // should go to zero and we die. The destructor will clean up the temp dir. | 501 // should go to zero and we die. The destructor will clean up the temp dir. |
501 } | 502 } |
502 | 503 |
503 void CrxInstaller::CompleteInstall() { | 504 void CrxInstaller::BeginInstall() { |
504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
505 | |
506 if (!current_version_.empty()) { | 506 if (!current_version_.empty()) { |
507 Version current_version(current_version_); | 507 Version current_version(current_version_); |
508 if (current_version.CompareTo(*(extension_->version())) > 0) { | 508 if (current_version.CompareTo(*(extension_->version())) > 0) { |
509 ReportFailureFromFileThread( | 509 ReportFailureFromFileThread( |
510 CrxInstallerError( | 510 CrxInstallerError( |
511 l10n_util::GetStringUTF16(extension_->is_app() ? | 511 l10n_util::GetStringUTF16(extension_->is_app() ? |
512 IDS_APP_CANT_DOWNGRADE_VERSION : | 512 IDS_APP_CANT_DOWNGRADE_VERSION : |
513 IDS_EXTENSION_CANT_DOWNGRADE_VERSION))); | 513 IDS_EXTENSION_CANT_DOWNGRADE_VERSION))); |
514 return; | 514 return; |
515 } | 515 } |
516 } | 516 } |
517 | 517 |
518 app_host_installer::InstallAppHostIfNecessary( | |
Aaron Boodman
2012/10/25 04:39:41
This seems out of place and like a layering violat
erikwright (departed)
2012/10/26 20:32:30
OK. It would be an API similar to the following:
Aaron Boodman
2012/10/29 23:37:29
Imagine a world after:
mv /chrome/browser/extensi
| |
519 *extension_, | |
520 base::Bind(&CrxInstaller::OnAppHostInstallationComplete, this)); | |
Aaron Boodman
2012/10/25 04:39:41
I didn't have time to read all the code behind Ins
erikwright (departed)
2012/10/26 20:32:30
We launch an external process, which can take an a
Aaron Boodman
2012/10/29 23:37:29
You could move CrxInstaller to use the BlockingTas
huangs
2012/11/01 22:55:48
Per our discussion, moving installation to AppShor
| |
521 } | |
522 | |
523 void CrxInstaller::OnAppHostInstallationComplete(bool success) { | |
524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
525 if (!success) { | |
526 ReportFailureFromFileThread(CrxInstallerError( | |
527 l10n_util::GetStringUTF16(IDS_EXTENSION_APP_HOST_INSTALL_ERROR))); | |
528 return; | |
529 } | |
530 | |
531 CompleteInstall(); | |
532 } | |
533 | |
534 void CrxInstaller::CompleteInstall() { | |
535 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
518 // See how long extension install paths are. This is important on | 536 // See how long extension install paths are. This is important on |
519 // windows, because file operations may fail if the path to a file | 537 // windows, because file operations may fail if the path to a file |
520 // exceeds a small constant. See crbug.com/69693 . | 538 // exceeds a small constant. See crbug.com/69693 . |
521 UMA_HISTOGRAM_CUSTOM_COUNTS( | 539 UMA_HISTOGRAM_CUSTOM_COUNTS( |
522 "Extensions.CrxInstallDirPathLength", | 540 "Extensions.CrxInstallDirPathLength", |
523 install_directory_.value().length(), 0, 500, 100); | 541 install_directory_.value().length(), 0, 500, 100); |
524 | 542 |
525 FilePath version_dir = extension_file_util::InstallExtension( | 543 FilePath version_dir = extension_file_util::InstallExtension( |
526 unpacked_extension_root_, | 544 unpacked_extension_root_, |
527 extension_->id(), | 545 extension_->id(), |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 // is problematic because they don't know anything about the | 664 // is problematic because they don't know anything about the |
647 // extension before it is unpacked, so they cannot filter based | 665 // extension before it is unpacked, so they cannot filter based |
648 // on the extension. | 666 // on the extension. |
649 content::NotificationService::current()->Notify( | 667 content::NotificationService::current()->Notify( |
650 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 668 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
651 content::Source<CrxInstaller>(this), | 669 content::Source<CrxInstaller>(this), |
652 content::Details<const Extension>(extension)); | 670 content::Details<const Extension>(extension)); |
653 } | 671 } |
654 | 672 |
655 } // namespace extensions | 673 } // namespace extensions |
OLD | NEW |