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 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 const std::string& extension_id) const { | 883 const std::string& extension_id) const { |
883 return IsExtensionEnabled(extension_id) && | 884 return IsExtensionEnabled(extension_id) && |
884 !GetTerminatedExtension(extension_id); | 885 !GetTerminatedExtension(extension_id); |
885 } | 886 } |
886 | 887 |
887 void ExtensionService::EnableExtension(const std::string& extension_id) { | 888 void ExtensionService::EnableExtension(const std::string& extension_id) { |
888 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 889 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
889 | 890 |
890 if (IsExtensionEnabled(extension_id)) | 891 if (IsExtensionEnabled(extension_id)) |
891 return; | 892 return; |
| 893 const Extension* extension = disabled_extensions_.GetByID(extension_id); |
| 894 |
| 895 ManagementPolicy* policy = system_->management_policy(); |
| 896 if (extension && policy->MustRemainDisabled(extension, NULL, NULL)) { |
| 897 UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1); |
| 898 return; |
| 899 } |
892 | 900 |
893 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); | 901 extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
894 extension_prefs_->ClearDisableReasons(extension_id); | 902 extension_prefs_->ClearDisableReasons(extension_id); |
895 | 903 |
896 const Extension* extension = disabled_extensions_.GetByID(extension_id); | |
897 // This can happen if sync enables an extension that is not | 904 // This can happen if sync enables an extension that is not |
898 // installed yet. | 905 // installed yet. |
899 if (!extension) | 906 if (!extension) |
900 return; | 907 return; |
901 | 908 |
902 if (IsUnacknowledgedExternalExtension(extension)) { | 909 if (IsUnacknowledgedExternalExtension(extension)) { |
903 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", | 910 UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", |
904 EXTERNAL_EXTENSION_REENABLED, | 911 EXTERNAL_EXTENSION_REENABLED, |
905 EXTERNAL_EXTENSION_BUCKET_BOUNDARY); | 912 EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
906 if (extensions::ManifestURL::UpdatesFromGallery(extension)) { | 913 if (extensions::ManifestURL::UpdatesFromGallery(extension)) { |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token), | 1203 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token), |
1197 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 1204 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
1198 return file_task_runner_.get(); | 1205 return file_task_runner_.get(); |
1199 } | 1206 } |
1200 | 1207 |
1201 extensions::ExtensionUpdater* ExtensionService::updater() { | 1208 extensions::ExtensionUpdater* ExtensionService::updater() { |
1202 return updater_.get(); | 1209 return updater_.get(); |
1203 } | 1210 } |
1204 | 1211 |
1205 void ExtensionService::CheckManagementPolicy() { | 1212 void ExtensionService::CheckManagementPolicy() { |
1206 std::vector<std::string> to_be_removed; | 1213 std::vector<std::string> to_unload; |
| 1214 std::map<std::string, Extension::DisableReason> to_disable; |
1207 | 1215 |
1208 // Loop through extensions list, unload installed extensions. | 1216 // Loop through the extensions list, finding extensions we need to unload or |
| 1217 // disable. |
1209 for (ExtensionSet::const_iterator iter = extensions_.begin(); | 1218 for (ExtensionSet::const_iterator iter = extensions_.begin(); |
1210 iter != extensions_.end(); ++iter) { | 1219 iter != extensions_.end(); ++iter) { |
1211 const Extension* extension = (iter->get()); | 1220 const Extension* extension = (iter->get()); |
1212 if (!system_->management_policy()->UserMayLoad(extension, NULL)) | 1221 if (!system_->management_policy()->UserMayLoad(extension, NULL)) |
1213 to_be_removed.push_back(extension->id()); | 1222 to_unload.push_back(extension->id()); |
| 1223 Extension::DisableReason disable_reason = Extension::DISABLE_NONE; |
| 1224 if (system_->management_policy()->MustRemainDisabled( |
| 1225 extension, &disable_reason, NULL)) |
| 1226 to_disable[extension->id()] = disable_reason; |
1214 } | 1227 } |
1215 | 1228 |
1216 // UnloadExtension will change the extensions_ list. So, we should | 1229 for (size_t i = 0; i < to_unload.size(); ++i) |
1217 // call it outside the iterator loop. | 1230 UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE); |
1218 for (size_t i = 0; i < to_be_removed.size(); ++i) | 1231 |
1219 UnloadExtension(to_be_removed[i], UnloadedExtensionInfo::REASON_DISABLE); | 1232 for (std::map<std::string, Extension::DisableReason>::const_iterator i = |
| 1233 to_disable.begin(); i != to_disable.end(); ++i) |
| 1234 DisableExtension(i->first, i->second); |
1220 } | 1235 } |
1221 | 1236 |
1222 void ExtensionService::CheckForUpdatesSoon() { | 1237 void ExtensionService::CheckForUpdatesSoon() { |
1223 if (updater()) { | 1238 if (updater()) { |
1224 if (AreAllExternalProvidersReady()) { | 1239 if (AreAllExternalProvidersReady()) { |
1225 updater()->CheckSoon(); | 1240 updater()->CheckSoon(); |
1226 } else { | 1241 } else { |
1227 // Sync can start updating before all the external providers are ready | 1242 // Sync can start updating before all the external providers are ready |
1228 // during startup. Start the update as soon as those providers are ready, | 1243 // during startup. Start the update as soon as those providers are ready, |
1229 // but not before. | 1244 // but not before. |
(...skipping 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2770 } | 2785 } |
2771 | 2786 |
2772 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { | 2787 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
2773 update_observers_.AddObserver(observer); | 2788 update_observers_.AddObserver(observer); |
2774 } | 2789 } |
2775 | 2790 |
2776 void ExtensionService::RemoveUpdateObserver( | 2791 void ExtensionService::RemoveUpdateObserver( |
2777 extensions::UpdateObserver* observer) { | 2792 extensions::UpdateObserver* observer) { |
2778 update_observers_.RemoveObserver(observer); | 2793 update_observers_.RemoveObserver(observer); |
2779 } | 2794 } |
OLD | NEW |