| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // For example, an extension that requires experimental permissions | 176 // For example, an extension that requires experimental permissions |
| 177 // will not be loaded if the experimental command line flag is not used. | 177 // will not be loaded if the experimental command line flag is not used. |
| 178 // In this case, do not uninstall. | 178 // In this case, do not uninstall. |
| 179 if (!GetInstalledExtension(id)) { | 179 if (!GetInstalledExtension(id)) { |
| 180 // We can't call UninstallExtension with an unloaded/invalid | 180 // We can't call UninstallExtension with an unloaded/invalid |
| 181 // extension ID. | 181 // extension ID. |
| 182 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " | 182 LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " |
| 183 << "with id: " << id; | 183 << "with id: " << id; |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 UninstallExtension(id, true, NULL); | 186 UninstallExtension(id, UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, NULL); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void ExtensionService::SetFileTaskRunnerForTesting( | 189 void ExtensionService::SetFileTaskRunnerForTesting( |
| 190 base::SequencedTaskRunner* task_runner) { | 190 base::SequencedTaskRunner* task_runner) { |
| 191 file_task_runner_ = task_runner; | 191 file_task_runner_ = task_runner; |
| 192 } | 192 } |
| 193 | 193 |
| 194 void ExtensionService::ClearProvidersForTesting() { | 194 void ExtensionService::ClearProvidersForTesting() { |
| 195 external_extension_providers_.clear(); | 195 external_extension_providers_.clear(); |
| 196 } | 196 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 creation_flags, | 239 creation_flags, |
| 240 mark_acknowledged)) { | 240 mark_acknowledged)) { |
| 241 return false; | 241 return false; |
| 242 } | 242 } |
| 243 | 243 |
| 244 update_once_all_providers_are_ready_ = true; | 244 update_once_all_providers_are_ready_ = true; |
| 245 return true; | 245 return true; |
| 246 } | 246 } |
| 247 | 247 |
| 248 // static | 248 // static |
| 249 // This function is used to implement the command-line switch | 249 // This function is used to uninstall an extension via sync. The LOG statements |
| 250 // --uninstall-extension, and to uninstall an extension via sync. The LOG | 250 // within this function are used to inform the user if the uninstall cannot be |
| 251 // statements within this function are used to inform the user if the uninstall | 251 // done. |
| 252 // cannot be done. | |
| 253 bool ExtensionService::UninstallExtensionHelper( | 252 bool ExtensionService::UninstallExtensionHelper( |
| 254 ExtensionService* extensions_service, | 253 ExtensionService* extensions_service, |
| 255 const std::string& extension_id) { | 254 const std::string& extension_id, |
| 255 UninstallReason reason) { |
| 256 // We can't call UninstallExtension with an invalid extension ID. | 256 // We can't call UninstallExtension with an invalid extension ID. |
| 257 if (!extensions_service->GetInstalledExtension(extension_id)) { | 257 if (!extensions_service->GetInstalledExtension(extension_id)) { |
| 258 LOG(WARNING) << "Attempted uninstallation of non-existent extension with " | 258 LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
| 259 << "id: " << extension_id; | 259 << "id: " << extension_id; |
| 260 return false; | 260 return false; |
| 261 } | 261 } |
| 262 | 262 |
| 263 // The following call to UninstallExtension will not allow an uninstall of a | 263 // The following call to UninstallExtension will not allow an uninstall of a |
| 264 // policy-controlled extension. | 264 // policy-controlled extension. |
| 265 base::string16 error; | 265 base::string16 error; |
| 266 if (!extensions_service->UninstallExtension(extension_id, false, &error)) { | 266 if (!extensions_service->UninstallExtension(extension_id, reason, &error)) { |
| 267 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id | 267 LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 268 << ": " << error; | 268 << ": " << error; |
| 269 return false; | 269 return false; |
| 270 } | 270 } |
| 271 | 271 |
| 272 return true; | 272 return true; |
| 273 } | 273 } |
| 274 | 274 |
| 275 ExtensionService::ExtensionService(Profile* profile, | 275 ExtensionService::ExtensionService(Profile* profile, |
| 276 const CommandLine* command_line, | 276 const CommandLine* command_line, |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 } | 702 } |
| 703 // When reloading is done, mark this extension as done reloading. | 703 // When reloading is done, mark this extension as done reloading. |
| 704 SetBeingReloaded(extension_id, false); | 704 SetBeingReloaded(extension_id, false); |
| 705 #endif // defined(ENABLE_EXTENSIONS) | 705 #endif // defined(ENABLE_EXTENSIONS) |
| 706 } | 706 } |
| 707 | 707 |
| 708 bool ExtensionService::UninstallExtension( | 708 bool ExtensionService::UninstallExtension( |
| 709 // "transient" because the process of uninstalling may cause the reference | 709 // "transient" because the process of uninstalling may cause the reference |
| 710 // to become invalid. Instead, use |extenson->id()|. | 710 // to become invalid. Instead, use |extenson->id()|. |
| 711 const std::string& transient_extension_id, | 711 const std::string& transient_extension_id, |
| 712 bool external_uninstall, | 712 UninstallReason reason, |
| 713 base::string16* error) { | 713 base::string16* error) { |
| 714 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 714 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 715 | 715 |
| 716 scoped_refptr<const Extension> extension = | 716 scoped_refptr<const Extension> extension = |
| 717 GetInstalledExtension(transient_extension_id); | 717 GetInstalledExtension(transient_extension_id); |
| 718 | 718 |
| 719 // Callers should not send us nonexistent extensions. | 719 // Callers should not send us nonexistent extensions. |
| 720 CHECK(extension.get()); | 720 CHECK(extension.get()); |
| 721 | 721 |
| 722 // Policy change which triggers an uninstall will always set | 722 // Policy change which triggers an uninstall will always set |
| 723 // |external_uninstall| to true so this is the only way to uninstall | 723 // |external_uninstall| to true so this is the only way to uninstall |
| 724 // managed extensions. | 724 // managed extensions. |
| 725 // Shared modules being uninstalled will also set |external_uninstall| to true | 725 // Shared modules being uninstalled will also set |external_uninstall| to true |
| 726 // so that we can guarantee users don't uninstall a shared module. | 726 // so that we can guarantee users don't uninstall a shared module. |
| 727 // (crbug.com/273300) | 727 // (crbug.com/273300) |
| 728 // TODO(rdevlin.cronin): This is probably not right. We should do something | 728 // TODO(rdevlin.cronin): This is probably not right. We should do something |
| 729 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so | 729 // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so |
| 730 // we don't do this. | 730 // we don't do this. |
| 731 bool external_uninstall = |
| 732 (reason == UNINSTALL_REASON_INTERNAL_MANAGEMENT) || |
| 733 (reason == UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION) || |
| 734 (reason == UNINSTALL_REASON_ORPHANED_SHARED_MODULE); |
| 731 if (!external_uninstall && | 735 if (!external_uninstall && |
| 732 !system_->management_policy()->UserMayModifySettings( | 736 !system_->management_policy()->UserMayModifySettings( |
| 733 extension.get(), error)) { | 737 extension.get(), error)) { |
| 734 content::NotificationService::current()->Notify( | 738 content::NotificationService::current()->Notify( |
| 735 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, | 739 chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
| 736 content::Source<Profile>(profile_), | 740 content::Source<Profile>(profile_), |
| 737 content::Details<const Extension>(extension.get())); | 741 content::Details<const Extension>(extension.get())); |
| 738 return false; | 742 return false; |
| 739 } | 743 } |
| 740 | 744 |
| (...skipping 1746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2487 } | 2491 } |
| 2488 | 2492 |
| 2489 void ExtensionService::OnProfileDestructionStarted() { | 2493 void ExtensionService::OnProfileDestructionStarted() { |
| 2490 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2494 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
| 2491 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2495 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
| 2492 it != ids_to_unload.end(); | 2496 it != ids_to_unload.end(); |
| 2493 ++it) { | 2497 ++it) { |
| 2494 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2498 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
| 2495 } | 2499 } |
| 2496 } | 2500 } |
| OLD | NEW |