Chromium Code Reviews| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 // For example, an extension that requires experimental permissions | 164 // For example, an extension that requires experimental permissions |
| 165 // will not be loaded if the experimental command line flag is not used. | 165 // will not be loaded if the experimental command line flag is not used. |
| 166 // In this case, do not uninstall. | 166 // In this case, do not uninstall. |
| 167 if (!GetInstalledExtension(id)) { | 167 if (!GetInstalledExtension(id)) { |
| 168 // We can't call UninstallExtension with an unloaded/invalid | 168 // We can't call UninstallExtension with an unloaded/invalid |
| 169 // extension ID. | 169 // extension ID. |
| 170 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " | 170 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " |
| 171 << "with id: " << id; | 171 << "with id: " << id; |
| 172 return; | 172 return; |
| 173 } | 173 } |
| 174 UninstallExtension(id, true, NULL); | 174 UninstallExtension(id, kUninstallReasonOrphanedExternalExtension, NULL); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void ExtensionService::SetFileTaskRunnerForTesting( | 177 void ExtensionService::SetFileTaskRunnerForTesting( |
| 178 base::SequencedTaskRunner* task_runner) { | 178 base::SequencedTaskRunner* task_runner) { |
| 179 file_task_runner_ = task_runner; | 179 file_task_runner_ = task_runner; |
| 180 } | 180 } |
| 181 | 181 |
| 182 void ExtensionService::ClearProvidersForTesting() { | 182 void ExtensionService::ClearProvidersForTesting() { |
| 183 external_extension_providers_.clear(); | 183 external_extension_providers_.clear(); |
| 184 } | 184 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 creation_flags, | 227 creation_flags, |
| 228 mark_acknowledged)) { | 228 mark_acknowledged)) { |
| 229 return false; | 229 return false; |
| 230 } | 230 } |
| 231 | 231 |
| 232 update_once_all_providers_are_ready_ = true; | 232 update_once_all_providers_are_ready_ = true; |
| 233 return true; | 233 return true; |
| 234 } | 234 } |
| 235 | 235 |
| 236 // static | 236 // static |
| 237 // This function is used to implement the command-line switch | 237 // This function is used to uninstall an extension via sync. The LOG statements |
| 238 // --uninstall-extension, and to uninstall an extension via sync. The LOG | 238 // within this function are used to inform the user if the uninstall cannot be |
| 239 // statements within this function are used to inform the user if the uninstall | 239 // done. |
| 240 // cannot be done. | |
| 241 bool ExtensionService::UninstallExtensionHelper( | 240 bool ExtensionService::UninstallExtensionHelper( |
| 242 ExtensionService* extensions_service, | 241 ExtensionService* extensions_service, |
| 243 const std::string& extension_id) { | 242 const std::string& extension_id, |
| 243 UninstallReason reason) { | |
| 244 // We can't call UninstallExtension with an invalid extension ID. | 244 // We can't call UninstallExtension with an invalid extension ID. |
| 245 if (!extensions_service->GetInstalledExtension(extension_id)) { | 245 if (!extensions_service->GetInstalledExtension(extension_id)) { |
| 246 LOG(WARNING) << "Attempted uninstallation of non-existent extension with " | 246 LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
| 247 << "id: " << extension_id; | 247 << "id: " << extension_id; |
| 248 return false; | 248 return false; |
| 249 } | 249 } |
| 250 | 250 |
| 251 // The following call to UninstallExtension will not allow an uninstall of a | 251 // The following call to UninstallExtension will not allow an uninstall of a |
| 252 // policy-controlled extension. | 252 // policy-controlled extension. |
| 253 base::string16 error; | 253 base::string16 error; |
| 254 if (!extensions_service->UninstallExtension(extension_id, false, &error)) { | 254 if (!extensions_service->UninstallExtension(extension_id, reason, &error)) { |
| 255 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id | 255 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 256 << ": " << error; | 256 << ": " << error; |
| 257 return false; | 257 return false; |
| 258 } | 258 } |
| 259 | 259 |
| 260 return true; | 260 return true; |
| 261 } | 261 } |
| 262 | 262 |
| 263 ExtensionService::ExtensionService(Profile* profile, | 263 ExtensionService::ExtensionService(Profile* profile, |
| 264 const CommandLine* command_line, | 264 const CommandLine* command_line, |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 // We should always be able to remember the extension's path. If it's not in | 655 // We should always be able to remember the extension's path. If it's not in |
| 656 // the map, someone failed to update |unloaded_extension_paths_|. | 656 // the map, someone failed to update |unloaded_extension_paths_|. |
| 657 CHECK(!path.empty()); | 657 CHECK(!path.empty()); |
| 658 extensions::UnpackedInstaller::Create(this)->Load(path); | 658 extensions::UnpackedInstaller::Create(this)->Load(path); |
| 659 } | 659 } |
| 660 // When reloading is done, mark this extension as done reloading. | 660 // When reloading is done, mark this extension as done reloading. |
| 661 SetBeingReloaded(extension_id, false); | 661 SetBeingReloaded(extension_id, false); |
| 662 } | 662 } |
| 663 | 663 |
| 664 bool ExtensionService::UninstallExtension(const std::string& extension_id, | 664 bool ExtensionService::UninstallExtension(const std::string& extension_id, |
| 665 bool external_uninstall, | 665 UninstallReason reason, |
| 666 base::string16* error) { | 666 base::string16* error) { |
| 667 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 667 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 668 | 668 |
| 669 scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id)); | 669 scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id)); |
| 670 | 670 |
| 671 // Callers should not send us nonexistent extensions. | 671 // Callers should not send us nonexistent extensions. |
| 672 CHECK(extension.get()); | 672 CHECK(extension.get()); |
| 673 | 673 |
| 674 // Policy change which triggers an uninstall will always set | 674 // Policy change which triggers an uninstall will always set |
| 675 // |external_uninstall| to true so this is the only way to uninstall | 675 // |external_uninstall| to true so this is the only way to uninstall |
| 676 // managed extensions. | 676 // managed extensions. |
| 677 // Shared modules being uninstalled will also set |external_uninstall| to true | 677 // Shared modules being uninstalled will also set |external_uninstall| to true |
| 678 // so that we can guarantee users don't uninstall a shared module. | 678 // so that we can guarantee users don't uninstall a shared module. |
| 679 // (crbug.com/273300) | 679 // (crbug.com/273300) |
| 680 // TODO(rdevlin.cronin): This is probably not right. We should do something | 680 // TODO(rdevlin.cronin): This is probably not right. We should do something |
| 681 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so | 681 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so |
| 682 // we don't do this. | 682 // we don't do this. |
| 683 bool external_uninstall = | |
| 684 (reason == kUninstallReasonOrphanedExternalExtension) || | |
| 685 (reason == kUninstallReasonOrphanedSharedModule); | |
|
Devlin
2014/05/14 23:14:20
Shame this is still here... ah well.
| |
| 683 if (!external_uninstall && | 686 if (!external_uninstall && |
| 684 !system_->management_policy()->UserMayModifySettings( | 687 !system_->management_policy()->UserMayModifySettings( |
| 685 extension.get(), error)) { | 688 extension.get(), error)) { |
| 686 content::NotificationService::current()->Notify( | 689 content::NotificationService::current()->Notify( |
| 687 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, | 690 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
| 688 content::Source<Profile>(profile_), | 691 content::Source<Profile>(profile_), |
| 689 content::Details<const Extension>(extension.get())); | 692 content::Details<const Extension>(extension.get())); |
| 690 return false; | 693 return false; |
| 691 } | 694 } |
| 692 | 695 |
| (...skipping 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2408 void ExtensionService::UnloadAllExtensionsInternal() { | 2411 void ExtensionService::UnloadAllExtensionsInternal() { |
| 2409 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); | 2412 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
| 2410 | 2413 |
| 2411 registry_->ClearAll(); | 2414 registry_->ClearAll(); |
| 2412 system_->runtime_data()->ClearAll(); | 2415 system_->runtime_data()->ClearAll(); |
| 2413 | 2416 |
| 2414 // TODO(erikkay) should there be a notification for this? We can't use | 2417 // TODO(erikkay) should there be a notification for this? We can't use |
| 2415 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 2418 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 2416 // or uninstalled. | 2419 // or uninstalled. |
| 2417 } | 2420 } |
| OLD | NEW |