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" |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 ExtensionService::RecordPermissionMessagesHistogram( | 478 ExtensionService::RecordPermissionMessagesHistogram( |
479 extension_, histogram_name.c_str()); | 479 extension_, histogram_name.c_str()); |
480 | 480 |
481 // Kill the theme loading bubble. | 481 // Kill the theme loading bubble. |
482 content::NotificationService* service = | 482 content::NotificationService* service = |
483 content::NotificationService::current(); | 483 content::NotificationService::current(); |
484 service->Notify(chrome::NOTIFICATION_NO_THEME_DETECTED, | 484 service->Notify(chrome::NOTIFICATION_NO_THEME_DETECTED, |
485 content::Source<CrxInstaller>(this), | 485 content::Source<CrxInstaller>(this), |
486 content::NotificationService::NoDetails()); | 486 content::NotificationService::NoDetails()); |
487 | 487 |
488 NotifyCrxInstallComplete(NULL); | 488 NotifyCrxInstallComplete(false); |
489 | 489 |
490 Release(); // balanced in ConfirmInstall(). | 490 Release(); // balanced in ConfirmInstall(). |
491 | 491 |
492 // We're done. Since we don't post any more tasks to ourself, our ref count | 492 // We're done. Since we don't post any more tasks to ourself, our ref count |
493 // should go to zero and we die. The destructor will clean up the temp dir. | 493 // should go to zero and we die. The destructor will clean up the temp dir. |
494 } | 494 } |
495 | 495 |
496 void CrxInstaller::CompleteInstall() { | 496 void CrxInstaller::CompleteInstall() { |
497 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); | 497 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); |
498 | 498 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 // see errors get reported via this interface. | 574 // see errors get reported via this interface. |
575 // | 575 // |
576 // TODO(aa): Need to go through unit tests and clean them up too, probably get | 576 // TODO(aa): Need to go through unit tests and clean them up too, probably get |
577 // rid of this line. | 577 // rid of this line. |
578 ExtensionErrorReporter::GetInstance()->ReportError( | 578 ExtensionErrorReporter::GetInstance()->ReportError( |
579 error.message(), false); // quiet | 579 error.message(), false); // quiet |
580 | 580 |
581 if (client_) | 581 if (client_) |
582 client_->OnInstallFailure(error); | 582 client_->OnInstallFailure(error); |
583 | 583 |
584 NotifyCrxInstallComplete(NULL); | 584 NotifyCrxInstallComplete(false); |
585 | 585 |
586 // Delete temporary files. | 586 // Delete temporary files. |
587 CleanupTempFiles(); | 587 CleanupTempFiles(); |
588 } | 588 } |
589 | 589 |
590 void CrxInstaller::ReportSuccessFromFileThread() { | 590 void CrxInstaller::ReportSuccessFromFileThread() { |
591 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); | 591 DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); |
592 | 592 |
593 // Tracking number of extensions installed by users | 593 // Tracking number of extensions installed by users |
594 if (install_cause() == extension_misc::INSTALL_CAUSE_USER_DOWNLOAD) | 594 if (install_cause() == extension_misc::INSTALL_CAUSE_USER_DOWNLOAD) |
(...skipping 25 matching lines...) Expand all Loading... |
620 // We update the extension's granted permissions if the user already approved | 620 // We update the extension's granted permissions if the user already approved |
621 // the install (client_ is non NULL), or we are allowed to install this | 621 // the install (client_ is non NULL), or we are allowed to install this |
622 // silently. | 622 // silently. |
623 if (client_ || allow_silent_install_) { | 623 if (client_ || allow_silent_install_) { |
624 PermissionsUpdater perms_updater(profile()); | 624 PermissionsUpdater perms_updater(profile()); |
625 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); | 625 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); |
626 } | 626 } |
627 | 627 |
628 // Tell the frontend about the installation and hand off ownership of | 628 // Tell the frontend about the installation and hand off ownership of |
629 // extension_ to it. | 629 // extension_ to it. |
630 frontend_weak_->OnExtensionInstalled(extension_, | 630 frontend_weak_->InstallExtensionAsync( |
631 page_ordinal_, | 631 extension_, |
632 has_requirement_errors_, | 632 page_ordinal_, |
633 install_wait_for_idle_); | 633 has_requirement_errors_, |
634 | 634 install_wait_for_idle_, |
635 NotifyCrxInstallComplete(extension_.get()); | 635 base::Bind(&CrxInstaller::NotifyCrxInstallComplete, this)); |
636 | |
637 extension_ = NULL; | |
638 | |
639 // We're done. We don't post any more tasks to ourselves so we are deleted | |
640 // soon. | |
641 } | 636 } |
642 | 637 |
643 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { | 638 void CrxInstaller::NotifyCrxInstallComplete(bool success) { |
644 // Some users (such as the download shelf) need to know when a | 639 // Some users (such as the download shelf) need to know when a |
645 // CRXInstaller is done. Listening for the EXTENSION_* events | 640 // CRXInstaller is done. Listening for the EXTENSION_* events |
646 // is problematic because they don't know anything about the | 641 // is problematic because they don't know anything about the |
647 // extension before it is unpacked, so they cannot filter based | 642 // extension before it is unpacked, so they cannot filter based |
648 // on the extension. | 643 // on the extension. |
649 content::NotificationService::current()->Notify( | 644 content::NotificationService::current()->Notify( |
650 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 645 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
651 content::Source<CrxInstaller>(this), | 646 content::Source<CrxInstaller>(this), |
652 content::Details<const Extension>(extension)); | 647 content::Details<const Extension>(success ? extension_.get() : NULL)); |
| 648 |
| 649 // We're done. We don't post any more tasks to ourselves so we are deleted |
| 650 // soon. |
| 651 extension_ = NULL; |
653 } | 652 } |
654 | 653 |
655 void CrxInstaller::CleanupTempFiles() { | 654 void CrxInstaller::CleanupTempFiles() { |
656 if (!installer_task_runner_->RunsTasksOnCurrentThread()) { | 655 if (!installer_task_runner_->RunsTasksOnCurrentThread()) { |
657 if (!installer_task_runner_->PostTask( | 656 if (!installer_task_runner_->PostTask( |
658 FROM_HERE, | 657 FROM_HERE, |
659 base::Bind(&CrxInstaller::CleanupTempFiles, this))) { | 658 base::Bind(&CrxInstaller::CleanupTempFiles, this))) { |
660 NOTREACHED(); | 659 NOTREACHED(); |
661 } | 660 } |
662 return; | 661 return; |
663 } | 662 } |
664 | 663 |
665 // Delete the temp directory and crx file as necessary. | 664 // Delete the temp directory and crx file as necessary. |
666 if (!temp_dir_.value().empty()) { | 665 if (!temp_dir_.value().empty()) { |
667 extension_file_util::DeleteFile(temp_dir_, true); | 666 extension_file_util::DeleteFile(temp_dir_, true); |
668 temp_dir_ = FilePath(); | 667 temp_dir_ = FilePath(); |
669 } | 668 } |
670 | 669 |
671 if (delete_source_ && !source_file_.value().empty()) { | 670 if (delete_source_ && !source_file_.value().empty()) { |
672 extension_file_util::DeleteFile(source_file_, false); | 671 extension_file_util::DeleteFile(source_file_, false); |
673 source_file_ = FilePath(); | 672 source_file_ = FilePath(); |
674 } | 673 } |
675 } | 674 } |
676 | 675 |
677 } // namespace extensions | 676 } // namespace extensions |
OLD | NEW |