Chromium Code Reviews| 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/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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 } | 604 } |
| 605 } | 605 } |
| 606 | 606 |
| 607 bool ExtensionService::UpdateExtension( | 607 bool ExtensionService::UpdateExtension( |
| 608 const std::string& id, | 608 const std::string& id, |
| 609 const FilePath& extension_path, | 609 const FilePath& extension_path, |
| 610 const GURL& download_url, | 610 const GURL& download_url, |
| 611 CrxInstaller** out_crx_installer) { | 611 CrxInstaller** out_crx_installer) { |
| 612 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 612 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 613 | 613 |
| 614 PendingExtensionInfo pending_extension_info; | 614 const PendingExtensionInfo* pending_extension_info = |
| 615 bool is_pending_extension = pending_extension_manager_.GetById( | 615 pending_extension_manager()->GetById(id); |
| 616 id, &pending_extension_info); | |
| 617 | 616 |
| 618 const Extension* extension = | 617 const Extension* extension = |
| 619 GetExtensionByIdInternal(id, true, true, false); | 618 GetExtensionByIdInternal(id, true, true, false); |
| 620 if (!is_pending_extension && !extension) { | 619 if (!pending_extension_info && !extension) { |
| 621 LOG(WARNING) << "Will not update extension " << id | 620 LOG(WARNING) << "Will not update extension " << id |
| 622 << " because it is not installed or pending"; | 621 << " because it is not installed or pending"; |
| 623 // Delete extension_path since we're not creating a CrxInstaller | 622 // Delete extension_path since we're not creating a CrxInstaller |
| 624 // that would do it for us. | 623 // that would do it for us. |
| 625 if (!BrowserThread::PostTask( | 624 if (!BrowserThread::PostTask( |
| 626 BrowserThread::FILE, FROM_HERE, | 625 BrowserThread::FILE, FROM_HERE, |
| 627 base::Bind( | 626 base::Bind( |
| 628 &extension_file_util::DeleteFile, extension_path, false))) | 627 &extension_file_util::DeleteFile, extension_path, false))) |
| 629 NOTREACHED(); | 628 NOTREACHED(); |
| 630 | 629 |
| 631 return false; | 630 return false; |
| 632 } | 631 } |
| 633 | 632 |
| 634 // We want a silent install only for non-pending extensions and | 633 // We want a silent install only for non-pending extensions and |
| 635 // pending extensions that have install_silently set. | 634 // pending extensions that have install_silently set. |
| 636 ExtensionInstallUI* client = | 635 ExtensionInstallUI* client = |
| 637 (!is_pending_extension || pending_extension_info.install_silently()) ? | 636 (!pending_extension_info || pending_extension_info->install_silently()) ? |
| 638 NULL : new ExtensionInstallUI(profile_); | 637 NULL : new ExtensionInstallUI(profile_); |
| 639 | 638 |
| 640 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, client)); | 639 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, client)); |
| 641 installer->set_expected_id(id); | 640 installer->set_expected_id(id); |
| 642 if (is_pending_extension) | 641 if (pending_extension_info) |
| 643 installer->set_install_source(pending_extension_info.install_source()); | 642 installer->set_install_source(pending_extension_info->install_source()); |
| 644 else if (extension) | 643 else if (extension) |
| 645 installer->set_install_source(extension->location()); | 644 installer->set_install_source(extension->location()); |
| 646 if (pending_extension_info.install_silently()) | 645 if (pending_extension_info->install_silently()) |
| 647 installer->set_allow_silent_install(true); | 646 installer->set_allow_silent_install(true); |
| 648 // If the extension came from sync and its auto-update URL is from the | 647 // If the extension came from sync and its auto-update URL is from the |
| 649 // webstore, treat it as a webstore install. Note that we ignore some older | 648 // webstore, treat it as a webstore install. Note that we ignore some older |
| 650 // extensions with blank auto-update URLs because we are mostly concerned | 649 // extensions with blank auto-update URLs because we are mostly concerned |
| 651 // with restrictions on NaCl extensions, which are newer. | 650 // with restrictions on NaCl extensions, which are newer. |
| 652 int creation_flags = Extension::NO_FLAGS; | 651 int creation_flags = Extension::NO_FLAGS; |
| 653 if ((extension && extension->from_webstore()) || | 652 if ((extension && extension->from_webstore()) || |
| 654 (!extension && pending_extension_info.is_from_sync() && | 653 (!extension && pending_extension_info->is_from_sync() && |
| 655 extension_urls::IsWebstoreUpdateUrl( | 654 extension_urls::IsWebstoreUpdateUrl( |
| 656 pending_extension_info.update_url()))) { | 655 pending_extension_info->update_url()))) { |
| 657 creation_flags |= Extension::FROM_WEBSTORE; | 656 creation_flags |= Extension::FROM_WEBSTORE; |
| 658 } | 657 } |
| 659 | 658 |
| 660 // Bookmark apps being updated is kind of a contradiction, but that's because | 659 // Bookmark apps being updated is kind of a contradiction, but that's because |
| 661 // we mark the default apps as bookmark apps, and they're hosted in the web | 660 // we mark the default apps as bookmark apps, and they're hosted in the web |
| 662 // store, thus they can get updated. See http://crbug.com/101605 for more | 661 // store, thus they can get updated. See http://crbug.com/101605 for more |
| 663 // details. | 662 // details. |
| 664 if (extension && extension->from_bookmark()) | 663 if (extension && extension->from_bookmark()) |
| 665 creation_flags |= Extension::FROM_BOOKMARK; | 664 creation_flags |= Extension::FROM_BOOKMARK; |
| 666 | 665 |
| (...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2182 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2181 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2183 | 2182 |
| 2184 // Ensure extension is deleted unless we transfer ownership. | 2183 // Ensure extension is deleted unless we transfer ownership. |
| 2185 scoped_refptr<const Extension> scoped_extension(extension); | 2184 scoped_refptr<const Extension> scoped_extension(extension); |
| 2186 const std::string& id = extension->id(); | 2185 const std::string& id = extension->id(); |
| 2187 // Extensions installed by policy can't be disabled. So even if a previous | 2186 // Extensions installed by policy can't be disabled. So even if a previous |
| 2188 // installation disabled the extension, make sure it is now enabled. | 2187 // installation disabled the extension, make sure it is now enabled. |
| 2189 bool initial_enable = | 2188 bool initial_enable = |
| 2190 !extension_prefs_->IsExtensionDisabled(id) || | 2189 !extension_prefs_->IsExtensionDisabled(id) || |
| 2191 !Extension::UserMayDisable(extension->location()); | 2190 !Extension::UserMayDisable(extension->location()); |
| 2192 PendingExtensionInfo pending_extension_info; | 2191 const PendingExtensionInfo* pending_extension_info; |
|
Aaron Boodman
2012/04/09 17:02:14
= NULL
mitchellwrosen
2012/04/13 22:20:18
Done.
| |
| 2193 if (pending_extension_manager()->GetById(id, &pending_extension_info)) { | 2192 if ((pending_extension_info = pending_extension_manager()->GetById(id))) { |
| 2194 pending_extension_manager()->Remove(id); | 2193 pending_extension_manager()->Remove(id); |
| 2195 | 2194 |
| 2196 if (!pending_extension_info.ShouldAllowInstall(*extension)) { | 2195 if (!pending_extension_info->ShouldAllowInstall(*extension)) { |
| 2197 LOG(WARNING) | 2196 LOG(WARNING) |
| 2198 << "ShouldAllowInstall() returned false for " | 2197 << "ShouldAllowInstall() returned false for " |
| 2199 << id << " of type " << extension->GetType() | 2198 << id << " of type " << extension->GetType() |
| 2200 << " and update URL " << extension->update_url().spec() | 2199 << " and update URL " << extension->update_url().spec() |
| 2201 << "; not installing"; | 2200 << "; not installing"; |
| 2202 | 2201 |
| 2203 content::NotificationService::current()->Notify( | 2202 content::NotificationService::current()->Notify( |
| 2204 chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED, | 2203 chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED, |
| 2205 content::Source<Profile>(profile_), | 2204 content::Source<Profile>(profile_), |
| 2206 content::Details<const Extension>(extension)); | 2205 content::Details<const Extension>(extension)); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2637 // To coexist with certain unit tests that don't have an IO thread message | 2636 // To coexist with certain unit tests that don't have an IO thread message |
| 2638 // loop available at ExtensionService shutdown, we lazy-initialize this | 2637 // loop available at ExtensionService shutdown, we lazy-initialize this |
| 2639 // object so that those cases neither create nor destroy an | 2638 // object so that those cases neither create nor destroy an |
| 2640 // APIResourceController. | 2639 // APIResourceController. |
| 2641 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2640 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2642 if (!api_resource_controller_) { | 2641 if (!api_resource_controller_) { |
| 2643 api_resource_controller_ = new extensions::APIResourceController(); | 2642 api_resource_controller_ = new extensions::APIResourceController(); |
| 2644 } | 2643 } |
| 2645 return api_resource_controller_; | 2644 return api_resource_controller_; |
| 2646 } | 2645 } |
| OLD | NEW |