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

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

Issue 7633029: Remove extension.h #include from profile.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit_tests. Created 9 years, 4 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 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 RecordPermissionMessagesHistogram( 862 RecordPermissionMessagesHistogram(
863 extension, "Extensions.Permissions_Uninstall"); 863 extension, "Extensions.Permissions_Uninstall");
864 864
865 TemplateURLService* url_service = 865 TemplateURLService* url_service =
866 TemplateURLServiceFactory::GetForProfile(profile_); 866 TemplateURLServiceFactory::GetForProfile(profile_);
867 if (url_service) 867 if (url_service)
868 url_service->UnregisterExtensionKeyword(extension); 868 url_service->UnregisterExtensionKeyword(extension);
869 869
870 // Unload before doing more cleanup to ensure that nothing is hanging on to 870 // Unload before doing more cleanup to ensure that nothing is hanging on to
871 // any of these resources. 871 // any of these resources.
872 UnloadExtension(extension_id, UnloadedExtensionInfo::UNINSTALL); 872 UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL);
873 873
874 extension_prefs_->OnExtensionUninstalled(extension_id, location, 874 extension_prefs_->OnExtensionUninstalled(extension_id, location,
875 external_uninstall); 875 external_uninstall);
876 876
877 // Tell the backend to start deleting installed extensions on the file thread. 877 // Tell the backend to start deleting installed extensions on the file thread.
878 if (Extension::LOAD != location) { 878 if (Extension::LOAD != location) {
879 if (!BrowserThread::PostTask( 879 if (!BrowserThread::PostTask(
880 BrowserThread::FILE, FROM_HERE, 880 BrowserThread::FILE, FROM_HERE,
881 NewRunnableFunction( 881 NewRunnableFunction(
882 &extension_file_util::UninstallExtension, 882 &extension_file_util::UninstallExtension,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 extension); 980 extension);
981 if (iter != extensions_.end()) { 981 if (iter != extensions_.end()) {
982 extensions_.erase(iter); 982 extensions_.erase(iter);
983 } else { 983 } else {
984 iter = std::find(terminated_extensions_.begin(), 984 iter = std::find(terminated_extensions_.begin(),
985 terminated_extensions_.end(), 985 terminated_extensions_.end(),
986 extension); 986 extension);
987 terminated_extensions_.erase(iter); 987 terminated_extensions_.erase(iter);
988 } 988 }
989 989
990 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE); 990 NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
991 } 991 }
992 992
993 void ExtensionService::GrantPermissions(const Extension* extension) { 993 void ExtensionService::GrantPermissions(const Extension* extension) {
994 CHECK(extension); 994 CHECK(extension);
995 995
996 // We only maintain the granted permissions prefs for extensions that can't 996 // We only maintain the granted permissions prefs for extensions that can't
997 // silently increase their permissions. 997 // silently increase their permissions.
998 if (extension->CanSilentlyIncreasePermissions()) 998 if (extension->CanSilentlyIncreasePermissions())
999 return; 999 return;
1000 1000
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 std::string public_key; 1118 std::string public_key;
1119 std::string public_key_bytes; 1119 std::string public_key_bytes;
1120 std::string id; 1120 std::string id;
1121 if (!static_cast<DictionaryValue*>(manifest.get())-> 1121 if (!static_cast<DictionaryValue*>(manifest.get())->
1122 GetString(extension_manifest_keys::kPublicKey, &public_key) || 1122 GetString(extension_manifest_keys::kPublicKey, &public_key) ||
1123 !Extension::ParsePEMKeyBytes(public_key, &public_key_bytes) || 1123 !Extension::ParsePEMKeyBytes(public_key, &public_key_bytes) ||
1124 !Extension::GenerateId(public_key_bytes, &id)) { 1124 !Extension::GenerateId(public_key_bytes, &id)) {
1125 LOG(ERROR) << "Failed to get extension id"; 1125 LOG(ERROR) << "Failed to get extension id";
1126 return; 1126 return;
1127 } 1127 }
1128 UnloadExtension(id, UnloadedExtensionInfo::DISABLE); 1128 UnloadExtension(id, extension_misc::UNLOAD_REASON_DISABLE);
1129 } 1129 }
1130 1130
1131 void ExtensionService::LoadAllExtensions() { 1131 void ExtensionService::LoadAllExtensions() {
1132 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1132 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1133 1133
1134 base::TimeTicks start_time = base::TimeTicks::Now(); 1134 base::TimeTicks start_time = base::TimeTicks::Now();
1135 1135
1136 // Load any component extensions. 1136 // Load any component extensions.
1137 LoadComponentExtensions(); 1137 LoadComponentExtensions();
1138 1138
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 input_method_manager->RegisterVirtualKeyboard(extension->url(), 1474 input_method_manager->RegisterVirtualKeyboard(extension->url(),
1475 component->layouts, 1475 component->layouts,
1476 is_system); 1476 is_system);
1477 } 1477 }
1478 #endif 1478 #endif
1479 } 1479 }
1480 #endif 1480 #endif
1481 } 1481 }
1482 1482
1483 void ExtensionService::NotifyExtensionUnloaded( 1483 void ExtensionService::NotifyExtensionUnloaded(
1484 const Extension* extension, UnloadedExtensionInfo::Reason reason) { 1484 const Extension* extension,
1485 extension_misc::UnloadedExtensionReason reason) {
1485 UnloadedExtensionInfo details(extension, reason); 1486 UnloadedExtensionInfo details(extension, reason);
1486 NotificationService::current()->Notify( 1487 NotificationService::current()->Notify(
1487 chrome::NOTIFICATION_EXTENSION_UNLOADED, 1488 chrome::NOTIFICATION_EXTENSION_UNLOADED,
1488 Source<Profile>(profile_), 1489 Source<Profile>(profile_),
1489 Details<UnloadedExtensionInfo>(&details)); 1490 Details<UnloadedExtensionInfo>(&details));
1490 1491
1491 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); 1492 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
1492 !i.IsAtEnd(); i.Advance()) { 1493 !i.IsAtEnd(); i.Advance()) {
1493 RenderProcessHost* host = i.GetCurrentValue(); 1494 RenderProcessHost* host = i.GetCurrentValue();
1494 Profile* host_profile = 1495 Profile* host_profile =
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 iter != extensions_.end(); ++iter) { 1562 iter != extensions_.end(); ++iter) {
1562 const Extension* extension = (*iter); 1563 const Extension* extension = (*iter);
1563 if (blacklist_set.find(extension->id()) != blacklist_set.end()) { 1564 if (blacklist_set.find(extension->id()) != blacklist_set.end()) {
1564 to_be_removed.push_back(extension->id()); 1565 to_be_removed.push_back(extension->id());
1565 } 1566 }
1566 } 1567 }
1567 1568
1568 // UnloadExtension will change the extensions_ list. So, we should 1569 // UnloadExtension will change the extensions_ list. So, we should
1569 // call it outside the iterator loop. 1570 // call it outside the iterator loop.
1570 for (unsigned int i = 0; i < to_be_removed.size(); ++i) { 1571 for (unsigned int i = 0; i < to_be_removed.size(); ++i) {
1571 UnloadExtension(to_be_removed[i], UnloadedExtensionInfo::DISABLE); 1572 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE);
1572 } 1573 }
1573 } 1574 }
1574 1575
1575 Profile* ExtensionService::profile() { 1576 Profile* ExtensionService::profile() {
1576 return profile_; 1577 return profile_;
1577 } 1578 }
1578 1579
1579 ExtensionPrefs* ExtensionService::extension_prefs() { 1580 ExtensionPrefs* ExtensionService::extension_prefs() {
1580 return extension_prefs_; 1581 return extension_prefs_;
1581 } 1582 }
(...skipping 17 matching lines...) Expand all
1599 for (ExtensionList::const_iterator iter = extensions_.begin(); 1600 for (ExtensionList::const_iterator iter = extensions_.begin();
1600 iter != extensions_.end(); ++iter) { 1601 iter != extensions_.end(); ++iter) {
1601 const Extension* extension = (*iter); 1602 const Extension* extension = (*iter);
1602 if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id())) 1603 if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id()))
1603 to_be_removed.push_back(extension->id()); 1604 to_be_removed.push_back(extension->id());
1604 } 1605 }
1605 1606
1606 // UnloadExtension will change the extensions_ list. So, we should 1607 // UnloadExtension will change the extensions_ list. So, we should
1607 // call it outside the iterator loop. 1608 // call it outside the iterator loop.
1608 for (unsigned int i = 0; i < to_be_removed.size(); ++i) 1609 for (unsigned int i = 0; i < to_be_removed.size(); ++i)
1609 UnloadExtension(to_be_removed[i], UnloadedExtensionInfo::DISABLE); 1610 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE);
1610 } 1611 }
1611 1612
1612 void ExtensionService::CheckForUpdatesSoon() { 1613 void ExtensionService::CheckForUpdatesSoon() {
1613 if (updater()) { 1614 if (updater()) {
1614 updater()->CheckSoon(); 1615 updater()->CheckSoon();
1615 } else { 1616 } else {
1616 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; 1617 LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off";
1617 } 1618 }
1618 } 1619 }
1619 1620
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); 1744 bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id);
1744 if (enabled == old_enabled) 1745 if (enabled == old_enabled)
1745 return; 1746 return;
1746 1747
1747 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); 1748 extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
1748 1749
1749 // If the extension is enabled (and not terminated), unload and 1750 // If the extension is enabled (and not terminated), unload and
1750 // reload it to update UI. 1751 // reload it to update UI.
1751 const Extension* enabled_extension = GetExtensionById(extension_id, false); 1752 const Extension* enabled_extension = GetExtensionById(extension_id, false);
1752 if (enabled_extension) { 1753 if (enabled_extension) {
1753 NotifyExtensionUnloaded(enabled_extension, UnloadedExtensionInfo::DISABLE); 1754 NotifyExtensionUnloaded(
1755 enabled_extension, extension_misc::UNLOAD_REASON_DISABLE);
1754 NotifyExtensionLoaded(enabled_extension); 1756 NotifyExtensionLoaded(enabled_extension);
1755 } 1757 }
1756 } 1758 }
1757 1759
1758 bool ExtensionService::CanCrossIncognito(const Extension* extension) { 1760 bool ExtensionService::CanCrossIncognito(const Extension* extension) {
1759 // We allow the extension to see events and data from another profile iff it 1761 // We allow the extension to see events and data from another profile iff it
1760 // uses "spanning" behavior and it has incognito access. "split" mode 1762 // uses "spanning" behavior and it has incognito access. "split" mode
1761 // extensions only see events for a matching profile. 1763 // extensions only see events for a matching profile.
1762 return IsIncognitoEnabled(extension->id()) && 1764 return IsIncognitoEnabled(extension->id()) &&
1763 !extension->incognito_split_mode(); 1765 !extension->incognito_split_mode();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 extension_prefs_->GetInstalledExtensionsInfo()); 1869 extension_prefs_->GetInstalledExtensionsInfo());
1868 for (size_t i = 0; i < extensions_info->size(); ++i) { 1870 for (size_t i = 0; i < extensions_info->size(); ++i) {
1869 ExtensionInfo* info = extensions_info->at(i).get(); 1871 ExtensionInfo* info = extensions_info->at(i).get();
1870 if (Extension::IsExternalLocation(info->extension_location)) 1872 if (Extension::IsExternalLocation(info->extension_location))
1871 CheckExternalUninstall(info->extension_id); 1873 CheckExternalUninstall(info->extension_id);
1872 } 1874 }
1873 } 1875 }
1874 1876
1875 void ExtensionService::UnloadExtension( 1877 void ExtensionService::UnloadExtension(
1876 const std::string& extension_id, 1878 const std::string& extension_id,
1877 UnloadedExtensionInfo::Reason reason) { 1879 extension_misc::UnloadedExtensionReason reason) {
1878 // Make sure the extension gets deleted after we return from this function. 1880 // Make sure the extension gets deleted after we return from this function.
1879 scoped_refptr<const Extension> extension( 1881 scoped_refptr<const Extension> extension(
1880 GetExtensionByIdInternal(extension_id, true, true, false)); 1882 GetExtensionByIdInternal(extension_id, true, true, false));
1881 1883
1882 // This method can be called via PostTask, so the extension may have been 1884 // This method can be called via PostTask, so the extension may have been
1883 // unloaded by the time this runs. 1885 // unloaded by the time this runs.
1884 if (!extension) { 1886 if (!extension) {
1885 // In case the extension may have crashed/uninstalled. Allow the profile to 1887 // In case the extension may have crashed/uninstalled. Allow the profile to
1886 // clean up its RequestContexts. 1888 // clean up its RequestContexts.
1887 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); 1889 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
2110 2112
2111 // Extensions get upgraded if the privileges are allowed to increase or 2113 // Extensions get upgraded if the privileges are allowed to increase or
2112 // the privileges haven't increased. 2114 // the privileges haven't increased.
2113 if (!is_privilege_increase) { 2115 if (!is_privilege_increase) {
2114 SetBeingUpgraded(old, true); 2116 SetBeingUpgraded(old, true);
2115 SetBeingUpgraded(extension, true); 2117 SetBeingUpgraded(extension, true);
2116 } 2118 }
2117 2119
2118 // To upgrade an extension in place, unload the old one and 2120 // To upgrade an extension in place, unload the old one and
2119 // then load the new one. 2121 // then load the new one.
2120 UnloadExtension(old->id(), UnloadedExtensionInfo::UPDATE); 2122 UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE);
2121 old = NULL; 2123 old = NULL;
2122 } 2124 }
2123 2125
2124 // Extension has changed permissions significantly. Disable it. A 2126 // Extension has changed permissions significantly. Disable it. A
2125 // notification should be sent by the caller. 2127 // notification should be sent by the caller.
2126 if (is_privilege_increase) { 2128 if (is_privilege_increase) {
2127 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { 2129 if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) {
2128 RecordPermissionMessagesHistogram( 2130 RecordPermissionMessagesHistogram(
2129 extension, "Extensions.Permissions_AutoDisable"); 2131 extension, "Extensions.Permissions_AutoDisable");
2130 } 2132 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 return *iter; 2263 return *iter;
2262 } 2264 }
2263 } 2265 }
2264 return NULL; 2266 return NULL;
2265 } 2267 }
2266 2268
2267 void ExtensionService::TrackTerminatedExtension(const Extension* extension) { 2269 void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
2268 if (terminated_extension_ids_.insert(extension->id()).second) 2270 if (terminated_extension_ids_.insert(extension->id()).second)
2269 terminated_extensions_.push_back(make_scoped_refptr(extension)); 2271 terminated_extensions_.push_back(make_scoped_refptr(extension));
2270 2272
2271 UnloadExtension(extension->id(), UnloadedExtensionInfo::DISABLE); 2273 UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_DISABLE);
2272 } 2274 }
2273 2275
2274 void ExtensionService::UntrackTerminatedExtension(const std::string& id) { 2276 void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
2275 std::string lowercase_id = StringToLowerASCII(id); 2277 std::string lowercase_id = StringToLowerASCII(id);
2276 if (terminated_extension_ids_.erase(lowercase_id) <= 0) 2278 if (terminated_extension_ids_.erase(lowercase_id) <= 0)
2277 return; 2279 return;
2278 2280
2279 for (ExtensionList::iterator iter = terminated_extensions_.begin(); 2281 for (ExtensionList::iterator iter = terminated_extensions_.begin();
2280 iter != terminated_extensions_.end(); ++iter) { 2282 iter != terminated_extensions_.end(); ++iter) {
2281 if ((*iter)->id() == lowercase_id) { 2283 if ((*iter)->id() == lowercase_id) {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
2595 2597
2596 ExtensionService::NaClModuleInfoList::iterator 2598 ExtensionService::NaClModuleInfoList::iterator
2597 ExtensionService::FindNaClModule(const GURL& url) { 2599 ExtensionService::FindNaClModule(const GURL& url) {
2598 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); 2600 for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin();
2599 iter != nacl_module_list_.end(); ++iter) { 2601 iter != nacl_module_list_.end(); ++iter) {
2600 if (iter->url == url) 2602 if (iter->url == url)
2601 return iter; 2603 return iter;
2602 } 2604 }
2603 return nacl_module_list_.end(); 2605 return nacl_module_list_.end();
2604 } 2606 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698