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

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 9595001: Apps on NTP should be in order of installation (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: ExtensionInstallUI -> ExtensionInstallPrompt Created 8 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 } 546 }
547 } 547 }
548 548
549 bool ExtensionService::UpdateExtension( 549 bool ExtensionService::UpdateExtension(
550 const std::string& id, 550 const std::string& id,
551 const FilePath& extension_path, 551 const FilePath& extension_path,
552 const GURL& download_url, 552 const GURL& download_url,
553 CrxInstaller** out_crx_installer) { 553 CrxInstaller** out_crx_installer) {
554 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 554 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
555 555
556 PendingExtensionInfo pending_extension_info; 556 const PendingExtensionInfo* pending_extension_info =
557 bool is_pending_extension = pending_extension_manager_.GetById( 557 pending_extension_manager()->GetById(id);
558 id, &pending_extension_info);
559 558
560 const Extension* extension = 559 const Extension* extension =
561 GetExtensionByIdInternal(id, true, true, false); 560 GetExtensionByIdInternal(id, true, true, false);
562 if (!is_pending_extension && !extension) { 561 if (!pending_extension_info && !extension) {
563 LOG(WARNING) << "Will not update extension " << id 562 LOG(WARNING) << "Will not update extension " << id
564 << " because it is not installed or pending"; 563 << " because it is not installed or pending";
565 // Delete extension_path since we're not creating a CrxInstaller 564 // Delete extension_path since we're not creating a CrxInstaller
566 // that would do it for us. 565 // that would do it for us.
567 if (!BrowserThread::PostTask( 566 if (!BrowserThread::PostTask(
568 BrowserThread::FILE, FROM_HERE, 567 BrowserThread::FILE, FROM_HERE,
569 base::Bind( 568 base::Bind(
570 &extension_file_util::DeleteFile, extension_path, false))) 569 &extension_file_util::DeleteFile, extension_path, false)))
571 NOTREACHED(); 570 NOTREACHED();
572 571
573 return false; 572 return false;
574 } 573 }
575 574
576 // We want a silent install only for non-pending extensions and 575 // We want a silent install only for non-pending extensions and
577 // pending extensions that have install_silently set. 576 // pending extensions that have install_silently set.
578 ExtensionInstallPrompt* client = 577 ExtensionInstallPrompt* client =
579 (!is_pending_extension || pending_extension_info.install_silently()) ? 578 (!pending_extension_info || pending_extension_info->install_silently()) ?
580 NULL : new ExtensionInstallPrompt(profile_); 579 NULL : new ExtensionInstallPrompt(profile_);
581 580
582 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, client)); 581 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, client));
583 installer->set_expected_id(id); 582 installer->set_expected_id(id);
584 if (is_pending_extension) 583 if (pending_extension_info) {
585 installer->set_install_source(pending_extension_info.install_source()); 584 installer->set_install_source(pending_extension_info->install_source());
586 else if (extension) 585 if (pending_extension_info->install_silently())
586 installer->set_allow_silent_install(true);
587 } else if (extension) {
587 installer->set_install_source(extension->location()); 588 installer->set_install_source(extension->location());
588 if (pending_extension_info.install_silently()) 589 }
589 installer->set_allow_silent_install(true);
590 // If the extension was installed from or has migrated to the webstore, or 590 // If the extension was installed from or has migrated to the webstore, or
591 // if the extension came from sync and its auto-update URL is from the 591 // if the extension came from sync and its auto-update URL is from the
592 // webstore, treat it as a webstore install. Note that we ignore some older 592 // webstore, treat it as a webstore install. Note that we ignore some older
593 // extensions with blank auto-update URLs because we are mostly concerned 593 // extensions with blank auto-update URLs because we are mostly concerned
594 // with restrictions on NaCl extensions, which are newer. 594 // with restrictions on NaCl extensions, which are newer.
595 int creation_flags = Extension::NO_FLAGS; 595 int creation_flags = Extension::NO_FLAGS;
596 if ((extension && extension->from_webstore()) || 596 if ((extension && extension->from_webstore()) ||
597 (extension && extension->UpdatesFromGallery()) || 597 (extension && extension->UpdatesFromGallery()) ||
598 (!extension && pending_extension_info.is_from_sync() && 598 (!extension && pending_extension_info->is_from_sync() &&
599 extension_urls::IsWebstoreUpdateUrl( 599 extension_urls::IsWebstoreUpdateUrl(
600 pending_extension_info.update_url()))) { 600 pending_extension_info->update_url()))) {
601 creation_flags |= Extension::FROM_WEBSTORE; 601 creation_flags |= Extension::FROM_WEBSTORE;
602 } 602 }
603 603
604 // Bookmark apps being updated is kind of a contradiction, but that's because 604 // Bookmark apps being updated is kind of a contradiction, but that's because
605 // we mark the default apps as bookmark apps, and they're hosted in the web 605 // we mark the default apps as bookmark apps, and they're hosted in the web
606 // store, thus they can get updated. See http://crbug.com/101605 for more 606 // store, thus they can get updated. See http://crbug.com/101605 for more
607 // details. 607 // details.
608 if (extension && extension->from_bookmark()) 608 if (extension && extension->from_bookmark())
609 creation_flags |= Extension::FROM_BOOKMARK; 609 creation_flags |= Extension::FROM_BOOKMARK;
610 610
(...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2091 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2092 2092
2093 // Ensure extension is deleted unless we transfer ownership. 2093 // Ensure extension is deleted unless we transfer ownership.
2094 scoped_refptr<const Extension> scoped_extension(extension); 2094 scoped_refptr<const Extension> scoped_extension(extension);
2095 const std::string& id = extension->id(); 2095 const std::string& id = extension->id();
2096 // Extensions installed by policy can't be disabled. So even if a previous 2096 // Extensions installed by policy can't be disabled. So even if a previous
2097 // installation disabled the extension, make sure it is now enabled. 2097 // installation disabled the extension, make sure it is now enabled.
2098 bool initial_enable = 2098 bool initial_enable =
2099 !extension_prefs_->IsExtensionDisabled(id) || 2099 !extension_prefs_->IsExtensionDisabled(id) ||
2100 system_->management_policy()->MustRemainEnabled(extension, NULL); 2100 system_->management_policy()->MustRemainEnabled(extension, NULL);
2101 PendingExtensionInfo pending_extension_info; 2101 const PendingExtensionInfo* pending_extension_info = NULL;
2102 if (pending_extension_manager()->GetById(id, &pending_extension_info)) { 2102 if ((pending_extension_info = pending_extension_manager()->GetById(id))) {
2103 pending_extension_manager()->Remove(id); 2103 if (!pending_extension_info->ShouldAllowInstall(*extension)) {
2104 pending_extension_manager()->Remove(id);
2104 2105
2105 if (!pending_extension_info.ShouldAllowInstall(*extension)) {
2106 LOG(WARNING) 2106 LOG(WARNING)
2107 << "ShouldAllowInstall() returned false for " 2107 << "ShouldAllowInstall() returned false for "
2108 << id << " of type " << extension->GetType() 2108 << id << " of type " << extension->GetType()
2109 << " and update URL " << extension->update_url().spec() 2109 << " and update URL " << extension->update_url().spec()
2110 << "; not installing"; 2110 << "; not installing";
2111 2111
2112 content::NotificationService::current()->Notify( 2112 content::NotificationService::current()->Notify(
2113 chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED, 2113 chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED,
2114 content::Source<Profile>(profile_), 2114 content::Source<Profile>(profile_),
2115 content::Details<const Extension>(extension)); 2115 content::Details<const Extension>(extension));
2116 2116
2117 // Delete the extension directory since we're not going to 2117 // Delete the extension directory since we're not going to
2118 // load it. 2118 // load it.
2119 if (!BrowserThread::PostTask( 2119 if (!BrowserThread::PostTask(
2120 BrowserThread::FILE, FROM_HERE, 2120 BrowserThread::FILE, FROM_HERE,
2121 base::Bind(&extension_file_util::DeleteFile, 2121 base::Bind(&extension_file_util::DeleteFile,
2122 extension->path(), true))) 2122 extension->path(), true)))
2123 NOTREACHED(); 2123 NOTREACHED();
2124 return; 2124 return;
2125 } 2125 }
2126
2127 pending_extension_manager()->Remove(id);
2126 } else { 2128 } else {
2127 // We explicitly want to re-enable an uninstalled external 2129 // We explicitly want to re-enable an uninstalled external
2128 // extension; if we're here, that means the user is manually 2130 // extension; if we're here, that means the user is manually
2129 // installing the extension. 2131 // installing the extension.
2130 if (IsExternalExtensionUninstalled(id)) { 2132 if (IsExternalExtensionUninstalled(id)) {
2131 initial_enable = true; 2133 initial_enable = true;
2132 } 2134 }
2133 } 2135 }
2134 2136
2135 // Do not record the install histograms for upgrades. 2137 // Do not record the install histograms for upgrades.
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
2547 2549
2548 // To coexist with certain unit tests that don't have a work-thread message 2550 // To coexist with certain unit tests that don't have a work-thread message
2549 // loop available at ExtensionService shutdown, we lazy-initialize this 2551 // loop available at ExtensionService shutdown, we lazy-initialize this
2550 // object so that those cases neither create nor destroy an 2552 // object so that those cases neither create nor destroy an
2551 // APIResourceController. 2553 // APIResourceController.
2552 if (!api_resource_controller_.get()) { 2554 if (!api_resource_controller_.get()) {
2553 api_resource_controller_.reset(new extensions::APIResourceController()); 2555 api_resource_controller_.reset(new extensions::APIResourceController());
2554 } 2556 }
2555 return api_resource_controller_.get(); 2557 return api_resource_controller_.get();
2556 } 2558 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698