| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shared_module_service.h" | 5 #include "chrome/browser/extensions/shared_module_service.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/version.h" | 9 #include "base/version.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 pending_extension_manager->AddFromExtensionImport( | 97 pending_extension_manager->AddFromExtensionImport( |
| 98 iter->extension_id, | 98 iter->extension_id, |
| 99 extension_urls::GetWebstoreUpdateUrl(), | 99 extension_urls::GetWebstoreUpdateUrl(), |
| 100 SharedModuleInfo::IsSharedModule); | 100 SharedModuleInfo::IsSharedModule); |
| 101 } | 101 } |
| 102 service->CheckForUpdatesSoon(); | 102 service->CheckForUpdatesSoon(); |
| 103 } | 103 } |
| 104 return status; | 104 return status; |
| 105 } | 105 } |
| 106 | 106 |
| 107 scoped_ptr<const ExtensionSet> SharedModuleService::GetDependentExtensions( | 107 scoped_ptr<ExtensionSet> SharedModuleService::GetDependentExtensions( |
| 108 const Extension* extension) { | 108 const Extension* extension) { |
| 109 scoped_ptr<ExtensionSet> dependents(new ExtensionSet()); | 109 scoped_ptr<ExtensionSet> dependents(new ExtensionSet()); |
| 110 | 110 |
| 111 if (SharedModuleInfo::IsSharedModule(extension)) { | 111 if (SharedModuleInfo::IsSharedModule(extension)) { |
| 112 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); | 112 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); |
| 113 ExtensionService* service = | 113 ExtensionService* service = |
| 114 ExtensionSystem::Get(browser_context_)->extension_service(); | 114 ExtensionSystem::Get(browser_context_)->extension_service(); |
| 115 | 115 |
| 116 ExtensionSet set_to_check; | 116 ExtensionSet set_to_check; |
| 117 set_to_check.InsertAll(registry->enabled_extensions()); | 117 set_to_check.InsertAll(registry->enabled_extensions()); |
| 118 set_to_check.InsertAll(registry->disabled_extensions()); | 118 set_to_check.InsertAll(registry->disabled_extensions()); |
| 119 set_to_check.InsertAll(*service->delayed_installs()); | 119 set_to_check.InsertAll(*service->delayed_installs()); |
| 120 | 120 |
| 121 for (ExtensionSet::const_iterator iter = set_to_check.begin(); | 121 for (ExtensionSet::const_iterator iter = set_to_check.begin(); |
| 122 iter != set_to_check.end(); | 122 iter != set_to_check.end(); |
| 123 ++iter) { | 123 ++iter) { |
| 124 if (SharedModuleInfo::ImportsExtensionById(iter->get(), | 124 if (SharedModuleInfo::ImportsExtensionById(iter->get(), |
| 125 extension->id())) { | 125 extension->id())) { |
| 126 dependents->Insert(*iter); | 126 dependents->Insert(*iter); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 return dependents.PassAs<const ExtensionSet>(); | 130 return dependents.PassAs<ExtensionSet>(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void SharedModuleService::OnExtensionUninstalled( | 133 void SharedModuleService::OnExtensionUninstalled( |
| 134 content::BrowserContext* browser_context, | 134 content::BrowserContext* browser_context, |
| 135 const Extension* extension) { | 135 const Extension* extension) { |
| 136 // Uninstalls shared modules that were only referenced by |extension|. | 136 // Uninstalls shared modules that were only referenced by |extension|. |
| 137 if (!SharedModuleInfo::ImportsModules(extension)) | 137 if (!SharedModuleInfo::ImportsModules(extension)) |
| 138 return; | 138 return; |
| 139 | 139 |
| 140 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); | 140 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_); |
| 141 ExtensionService* service = | 141 ExtensionService* service = |
| 142 ExtensionSystem::Get(browser_context_)->extension_service(); | 142 ExtensionSystem::Get(browser_context_)->extension_service(); |
| 143 | 143 |
| 144 const ImportInfoVector& imports = SharedModuleInfo::GetImports(extension); | 144 const ImportInfoVector& imports = SharedModuleInfo::GetImports(extension); |
| 145 for (ImportInfoVector::const_iterator iter = imports.begin(); | 145 for (ImportInfoVector::const_iterator iter = imports.begin(); |
| 146 iter != imports.end(); | 146 iter != imports.end(); |
| 147 ++iter) { | 147 ++iter) { |
| 148 const Extension* imported_module = | 148 const Extension* imported_module = |
| 149 registry->GetExtensionById(iter->extension_id, | 149 registry->GetExtensionById(iter->extension_id, |
| 150 ExtensionRegistry::EVERYTHING); | 150 ExtensionRegistry::EVERYTHING); |
| 151 if (imported_module && imported_module->from_webstore()) { | 151 if (imported_module && imported_module->from_webstore()) { |
| 152 scoped_ptr<const ExtensionSet> dependents = | 152 scoped_ptr<ExtensionSet> dependents = |
| 153 GetDependentExtensions(imported_module); | 153 GetDependentExtensions(imported_module); |
| 154 if (dependents->is_empty()) { | 154 if (dependents->is_empty()) { |
| 155 service->UninstallExtension(iter->extension_id, | 155 service->UninstallExtension(iter->extension_id, |
| 156 true, // External uninstall. | 156 true, // External uninstall. |
| 157 NULL); // Ignore error. | 157 NULL); // Ignore error. |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace extensions | 163 } // namespace extensions |
| OLD | NEW |