| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // For example, an extension that requires experimental permissions | 169 // For example, an extension that requires experimental permissions |
| 170 // will not be loaded if the experimental command line flag is not used. | 170 // will not be loaded if the experimental command line flag is not used. |
| 171 // In this case, do not uninstall. | 171 // In this case, do not uninstall. |
| 172 if (!GetInstalledExtension(id)) { | 172 if (!GetInstalledExtension(id)) { |
| 173 // We can't call UninstallExtension with an unloaded/invalid | 173 // We can't call UninstallExtension with an unloaded/invalid |
| 174 // extension ID. | 174 // extension ID. |
| 175 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " | 175 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " |
| 176 << "with id: " << id; | 176 << "with id: " << id; |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 UninstallExtension(id, true, NULL); | 179 UninstallExtension(id, UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, NULL); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void ExtensionService::SetFileTaskRunnerForTesting( | 182 void ExtensionService::SetFileTaskRunnerForTesting( |
| 183 base::SequencedTaskRunner* task_runner) { | 183 base::SequencedTaskRunner* task_runner) { |
| 184 file_task_runner_ = task_runner; | 184 file_task_runner_ = task_runner; |
| 185 } | 185 } |
| 186 | 186 |
| 187 void ExtensionService::ClearProvidersForTesting() { | 187 void ExtensionService::ClearProvidersForTesting() { |
| 188 external_extension_providers_.clear(); | 188 external_extension_providers_.clear(); |
| 189 } | 189 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 creation_flags, | 232 creation_flags, |
| 233 mark_acknowledged)) { | 233 mark_acknowledged)) { |
| 234 return false; | 234 return false; |
| 235 } | 235 } |
| 236 | 236 |
| 237 update_once_all_providers_are_ready_ = true; | 237 update_once_all_providers_are_ready_ = true; |
| 238 return true; | 238 return true; |
| 239 } | 239 } |
| 240 | 240 |
| 241 // static | 241 // static |
| 242 // This function is used to implement the command-line switch | 242 // This function is used to uninstall an extension via sync. The LOG statements |
| 243 // --uninstall-extension, and to uninstall an extension via sync. The LOG | 243 // within this function are used to inform the user if the uninstall cannot be |
| 244 // statements within this function are used to inform the user if the uninstall | 244 // done. |
| 245 // cannot be done. | |
| 246 bool ExtensionService::UninstallExtensionHelper( | 245 bool ExtensionService::UninstallExtensionHelper( |
| 247 ExtensionService* extensions_service, | 246 ExtensionService* extensions_service, |
| 248 const std::string& extension_id) { | 247 const std::string& extension_id, |
| 248 UninstallReason reason) { |
| 249 // We can't call UninstallExtension with an invalid extension ID. | 249 // We can't call UninstallExtension with an invalid extension ID. |
| 250 if (!extensions_service->GetInstalledExtension(extension_id)) { | 250 if (!extensions_service->GetInstalledExtension(extension_id)) { |
| 251 LOG(WARNING) << "Attempted uninstallation of non-existent extension with " | 251 LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
| 252 << "id: " << extension_id; | 252 << "id: " << extension_id; |
| 253 return false; | 253 return false; |
| 254 } | 254 } |
| 255 | 255 |
| 256 // The following call to UninstallExtension will not allow an uninstall of a | 256 // The following call to UninstallExtension will not allow an uninstall of a |
| 257 // policy-controlled extension. | 257 // policy-controlled extension. |
| 258 base::string16 error; | 258 base::string16 error; |
| 259 if (!extensions_service->UninstallExtension(extension_id, false, &error)) { | 259 if (!extensions_service->UninstallExtension(extension_id, reason, &error)) { |
| 260 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id | 260 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 261 << ": " << error; | 261 << ": " << error; |
| 262 return false; | 262 return false; |
| 263 } | 263 } |
| 264 | 264 |
| 265 return true; | 265 return true; |
| 266 } | 266 } |
| 267 | 267 |
| 268 ExtensionService::ExtensionService(Profile* profile, | 268 ExtensionService::ExtensionService(Profile* profile, |
| 269 const CommandLine* command_line, | 269 const CommandLine* command_line, |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 extensions::UnpackedInstaller::Create(this)->Load(path); | 687 extensions::UnpackedInstaller::Create(this)->Load(path); |
| 688 } | 688 } |
| 689 // When reloading is done, mark this extension as done reloading. | 689 // When reloading is done, mark this extension as done reloading. |
| 690 SetBeingReloaded(extension_id, false); | 690 SetBeingReloaded(extension_id, false); |
| 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 bool external_uninstall, | 697 UninstallReason reason, |
| 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); |
| 716 if (!external_uninstall && | 719 if (!external_uninstall && |
| 717 !system_->management_policy()->UserMayModifySettings( | 720 !system_->management_policy()->UserMayModifySettings( |
| 718 extension.get(), error)) { | 721 extension.get(), error)) { |
| 719 content::NotificationService::current()->Notify( | 722 content::NotificationService::current()->Notify( |
| 720 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, | 723 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
| 721 content::Source<Profile>(profile_), | 724 content::Source<Profile>(profile_), |
| 722 content::Details<const Extension>(extension.get())); | 725 content::Details<const Extension>(extension.get())); |
| 723 return false; | 726 return false; |
| 724 } | 727 } |
| 725 | 728 |
| (...skipping 1730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2456 } | 2459 } |
| 2457 | 2460 |
| 2458 void ExtensionService::OnProfileDestructionStarted() { | 2461 void ExtensionService::OnProfileDestructionStarted() { |
| 2459 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2462 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
| 2460 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2463 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
| 2461 it != ids_to_unload.end(); | 2464 it != ids_to_unload.end(); |
| 2462 ++it) { | 2465 ++it) { |
| 2463 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2466 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
| 2464 } | 2467 } |
| 2465 } | 2468 } |
| OLD | NEW |