| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 LoadAllExtensions(); | 593 LoadAllExtensions(); |
| 594 | 594 |
| 595 // TODO(erikkay) this should probably be deferred to a future point | 595 // TODO(erikkay) this should probably be deferred to a future point |
| 596 // rather than running immediately at startup. | 596 // rather than running immediately at startup. |
| 597 CheckForExternalUpdates(); | 597 CheckForExternalUpdates(); |
| 598 | 598 |
| 599 // TODO(erikkay) this should probably be deferred as well. | 599 // TODO(erikkay) this should probably be deferred as well. |
| 600 GarbageCollectExtensions(); | 600 GarbageCollectExtensions(); |
| 601 } | 601 } |
| 602 | 602 |
| 603 void ExtensionService::UpdateExtension(const std::string& id, | 603 bool ExtensionService::UpdateExtension( |
| 604 const FilePath& extension_path, | 604 const std::string& id, |
| 605 const GURL& download_url) { | 605 const FilePath& extension_path, |
| 606 const GURL& download_url, |
| 607 CrxInstaller** out_crx_installer) { |
| 606 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 608 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 607 | 609 |
| 608 PendingExtensionInfo pending_extension_info; | 610 PendingExtensionInfo pending_extension_info; |
| 609 bool is_pending_extension = pending_extension_manager_.GetById( | 611 bool is_pending_extension = pending_extension_manager_.GetById( |
| 610 id, &pending_extension_info); | 612 id, &pending_extension_info); |
| 611 | 613 |
| 612 const Extension* extension = | 614 const Extension* extension = |
| 613 GetExtensionByIdInternal(id, true, true, false); | 615 GetExtensionByIdInternal(id, true, true, false); |
| 614 if (!is_pending_extension && !extension) { | 616 if (!is_pending_extension && !extension) { |
| 615 LOG(WARNING) << "Will not update extension " << id | 617 LOG(WARNING) << "Will not update extension " << id |
| 616 << " because it is not installed or pending"; | 618 << " because it is not installed or pending"; |
| 617 // Delete extension_path since we're not creating a CrxInstaller | 619 // Delete extension_path since we're not creating a CrxInstaller |
| 618 // that would do it for us. | 620 // that would do it for us. |
| 619 if (!BrowserThread::PostTask( | 621 if (!BrowserThread::PostTask( |
| 620 BrowserThread::FILE, FROM_HERE, | 622 BrowserThread::FILE, FROM_HERE, |
| 621 NewRunnableFunction( | 623 NewRunnableFunction( |
| 622 extension_file_util::DeleteFile, extension_path, false))) | 624 extension_file_util::DeleteFile, extension_path, false))) |
| 623 NOTREACHED(); | 625 NOTREACHED(); |
| 624 return; | 626 |
| 627 return false; |
| 625 } | 628 } |
| 626 | 629 |
| 627 // We want a silent install only for non-pending extensions and | 630 // We want a silent install only for non-pending extensions and |
| 628 // pending extensions that have install_silently set. | 631 // pending extensions that have install_silently set. |
| 629 ExtensionInstallUI* client = | 632 ExtensionInstallUI* client = |
| 630 (!is_pending_extension || pending_extension_info.install_silently()) ? | 633 (!is_pending_extension || pending_extension_info.install_silently()) ? |
| 631 NULL : new ExtensionInstallUI(profile_); | 634 NULL : new ExtensionInstallUI(profile_); |
| 632 | 635 |
| 633 scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(client)); | 636 scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(client)); |
| 634 installer->set_expected_id(id); | 637 installer->set_expected_id(id); |
| 635 if (is_pending_extension) | 638 if (is_pending_extension) |
| 636 installer->set_install_source(pending_extension_info.install_source()); | 639 installer->set_install_source(pending_extension_info.install_source()); |
| 637 else if (extension) | 640 else if (extension) |
| 638 installer->set_install_source(extension->location()); | 641 installer->set_install_source(extension->location()); |
| 639 installer->set_delete_source(true); | 642 installer->set_delete_source(true); |
| 640 installer->set_original_url(download_url); | 643 installer->set_original_url(download_url); |
| 641 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); | 644 installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
| 642 installer->InstallCrx(extension_path); | 645 installer->InstallCrx(extension_path); |
| 646 |
| 647 if (out_crx_installer) |
| 648 *out_crx_installer = installer; |
| 649 |
| 650 return true; |
| 643 } | 651 } |
| 644 | 652 |
| 645 void ExtensionService::ReloadExtension(const std::string& extension_id) { | 653 void ExtensionService::ReloadExtension(const std::string& extension_id) { |
| 646 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 654 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 647 FilePath path; | 655 FilePath path; |
| 648 const Extension* current_extension = GetExtensionById(extension_id, false); | 656 const Extension* current_extension = GetExtensionById(extension_id, false); |
| 649 | 657 |
| 650 // Disable the extension if it's loaded. It might not be loaded if it crashed. | 658 // Disable the extension if it's loaded. It might not be loaded if it crashed. |
| 651 if (current_extension) { | 659 if (current_extension) { |
| 652 // If the extension has an inspector open for its background page, detach | 660 // If the extension has an inspector open for its background page, detach |
| (...skipping 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2255 | 2263 |
| 2256 ExtensionService::NaClModuleInfoList::iterator | 2264 ExtensionService::NaClModuleInfoList::iterator |
| 2257 ExtensionService::FindNaClModule(const GURL& url) { | 2265 ExtensionService::FindNaClModule(const GURL& url) { |
| 2258 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); | 2266 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2259 iter != nacl_module_list_.end(); ++iter) { | 2267 iter != nacl_module_list_.end(); ++iter) { |
| 2260 if (iter->url == url) | 2268 if (iter->url == url) |
| 2261 return iter; | 2269 return iter; |
| 2262 } | 2270 } |
| 2263 return nacl_module_list_.end(); | 2271 return nacl_module_list_.end(); |
| 2264 } | 2272 } |
| OLD | NEW |