Move ExtensionService::GenerateInstalledExtensionsSet() to ExtensionRegistry.
Also fix profile->GetExtensionService() where seen.
BUG=351891
[email protected] (c/b/sync)
[email protected] (c/b/themes)
[email protected] (c/b/apps)
[email protected] (c/b/ui/webui/net_internals)
[email protected] (c/b/metrics)
All TBRs are for strictly mechanical changes.
Review URL: https://codereview.chromium.org/198373002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258059 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/apps/ephemeral_app_service.cc b/chrome/browser/apps/ephemeral_app_service.cc
index 8418e35..86ea100 100644
--- a/chrome/browser/apps/ephemeral_app_service.cc
+++ b/chrome/browser/apps/ephemeral_app_service.cc
@@ -15,6 +15,7 @@
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "extensions/browser/extension_prefs.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
@@ -123,11 +124,9 @@
}
void EphemeralAppService::InitEphemeralAppCount() {
- ExtensionService* service =
- ExtensionSystem::Get(profile_)->extension_service();
- DCHECK(service);
scoped_ptr<ExtensionSet> extensions =
- service->GenerateInstalledExtensionsSet();
+ extensions::ExtensionRegistry::Get(profile_)
+ ->GenerateInstalledExtensionsSet();
ephemeral_app_count_ = 0;
for (ExtensionSet::const_iterator it = extensions->begin();
@@ -148,13 +147,10 @@
}
void EphemeralAppService::GarbageCollectApps() {
- ExtensionSystem* system = ExtensionSystem::Get(profile_);
- DCHECK(system);
- ExtensionService* service = system->extension_service();
- DCHECK(service);
- ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
scoped_ptr<ExtensionSet> extensions =
- service->GenerateInstalledExtensionsSet();
+ extensions::ExtensionRegistry::Get(profile_)
+ ->GenerateInstalledExtensionsSet();
+ ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
int app_count = 0;
LaunchTimeAppMap app_launch_times;
@@ -184,6 +180,9 @@
app_launch_times.insert(std::make_pair(last_launch_time, extension->id()));
}
+ ExtensionService* service =
+ ExtensionSystem::Get(profile_)->extension_service();
+ DCHECK(service);
// Execute the replacement policies and remove apps marked for deletion.
if (!app_launch_times.empty()) {
GetAppsToRemove(app_count, app_launch_times, &remove_app_ids);
diff --git a/chrome/browser/extensions/api/storage/managed_value_store_cache.cc b/chrome/browser/extensions/api/storage/managed_value_store_cache.cc
index c8cf7b6..562117be 100644
--- a/chrome/browser/extensions/api/storage/managed_value_store_cache.cc
+++ b/chrome/browser/extensions/api/storage/managed_value_store_cache.cc
@@ -12,7 +12,6 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/storage/policy_value_store.h"
-#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/policy/schema_registry_service.h"
@@ -30,6 +29,7 @@
#include "content/public/browser/notification_source.h"
#include "extensions/browser/api/storage/settings_storage_factory.h"
#include "extensions/browser/extension_prefs.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/value_store/value_store_change.h"
#include "extensions/common/api/storage.h"
@@ -78,7 +78,7 @@
const content::NotificationDetails& details) OVERRIDE;
private:
- // Handler for NOTIFICATION_EXTENSIONS_READY.
+ // Handler for the signal from ExtensionSystem::ready().
void OnExtensionsReady();
// Starts a schema load for all extensions that use managed storage.
@@ -123,7 +123,7 @@
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- // Some extensions are installed on the first run before the ExtensionService
+ // Some extensions are installed on the first run before the ExtensionSystem
// becomes ready. Wait until all of them are ready before registering the
// schemas of managed extensions, so that the policy loaders are reloaded at
// most once.
@@ -155,9 +155,8 @@
void ManagedValueStoreCache::ExtensionTracker::OnExtensionsReady() {
// Load schemas for all installed extensions.
- ExtensionService* service =
- ExtensionSystem::Get(profile_)->extension_service();
- LoadSchemas(service->GenerateInstalledExtensionsSet());
+ LoadSchemas(
+ ExtensionRegistry::Get(profile_)->GenerateInstalledExtensionsSet());
}
void ManagedValueStoreCache::ExtensionTracker::LoadSchemas(
@@ -226,11 +225,11 @@
schema_registry_->RegisterComponents(policy::POLICY_DOMAIN_EXTENSIONS,
*components);
- // The first SetReady() call is performed after receiving
- // NOTIFICATION_EXTENSIONS_READY, even if there are no managed extensions.
- // It will trigger a loading of the initial policy for any managed
- // extensions, and eventually the PolicyService will become ready for
- // POLICY_DOMAIN_EXTENSIONS, and OnPolicyServiceInitialized() will be invoked.
+ // The first SetReady() call is performed after the ExtensionSystem is ready,
+ // even if there are no managed extensions. It will trigger a loading of the
+ // initial policy for any managed extensions, and eventually the PolicyService
+ // will become ready for POLICY_DOMAIN_EXTENSIONS, and
+ // OnPolicyServiceInitialized() will be invoked.
// Subsequent calls to SetReady() are ignored.
schema_registry_->SetReady(policy::POLICY_DOMAIN_EXTENSIONS);
}
diff --git a/chrome/browser/extensions/extension_message_bubble_controller.cc b/chrome/browser/extensions/extension_message_bubble_controller.cc
index 383d216..c5beb13 100644
--- a/chrome/browser/extensions/extension_message_bubble_controller.cc
+++ b/chrome/browser/extensions/extension_message_bubble_controller.cc
@@ -8,14 +8,12 @@
#include "base/metrics/histogram.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_message_bubble.h"
-#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/user_metrics.h"
-#include "extensions/browser/extension_prefs.h"
-#include "extensions/browser/extension_system.h"
+#include "extensions/browser/extension_registry.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -36,8 +34,7 @@
ExtensionMessageBubbleController::ExtensionMessageBubbleController(
Delegate* delegate, Profile* profile)
- : service_(extensions::ExtensionSystem::Get(profile)->extension_service()),
- profile_(profile),
+ : profile_(profile),
user_action_(ACTION_BOUNDARY),
delegate_(delegate),
initialized_(false) {
@@ -52,10 +49,12 @@
if (list->empty())
return std::vector<base::string16>();
+ ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
std::vector<base::string16> return_value;
for (ExtensionIdList::const_iterator it = list->begin();
it != list->end(); ++it) {
- const Extension* extension = service_->GetInstalledExtension(*it);
+ const Extension* extension =
+ registry->GetExtensionById(*it, ExtensionRegistry::EVERYTHING);
if (extension) {
return_value.push_back(base::UTF8ToUTF16(extension->name()));
} else {
@@ -132,12 +131,9 @@
}
ExtensionIdList* ExtensionMessageBubbleController::GetOrCreateExtensionList() {
- if (!service_)
- return &extension_list_; // Can occur during testing.
-
if (!initialized_) {
scoped_ptr<const ExtensionSet> extension_set(
- service_->GenerateInstalledExtensionsSet());
+ ExtensionRegistry::Get(profile_)->GenerateInstalledExtensionsSet());
for (ExtensionSet::const_iterator it = extension_set->begin();
it != extension_set->end(); ++it) {
std::string id = (*it)->id();
diff --git a/chrome/browser/extensions/extension_message_bubble_controller.h b/chrome/browser/extensions/extension_message_bubble_controller.h
index f32b3d4..bbadca1 100644
--- a/chrome/browser/extensions/extension_message_bubble_controller.h
+++ b/chrome/browser/extensions/extension_message_bubble_controller.h
@@ -11,7 +11,6 @@
#include "extensions/common/extension.h"
class Browser;
-class ExtensionService;
class Profile;
namespace extensions {
@@ -84,9 +83,6 @@
// Get the data this class needs.
ExtensionIdList* GetOrCreateExtensionList();
- // Our extension service. Weak, not owned by us.
- ExtensionService* service_;
-
// A weak pointer to the profile we are associated with. Not owned by us.
Profile* profile_;
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 24b52911..8efd376 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -446,16 +446,6 @@
return &delayed_installs_;
}
-scoped_ptr<ExtensionSet>
- ExtensionService::GenerateInstalledExtensionsSet() const {
- scoped_ptr<ExtensionSet> installed_extensions(new ExtensionSet());
- installed_extensions->InsertAll(registry_->enabled_extensions());
- installed_extensions->InsertAll(registry_->disabled_extensions());
- installed_extensions->InsertAll(registry_->terminated_extensions());
- installed_extensions->InsertAll(registry_->blacklisted_extensions());
- return installed_extensions.Pass();
-}
-
extensions::PendingExtensionManager*
ExtensionService::pending_extension_manager() {
return &pending_extension_manager_;
@@ -585,7 +575,8 @@
}
void ExtensionService::LoadGreylistFromPrefs() {
- scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet();
+ scoped_ptr<ExtensionSet> all_extensions =
+ registry_->GenerateInstalledExtensionsSet();
for (ExtensionSet::const_iterator it = all_extensions->begin();
it != all_extensions->end(); ++it) {
@@ -606,7 +597,7 @@
do_bootstrap = true;
} else {
scoped_ptr<extensions::ExtensionSet> extensions =
- GenerateInstalledExtensionsSet();
+ registry_->GenerateInstalledExtensionsSet();
for (extensions::ExtensionSet::const_iterator i = extensions->begin();
i != extensions->end();
++i) {
@@ -625,7 +616,8 @@
void ExtensionService::VerifyAllExtensions(bool bootstrap) {
ExtensionIdSet to_add;
- scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet();
+ scoped_ptr<ExtensionSet> all_extensions =
+ registry_->GenerateInstalledExtensionsSet();
for (ExtensionSet::const_iterator i = all_extensions->begin();
i != all_extensions->end(); ++i) {
@@ -2701,7 +2693,7 @@
void ExtensionService::OnBlacklistUpdated() {
blacklist_->GetBlacklistedIDs(
- GenerateInstalledExtensionsSet()->GetIDs(),
+ registry_->GenerateInstalledExtensionsSet()->GetIDs(),
base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
}
diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h
index b908448..2606fca 100644
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -168,10 +168,6 @@
const extensions::ExtensionSet* delayed_installs() const;
- // Returns a set of all installed, disabled, blacklisted, and terminated
- // extensions.
- scoped_ptr<extensions::ExtensionSet> GenerateInstalledExtensionsSet() const;
-
// Gets the object managing the set of pending extensions.
virtual extensions::PendingExtensionManager*
pending_extension_manager() OVERRIDE;
diff --git a/chrome/browser/metrics/extension_metrics.cc b/chrome/browser/metrics/extension_metrics.cc
index 89ef66d..65424d47 100644
--- a/chrome/browser/metrics/extension_metrics.cc
+++ b/chrome/browser/metrics/extension_metrics.cc
@@ -10,9 +10,9 @@
#include "base/memory/scoped_ptr.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/metrics/proto/system_profile.pb.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension_set.h"
// From third_party/smhasher/src/City.h; that file can't be included here due
@@ -77,9 +77,8 @@
// profiles.
Profile* profile = GetMetricsProfile();
if (profile) {
- ExtensionService* service = profile->GetExtensionService();
- if (service)
- return service->GenerateInstalledExtensionsSet();
+ return extensions::ExtensionRegistry::Get(profile)
+ ->GenerateInstalledExtensionsSet();
}
#endif // defined(ENABLE_EXTENSIONS)
return scoped_ptr<extensions::ExtensionSet>();
diff --git a/chrome/browser/sync/test/integration/sync_app_helper.cc b/chrome/browser/sync/test/integration/sync_app_helper.cc
index 6c3a48e..17578af 100644
--- a/chrome/browser/sync/test/integration/sync_app_helper.cc
+++ b/chrome/browser/sync/test/integration/sync_app_helper.cc
@@ -14,6 +14,7 @@
#include "chrome/common/extensions/sync_helper.h"
#include "extensions/browser/app_sorting.h"
#include "extensions/browser/extension_prefs.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
@@ -64,10 +65,9 @@
AppStateMap GetAppStates(Profile* profile) {
AppStateMap app_state_map;
- ExtensionService* extension_service = profile->GetExtensionService();
-
scoped_ptr<const extensions::ExtensionSet> extensions(
- extension_service->GenerateInstalledExtensionsSet());
+ extensions::ExtensionRegistry::Get(profile)
+ ->GenerateInstalledExtensionsSet());
for (extensions::ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
if (extensions::sync_helper::IsSyncableApp(it->get())) {
@@ -77,7 +77,9 @@
}
const extensions::PendingExtensionManager* pending_extension_manager =
- extension_service->pending_extension_manager();
+ extensions::ExtensionSystem::Get(profile)
+ ->extension_service()
+ ->pending_extension_manager();
std::list<std::string> pending_crx_ids;
pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_crx_ids);
diff --git a/chrome/browser/sync/test/integration/sync_extension_helper.cc b/chrome/browser/sync/test/integration/sync_extension_helper.cc
index 6e093779..467b3f5 100644
--- a/chrome/browser/sync/test/integration/sync_extension_helper.cc
+++ b/chrome/browser/sync/test/integration/sync_extension_helper.cc
@@ -69,7 +69,8 @@
NOTREACHED() << "Could not install extension " << name;
return std::string();
}
- profile->GetExtensionService()
+ extensions::ExtensionSystem::Get(profile)
+ ->extension_service()
->OnExtensionInstalled(extension.get(),
syncer::StringOrdinal(),
false /* no requirement errors */,
@@ -81,17 +82,17 @@
void SyncExtensionHelper::UninstallExtension(
Profile* profile, const std::string& name) {
ExtensionService::UninstallExtensionHelper(
- profile->GetExtensionService(),
+ extensions::ExtensionSystem::Get(profile)->extension_service(),
extensions::id_util::GenerateId(name));
}
std::vector<std::string> SyncExtensionHelper::GetInstalledExtensionNames(
Profile* profile) const {
std::vector<std::string> names;
- ExtensionService* extension_service = profile->GetExtensionService();
scoped_ptr<const extensions::ExtensionSet> extensions(
- extension_service->GenerateInstalledExtensionsSet());
+ extensions::ExtensionRegistry::Get(profile)
+ ->GenerateInstalledExtensionsSet());
for (extensions::ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
names.push_back((*it)->name());
@@ -102,20 +103,24 @@
void SyncExtensionHelper::EnableExtension(Profile* profile,
const std::string& name) {
- profile->GetExtensionService()->EnableExtension(
- extensions::id_util::GenerateId(name));
+ extensions::ExtensionSystem::Get(profile)
+ ->extension_service()
+ ->EnableExtension(extensions::id_util::GenerateId(name));
}
void SyncExtensionHelper::DisableExtension(Profile* profile,
const std::string& name) {
- profile->GetExtensionService()->DisableExtension(
- extensions::id_util::GenerateId(name), Extension::DISABLE_USER_ACTION);
+ extensions::ExtensionSystem::Get(profile)
+ ->extension_service()
+ ->DisableExtension(extensions::id_util::GenerateId(name),
+ Extension::DISABLE_USER_ACTION);
}
bool SyncExtensionHelper::IsExtensionEnabled(
Profile* profile, const std::string& name) const {
- return profile->GetExtensionService()->IsExtensionEnabled(
- extensions::id_util::GenerateId(name));
+ return extensions::ExtensionSystem::Get(profile)
+ ->extension_service()
+ ->IsExtensionEnabled(extensions::id_util::GenerateId(name));
}
void SyncExtensionHelper::IncognitoEnableExtension(
@@ -140,7 +145,9 @@
bool SyncExtensionHelper::IsExtensionPendingInstallForSync(
Profile* profile, const std::string& id) const {
const extensions::PendingExtensionManager* pending_extension_manager =
- profile->GetExtensionService()->pending_extension_manager();
+ extensions::ExtensionSystem::Get(profile)
+ ->extension_service()
+ ->pending_extension_manager();
const extensions::PendingExtensionInfo* info =
pending_extension_manager->GetById(id);
if (!info)
@@ -156,7 +163,9 @@
// We make a copy here since InstallExtension() removes the
// extension from the extensions service's copy.
const extensions::PendingExtensionManager* pending_extension_manager =
- profile->GetExtensionService()->pending_extension_manager();
+ extensions::ExtensionSystem::Get(profile)
+ ->extension_service()
+ ->pending_extension_manager();
std::list<std::string> pending_crx_ids;
pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_crx_ids);
@@ -189,10 +198,12 @@
ExtensionStateMap extension_state_map;
- ExtensionService* extension_service = profile->GetExtensionService();
-
scoped_ptr<const extensions::ExtensionSet> extensions(
- extension_service->GenerateInstalledExtensionsSet());
+ extensions::ExtensionRegistry::Get(profile)
+ ->GenerateInstalledExtensionsSet());
+
+ ExtensionService* extension_service =
+ extensions::ExtensionSystem::Get(profile)->extension_service();
for (extensions::ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
const std::string& id = (*it)->id();
@@ -363,8 +374,11 @@
}
scoped_refptr<Extension> extension =
- CreateExtension(profile->GetExtensionService()->install_directory(),
- name, type);
+ CreateExtension(extensions::ExtensionSystem::Get(profile)
+ ->extension_service()
+ ->install_directory(),
+ name,
+ type);
if (!extension.get()) {
ADD_FAILURE();
return NULL;
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc
index f4278d3..91c7cdbb 100644
--- a/chrome/browser/themes/theme_service.cc
+++ b/chrome/browser/themes/theme_service.cc
@@ -24,6 +24,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/user_metrics.h"
#include "extensions/browser/extension_prefs.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
@@ -336,13 +337,16 @@
if (!ignore_infobars && number_of_infobars_ != 0)
return;
- ExtensionService* service = profile_->GetExtensionService();
+ ExtensionService* service =
+ extensions::ExtensionSystem::Get(profile_)->extension_service();
if (!service)
return;
+
std::string current_theme = GetThemeID();
std::vector<std::string> remove_list;
scoped_ptr<const extensions::ExtensionSet> extensions(
- service->GenerateInstalledExtensionsSet());
+ extensions::ExtensionRegistry::Get(profile_)
+ ->GenerateInstalledExtensionsSet());
extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
for (extensions::ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
diff --git a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc
index b016ec9..07ae093b 100644
--- a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc
+++ b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc
@@ -57,6 +57,7 @@
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension_set.h"
#include "grit/generated_resources.h"
@@ -865,7 +866,8 @@
ExtensionService* extension_service = extension_system->extension_service();
if (extension_service) {
scoped_ptr<const extensions::ExtensionSet> extensions(
- extension_service->GenerateInstalledExtensionsSet());
+ extensions::ExtensionRegistry::Get(profile)
+ ->GenerateInstalledExtensionsSet());
for (extensions::ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
base::DictionaryValue* extension_info = new base::DictionaryValue();
diff --git a/extensions/browser/extension_registry.cc b/extensions/browser/extension_registry.cc
index 5c4cf5d..1d64ced9 100644
--- a/extensions/browser/extension_registry.cc
+++ b/extensions/browser/extension_registry.cc
@@ -18,6 +18,16 @@
return ExtensionRegistryFactory::GetForBrowserContext(context);
}
+scoped_ptr<ExtensionSet> ExtensionRegistry::GenerateInstalledExtensionsSet()
+ const {
+ scoped_ptr<ExtensionSet> installed_extensions(new ExtensionSet);
+ installed_extensions->InsertAll(enabled_extensions_);
+ installed_extensions->InsertAll(disabled_extensions_);
+ installed_extensions->InsertAll(terminated_extensions_);
+ installed_extensions->InsertAll(blacklisted_extensions_);
+ return installed_extensions.Pass();
+}
+
void ExtensionRegistry::AddObserver(ExtensionRegistryObserver* observer) {
observers_.AddObserver(observer);
}
diff --git a/extensions/browser/extension_registry.h b/extensions/browser/extension_registry.h
index ec15f2ec..9f2fae3 100644
--- a/extensions/browser/extension_registry.h
+++ b/extensions/browser/extension_registry.h
@@ -57,6 +57,10 @@
return blacklisted_extensions_;
}
+ // Returns a set of all installed, disabled, blacklisted, and terminated
+ // extensions.
+ scoped_ptr<ExtensionSet> GenerateInstalledExtensionsSet() const;
+
// The usual observer interface.
void AddObserver(ExtensionRegistryObserver* observer);
void RemoveObserver(ExtensionRegistryObserver* observer);