OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <iterator> | 8 #include <iterator> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 #endif | 112 #endif |
113 | 113 |
114 using content::BrowserContext; | 114 using content::BrowserContext; |
115 using content::BrowserThread; | 115 using content::BrowserThread; |
116 using content::DevToolsAgentHost; | 116 using content::DevToolsAgentHost; |
117 using extensions::CrxInstaller; | 117 using extensions::CrxInstaller; |
118 using extensions::Extension; | 118 using extensions::Extension; |
119 using extensions::ExtensionIdSet; | 119 using extensions::ExtensionIdSet; |
120 using extensions::ExtensionInfo; | 120 using extensions::ExtensionInfo; |
121 using extensions::FeatureSwitch; | 121 using extensions::FeatureSwitch; |
122 using extensions::ManagementPolicy; | |
122 using extensions::Manifest; | 123 using extensions::Manifest; |
123 using extensions::PermissionMessage; | 124 using extensions::PermissionMessage; |
124 using extensions::PermissionMessages; | 125 using extensions::PermissionMessages; |
125 using extensions::PermissionSet; | 126 using extensions::PermissionSet; |
126 using extensions::SharedModuleInfo; | 127 using extensions::SharedModuleInfo; |
127 using extensions::UnloadedExtensionInfo; | 128 using extensions::UnloadedExtensionInfo; |
128 | 129 |
129 namespace errors = extensions::manifest_errors; | 130 namespace errors = extensions::manifest_errors; |
130 | 131 |
131 namespace { | 132 namespace { |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
884 const std::string& extension_id) const { | 885 const std::string& extension_id) const { |
885 return IsExtensionEnabled(extension_id) && | 886 return IsExtensionEnabled(extension_id) && |
886 !GetTerminatedExtension(extension_id); | 887 !GetTerminatedExtension(extension_id); |
887 } | 888 } |
888 | 889 |
889 void ExtensionService::EnableExtension(const std::string& extension_id) { | 890 void ExtensionService::EnableExtension(const std::string& extension_id) { |
890 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 891 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
891 | 892 |
892 if (IsExtensionEnabled(extension_id)) | 893 if (IsExtensionEnabled(extension_id)) |
893 return; | 894 return; |
895 const Extension* extension = disabled_extensions_.GetByID(extension_id); | |
896 | |
897 ManagementPolicy* policy = system_->management_policy(); | |
898 if (extension && policy->MustRemainDisabled(extension, NULL, NULL)) | |
miket_OOO
2013/11/04 23:18:10
I can't tell for sure whether this is always calle
asargent_no_longer_on_chrome
2013/11/05 00:20:44
The InstalledLoader should catch cases during init
| |
899 return; | |
894 | 900 |
895 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); | 901 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
896 extension_prefs_->ClearDisableReasons(extension_id); | 902 extension_prefs_->ClearDisableReasons(extension_id); |
897 | 903 |
898 const Extension* extension = disabled_extensions_.GetByID(extension_id); | |
899 // This can happen if sync enables an extension that is not | 904 // This can happen if sync enables an extension that is not |
900 // installed yet. | 905 // installed yet. |
901 if (!extension) | 906 if (!extension) |
902 return; | 907 return; |
903 | 908 |
909 | |
miket_OOO
2013/11/04 23:18:10
WHA?!
asargent_no_longer_on_chrome
2013/11/05 00:20:44
oops, fixed.
| |
904 if (IsUnacknowledgedExternalExtension(extension)) { | 910 if (IsUnacknowledgedExternalExtension(extension)) { |
905 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", | 911 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", |
906 EXTERNAL_EXTENSION_REENABLED, | 912 EXTERNAL_EXTENSION_REENABLED, |
907 EXTERNAL_EXTENSION_BUCKET_BOUNDARY); | 913 EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
908 if (extensions::ManifestURL::UpdatesFromGallery(extension)) { | 914 if (extensions::ManifestURL::UpdatesFromGallery(extension)) { |
909 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore", | 915 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore", |
910 EXTERNAL_EXTENSION_REENABLED, | 916 EXTERNAL_EXTENSION_REENABLED, |
911 EXTERNAL_EXTENSION_BUCKET_BOUNDARY); | 917 EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
912 } else { | 918 } else { |
913 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore", | 919 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore", |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1198 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token), | 1204 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token), |
1199 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 1205 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
1200 return file_task_runner_.get(); | 1206 return file_task_runner_.get(); |
1201 } | 1207 } |
1202 | 1208 |
1203 extensions::ExtensionUpdater* ExtensionService::updater() { | 1209 extensions::ExtensionUpdater* ExtensionService::updater() { |
1204 return updater_.get(); | 1210 return updater_.get(); |
1205 } | 1211 } |
1206 | 1212 |
1207 void ExtensionService::CheckManagementPolicy() { | 1213 void ExtensionService::CheckManagementPolicy() { |
1208 std::vector<std::string> to_be_removed; | 1214 std::vector<std::string> to_unload; |
1215 std::map<std::string, Extension::DisableReason> to_disable; | |
1209 | 1216 |
1210 // Loop through extensions list, unload installed extensions. | 1217 // Loop through the extensions list, finding extensions we need to unload or |
1218 // disable. | |
1211 for (ExtensionSet::const_iterator iter = extensions_.begin(); | 1219 for (ExtensionSet::const_iterator iter = extensions_.begin(); |
1212 iter != extensions_.end(); ++iter) { | 1220 iter != extensions_.end(); ++iter) { |
1213 const Extension* extension = (iter->get()); | 1221 const Extension* extension = (iter->get()); |
1214 if (!system_->management_policy()->UserMayLoad(extension, NULL)) | 1222 if (!system_->management_policy()->UserMayLoad(extension, NULL)) |
1215 to_be_removed.push_back(extension->id()); | 1223 to_unload.push_back(extension->id()); |
1224 Extension::DisableReason disable_reason = Extension::DISABLE_NONE; | |
1225 if (!system_->management_policy()->MustRemainDisabled( | |
1226 extension, &disable_reason, NULL)) | |
1227 to_disable[extension->id()] = disable_reason; | |
miket_OOO
2013/11/04 23:18:10
Check logic.
asargent_no_longer_on_chrome
2013/11/05 00:20:44
Good catch. The "!" was a typo.
Fixed.
| |
1216 } | 1228 } |
1217 | 1229 |
1218 // UnloadExtension will change the extensions_ list. So, we should | 1230 for (size_t i = 0; i < to_unload.size(); ++i) |
1219 // call it outside the iterator loop. | 1231 UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE); |
1220 for (size_t i = 0; i < to_be_removed.size(); ++i) | 1232 |
1221 UnloadExtension(to_be_removed[i], UnloadedExtensionInfo::REASON_DISABLE); | 1233 for (std::map<std::string, Extension::DisableReason>::const_iterator i = |
1234 to_disable.begin(); i != to_disable.end(); ++i) | |
1235 DisableExtension(i->first, i->second); | |
1222 } | 1236 } |
1223 | 1237 |
1224 void ExtensionService::CheckForUpdatesSoon() { | 1238 void ExtensionService::CheckForUpdatesSoon() { |
1225 if (updater()) { | 1239 if (updater()) { |
1226 if (AreAllExternalProvidersReady()) { | 1240 if (AreAllExternalProvidersReady()) { |
1227 updater()->CheckSoon(); | 1241 updater()->CheckSoon(); |
1228 } else { | 1242 } else { |
1229 // Sync can start updating before all the external providers are ready | 1243 // Sync can start updating before all the external providers are ready |
1230 // during startup. Start the update as soon as those providers are ready, | 1244 // during startup. Start the update as soon as those providers are ready, |
1231 // but not before. | 1245 // but not before. |
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2763 } | 2777 } |
2764 | 2778 |
2765 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { | 2779 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
2766 update_observers_.AddObserver(observer); | 2780 update_observers_.AddObserver(observer); |
2767 } | 2781 } |
2768 | 2782 |
2769 void ExtensionService::RemoveUpdateObserver( | 2783 void ExtensionService::RemoveUpdateObserver( |
2770 extensions::UpdateObserver* observer) { | 2784 extensions::UpdateObserver* observer) { |
2771 update_observers_.RemoveObserver(observer); | 2785 update_observers_.RemoveObserver(observer); |
2772 } | 2786 } |
OLD | NEW |