| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // For example, an extension that requires experimental permissions | 161 // For example, an extension that requires experimental permissions |
| 162 // will not be loaded if the experimental command line flag is not used. | 162 // will not be loaded if the experimental command line flag is not used. |
| 163 // In this case, do not uninstall. | 163 // In this case, do not uninstall. |
| 164 if (!GetInstalledExtension(id)) { | 164 if (!GetInstalledExtension(id)) { |
| 165 // We can't call UninstallExtension with an unloaded/invalid | 165 // We can't call UninstallExtension with an unloaded/invalid |
| 166 // extension ID. | 166 // extension ID. |
| 167 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " | 167 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " |
| 168 << "with id: " << id; | 168 << "with id: " << id; |
| 169 return; | 169 return; |
| 170 } | 170 } |
| 171 UninstallExtension(id, UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, NULL); | 171 UninstallExtension(id, true, NULL); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void ExtensionService::SetFileTaskRunnerForTesting( | 174 void ExtensionService::SetFileTaskRunnerForTesting( |
| 175 base::SequencedTaskRunner* task_runner) { | 175 base::SequencedTaskRunner* task_runner) { |
| 176 file_task_runner_ = task_runner; | 176 file_task_runner_ = task_runner; |
| 177 } | 177 } |
| 178 | 178 |
| 179 void ExtensionService::ClearProvidersForTesting() { | 179 void ExtensionService::ClearProvidersForTesting() { |
| 180 external_extension_providers_.clear(); | 180 external_extension_providers_.clear(); |
| 181 } | 181 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 creation_flags, | 224 creation_flags, |
| 225 mark_acknowledged)) { | 225 mark_acknowledged)) { |
| 226 return false; | 226 return false; |
| 227 } | 227 } |
| 228 | 228 |
| 229 update_once_all_providers_are_ready_ = true; | 229 update_once_all_providers_are_ready_ = true; |
| 230 return true; | 230 return true; |
| 231 } | 231 } |
| 232 | 232 |
| 233 // static | 233 // static |
| 234 // This function is used to uninstall an extension via sync. The LOG statements | 234 // This function is used to implement the command-line switch |
| 235 // within this function are used to inform the user if the uninstall cannot be | 235 // --uninstall-extension, and to uninstall an extension via sync. The LOG |
| 236 // done. | 236 // statements within this function are used to inform the user if the uninstall |
| 237 // cannot be done. |
| 237 bool ExtensionService::UninstallExtensionHelper( | 238 bool ExtensionService::UninstallExtensionHelper( |
| 238 ExtensionService* extensions_service, | 239 ExtensionService* extensions_service, |
| 239 const std::string& extension_id, | 240 const std::string& extension_id) { |
| 240 UninstallReason reason) { | |
| 241 // We can't call UninstallExtension with an invalid extension ID. | 241 // We can't call UninstallExtension with an invalid extension ID. |
| 242 if (!extensions_service->GetInstalledExtension(extension_id)) { | 242 if (!extensions_service->GetInstalledExtension(extension_id)) { |
| 243 LOG(WARNING) << "Attempted uninstallation of non-existent extension with " | 243 LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
| 244 << "id: " << extension_id; | 244 << "id: " << extension_id; |
| 245 return false; | 245 return false; |
| 246 } | 246 } |
| 247 | 247 |
| 248 // The following call to UninstallExtension will not allow an uninstall of a | 248 // The following call to UninstallExtension will not allow an uninstall of a |
| 249 // policy-controlled extension. | 249 // policy-controlled extension. |
| 250 base::string16 error; | 250 base::string16 error; |
| 251 if (!extensions_service->UninstallExtension(extension_id, reason, &error)) { | 251 if (!extensions_service->UninstallExtension(extension_id, false, &error)) { |
| 252 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id | 252 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 253 << ": " << error; | 253 << ": " << error; |
| 254 return false; | 254 return false; |
| 255 } | 255 } |
| 256 | 256 |
| 257 return true; | 257 return true; |
| 258 } | 258 } |
| 259 | 259 |
| 260 ExtensionService::ExtensionService(Profile* profile, | 260 ExtensionService::ExtensionService(Profile* profile, |
| 261 const CommandLine* command_line, | 261 const CommandLine* command_line, |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 } | 687 } |
| 688 // When reloading is done, mark this extension as done reloading. | 688 // When reloading is done, mark this extension as done reloading. |
| 689 SetBeingReloaded(extension_id, false); | 689 SetBeingReloaded(extension_id, false); |
| 690 #endif // defined(ENABLE_EXTENSIONS) | 690 #endif // defined(ENABLE_EXTENSIONS) |
| 691 } | 691 } |
| 692 | 692 |
| 693 bool ExtensionService::UninstallExtension( | 693 bool ExtensionService::UninstallExtension( |
| 694 // "transient" because the process of uninstalling may cause the reference | 694 // "transient" because the process of uninstalling may cause the reference |
| 695 // to become invalid. Instead, use |extenson->id()|. | 695 // to become invalid. Instead, use |extenson->id()|. |
| 696 const std::string& transient_extension_id, | 696 const std::string& transient_extension_id, |
| 697 UninstallReason reason, | 697 bool external_uninstall, |
| 698 base::string16* error) { | 698 base::string16* error) { |
| 699 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 699 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 700 | 700 |
| 701 scoped_refptr<const Extension> extension = | 701 scoped_refptr<const Extension> extension = |
| 702 GetInstalledExtension(transient_extension_id); | 702 GetInstalledExtension(transient_extension_id); |
| 703 | 703 |
| 704 // Callers should not send us nonexistent extensions. | 704 // Callers should not send us nonexistent extensions. |
| 705 CHECK(extension.get()); | 705 CHECK(extension.get()); |
| 706 | 706 |
| 707 // Policy change which triggers an uninstall will always set | 707 // Policy change which triggers an uninstall will always set |
| 708 // |external_uninstall| to true so this is the only way to uninstall | 708 // |external_uninstall| to true so this is the only way to uninstall |
| 709 // managed extensions. | 709 // managed extensions. |
| 710 // Shared modules being uninstalled will also set |external_uninstall| to true | 710 // Shared modules being uninstalled will also set |external_uninstall| to true |
| 711 // so that we can guarantee users don't uninstall a shared module. | 711 // so that we can guarantee users don't uninstall a shared module. |
| 712 // (crbug.com/273300) | 712 // (crbug.com/273300) |
| 713 // TODO(rdevlin.cronin): This is probably not right. We should do something | 713 // TODO(rdevlin.cronin): This is probably not right. We should do something |
| 714 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so | 714 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so |
| 715 // we don't do this. | 715 // we don't do this. |
| 716 bool external_uninstall = | |
| 717 (reason == UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) || | |
| 718 (reason == UNINSTALL_REASON_ORPHANED_SHARED_MODULE); | |
| 719 if (!external_uninstall && | 716 if (!external_uninstall && |
| 720 !system_->management_policy()->UserMayModifySettings( | 717 !system_->management_policy()->UserMayModifySettings( |
| 721 extension.get(), error)) { | 718 extension.get(), error)) { |
| 722 content::NotificationService::current()->Notify( | 719 content::NotificationService::current()->Notify( |
| 723 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, | 720 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
| 724 content::Source<Profile>(profile_), | 721 content::Source<Profile>(profile_), |
| 725 content::Details<const Extension>(extension.get())); | 722 content::Details<const Extension>(extension.get())); |
| 726 return false; | 723 return false; |
| 727 } | 724 } |
| 728 | 725 |
| (...skipping 1621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2350 } | 2347 } |
| 2351 | 2348 |
| 2352 void ExtensionService::OnProfileDestructionStarted() { | 2349 void ExtensionService::OnProfileDestructionStarted() { |
| 2353 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2350 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
| 2354 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2351 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
| 2355 it != ids_to_unload.end(); | 2352 it != ids_to_unload.end(); |
| 2356 ++it) { | 2353 ++it) { |
| 2357 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2354 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
| 2358 } | 2355 } |
| 2359 } | 2356 } |
| OLD | NEW |