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

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

Issue 6903127: [Sync] Add support for enabling/disabling an extension before it's installed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
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 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 } 742 }
743 743
744 bool ExtensionService::IsExternalExtensionUninstalled( 744 bool ExtensionService::IsExternalExtensionUninstalled(
745 const std::string& extension_id) const { 745 const std::string& extension_id) const {
746 return extension_prefs_->IsExternalExtensionUninstalled(extension_id); 746 return extension_prefs_->IsExternalExtensionUninstalled(extension_id);
747 } 747 }
748 748
749 void ExtensionService::EnableExtension(const std::string& extension_id) { 749 void ExtensionService::EnableExtension(const std::string& extension_id) {
750 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 750 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
751 751
752 const Extension* extension = 752 if (IsExtensionEnabled(extension_id))
753 GetExtensionByIdInternal(extension_id, false, true, false);
754 if (!extension)
755 return; 753 return;
756 754
757 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); 755 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED);
758 756
757 const Extension* extension =
758 GetExtensionByIdInternal(extension_id, false, true, false);
759 // This can happen if sync enables an extension that is not
760 // installed yet.
761 if (!extension)
762 return;
763
759 // Move it over to the enabled list. 764 // Move it over to the enabled list.
760 extensions_.push_back(make_scoped_refptr(extension)); 765 extensions_.push_back(make_scoped_refptr(extension));
761 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), 766 ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
762 disabled_extensions_.end(), 767 disabled_extensions_.end(),
763 extension); 768 extension);
764 disabled_extensions_.erase(iter); 769 disabled_extensions_.erase(iter);
765 770
766 // Make sure any browser action contained within it is not hidden. 771 // Make sure any browser action contained within it is not hidden.
767 extension_prefs_->SetBrowserActionVisibility(extension, true); 772 extension_prefs_->SetBrowserActionVisibility(extension, true);
768 773
769 NotifyExtensionLoaded(extension); 774 NotifyExtensionLoaded(extension);
770 } 775 }
771 776
772 void ExtensionService::DisableExtension(const std::string& extension_id) { 777 void ExtensionService::DisableExtension(const std::string& extension_id) {
773 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 778 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
774 779
775 const Extension* extension =
776 GetExtensionByIdInternal(extension_id, true, false, false);
777 // The extension may have been disabled already. 780 // The extension may have been disabled already.
778 if (!extension) 781 if (!IsExtensionEnabled(extension_id))
779 return; 782 return;
780 783
781 if (!Extension::UserMayDisable(extension->location())) 784 const Extension* extension = GetInstalledExtension(extension_id);
785 // |extension| can be NULL if sync disables an extension that is not
786 // installed yet.
787 if (extension && !Extension::UserMayDisable(extension->location()))
782 return; 788 return;
783 789
784 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); 790 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
785 791
792 extension = GetExtensionByIdInternal(extension_id, true, false, true);
793 if (!extension)
794 return;
795
786 // Move it over to the disabled list. 796 // Move it over to the disabled list.
787 disabled_extensions_.push_back(make_scoped_refptr(extension)); 797 disabled_extensions_.push_back(make_scoped_refptr(extension));
788 ExtensionList::iterator iter = std::find(extensions_.begin(), 798 ExtensionList::iterator iter = std::find(extensions_.begin(),
789 extensions_.end(), 799 extensions_.end(),
790 extension); 800 extension);
791 extensions_.erase(iter); 801 if (iter != extensions_.end()) {
802 extensions_.erase(iter);
803 } else {
804 iter = std::find(terminated_extensions_.begin(),
805 terminated_extensions_.end(),
806 extension);
807 terminated_extensions_.erase(iter);
808 }
792 809
793 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE); 810 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE);
794 } 811 }
795 812
796 void ExtensionService::GrantPermissions(const Extension* extension) { 813 void ExtensionService::GrantPermissions(const Extension* extension) {
797 CHECK(extension); 814 CHECK(extension);
798 815
799 // We only maintain the granted permissions prefs for INTERNAL extensions. 816 // We only maintain the granted permissions prefs for INTERNAL extensions.
800 CHECK_EQ(Extension::INTERNAL, extension->location()); 817 CHECK_EQ(Extension::INTERNAL, extension->location());
801 818
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 // Handle uninstalls first. 1362 // Handle uninstalls first.
1346 if (extension_sync_data.uninstalled) { 1363 if (extension_sync_data.uninstalled) {
1347 std::string error; 1364 std::string error;
1348 if (!UninstallExtensionHelper(this, id)) { 1365 if (!UninstallExtensionHelper(this, id)) {
1349 LOG(WARNING) << "Could not uninstall extension " << id 1366 LOG(WARNING) << "Could not uninstall extension " << id
1350 << " for sync"; 1367 << " for sync";
1351 } 1368 }
1352 return; 1369 return;
1353 } 1370 }
1354 1371
1372 // Set user settings.
1373 if (extension_sync_data.enabled) {
1374 EnableExtension(id);
1375 } else {
1376 DisableExtension(id);
1377 }
1355 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled); 1378 SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled);
1356 1379
1357 const Extension* extension = 1380 const Extension* extension = GetInstalledExtension(id);
1358 GetExtensionByIdInternal(id, true, true, false);
1359 // TODO(akalin): Figure out what to do with terminated extensions.
1360
1361 // Handle already-installed extensions.
1362 if (extension) { 1381 if (extension) {
1363 // TODO(akalin): Make it so we can enable/disable an extension 1382 // If the extension is already installed, check if it's outdated.
1364 // even if it's not installed yet.
1365 if (extension_sync_data.enabled) {
1366 EnableExtension(id);
1367 } else {
1368 DisableExtension(id);
1369 }
1370 int result = extension->version()->CompareTo(extension_sync_data.version); 1383 int result = extension->version()->CompareTo(extension_sync_data.version);
1371 if (result < 0) { 1384 if (result < 0) {
1372 // Extension is outdated. 1385 // Extension is outdated.
1373 CheckForUpdatesSoon(); 1386 CheckForUpdatesSoon();
1374 } else if (result > 0) { 1387 } else if (result > 0) {
1375 // Sync version is outdated. Do nothing for now, as sync code 1388 // Sync version is outdated. Do nothing for now, as sync code
1376 // in other places will eventually update the sync data. 1389 // in other places will eventually update the sync data.
1377 // 1390 //
1378 // TODO(akalin): Move that code here. 1391 // TODO(akalin): Move that code here.
1379 } 1392 }
1380 return; 1393 return;
1394 } else {
1395 // TODO(akalin): Remove need to pass the enabled flag.
1396 //
1397 // TODO(akalin): Replace silent update with a list of enabled
1398 // permissions.
1399 if (!pending_extension_manager()->AddFromSync(
1400 id,
1401 extension_sync_data.update_url,
1402 filter,
1403 true, // install_silently
1404 extension_sync_data.enabled)) {
1405 LOG(WARNING) << "Could not add pending extension for " << id;
1406 return;
1407 }
1408 CheckForUpdatesSoon();
1381 } 1409 }
1382
1383 // Handle not-yet-installed extensions.
1384 //
1385 // TODO(akalin): Replace silent update with a list of enabled
1386 // permissions.
1387 if (!pending_extension_manager()->AddFromSync(
1388 id,
1389 extension_sync_data.update_url,
1390 filter,
1391 true, // install_silently
1392 extension_sync_data.enabled)) {
1393 LOG(WARNING) << "Could not add pending extension for " << id;
1394 return;
1395 }
1396 CheckForUpdatesSoon();
1397 } 1410 }
1398 1411
1399 bool ExtensionService::IsIncognitoEnabled( 1412 bool ExtensionService::IsIncognitoEnabled(
1400 const std::string& extension_id) const { 1413 const std::string& extension_id) const {
1401 // If this is an existing component extension we always allow it to 1414 // If this is an existing component extension we always allow it to
1402 // work in incognito mode. 1415 // work in incognito mode.
1403 const Extension* extension = GetInstalledExtension(extension_id); 1416 const Extension* extension = GetInstalledExtension(extension_id);
1404 if (extension && extension->location() == Extension::COMPONENT) 1417 if (extension && extension->location() == Extension::COMPONENT)
1405 return true; 1418 return true;
1406 1419
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
2191 2204
2192 ExtensionService::NaClModuleInfoList::iterator 2205 ExtensionService::NaClModuleInfoList::iterator
2193 ExtensionService::FindNaClModule(const GURL& url) { 2206 ExtensionService::FindNaClModule(const GURL& url) {
2194 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); 2207 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2195 iter != nacl_module_list_.end(); ++iter) { 2208 iter != nacl_module_list_.end(); ++iter) {
2196 if (iter->url == url) 2209 if (iter->url == url)
2197 return iter; 2210 return iter;
2198 } 2211 }
2199 return nacl_module_list_.end(); 2212 return nacl_module_list_.end();
2200 } 2213 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698