summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-06 18:22:46 +0000
committeryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-06 18:22:46 +0000
commit84df8330d252faf3ac552ba40364d973ee19af81 (patch)
tree98a7f3fee4d8226e41a8e80628bd8c906b69414b /chrome
parent8a0941d2abb68b9626ac17cb5d1e4d9ecaa6303a (diff)
downloadchromium_src-84df8330d252faf3ac552ba40364d973ee19af81.zip
chromium_src-84df8330d252faf3ac552ba40364d973ee19af81.tar.gz
chromium_src-84df8330d252faf3ac552ba40364d973ee19af81.tar.bz2
Revert 113071 - Revert 113047 - Make ExtensionService use ExtensionSet.
ExtensionManagementApiBrowserTest.LaunchApp fixed by r113141. Make ExtensionSet iterate like a set instead of a map. BUG=104091 TEST=existing tests Review URL: http://codereview.chromium.org/8733004 TBR=yoz@chromium.org Review URL: http://codereview.chromium.org/8789018 TBR=yoz@chromium.org Review URL: http://codereview.chromium.org/8822021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113233 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/extension_app_provider.cc4
-rw-r--r--chrome/browser/automation/automation_provider_observers.cc10
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc4
-rw-r--r--chrome/browser/background/background_application_list_model.cc6
-rw-r--r--chrome/browser/background/background_application_list_model_unittest.cc13
-rw-r--r--chrome/browser/background/background_contents_service.cc4
-rw-r--r--chrome/browser/debugger/devtools_window.cc4
-rw-r--r--chrome/browser/extensions/browser_action_apitest.cc27
-rw-r--r--chrome/browser/extensions/component_loader_unittest.cc26
-rw-r--r--chrome/browser/extensions/extension_apitest.cc15
-rw-r--r--chrome/browser/extensions/extension_browsertest.cc13
-rw-r--r--chrome/browser/extensions/extension_browsertests_misc.cc158
-rw-r--r--chrome/browser/extensions/extension_context_menu_browsertest.cc4
-rw-r--r--chrome/browser/extensions/extension_crash_recovery_browsertest.cc117
-rw-r--r--chrome/browser/extensions/extension_file_browser_private_api.cc4
-rw-r--r--chrome/browser/extensions/extension_info_map.cc8
-rw-r--r--chrome/browser/extensions/extension_management_api.cc4
-rw-r--r--chrome/browser/extensions/extension_management_browsertest.cc12
-rw-r--r--chrome/browser/extensions/extension_override_apitest.cc16
-rw-r--r--chrome/browser/extensions/extension_preference_api.cc4
-rw-r--r--chrome/browser/extensions/extension_process_manager.cc4
-rw-r--r--chrome/browser/extensions/extension_service.cc171
-rw-r--r--chrome/browser/extensions/extension_service.h20
-rw-r--r--chrome/browser/extensions/extension_service_unittest.cc16
-rw-r--r--chrome/browser/extensions/extension_startup_browsertest.cc31
-rw-r--r--chrome/browser/extensions/extension_tab_helper.cc9
-rw-r--r--chrome/browser/extensions/extension_toolbar_model.cc5
-rw-r--r--chrome/browser/extensions/extension_tts_engine_api.cc8
-rw-r--r--chrome/browser/extensions/extension_updater.cc4
-rw-r--r--chrome/browser/extensions/extension_updater_unittest.cc17
-rw-r--r--chrome/browser/extensions/extension_webrequest_api.cc4
-rw-r--r--chrome/browser/extensions/installed_loader.cc6
-rw-r--r--chrome/browser/extensions/network_delay_listener_unittest.cc13
-rw-r--r--chrome/browser/extensions/test_extension_service.cc2
-rw-r--r--chrome/browser/extensions/test_extension_service.h2
-rw-r--r--chrome/browser/extensions/unpacked_installer.cc7
-rw-r--r--chrome/browser/extensions/user_script_listener.cc2
-rw-r--r--chrome/browser/extensions/user_script_listener_unittest.cc4
-rw-r--r--chrome/browser/intents/web_intents_registry.cc4
-rw-r--r--chrome/browser/intents/web_intents_registry_unittest.cc60
-rw-r--r--chrome/browser/sync/test/integration/sync_extension_helper.cc20
-rw-r--r--chrome/browser/themes/theme_service.cc4
-rw-r--r--chrome/browser/ui/browser_browsertest.cc9
-rw-r--r--chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm8
-rw-r--r--chrome/browser/ui/gtk/location_bar_view_gtk.cc7
-rw-r--r--chrome/browser/ui/views/browser_actions_container_browsertest.cc13
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.cc7
-rw-r--r--chrome/browser/ui/webui/ntp/app_launcher_handler.cc13
-rw-r--r--chrome/browser/ui/webui/options/extension_settings_handler.cc8
-rw-r--r--chrome/browser/ui/webui/options/search_engine_manager_handler.cc4
-rw-r--r--chrome/common/extensions/extension_set.cc10
-rw-r--r--chrome/common/extensions/extension_set.h37
-rw-r--r--chrome/renderer/extensions/extension_dispatcher.cc2
53 files changed, 499 insertions, 485 deletions
diff --git a/chrome/browser/autocomplete/extension_app_provider.cc b/chrome/browser/autocomplete/extension_app_provider.cc
index b3ceac1..8365cb1 100644
--- a/chrome/browser/autocomplete/extension_app_provider.cc
+++ b/chrome/browser/autocomplete/extension_app_provider.cc
@@ -98,9 +98,9 @@ void ExtensionAppProvider::RefreshAppList() {
ExtensionService* extension_service = profile_->GetExtensionService();
if (!extension_service)
return; // During testing, there is no extension service.
- const ExtensionList* extensions = extension_service->extensions();
+ const ExtensionSet* extensions = extension_service->extensions();
extension_apps_.clear();
- for (ExtensionList::const_iterator app = extensions->begin();
+ for (ExtensionSet::const_iterator app = extensions->begin();
app != extensions->end(); ++app) {
if ((*app)->is_app() && (*app)->GetFullLaunchURL().is_valid()) {
if (profile_->IsOffTheRecord() &&
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index a2decb9..670d01e 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -2018,11 +2018,11 @@ namespace {
// as identified from a given list of extensions. The caller takes ownership
// of the created vector.
std::vector<DictionaryValue*>* GetAppInfoFromExtensions(
- const ExtensionList* extensions,
+ const ExtensionSet* extensions,
ExtensionService* ext_service) {
std::vector<DictionaryValue*>* apps_list =
new std::vector<DictionaryValue*>();
- for (ExtensionList::const_iterator ext = extensions->begin();
+ for (ExtensionSet::const_iterator ext = extensions->begin();
ext != extensions->end(); ++ext) {
// Only return information about extensions that are actually apps.
if ((*ext)->is_app()) {
@@ -2090,7 +2090,7 @@ NTPInfoObserver::NTPInfoObserver(
}
// Process enabled extensions.
ListValue* apps_list = new ListValue();
- const ExtensionList* extensions = ext_service->extensions();
+ const ExtensionSet* extensions = ext_service->extensions();
std::vector<DictionaryValue*>* enabled_apps = GetAppInfoFromExtensions(
extensions, ext_service);
for (std::vector<DictionaryValue*>::const_iterator app =
@@ -2100,7 +2100,7 @@ NTPInfoObserver::NTPInfoObserver(
}
delete enabled_apps;
// Process disabled extensions.
- const ExtensionList* disabled_extensions = ext_service->disabled_extensions();
+ const ExtensionSet* disabled_extensions = ext_service->disabled_extensions();
std::vector<DictionaryValue*>* disabled_apps = GetAppInfoFromExtensions(
disabled_extensions, ext_service);
for (std::vector<DictionaryValue*>::const_iterator app =
@@ -2110,7 +2110,7 @@ NTPInfoObserver::NTPInfoObserver(
}
delete disabled_apps;
// Process terminated extensions.
- const ExtensionList* terminated_extensions =
+ const ExtensionSet* terminated_extensions =
ext_service->terminated_extensions();
std::vector<DictionaryValue*>* terminated_apps = GetAppInfoFromExtensions(
terminated_extensions, ext_service);
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 3230157..498c512 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -4381,8 +4381,8 @@ void TestingAutomationProvider::GetExtensionsInfo(
}
scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
ListValue* extensions_values = new ListValue;
- const ExtensionList* extensions = service->extensions();
- const ExtensionList* disabled_extensions = service->disabled_extensions();
+ const ExtensionSet* extensions = service->extensions();
+ const ExtensionSet* disabled_extensions = service->disabled_extensions();
ExtensionList all;
all.insert(all.end(),
extensions->begin(),
diff --git a/chrome/browser/background/background_application_list_model.cc b/chrome/browser/background/background_application_list_model.cc
index 6550ba2..d7d4740 100644
--- a/chrome/browser/background/background_application_list_model.cc
+++ b/chrome/browser/background/background_application_list_model.cc
@@ -71,9 +71,9 @@ class BackgroundApplicationListModel::Application
namespace {
void GetServiceApplications(ExtensionService* service,
ExtensionList* applications_result) {
- const ExtensionList* extensions = service->extensions();
+ const ExtensionSet* extensions = service->extensions();
- for (ExtensionList::const_iterator cursor = extensions->begin();
+ for (ExtensionSet::const_iterator cursor = extensions->begin();
cursor != extensions->end();
++cursor) {
const Extension* extension = *cursor;
@@ -84,7 +84,7 @@ void GetServiceApplications(ExtensionService* service,
// Walk the list of terminated extensions also (just because an extension
// crashed doesn't mean we should ignore it).
extensions = service->terminated_extensions();
- for (ExtensionList::const_iterator cursor = extensions->begin();
+ for (ExtensionSet::const_iterator cursor = extensions->begin();
cursor != extensions->end();
++cursor) {
const Extension* extension = *cursor;
diff --git a/chrome/browser/background/background_application_list_model_unittest.cc b/chrome/browser/background/background_application_list_model_unittest.cc
index f3fff07..4024fad 100644
--- a/chrome/browser/background/background_application_list_model_unittest.cc
+++ b/chrome/browser/background/background_application_list_model_unittest.cc
@@ -60,8 +60,11 @@ static scoped_refptr<Extension> CreateExtension(const std::string& name,
}
std::string error;
scoped_refptr<Extension> extension = Extension::Create(
- bogus_file_path().AppendASCII(name), Extension::INVALID, manifest,
- Extension::STRICT_ERROR_CHECKS, &error);
+ bogus_file_path().AppendASCII(name),
+ Extension::INVALID,
+ manifest,
+ Extension::STRICT_ERROR_CHECKS,
+ &error);
// Cannot ASSERT_* here because that attempts an illegitimate return.
// Cannot EXPECT_NE here because that assumes non-pointers unlike EXPECT_EQ
EXPECT_TRUE(extension.get() != NULL) << error;
@@ -105,7 +108,7 @@ TEST_F(BackgroundApplicationListModelTest, ExplicitTest) {
ASSERT_TRUE(service);
ASSERT_TRUE(service->is_ready());
ASSERT_TRUE(service->extensions());
- ASSERT_TRUE(service->extensions()->empty());
+ ASSERT_TRUE(service->extensions()->is_empty());
scoped_ptr<BackgroundApplicationListModel> model(
new BackgroundApplicationListModel(profile_.get()));
ASSERT_EQ(0U, model->size());
@@ -171,7 +174,7 @@ TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) {
ASSERT_TRUE(service);
ASSERT_TRUE(service->is_ready());
ASSERT_TRUE(service->extensions());
- ASSERT_TRUE(service->extensions()->empty());
+ ASSERT_TRUE(service->extensions()->is_empty());
scoped_ptr<BackgroundApplicationListModel> model(
new BackgroundApplicationListModel(profile_.get()));
ASSERT_EQ(0U, model->size());
@@ -310,7 +313,7 @@ TEST_F(BackgroundApplicationListModelTest, RandomTest) {
ASSERT_TRUE(service);
ASSERT_TRUE(service->is_ready());
ASSERT_TRUE(service->extensions());
- ASSERT_TRUE(service->extensions()->empty());
+ ASSERT_TRUE(service->extensions()->is_empty());
scoped_ptr<BackgroundApplicationListModel> model(
new BackgroundApplicationListModel(profile_.get()));
ASSERT_EQ(0U, model->size());
diff --git a/chrome/browser/background/background_contents_service.cc b/chrome/browser/background/background_contents_service.cc
index 1bc42a5..16f7bf7 100644
--- a/chrome/browser/background/background_contents_service.cc
+++ b/chrome/browser/background/background_contents_service.cc
@@ -418,9 +418,9 @@ void BackgroundContentsService::LoadBackgroundContentsFromDictionary(
void BackgroundContentsService::LoadBackgroundContentsFromManifests(
Profile* profile) {
- const ExtensionList* extensions =
+ const ExtensionSet* extensions =
profile->GetExtensionService()->extensions();
- ExtensionList::const_iterator iter = extensions->begin();
+ ExtensionSet::const_iterator iter = extensions->begin();
for (; iter != extensions->end(); ++iter) {
const Extension* extension = *iter;
if (extension->is_hosted_app() &&
diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc
index 9d1dd6b..2a1fb5e 100644
--- a/chrome/browser/debugger/devtools_window.cc
+++ b/chrome/browser/debugger/devtools_window.cc
@@ -414,9 +414,9 @@ void DevToolsWindow::AddDevToolsExtensionsToClient() {
if (!extension_service)
return;
- const ExtensionList* extensions = extension_service->extensions();
+ const ExtensionSet* extensions = extension_service->extensions();
- for (ExtensionList::const_iterator extension = extensions->begin();
+ for (ExtensionSet::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
if ((*extension)->devtools_url().is_empty())
continue;
diff --git a/chrome/browser/extensions/browser_action_apitest.cc b/chrome/browser/extensions/browser_action_apitest.cc
index 943eaa7..08e65fd 100644
--- a/chrome/browser/extensions/browser_action_apitest.cc
+++ b/chrome/browser/extensions/browser_action_apitest.cc
@@ -316,12 +316,15 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoDragging) {
const size_t size_before = service->extensions()->size();
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
- "browser_action/basics")));
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
- "browser_action/popup")));
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(
- "browser_action/add_popup")));
+ const Extension* extension_a = LoadExtension(test_data_dir_.AppendASCII(
+ "browser_action/basics"));
+ const Extension* extension_b = LoadExtension(test_data_dir_.AppendASCII(
+ "browser_action/popup"));
+ const Extension* extension_c = LoadExtension(test_data_dir_.AppendASCII(
+ "browser_action/add_popup"));
+ ASSERT_TRUE(extension_a);
+ ASSERT_TRUE(extension_b);
+ ASSERT_TRUE(extension_c);
// Test that there are 3 browser actions in the toolbar.
ASSERT_EQ(size_before + 3, service->extensions()->size());
@@ -329,10 +332,8 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoDragging) {
// Now enable 2 of the extensions in incognito mode, and test that the browser
// actions show up.
- service->extension_prefs()->SetIsIncognitoEnabled(
- service->extensions()->at(size_before)->id(), true);
- service->extension_prefs()->SetIsIncognitoEnabled(
- service->extensions()->at(size_before + 2)->id(), true);
+ service->extension_prefs()->SetIsIncognitoEnabled(extension_a->id(), true);
+ service->extension_prefs()->SetIsIncognitoEnabled(extension_c->id(), true);
Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
Browser* incognito_browser = Browser::Create(incognito_profile);
@@ -355,8 +356,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoDragging) {
// regular and incognito mode.
// ABC -> CAB
- service->toolbar_model()->MoveBrowserAction(
- service->extensions()->at(size_before + 2), 0);
+ service->toolbar_model()->MoveBrowserAction(extension_c, 0);
EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0));
EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(1));
@@ -366,8 +366,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoDragging) {
EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1));
// CAB -> CBA
- service->toolbar_model()->MoveBrowserAction(
- service->extensions()->at(size_before + 1), 1);
+ service->toolbar_model()->MoveBrowserAction(extension_b, 1);
EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0));
EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(1));
diff --git a/chrome/browser/extensions/component_loader_unittest.cc b/chrome/browser/extensions/component_loader_unittest.cc
index 3e3d8c8..89f4762 100644
--- a/chrome/browser/extensions/component_loader_unittest.cc
+++ b/chrome/browser/extensions/component_loader_unittest.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/extensions/test_extension_service.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/extension_set.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -20,7 +21,7 @@ namespace {
class MockExtensionService : public TestExtensionService {
private:
bool ready_;
- ExtensionList extension_list_;
+ ExtensionSet extension_set_;
public:
MockExtensionService() : ready_(false) {
@@ -28,37 +29,30 @@ class MockExtensionService : public TestExtensionService {
virtual void AddExtension(const Extension* extension) OVERRIDE {
// ExtensionService must become the owner of the extension object.
- extension_list_.push_back(extension);
+ extension_set_.Insert(extension);
}
virtual void UnloadExtension(
const std::string& extension_id,
extension_misc::UnloadedExtensionReason reason) OVERRIDE {
// Remove the extension with the matching id.
- for (ExtensionList::iterator it = extension_list_.begin();
- it != extension_list_.end();
- ++it) {
- if ((*it)->id() == extension_id) {
- extension_list_.erase(it);
- return;
- }
- }
+ extension_set_.Remove(extension_id);
}
virtual bool is_ready() OVERRIDE {
return ready_;
}
- virtual const ExtensionList* extensions() const OVERRIDE {
- return &extension_list_;
+ virtual const ExtensionSet* extensions() const OVERRIDE {
+ return &extension_set_;
}
void set_ready(bool ready) {
ready_ = ready;
}
- void clear_extension_list() {
- extension_list_.clear();
+ void clear_extensions() {
+ extension_set_.Clear();
}
};
@@ -217,7 +211,7 @@ TEST_F(ComponentLoaderTest, LoadAll) {
unsigned int default_count = extension_service_.extensions()->size();
// Clear the list of loaded extensions, and reload with one more.
- extension_service_.clear_extension_list();
+ extension_service_.clear_extensions();
component_loader_.Add(manifest_contents_, extension_path_);
component_loader_.LoadAll();
@@ -237,7 +231,7 @@ TEST_F(ComponentLoaderTest, EnterpriseWebStore) {
// Now that the pref is set, check if it's added by default.
extension_service_.set_ready(false);
- extension_service_.clear_extension_list();
+ extension_service_.clear_extensions();
component_loader_.ClearAllRegistered();
component_loader_.AddDefaultComponentExtensions();
component_loader_.LoadAll();
diff --git a/chrome/browser/extensions/extension_apitest.cc b/chrome/browser/extensions/extension_apitest.cc
index 893a25d..624f036 100644
--- a/chrome/browser/extensions/extension_apitest.cc
+++ b/chrome/browser/extensions/extension_apitest.cc
@@ -202,28 +202,29 @@ bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name,
}
}
-// Test that exactly one extension loaded.
+// Test that exactly one extension is loaded, and return it.
const Extension* ExtensionApiTest::GetSingleLoadedExtension() {
ExtensionService* service = browser()->profile()->GetExtensionService();
- int found_extension_index = -1;
- for (size_t i = 0; i < service->extensions()->size(); ++i) {
+ const Extension* extension = NULL;
+ for (ExtensionSet::const_iterator it = service->extensions()->begin();
+ it != service->extensions()->end(); ++it) {
// Ignore any component extensions. They are automatically loaded into all
// profiles and aren't the extension we're looking for here.
- if (service->extensions()->at(i)->location() == Extension::COMPONENT)
+ if ((*it)->location() == Extension::COMPONENT)
continue;
- if (found_extension_index != -1) {
+ if (extension != NULL) {
+ // TODO(yoz): this is misleading; it counts component extensions.
message_ = base::StringPrintf(
"Expected only one extension to be present. Found %u.",
static_cast<unsigned>(service->extensions()->size()));
return NULL;
}
- found_extension_index = static_cast<int>(i);
+ extension = *it;
}
- const Extension* extension = service->extensions()->at(found_extension_index);
if (!extension) {
message_ = "extension pointer is NULL.";
return NULL;
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc
index b3f3d1b..339a28c 100644
--- a/chrome/browser/extensions/extension_browsertest.cc
+++ b/chrome/browser/extensions/extension_browsertest.cc
@@ -72,13 +72,13 @@ const Extension* ExtensionBrowserTest::LoadExtensionWithOptions(
ui_test_utils::RunMessageLoop();
}
- // Find the extension by iterating backwards since it is likely last.
+ // Find the loaded extension by its path. See crbug.com/59531 for why
+ // we cannot just use last_loaded_extension_id_.
FilePath extension_path = path;
file_util::AbsolutePath(&extension_path);
const Extension* extension = NULL;
- for (ExtensionList::const_reverse_iterator iter =
- service->extensions()->rbegin();
- iter != service->extensions()->rend(); ++iter) {
+ for (ExtensionSet::const_iterator iter = service->extensions()->begin();
+ iter != service->extensions()->end(); ++iter) {
if ((*iter)->path() == extension_path) {
extension = *iter;
break;
@@ -296,8 +296,9 @@ const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
<< " num after: " << base::IntToString(num_after)
<< " Installed extensions follow:";
- for (size_t i = 0; i < service->extensions()->size(); ++i)
- VLOG(1) << " " << (*service->extensions())[i]->id();
+ for (ExtensionSet::const_iterator it = service->extensions()->begin();
+ it != service->extensions()->end(); ++it)
+ VLOG(1) << " " << (*it)->id();
VLOG(1) << "Errors follow:";
const std::vector<std::string>* errors =
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc
index 5d843aa..86e3da7 100644
--- a/chrome/browser/extensions/extension_browsertests_misc.cc
+++ b/chrome/browser/extensions/extension_browsertests_misc.cc
@@ -212,29 +212,30 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionRefreshCrash) {
FilePath base_path = test_data_dir_.AppendASCII("browsertest")
.AppendASCII("crash_44415");
// Load extension A.
- ASSERT_TRUE(LoadExtension(base_path.AppendASCII("ExtA")));
+ const Extension* extensionA = LoadExtension(base_path.AppendASCII("ExtA"));
+ ASSERT_TRUE(extensionA);
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
ASSERT_EQ(size_before + 1, service->extensions()->size());
- const Extension* extensionA = service->extensions()->at(size_before);
LOG(INFO) << "Load extension A done : "
<< (base::TimeTicks::Now() - start_time).InMilliseconds()
<< " ms" << std::flush;
// Load extension B.
- ASSERT_TRUE(LoadExtension(base_path.AppendASCII("ExtB")));
+ const Extension* extensionB = LoadExtension(base_path.AppendASCII("ExtB"));
+ ASSERT_TRUE(extensionB);
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(2));
ASSERT_EQ(size_before + 2, service->extensions()->size());
- const Extension* extensionB = service->extensions()->at(size_before + 1);
LOG(INFO) << "Load extension B done : "
<< (base::TimeTicks::Now() - start_time).InMilliseconds()
<< " ms" << std::flush;
+ std::string idA = extensionA->id();
ReloadExtension(extensionA->id());
// ExtensionA has changed, so refetch it.
ASSERT_EQ(size_before + 2, service->extensions()->size());
- extensionA = service->extensions()->at(size_before + 1);
+ extensionA = service->extensions()->GetByID(idA);
LOG(INFO) << "Reload extension A done: "
<< (base::TimeTicks::Now() - start_time).InMilliseconds()
@@ -278,10 +279,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationBrowserAction) {
const size_t size_before = service->extensions()->size();
FilePath extension_path(test_data_dir_.AppendASCII("browsertest")
.AppendASCII("title_localized"));
- ASSERT_TRUE(LoadExtension(extension_path));
+ const Extension* extension = LoadExtension(extension_path);
+ ASSERT_TRUE(extension);
ASSERT_EQ(size_before + 1, service->extensions()->size());
- const Extension* extension = service->extensions()->at(size_before);
EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur: l10n browser action").c_str(),
extension->description().c_str());
@@ -302,7 +303,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) {
FilePath extension_path(test_data_dir_.AppendASCII("browsertest")
.AppendASCII("title_localized_pa"));
- ASSERT_TRUE(LoadExtension(extension_path));
+ const Extension* extension = LoadExtension(extension_path);
+ ASSERT_TRUE(extension);
// Any navigation prompts the location bar to load the page action.
GURL url = test_server()->GetURL(kLocalization);
@@ -310,7 +312,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) {
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
ASSERT_EQ(size_before + 1, service->extensions()->size());
- const Extension* extension = service->extensions()->at(size_before);
EXPECT_STREQ(WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(),
extension->description().c_str());
@@ -387,6 +388,7 @@ bool ValidatePageElement(TabContents* tab,
void NavigateToFeedAndValidate(net::TestServer* server,
const std::string& url,
Browser* browser,
+ std::string extension_id,
bool sniff_xml_type,
const std::string& expected_feed_title,
const std::string& expected_item_title,
@@ -396,12 +398,9 @@ void NavigateToFeedAndValidate(net::TestServer* server,
// TODO(finnur): Implement this is a non-flaky way.
}
- ExtensionService* service = browser->profile()->GetExtensionService();
- const Extension* extension = service->extensions()->back();
- std::string id = extension->id();
-
// Navigate to the subscribe page directly.
- ui_test_utils::NavigateToURL(browser, GetFeedUrl(server, url, true, id));
+ ui_test_utils::NavigateToURL(browser,
+ GetFeedUrl(server, url, true, extension_id));
TabContents* tab = browser->GetSelectedTabContents();
ASSERT_TRUE(ValidatePageElement(tab,
@@ -425,10 +424,12 @@ void NavigateToFeedAndValidate(net::TestServer* server,
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed1) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
- NavigateToFeedAndValidate(test_server(), kValidFeed1, browser(), true,
+ NavigateToFeedAndValidate(test_server(), kValidFeed1, browser(), id, true,
"Feed for MyFeedTitle",
"Title 1",
"Desc",
@@ -438,10 +439,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed1) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed2) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
- NavigateToFeedAndValidate(test_server(), kValidFeed2, browser(), true,
+ NavigateToFeedAndValidate(test_server(), kValidFeed2, browser(), id, true,
"Feed for MyFeed2",
"My item title1",
"This is a summary.",
@@ -451,10 +454,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed2) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed3) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
- NavigateToFeedAndValidate(test_server(), kValidFeed3, browser(), true,
+ NavigateToFeedAndValidate(test_server(), kValidFeed3, browser(), id, true,
"Feed for Google Code buglist rss feed",
"My dear title",
"My dear content",
@@ -464,10 +469,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed3) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed4) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
- NavigateToFeedAndValidate(test_server(), kValidFeed4, browser(), true,
+ NavigateToFeedAndValidate(test_server(), kValidFeed4, browser(), id, true,
"Feed for Title chars <script> %23 stop",
"Title chars %23 stop",
"My dear content %23 stop",
@@ -477,12 +484,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed4) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed0) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
// Try a feed with a link with an onclick handler (before r27440 this would
// trigger a NOTREACHED).
- NavigateToFeedAndValidate(test_server(), kValidFeed0, browser(), true,
+ NavigateToFeedAndValidate(test_server(), kValidFeed0, browser(), id, true,
"Feed for MyFeedTitle",
"Title 1",
"Desc VIDEO",
@@ -492,11 +501,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed0) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed5) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
// Feed with valid but mostly empty xml.
- NavigateToFeedAndValidate(test_server(), kValidFeed5, browser(), true,
+ NavigateToFeedAndValidate(test_server(), kValidFeed5, browser(), id, true,
"Feed for Unknown feed name",
"element 'anchor_0' not found",
"element 'desc_0' not found",
@@ -506,11 +517,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed5) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed6) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
// Feed that is technically invalid but still parseable.
- NavigateToFeedAndValidate(test_server(), kValidFeed6, browser(), true,
+ NavigateToFeedAndValidate(test_server(), kValidFeed6, browser(), id, true,
"Feed for MyFeedTitle",
"Title 1",
"Desc",
@@ -520,11 +533,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed6) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed1) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
// Try an empty feed.
- NavigateToFeedAndValidate(test_server(), kInvalidFeed1, browser(), false,
+ NavigateToFeedAndValidate(test_server(), kInvalidFeed1, browser(), id, false,
"Feed for Unknown feed name",
"element 'anchor_0' not found",
"element 'desc_0' not found",
@@ -534,11 +549,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed1) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed2) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
// Try a garbage feed.
- NavigateToFeedAndValidate(test_server(), kInvalidFeed2, browser(), false,
+ NavigateToFeedAndValidate(test_server(), kInvalidFeed2, browser(), id, false,
"Feed for Unknown feed name",
"element 'anchor_0' not found",
"element 'desc_0' not found",
@@ -548,11 +565,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed2) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed3) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
// Try a feed that doesn't exist.
- NavigateToFeedAndValidate(test_server(), "foo.xml", browser(), false,
+ NavigateToFeedAndValidate(test_server(), "foo.xml", browser(), id, false,
"Feed for Unknown feed name",
"element 'anchor_0' not found",
"element 'desc_0' not found",
@@ -562,8 +581,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed3) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed4) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
// subscribe.js shouldn't double-decode the URL passed in. Otherwise feed
// links such as http://search.twitter.com/search.atom?lang=en&q=%23chrome
@@ -572,25 +593,29 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed4) {
// uses an underscore instead of a hash, but the principle is the same. If
// we start erroneously double decoding again, the path (and the feed) will
// become valid resulting in a failure for this test.
- NavigateToFeedAndValidate(test_server(), kFeedTripleEncoded, browser(), true,
- "Feed for Unknown feed name",
- "element 'anchor_0' not found",
- "element 'desc_0' not found",
- "This feed contains no entries.");
+ NavigateToFeedAndValidate(
+ test_server(), kFeedTripleEncoded, browser(), id, true,
+ "Feed for Unknown feed name",
+ "element 'anchor_0' not found",
+ "element 'desc_0' not found",
+ "This feed contains no entries.");
}
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeedNoLinks) {
ASSERT_TRUE(test_server()->Start());
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("subscribe_page_action")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("subscribe_page_action"));
+ ASSERT_TRUE(extension);
+ std::string id = extension->id();
// Valid feed but containing no links.
- NavigateToFeedAndValidate(test_server(), kValidFeedNoLinks, browser(), true,
- "Feed for MyFeedTitle",
- "Title with no link",
- "Desc",
- "No error");
+ NavigateToFeedAndValidate(
+ test_server(), kValidFeedNoLinks, browser(), id, true,
+ "Feed for MyFeedTitle",
+ "Title with no link",
+ "Desc",
+ "No error");
}
// Tests that an error raised during an async function still fires
@@ -722,7 +747,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginLoadUnload) {
ExtensionService* service = browser()->profile()->GetExtensionService();
service->set_show_extensions_prompts(false);
const size_t size_before = service->extensions()->size();
- ASSERT_TRUE(LoadExtension(extension_dir));
+ const Extension* extension = LoadExtension(extension_dir);
+ ASSERT_TRUE(extension);
EXPECT_EQ(size_before + 1, service->extensions()->size());
// Now the plugin should be in the cache, but we have to reload the page for
// it to work.
@@ -742,7 +768,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginLoadUnload) {
EXPECT_TRUE(result);
EXPECT_EQ(size_before + 1, service->extensions()->size());
- UnloadExtension(service->extensions()->at(size_before)->id());
+ UnloadExtension(extension->id());
EXPECT_EQ(size_before, service->extensions()->size());
// Now the plugin should be unloaded, and the page should be broken.
@@ -784,11 +810,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginPrivate) {
ExtensionService* service = browser()->profile()->GetExtensionService();
service->set_show_extensions_prompts(false);
const size_t size_before = service->extensions()->size();
- ASSERT_TRUE(LoadExtension(extension_dir));
+ const Extension* extension = LoadExtension(extension_dir);
+ ASSERT_TRUE(extension);
EXPECT_EQ(size_before + 1, service->extensions()->size());
// Load the test page through the extension URL, and the plugin should work.
- const Extension* extension = service->extensions()->back();
ui_test_utils::NavigateToURL(browser(),
extension->GetResourceURL("test.html"));
TabContents* tab = browser()->GetSelectedTabContents();
@@ -825,11 +851,11 @@ static const wchar_t* jscript_click_option_button =
// Disabled. See http://crbug.com/26948 for details.
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_OptionsPage) {
// Install an extension with an options page.
- ASSERT_TRUE(InstallExtension(test_data_dir_.AppendASCII("options.crx"), 1));
+ const Extension* extension =
+ InstallExtension(test_data_dir_.AppendASCII("options.crx"), 1);
+ ASSERT_TRUE(extension);
ExtensionService* service = browser()->profile()->GetExtensionService();
- const ExtensionList* extensions = service->extensions();
- ASSERT_EQ(1u, extensions->size());
- const Extension* extension = extensions->at(0);
+ ASSERT_EQ(1u, service->extensions()->size());
// Go to the Extension Settings page and click the Options button.
ui_test_utils::NavigateToURL(
diff --git a/chrome/browser/extensions/extension_context_menu_browsertest.cc b/chrome/browser/extensions/extension_context_menu_browsertest.cc
index 1fe2247..2be1464 100644
--- a/chrome/browser/extensions/extension_context_menu_browsertest.cc
+++ b/chrome/browser/extensions/extension_context_menu_browsertest.cc
@@ -156,9 +156,9 @@ class ExtensionContextMenuBrowserTest : public ExtensionBrowserTest {
// Returns a pointer to the currently loaded extension with |name|, or null
// if not found.
const Extension* GetExtensionNamed(std::string name) {
- const ExtensionList* extensions =
+ const ExtensionSet* extensions =
browser()->profile()->GetExtensionService()->extensions();
- ExtensionList::const_iterator i;
+ ExtensionSet::const_iterator i;
for (i = extensions->begin(); i != extensions->end(); ++i) {
if ((*i)->name() == name) {
return *i;
diff --git a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
index 6ee66af..2dd874a 100644
--- a/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
+++ b/chrome/browser/extensions/extension_crash_recovery_browsertest.cc
@@ -62,12 +62,10 @@ class ExtensionCrashRecoveryTest : public ExtensionBrowserTest {
return balloons.size();
}
- void CrashExtension(size_t index) {
- ASSERT_LT(index, GetExtensionService()->extensions()->size());
+ void CrashExtension(std::string extension_id) {
const Extension* extension =
- GetExtensionService()->extensions()->at(index);
+ GetExtensionService()->extensions()->GetByID(extension_id);
ASSERT_TRUE(extension);
- std::string extension_id(extension->id());
ExtensionHost* extension_host = GetExtensionProcessManager()->
GetBackgroundHostForExtension(extension_id);
ASSERT_TRUE(extension_host);
@@ -81,43 +79,36 @@ class ExtensionCrashRecoveryTest : public ExtensionBrowserTest {
GetBackgroundHostForExtension(extension_id));
}
- void CheckExtensionConsistency(size_t index) {
- ASSERT_LT(index, GetExtensionService()->extensions()->size());
+ void CheckExtensionConsistency(std::string extension_id) {
const Extension* extension =
- GetExtensionService()->extensions()->at(index);
+ GetExtensionService()->extensions()->GetByID(extension_id);
ASSERT_TRUE(extension);
ExtensionHost* extension_host = GetExtensionProcessManager()->
- GetBackgroundHostForExtension(extension->id());
+ GetBackgroundHostForExtension(extension_id);
ASSERT_TRUE(extension_host);
ASSERT_TRUE(GetExtensionProcessManager()->HasExtensionHost(extension_host));
ASSERT_TRUE(extension_host->IsRenderViewLive());
extensions::ProcessMap* process_map =
browser()->profile()->GetExtensionService()->process_map();
ASSERT_TRUE(process_map->Contains(
- extension->id(), extension_host->render_view_host()->process()->
- GetID()));
+ extension_id, extension_host->render_view_host()->process()->GetID()));
}
void LoadTestExtension() {
ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
- const size_t size_before = GetExtensionService()->extensions()->size();
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
- const Extension* extension = GetExtensionService()->extensions()->back();
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("common").AppendASCII("background_page"));
ASSERT_TRUE(extension);
first_extension_id_ = extension->id();
- CheckExtensionConsistency(size_before);
+ CheckExtensionConsistency(first_extension_id_);
}
void LoadSecondExtension() {
- int offset = GetExtensionService()->extensions()->size();
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("install").AppendASCII("install")));
- const Extension* extension =
- GetExtensionService()->extensions()->at(offset);
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("install").AppendASCII("install"));
ASSERT_TRUE(extension);
second_extension_id_ = extension->id();
- CheckExtensionConsistency(offset);
+ CheckExtensionConsistency(second_extension_id_);
}
std::string first_extension_id_;
@@ -129,14 +120,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) {
const size_t crash_size_before =
GetExtensionService()->terminated_extensions()->size();
LoadTestExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
ASSERT_EQ(crash_size_before + 1,
GetExtensionService()->terminated_extensions()->size());
AcceptNotification(0);
SCOPED_TRACE("after clicking the balloon");
- CheckExtensionConsistency(size_before);
+ CheckExtensionConsistency(first_extension_id_);
ASSERT_EQ(crash_size_before,
GetExtensionService()->terminated_extensions()->size());
}
@@ -146,7 +137,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CloseAndReload) {
const size_t crash_size_before =
GetExtensionService()->terminated_extensions()->size();
LoadTestExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
ASSERT_EQ(crash_size_before + 1,
@@ -156,7 +147,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CloseAndReload) {
ReloadExtension(first_extension_id_);
SCOPED_TRACE("after reloading");
- CheckExtensionConsistency(size_before);
+ CheckExtensionConsistency(first_extension_id_);
ASSERT_EQ(crash_size_before,
GetExtensionService()->terminated_extensions()->size());
}
@@ -164,13 +155,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CloseAndReload) {
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
ReloadExtension(first_extension_id_);
SCOPED_TRACE("after reloading");
- CheckExtensionConsistency(size_before);
+ CheckExtensionConsistency(first_extension_id_);
TabContents* current_tab = browser()->GetSelectedTabContents();
ASSERT_TRUE(current_tab);
@@ -184,7 +175,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
ReloadIndependentlyChangeTabs) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
TabContents* original_tab = browser()->GetSelectedTabContents();
@@ -201,7 +192,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
ReloadExtension(first_extension_id_);
SCOPED_TRACE("after reloading");
- CheckExtensionConsistency(size_before);
+ CheckExtensionConsistency(first_extension_id_);
// The balloon should automatically hide after the extension is successfully
// reloaded.
@@ -212,7 +203,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
ReloadIndependentlyNavigatePage) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
TabContents* current_tab = browser()->GetSelectedTabContents();
@@ -228,7 +219,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
ReloadExtension(first_extension_id_);
SCOPED_TRACE("after reloading");
- CheckExtensionConsistency(size_before);
+ CheckExtensionConsistency(first_extension_id_);
// The balloon should automatically hide after the extension is successfully
// reloaded.
@@ -249,7 +240,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, MAYBE_ShutdownWhileCrashed) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
}
@@ -257,26 +248,26 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashFirst) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
LoadSecondExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
AcceptNotification(0);
SCOPED_TRACE("after clicking the balloon");
- CheckExtensionConsistency(size_before);
- CheckExtensionConsistency(size_before + 1);
+ CheckExtensionConsistency(first_extension_id_);
+ CheckExtensionConsistency(second_extension_id_);
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashSecond) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
LoadSecondExtension();
- CrashExtension(size_before + 1);
+ CrashExtension(second_extension_id_);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
AcceptNotification(0);
SCOPED_TRACE("after clicking the balloon");
- CheckExtensionConsistency(size_before);
- CheckExtensionConsistency(size_before + 1);
+ CheckExtensionConsistency(first_extension_id_);
+ CheckExtensionConsistency(second_extension_id_);
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
@@ -286,11 +277,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
GetExtensionService()->terminated_extensions()->size();
LoadTestExtension();
LoadSecondExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
ASSERT_EQ(crash_size_before + 1,
GetExtensionService()->terminated_extensions()->size());
- CrashExtension(size_before);
+ CrashExtension(second_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
ASSERT_EQ(crash_size_before + 2,
GetExtensionService()->terminated_extensions()->size());
@@ -298,37 +289,37 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
{
SCOPED_TRACE("first balloon");
AcceptNotification(0);
- CheckExtensionConsistency(size_before);
+ CheckExtensionConsistency(first_extension_id_);
}
{
SCOPED_TRACE("second balloon");
AcceptNotification(0);
- CheckExtensionConsistency(size_before);
- CheckExtensionConsistency(size_before + 1);
+ CheckExtensionConsistency(first_extension_id_);
+ CheckExtensionConsistency(second_extension_id_);
}
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsOneByOne) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
LoadSecondExtension();
- CrashExtension(size_before);
+ CrashExtension(second_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
{
SCOPED_TRACE("first balloon");
AcceptNotification(0);
- CheckExtensionConsistency(size_before);
+ CheckExtensionConsistency(first_extension_id_);
}
{
SCOPED_TRACE("second balloon");
AcceptNotification(0);
- CheckExtensionConsistency(size_before);
- CheckExtensionConsistency(size_before + 1);
+ CheckExtensionConsistency(first_extension_id_);
+ CheckExtensionConsistency(second_extension_id_);
}
}
@@ -348,10 +339,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
MAYBE_TwoExtensionsShutdownWhileCrashed) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
LoadSecondExtension();
- CrashExtension(size_before);
+ CrashExtension(second_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
}
@@ -360,9 +351,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
LoadSecondExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
- CrashExtension(size_before);
+ CrashExtension(second_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
// Accept notification 1 before canceling notification 0.
@@ -373,9 +364,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
SCOPED_TRACE("balloons done");
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
- EXPECT_EQ(second_extension_id_,
- GetExtensionService()->extensions()->at(size_before)->id());
- CheckExtensionConsistency(size_before);
+ CheckExtensionConsistency(second_extension_id_);
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
@@ -383,9 +372,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
LoadSecondExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
- CrashExtension(size_before);
+ CrashExtension(second_extension_id_);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
{
@@ -397,14 +386,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
ReloadExtension(first_extension_id_);
// One of the balloons should hide after the extension is reloaded.
ASSERT_EQ(1U, CountBalloons());
- CheckExtensionConsistency(size_before);
+ CheckExtensionConsistency(first_extension_id_);
}
{
SCOPED_TRACE("second: balloon");
AcceptNotification(0);
- CheckExtensionConsistency(size_before);
- CheckExtensionConsistency(size_before + 1);
+ CheckExtensionConsistency(first_extension_id_);
+ CheckExtensionConsistency(second_extension_id_);
}
}
@@ -414,7 +403,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) {
GetExtensionService()->terminated_extensions()->size();
LoadTestExtension();
LoadSecondExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
ASSERT_EQ(crash_size_before + 1,
GetExtensionService()->terminated_extensions()->size());
@@ -443,7 +432,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, MAYBE_CrashAndUnloadAll) {
GetExtensionService()->terminated_extensions()->size();
LoadTestExtension();
LoadSecondExtension();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
ASSERT_EQ(crash_size_before + 1,
GetExtensionService()->terminated_extensions()->size());
@@ -471,7 +460,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
GURL("chrome-extension://" + first_extension_id_ + "/background.html"));
const int tabs_before = tab_strip->count();
- CrashExtension(size_before);
+ CrashExtension(first_extension_id_);
// Tab should still be open, and extension should be crashed.
EXPECT_EQ(tabs_before, tab_strip->count());
@@ -488,6 +477,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
observer.Wait();
}
// Extension should now be loaded.
+ SCOPED_TRACE("after reloading the tab");
+ CheckExtensionConsistency(first_extension_id_);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
ASSERT_EQ(0U, CountBalloons());
}
diff --git a/chrome/browser/extensions/extension_file_browser_private_api.cc b/chrome/browser/extensions/extension_file_browser_private_api.cc
index c6456c0..f529e06 100644
--- a/chrome/browser/extensions/extension_file_browser_private_api.cc
+++ b/chrome/browser/extensions/extension_file_browser_private_api.cc
@@ -130,10 +130,10 @@ bool GetFileBrowserHandlers(Profile* profile,
if (!service)
return false; // In unit-tests, we may not have an ExtensionService.
- for (ExtensionList::const_iterator iter = service->extensions()->begin();
+ for (ExtensionSet::const_iterator iter = service->extensions()->begin();
iter != service->extensions()->end();
++iter) {
- const Extension* extension = iter->get();
+ const Extension* extension = *iter;
if (!extension->file_browser_handlers())
continue;
diff --git a/chrome/browser/extensions/extension_info_map.cc b/chrome/browser/extensions/extension_info_map.cc
index fdbd66a..929e106 100644
--- a/chrome/browser/extensions/extension_info_map.cc
+++ b/chrome/browser/extensions/extension_info_map.cc
@@ -138,11 +138,11 @@ bool ExtensionInfoMap::SecurityOriginHasAPIPermission(
process_map_.Contains(id, process_id);
}
- ExtensionSet::ExtensionMap::const_iterator i = extensions_.begin();
+ ExtensionSet::const_iterator i = extensions_.begin();
for (; i != extensions_.end(); ++i) {
- if (i->second->web_extent().MatchesSecurityOrigin(origin) &&
- process_map_.Contains(i->first, process_id) &&
- i->second->HasAPIPermission(permission)) {
+ if ((*i)->web_extent().MatchesSecurityOrigin(origin) &&
+ process_map_.Contains((*i)->id(), process_id) &&
+ (*i)->HasAPIPermission(permission)) {
return true;
}
}
diff --git a/chrome/browser/extensions/extension_management_api.cc b/chrome/browser/extensions/extension_management_api.cc
index 361a4ae..15d67a2 100644
--- a/chrome/browser/extensions/extension_management_api.cc
+++ b/chrome/browser/extensions/extension_management_api.cc
@@ -123,10 +123,10 @@ static DictionaryValue* CreateExtensionInfo(const Extension& extension,
}
static void AddExtensionInfo(ListValue* list,
- const ExtensionList& extensions,
+ const ExtensionSet& extensions,
bool enabled,
ExtensionPrefs* prefs) {
- for (ExtensionList::const_iterator i = extensions.begin();
+ for (ExtensionSet::const_iterator i = extensions.begin();
i != extensions.end(); ++i) {
const Extension& extension = **i;
diff --git a/chrome/browser/extensions/extension_management_browsertest.cc b/chrome/browser/extensions/extension_management_browsertest.cc
index 221f347..08c90dc 100644
--- a/chrome/browser/extensions/extension_management_browsertest.cc
+++ b/chrome/browser/extensions/extension_management_browsertest.cc
@@ -314,7 +314,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, AutoUpdate) {
ExtensionTestMessageListener listener1("v1 installed", false);
ExtensionService* service = browser()->profile()->GetExtensionService();
const size_t size_before = service->extensions()->size();
- ASSERT_TRUE(service->disabled_extensions()->empty());
+ ASSERT_TRUE(service->disabled_extensions()->is_empty());
const Extension* extension =
InstallExtension(basedir.AppendASCII("v1.crx"), 1);
ASSERT_TRUE(extension);
@@ -382,7 +382,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalUrlUpdate) {
basedir.AppendASCII("v2.crx"));
const size_t size_before = service->extensions()->size();
- ASSERT_TRUE(service->disabled_extensions()->empty());
+ ASSERT_TRUE(service->disabled_extensions()->is_empty());
PendingExtensionManager* pending_extension_manager =
service->pending_extension_manager();
@@ -465,7 +465,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, ExternalPolicyRefresh) {
basedir.AppendASCII("v2.crx"));
const size_t size_before = service->extensions()->size();
- ASSERT_TRUE(service->disabled_extensions()->empty());
+ ASSERT_TRUE(service->disabled_extensions()->is_empty());
PrefService* prefs = browser()->profile()->GetPrefs();
const ListValue* forcelist =
@@ -520,7 +520,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, PolicyOverridesUserInstall) {
service->updater()->set_blacklist_checks_enabled(false);
const size_t size_before = service->extensions()->size();
FilePath basedir = test_data_dir_.AppendASCII("autoupdate");
- ASSERT_TRUE(service->disabled_extensions()->empty());
+ ASSERT_TRUE(service->disabled_extensions()->is_empty());
// Note: This interceptor gets requests on the IO thread.
scoped_refptr<AutoUpdateInterceptor> interceptor(new AutoUpdateInterceptor());
@@ -581,7 +581,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, PolicyOverridesUserInstall) {
ASSERT_TRUE(extension);
EXPECT_EQ(Extension::INTERNAL, extension->location());
EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
- EXPECT_TRUE(service->disabled_extensions()->empty());
+ EXPECT_TRUE(service->disabled_extensions()->is_empty());
service->DisableExtension(kExtensionId);
EXPECT_EQ(1u, service->disabled_extensions()->size());
@@ -604,5 +604,5 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, PolicyOverridesUserInstall) {
ASSERT_TRUE(extension);
EXPECT_EQ(Extension::EXTERNAL_POLICY_DOWNLOAD, extension->location());
EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
- EXPECT_TRUE(service->disabled_extensions()->empty());
+ EXPECT_TRUE(service->disabled_extensions()->is_empty());
}
diff --git a/chrome/browser/extensions/extension_override_apitest.cc b/chrome/browser/extensions/extension_override_apitest.cc
index 518d333..778ec2e 100644
--- a/chrome/browser/extensions/extension_override_apitest.cc
+++ b/chrome/browser/extensions/extension_override_apitest.cc
@@ -114,15 +114,16 @@ IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, MAYBE_OverrideHistory) {
// Regression test for http://crbug.com/41442.
IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, ShouldNotCreateDuplicateEntries) {
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("override/history")));
+ const Extension* extension =
+ LoadExtension(test_data_dir_.AppendASCII("override/history"));
+ ASSERT_TRUE(extension);
// Simulate several LoadExtension() calls happening over the lifetime of
// a preferences file without corresponding UnloadExtension() calls.
for (size_t i = 0; i < 3; ++i) {
ExtensionWebUI::RegisterChromeURLOverrides(
browser()->profile(),
- browser()->profile()->GetExtensionService()->extensions()->back()->
- GetChromeURLOverrides());
+ extension->GetChromeURLOverrides());
}
ASSERT_TRUE(CheckHistoryOverridesContainsNoDupes());
@@ -160,8 +161,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, OverrideKeyboard) {
}
// Load the failing version. This should take precedence.
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("override").AppendASCII("keyboard_fails")));
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("override").AppendASCII("keyboard_fails"));
+ ASSERT_TRUE(extension);
{
ResultCatcher catcher;
NavigateToKeyboard();
@@ -169,9 +171,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, OverrideKeyboard) {
}
// Unload the failing version. We should be back to passing now.
- const ExtensionList *extensions =
- browser()->profile()->GetExtensionService()->extensions();
- UnloadExtension((*extensions->rbegin())->id());
+ UnloadExtension(extension->id());
{
ResultCatcher catcher;
NavigateToKeyboard();
diff --git a/chrome/browser/extensions/extension_preference_api.cc b/chrome/browser/extensions/extension_preference_api.cc
index 31b3161..ffbfc80 100644
--- a/chrome/browser/extensions/extension_preference_api.cc
+++ b/chrome/browser/extensions/extension_preference_api.cc
@@ -316,8 +316,8 @@ void ExtensionPreferenceEventRouter::OnPrefChanged(
ExtensionEventRouter* router = profile_->GetExtensionEventRouter();
if (!router || !router->HasEventListener(event_name))
return;
- const ExtensionList* extensions = extension_service->extensions();
- for (ExtensionList::const_iterator it = extensions->begin();
+ const ExtensionSet* extensions = extension_service->extensions();
+ for (ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
std::string extension_id = (*it)->id();
// TODO(bauerb): Only iterate over registered event listeners.
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index 4f60ea3..50e8536 100644
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -74,8 +74,8 @@ static void CreateBackgroundHostForExtensionLoad(
}
static void CreateBackgroundHostsForProfileStartup(
- ExtensionProcessManager* manager, const ExtensionList* extensions) {
- for (ExtensionList::const_iterator extension = extensions->begin();
+ ExtensionProcessManager* manager, const ExtensionSet* extensions) {
+ for (ExtensionSet::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
CreateBackgroundHostForExtensionLoad(manager, *extension);
}
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 0b78055..5da59ed 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -444,15 +444,15 @@ ExtensionService::ExtensionService(Profile* profile,
install_directory_.value().length(), 0, 500, 100);
}
-const ExtensionList* ExtensionService::extensions() const {
+const ExtensionSet* ExtensionService::extensions() const {
return &extensions_;
}
-const ExtensionList* ExtensionService::disabled_extensions() const {
+const ExtensionSet* ExtensionService::disabled_extensions() const {
return &disabled_extensions_;
}
-const ExtensionList* ExtensionService::terminated_extensions() const {
+const ExtensionSet* ExtensionService::terminated_extensions() const {
return &terminated_extensions_;
}
@@ -766,14 +766,11 @@ bool ExtensionService::UninstallExtension(
bool ExtensionService::IsExtensionEnabled(
const std::string& extension_id) const {
- const Extension* extension =
- GetExtensionByIdInternal(extension_id, true, false, true);
- if (extension)
+ if (extensions_.Contains(extension_id) ||
+ terminated_extensions_.Contains(extension_id))
return true;
- extension =
- GetExtensionByIdInternal(extension_id, false, true, false);
- if (extension)
+ if (disabled_extensions_.Contains(extension_id))
return false;
// If the extension hasn't been loaded yet, check the prefs for it. Assume
@@ -803,11 +800,8 @@ void ExtensionService::EnableExtension(const std::string& extension_id) {
return;
// Move it over to the enabled list.
- extensions_.push_back(make_scoped_refptr(extension));
- ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
- disabled_extensions_.end(),
- extension);
- disabled_extensions_.erase(iter);
+ extensions_.Insert(make_scoped_refptr(extension));
+ disabled_extensions_.Remove(extension->id());
// Make sure any browser action contained within it is not hidden.
extension_prefs_->SetBrowserActionVisibility(extension, true);
@@ -837,18 +831,11 @@ void ExtensionService::DisableExtension(const std::string& extension_id) {
return;
// Move it over to the disabled list.
- disabled_extensions_.push_back(make_scoped_refptr(extension));
- ExtensionList::iterator iter = std::find(extensions_.begin(),
- extensions_.end(),
- extension);
- if (iter != extensions_.end()) {
- extensions_.erase(iter);
- } else {
- iter = std::find(terminated_extensions_.begin(),
- terminated_extensions_.end(),
- extension);
- terminated_extensions_.erase(iter);
- }
+ disabled_extensions_.Insert(make_scoped_refptr(extension));
+ if (extensions_.Contains(extension->id()))
+ extensions_.Remove(extension->id());
+ else
+ terminated_extensions_.Remove(extension->id());
NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
@@ -1115,7 +1102,7 @@ void ExtensionService::UpdateExtensionBlacklist(
extension_prefs_->UpdateBlacklist(blacklist_set);
std::vector<std::string> to_be_removed;
// Loop current extensions, unload installed extensions.
- for (ExtensionList::const_iterator iter = extensions_.begin();
+ for (ExtensionSet::const_iterator iter = extensions_.begin();
iter != extensions_.end(); ++iter) {
const Extension* extension = (*iter);
if (blacklist_set.find(extension->id()) != blacklist_set.end()) {
@@ -1158,7 +1145,7 @@ ExtensionUpdater* ExtensionService::updater() {
void ExtensionService::CheckAdminBlacklist() {
std::vector<std::string> to_be_removed;
// Loop through extensions list, unload installed extensions.
- for (ExtensionList::const_iterator iter = extensions_.begin();
+ for (ExtensionSet::const_iterator iter = extensions_.begin();
iter != extensions_.end(); ++iter) {
const Extension* extension = (*iter);
if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id(),
@@ -1359,10 +1346,10 @@ SyncError ExtensionService::ProcessSyncChanges(
}
void ExtensionService::GetSyncDataListHelper(
- const ExtensionList& extensions,
+ const ExtensionSet& extensions,
const SyncBundle& bundle,
std::vector<ExtensionSyncData>* sync_data_list) const {
- for (ExtensionList::const_iterator it = extensions.begin();
+ for (ExtensionSet::const_iterator it = extensions.begin();
it != extensions.end(); ++it) {
const Extension& extension = **it;
if (bundle.filter(extension) &&
@@ -1498,8 +1485,7 @@ void ExtensionService::SetIsIncognitoEnabled(
extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
- bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(),
- extension) != extensions_.end();
+ bool extension_is_enabled = extensions_.Contains(extension->id());
// When we reload the extension the ID may be invalidated if we've passed it
// by const ref everywhere. Make a copy to be safe.
@@ -1576,8 +1562,7 @@ void ExtensionService::SetAllowFileAccess(const Extension* extension,
extension_prefs_->SetAllowFileAccess(extension->id(), allow);
- bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(),
- extension) != extensions_.end();
+ bool extension_is_enabled = extensions_.Contains(extension->id());
if (extension_is_enabled)
ReloadExtension(extension->id());
}
@@ -1681,12 +1666,9 @@ void ExtensionService::IdentifyAlertableExtensions() {
scoped_ptr<ExtensionGlobalError> global_error(
new ExtensionGlobalError(AsWeakPtr()));
bool needs_alert = false;
- for (ExtensionList::const_iterator iter = extensions_.begin();
+ for (ExtensionSet::const_iterator iter = extensions_.begin();
iter != extensions_.end(); ++iter) {
const Extension* e = *iter;
- if (!IsExtensionEnabled(e->id())) {
- continue;
- }
if (Extension::IsExternalLocation(e->location())) {
if (!extension_prefs_->IsExternalExtensionAcknowledged(e->id())) {
global_error->AddExternalExtension(e->id());
@@ -1790,13 +1772,10 @@ void ExtensionService::UnloadExtension(
// Clean up runtime data.
extension_runtime_data_.erase(extension_id);
- ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
- disabled_extensions_.end(),
- extension.get());
- if (iter != disabled_extensions_.end()) {
+if (disabled_extensions_.Contains(extension->id())) {
UnloadedExtensionInfo details(extension, reason);
details.already_disabled = true;
- disabled_extensions_.erase(iter);
+ disabled_extensions_.Remove(extension->id());
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_UNLOADED,
content::Source<Profile>(profile_),
@@ -1808,10 +1787,8 @@ void ExtensionService::UnloadExtension(
return;
}
- iter = std::find(extensions_.begin(), extensions_.end(), extension.get());
-
- // Remove the extension from our list.
- extensions_.erase(iter);
+// Remove the extension from our list.
+ extensions_.Remove(extension->id());
NotifyExtensionUnloaded(extension.get(), reason);
}
@@ -1820,10 +1797,9 @@ void ExtensionService::UnloadAllExtensions() {
profile_->GetExtensionSpecialStoragePolicy()->
RevokeRightsForAllExtensions();
- extensions_.clear();
- disabled_extensions_.clear();
- terminated_extension_ids_.clear();
- terminated_extensions_.clear();
+ extensions_.Clear();
+ disabled_extensions_.Clear();
+ terminated_extensions_.Clear();
extension_runtime_data_.clear();
// TODO(erikkay) should there be a notification for this? We can't use
@@ -1907,10 +1883,10 @@ void ExtensionService::AddExtension(const Extension* extension) {
bool disabled = extension_prefs_->IsExtensionDisabled(extension->id());
if (disabled) {
- disabled_extensions_.push_back(scoped_extension);
- // TODO(aa): This seems dodgy. It seems that AddExtension() could get called
- // with a disabled extension for other reasons other than that an update was
- // disabled.
+ disabled_extensions_.Insert(scoped_extension);
+ // TODO(aa): This seems dodgy. AddExtension() could get called with a
+ // disabled extension for other reasons other than that an update was
+ // disabled, e.g. as in ExtensionManagementTest.InstallRequiresConfirm.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
content::Source<Profile>(profile_),
@@ -1919,7 +1895,7 @@ void ExtensionService::AddExtension(const Extension* extension) {
return;
}
- extensions_.push_back(scoped_extension);
+ extensions_.Insert(scoped_extension);
SyncExtensionChangeIfNeeded(*extension);
NotifyExtensionLoaded(extension);
IdentifyAlertableExtensions();
@@ -2031,10 +2007,11 @@ void ExtensionService::InitializePermissions(const Extension* extension) {
void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
std::set<std::string> extension_ids;
- for (size_t i = 0; i < extensions_.size(); ++i) {
- if (!extensions_[i]->is_theme() &&
- extensions_[i]->location() != Extension::COMPONENT)
- extension_ids.insert(extensions_[i]->id());
+ for (ExtensionSet::const_iterator iter = extensions_.begin();
+ iter != extensions_.end(); ++iter) {
+ const Extension* extension = *iter;
+ if (!extension->is_theme() && extension->location() != Extension::COMPONENT)
+ extension_ids.insert(extension->id());
}
child_process_logging::SetActiveExtensions(extension_ids);
@@ -2127,51 +2104,33 @@ const Extension* ExtensionService::GetExtensionByIdInternal(
bool include_terminated) const {
std::string lowercase_id = StringToLowerASCII(id);
if (include_enabled) {
- for (ExtensionList::const_iterator iter = extensions_.begin();
- iter != extensions_.end(); ++iter) {
- if ((*iter)->id() == lowercase_id)
- return *iter;
- }
+ const Extension* extension = extensions_.GetByID(lowercase_id);
+ if (extension)
+ return extension;
}
if (include_disabled) {
- for (ExtensionList::const_iterator iter = disabled_extensions_.begin();
- iter != disabled_extensions_.end(); ++iter) {
- if ((*iter)->id() == lowercase_id)
- return *iter;
- }
+ const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
+ if (extension)
+ return extension;
}
if (include_terminated) {
- for (ExtensionList::const_iterator iter = terminated_extensions_.begin();
- iter != terminated_extensions_.end(); ++iter) {
- if ((*iter)->id() == lowercase_id)
- return *iter;
- }
+ const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
+ if (extension)
+ return extension;
}
return NULL;
}
void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
- if (terminated_extension_ids_.insert(extension->id()).second)
- terminated_extensions_.push_back(make_scoped_refptr(extension));
-
- // TODO(yoz): Listen to navcontrollers for that extension. Is this a todo?
+ if (!terminated_extensions_.Contains(extension->id()))
+ terminated_extensions_.Insert(make_scoped_refptr(extension));
- // TODO(yoz): make sure this is okay in *ALL* the listeners!
UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE);
}
void ExtensionService::UntrackTerminatedExtension(const std::string& id) {
std::string lowercase_id = StringToLowerASCII(id);
- if (terminated_extension_ids_.erase(lowercase_id) <= 0)
- return;
-
- for (ExtensionList::iterator iter = terminated_extensions_.begin();
- iter != terminated_extensions_.end(); ++iter) {
- if ((*iter)->id() == lowercase_id) {
- terminated_extensions_.erase(iter);
- return;
- }
- }
+ terminated_extensions_.Remove(lowercase_id);
}
const Extension* ExtensionService::GetTerminatedExtension(
@@ -2194,18 +2153,22 @@ const Extension* ExtensionService::GetExtensionByURL(const GURL& url) {
}
const Extension* ExtensionService::GetExtensionByWebExtent(const GURL& url) {
- for (size_t i = 0; i < extensions_.size(); ++i) {
- if (extensions_[i]->web_extent().MatchesURL(url))
- return extensions_[i];
+ // TODO(yoz): Should be ExtensionSet::GetByURL.
+ for (ExtensionSet::const_iterator iter = extensions_.begin();
+ iter != extensions_.end(); ++iter) {
+ if ((*iter)->web_extent().MatchesURL(url))
+ return *iter;
}
return NULL;
}
const Extension* ExtensionService::GetDisabledExtensionByWebExtent(
const GURL& url) {
- for (size_t i = 0; i < disabled_extensions_.size(); ++i) {
- if (disabled_extensions_[i]->web_extent().MatchesURL(url))
- return disabled_extensions_[i];
+ // TODO(yoz): Should be ExtensionSet::GetByURL.
+ for (ExtensionSet::const_iterator iter = disabled_extensions_.begin();
+ iter != disabled_extensions_.end(); ++iter) {
+ if ((*iter)->web_extent().MatchesURL(url))
+ return *iter;
}
return NULL;
}
@@ -2226,9 +2189,11 @@ bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
const Extension* ExtensionService::GetExtensionByOverlappingWebExtent(
const URLPatternSet& extent) {
- for (size_t i = 0; i < extensions_.size(); ++i) {
- if (extensions_[i]->web_extent().OverlapsWith(extent))
- return extensions_[i];
+ // TODO(yoz): Should be in ExtensionSet.
+ for (ExtensionSet::const_iterator iter = extensions_.begin();
+ iter != extensions_.end(); ++iter) {
+ if ((*iter)->web_extent().OverlapsWith(extent))
+ return *iter;
}
return NULL;
@@ -2370,9 +2335,9 @@ void ExtensionService::Observe(int type,
// Loaded extensions.
std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
- for (size_t i = 0; i < extensions_.size(); ++i) {
- loaded_extensions.push_back(
- ExtensionMsg_Loaded_Params(extensions_[i]));
+ for (ExtensionSet::const_iterator iter = extensions_.begin();
+ iter != extensions_.end(); ++iter) {
+ loaded_extensions.push_back(ExtensionMsg_Loaded_Params(*iter));
}
process->Send(new ExtensionMsg_Loaded(loaded_extensions));
break;
@@ -2423,7 +2388,7 @@ bool ExtensionService::HasApps() const {
ExtensionIdSet ExtensionService::GetAppIds() const {
ExtensionIdSet result;
- for (ExtensionList::const_iterator it = extensions_.begin();
+ for (ExtensionSet::const_iterator it = extensions_.begin();
it != extensions_.end(); ++it) {
if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT)
result.insert((*it)->id());
diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h
index 370ad22..67b0f4d 100644
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -41,6 +41,7 @@
#include "chrome/browser/sync/api/syncable_service.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/extensions/extension_set.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@@ -86,7 +87,7 @@ class ExtensionServiceInterface : public SyncableService {
typedef bool (*ExtensionFilter)(const Extension&);
virtual ~ExtensionServiceInterface() {}
- virtual const ExtensionList* extensions() const = 0;
+ virtual const ExtensionSet* extensions() const = 0;
virtual PendingExtensionManager* pending_extension_manager() = 0;
// Install an update. Return true if the install can be started.
@@ -192,9 +193,9 @@ class ExtensionService
virtual ~ExtensionService();
// Gets the list of currently installed extensions.
- virtual const ExtensionList* extensions() const OVERRIDE;
- const ExtensionList* disabled_extensions() const;
- const ExtensionList* terminated_extensions() const;
+ virtual const ExtensionSet* extensions() const OVERRIDE;
+ const ExtensionSet* disabled_extensions() const;
+ const ExtensionSet* terminated_extensions() const;
// Gets the object managing the set of pending extensions.
virtual PendingExtensionManager* pending_extension_manager() OVERRIDE;
@@ -635,7 +636,7 @@ class ExtensionService
// Appends sync data objects for every extension in |extensions|
// that passes |filter|.
void GetSyncDataListHelper(
- const ExtensionList& extensions,
+ const ExtensionSet& extensions,
const SyncBundle& bundle,
std::vector<ExtensionSyncData>* sync_data_list) const;
@@ -695,16 +696,13 @@ class ExtensionService
// The current list of installed extensions.
// TODO(aa): This should use chrome/common/extensions/extension_set.h.
- ExtensionList extensions_;
+ ExtensionSet extensions_;
// The list of installed extensions that have been disabled.
- ExtensionList disabled_extensions_;
+ ExtensionSet disabled_extensions_;
// The list of installed extensions that have been terminated.
- ExtensionList terminated_extensions_;
-
- // Used to quickly check if an extension was terminated.
- std::set<std::string> terminated_extension_ids_;
+ ExtensionSet terminated_extensions_;
// Hold the set of pending extensions.
PendingExtensionManager pending_extension_manager_;
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 78ef149..eaee17a 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -1875,7 +1875,7 @@ TEST_F(ExtensionServiceTest, UpdateApps) {
TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
InitializeEmptyExtensionService();
InitializeRequestContext();
- EXPECT_TRUE(service_->extensions()->empty());
+ EXPECT_TRUE(service_->extensions()->is_empty());
int pref_count = 0;
@@ -1926,7 +1926,7 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
InitializeEmptyExtensionService();
InitializeRequestContext();
- EXPECT_TRUE(service_->extensions()->empty());
+ EXPECT_TRUE(service_->extensions()->is_empty());
int pref_count = 0;
@@ -1955,7 +1955,7 @@ TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
UninstallExtension(id2, false);
- EXPECT_TRUE(service_->extensions()->empty());
+ EXPECT_TRUE(service_->extensions()->is_empty());
EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
IsStorageProtected(origin1));
EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
@@ -2676,18 +2676,18 @@ TEST_F(ExtensionServiceTest, DisableExtension) {
InitializeEmptyExtensionService();
InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
- EXPECT_FALSE(service_->extensions()->empty());
+ EXPECT_FALSE(service_->extensions()->is_empty());
EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
- EXPECT_TRUE(service_->disabled_extensions()->empty());
+ EXPECT_TRUE(service_->disabled_extensions()->is_empty());
// Disable it.
service_->DisableExtension(good_crx);
- EXPECT_TRUE(service_->extensions()->empty());
+ EXPECT_TRUE(service_->extensions()->is_empty());
EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
EXPECT_FALSE(service_->GetExtensionById(good_crx, false));
- EXPECT_FALSE(service_->disabled_extensions()->empty());
+ EXPECT_FALSE(service_->disabled_extensions()->is_empty());
}
TEST_F(ExtensionServiceTest, DisableTerminatedExtension) {
@@ -2702,7 +2702,7 @@ TEST_F(ExtensionServiceTest, DisableTerminatedExtension) {
EXPECT_FALSE(service_->GetTerminatedExtension(good_crx));
EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
- EXPECT_FALSE(service_->disabled_extensions()->empty());
+ EXPECT_FALSE(service_->disabled_extensions()->is_empty());
}
// Tests disabling all extensions (simulating --disable-extensions flag).
diff --git a/chrome/browser/extensions/extension_startup_browsertest.cc b/chrome/browser/extensions/extension_startup_browsertest.cc
index 835d274..20234e6 100644
--- a/chrome/browser/extensions/extension_startup_browsertest.cc
+++ b/chrome/browser/extensions/extension_startup_browsertest.cc
@@ -83,8 +83,9 @@ class ExtensionStartupTestBase : public InProcessBrowserTest {
// Count the number of non-component extensions.
int found_extensions = 0;
- for (size_t i = 0; i < service->extensions()->size(); i++)
- if (service->extensions()->at(i)->location() != Extension::COMPONENT)
+ for (ExtensionSet::const_iterator it = service->extensions()->begin();
+ it != service->extensions()->end(); ++it)
+ if ((*it)->location() != Extension::COMPONENT)
found_extensions++;
ASSERT_EQ(static_cast<uint32>(num_expected_extensions),
@@ -163,17 +164,25 @@ IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, Test) {
IN_PROC_BROWSER_TEST_F(ExtensionsStartupTest, MAYBE_NoFileAccess) {
WaitForServicesToStart(num_expected_extensions_, true);
+ // Keep a separate list of extensions for which to disable file access, since
+ // doing so reloads them.
+ std::vector<const Extension*> extension_list;
+
ExtensionService* service = browser()->profile()->GetExtensionService();
- for (size_t i = 0; i < service->extensions()->size(); ++i) {
- if (service->extensions()->at(i)->location() == Extension::COMPONENT)
+ for (ExtensionSet::const_iterator it = service->extensions()->begin();
+ it != service->extensions()->end(); ++it) {
+ if ((*it)->location() == Extension::COMPONENT)
continue;
- if (service->AllowFileAccess(service->extensions()->at(i))) {
- ui_test_utils::WindowedNotificationObserver user_scripts_observer(
- chrome::NOTIFICATION_USER_SCRIPTS_UPDATED,
- content::NotificationService::AllSources());
- service->SetAllowFileAccess(service->extensions()->at(i), false);
- user_scripts_observer.Wait();
- }
+ if (service->AllowFileAccess(*it))
+ extension_list.push_back(*it);
+ }
+
+ for (size_t i = 0; i < extension_list.size(); ++i) {
+ ui_test_utils::WindowedNotificationObserver user_scripts_observer(
+ chrome::NOTIFICATION_USER_SCRIPTS_UPDATED,
+ content::NotificationService::AllSources());
+ service->SetAllowFileAccess(extension_list[i], false);
+ user_scripts_observer.Wait();
}
TestInjection(false, false);
diff --git a/chrome/browser/extensions/extension_tab_helper.cc b/chrome/browser/extensions/extension_tab_helper.cc
index 1853360..7fe6986 100644
--- a/chrome/browser/extensions/extension_tab_helper.cc
+++ b/chrome/browser/extensions/extension_tab_helper.cc
@@ -98,9 +98,9 @@ void ExtensionTabHelper::DidNavigateMainFrame(
if (!service)
return;
- for (size_t i = 0; i < service->extensions()->size(); ++i) {
- ExtensionAction* browser_action =
- service->extensions()->at(i)->browser_action();
+ for (ExtensionSet::const_iterator it = service->extensions()->begin();
+ it != service->extensions()->end(); ++it) {
+ ExtensionAction* browser_action = (*it)->browser_action();
if (browser_action) {
browser_action->ClearAllValuesForTab(
wrapper_->restore_tab_helper()->session_id().id());
@@ -110,8 +110,7 @@ void ExtensionTabHelper::DidNavigateMainFrame(
content::NotificationService::NoDetails());
}
- ExtensionAction* page_action =
- service->extensions()->at(i)->page_action();
+ ExtensionAction* page_action = (*it)->page_action();
if (page_action) {
page_action->ClearAllValuesForTab(
wrapper_->restore_tab_helper()->session_id().id());
diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc
index 6f8c695..24f9629 100644
--- a/chrome/browser/extensions/extension_toolbar_model.cc
+++ b/chrome/browser/extensions/extension_toolbar_model.cc
@@ -181,8 +181,9 @@ void ExtensionToolbarModel::InitializeExtensionList() {
ExtensionList unsorted;
// Create the lists.
- for (size_t i = 0; i < service_->extensions()->size(); ++i) {
- const Extension* extension = service_->extensions()->at(i);
+ for (ExtensionSet::const_iterator it = service_->extensions()->begin();
+ it != service_->extensions()->end(); ++it) {
+ const Extension* extension = *it;
if (!extension->browser_action())
continue;
if (!service_->GetBrowserActionVisibility(extension))
diff --git a/chrome/browser/extensions/extension_tts_engine_api.cc b/chrome/browser/extensions/extension_tts_engine_api.cc
index 5eb86b9..db0d6fe 100644
--- a/chrome/browser/extensions/extension_tts_engine_api.cc
+++ b/chrome/browser/extensions/extension_tts_engine_api.cc
@@ -28,8 +28,8 @@ void GetExtensionVoices(Profile* profile, ListValue* result_voices) {
ExtensionEventRouter* event_router = profile->GetExtensionEventRouter();
DCHECK(event_router);
- const ExtensionList* extensions = service->extensions();
- ExtensionList::const_iterator iter;
+ const ExtensionSet* extensions = service->extensions();
+ ExtensionSet::const_iterator iter;
for (iter = extensions->begin(); iter != extensions->end(); ++iter) {
const Extension* extension = *iter;
@@ -93,8 +93,8 @@ bool GetMatchingExtensionVoice(
*matching_extension = NULL;
*voice_index = -1;
- const ExtensionList* extensions = service->extensions();
- ExtensionList::const_iterator iter;
+ const ExtensionSet* extensions = service->extensions();
+ ExtensionSet::const_iterator iter;
for (iter = extensions->begin(); iter != extensions->end(); ++iter) {
const Extension* extension = *iter;
diff --git a/chrome/browser/extensions/extension_updater.cc b/chrome/browser/extensions/extension_updater.cc
index ff1b8ce..2048d9f 100644
--- a/chrome/browser/extensions/extension_updater.cc
+++ b/chrome/browser/extensions/extension_updater.cc
@@ -1025,8 +1025,8 @@ void ExtensionUpdater::CheckNow() {
}
}
- const ExtensionList* extensions = service_->extensions();
- for (ExtensionList::const_iterator iter = extensions->begin();
+ const ExtensionSet* extensions = service_->extensions();
+ for (ExtensionSet::const_iterator iter = extensions->begin();
iter != extensions->end(); ++iter) {
// An extension might be overwritten by policy, and have its update url
// changed. Make sure existing extensions aren't fetched again, if a
diff --git a/chrome/browser/extensions/extension_updater_unittest.cc b/chrome/browser/extensions/extension_updater_unittest.cc
index e8f3c52..e475feb 100644
--- a/chrome/browser/extensions/extension_updater_unittest.cc
+++ b/chrome/browser/extensions/extension_updater_unittest.cc
@@ -153,16 +153,10 @@ class ServiceForManifestTests : public MockService {
virtual const Extension* GetExtensionById(
const std::string& id, bool include_disabled) const OVERRIDE {
- for (ExtensionList::const_iterator iter = extensions_.begin();
- iter != extensions_.end(); ++iter) {
- if ((*iter)->id() == id) {
- return *iter;
- }
- }
- return NULL;
+ return extensions_.GetByID(id);
}
- virtual const ExtensionList* extensions() const OVERRIDE {
+ virtual const ExtensionSet* extensions() const OVERRIDE {
return &extensions_;
}
@@ -171,11 +165,14 @@ class ServiceForManifestTests : public MockService {
}
void set_extensions(ExtensionList extensions) {
- extensions_ = extensions;
+ for (ExtensionList::const_iterator it = extensions.begin();
+ it != extensions.end(); ++it) {
+ extensions_.Insert(*it);
+ }
}
private:
- ExtensionList extensions_;
+ ExtensionSet extensions_;
};
class ServiceForDownloadTests : public MockService {
diff --git a/chrome/browser/extensions/extension_webrequest_api.cc b/chrome/browser/extensions/extension_webrequest_api.cc
index 21fdce9..481c015 100644
--- a/chrome/browser/extensions/extension_webrequest_api.cc
+++ b/chrome/browser/extensions/extension_webrequest_api.cc
@@ -1697,9 +1697,9 @@ void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host) {
bool adblock = false;
bool adblock_plus = false;
bool other = false;
- const ExtensionList* extensions =
+ const ExtensionSet* extensions =
profile->GetExtensionService()->extensions();
- for (ExtensionList::const_iterator it = extensions->begin();
+ for (ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
if (profile->GetExtensionService()->HasUsedWebRequest(*it)) {
if ((*it)->name().find("Adblock Plus") != std::string::npos) {
diff --git a/chrome/browser/extensions/installed_loader.cc b/chrome/browser/extensions/installed_loader.cc
index 2fb5e2d..d74bff4 100644
--- a/chrome/browser/extensions/installed_loader.cc
+++ b/chrome/browser/extensions/installed_loader.cc
@@ -181,8 +181,8 @@ void InstalledLoader::LoadAllExtensions() {
int theme_count = 0;
int page_action_count = 0;
int browser_action_count = 0;
- const ExtensionList* extensions = extension_service_->extensions();
- ExtensionList::const_iterator ex;
+ const ExtensionSet* extensions = extension_service_->extensions();
+ ExtensionSet::const_iterator ex;
for (ex = extensions->begin(); ex != extensions->end(); ++ex) {
Extension::Location location = (*ex)->location();
Extension::Type type = (*ex)->GetType();
@@ -246,7 +246,7 @@ void InstalledLoader::LoadAllExtensions() {
++browser_action_count;
extension_service_->RecordPermissionMessagesHistogram(
- ex->get(), "Extensions.Permissions_Load");
+ *ex, "Extensions.Permissions_Load");
}
UMA_HISTOGRAM_COUNTS_100("Extensions.LoadApp",
app_user_count + app_external_count);
diff --git a/chrome/browser/extensions/network_delay_listener_unittest.cc b/chrome/browser/extensions/network_delay_listener_unittest.cc
index 4e48472..e9d8f58 100644
--- a/chrome/browser/extensions/network_delay_listener_unittest.cc
+++ b/chrome/browser/extensions/network_delay_listener_unittest.cc
@@ -127,9 +127,9 @@ class NetworkDelayListenerTest
void LoadTestExtension1() {
LoadTestExtension(kTestExtensionId1);
- ASSERT_FALSE(service_->extensions()->empty());
- extension1_ = service_->extensions()->at(0).get();
- ASSERT_FALSE(extension1_ == NULL);
+ ASSERT_FALSE(service_->extensions()->is_empty());
+ extension1_ = service_->extensions()->GetByID(kTestExtensionId1);
+ ASSERT_TRUE(extension1_);
}
void SendExtensionLoadedNotification(const Extension* extension) {
@@ -197,8 +197,9 @@ TEST_F(NetworkDelayListenerTest, TwoBlockingExtensions) {
LoadTestExtension1();
LoadTestExtension(kTestExtensionId2);
ASSERT_EQ(2u, service_->extensions()->size());
- const Extension* extension2 = service_->extensions()->at(1).get();
- ASSERT_FALSE(extension2 == NULL);
+ const Extension* extension2 =
+ service_->extensions()->GetByID(kTestExtensionId2);
+ ASSERT_TRUE(extension2);
TestDelegate delegate;
scoped_ptr<TestURLRequest> request(StartTestRequest(&delegate, kTestUrl));
@@ -231,7 +232,7 @@ TEST_F(NetworkDelayListenerTest, ExtensionReadyTwice) {
// Tests that there's no delay if no loaded extension needs one.
TEST_F(NetworkDelayListenerTest, NoDelayNoWebRequest) {
LoadTestExtension(kTestExtensionNoNetworkDelay);
- ASSERT_FALSE(service_->extensions()->empty());
+ ASSERT_FALSE(service_->extensions()->is_empty());
TestDelegate delegate;
scoped_ptr<TestURLRequest> request(StartTestRequest(&delegate, kTestUrl));
diff --git a/chrome/browser/extensions/test_extension_service.cc b/chrome/browser/extensions/test_extension_service.cc
index 9e0be6e..e21ec88 100644
--- a/chrome/browser/extensions/test_extension_service.cc
+++ b/chrome/browser/extensions/test_extension_service.cc
@@ -9,7 +9,7 @@
TestExtensionService::~TestExtensionService() {}
-const ExtensionList* TestExtensionService::extensions() const {
+const ExtensionSet* TestExtensionService::extensions() const {
ADD_FAILURE();
return NULL;
}
diff --git a/chrome/browser/extensions/test_extension_service.h b/chrome/browser/extensions/test_extension_service.h
index 2e7d2e4..fa3ee0d 100644
--- a/chrome/browser/extensions/test_extension_service.h
+++ b/chrome/browser/extensions/test_extension_service.h
@@ -21,7 +21,7 @@ class TestExtensionService : public ExtensionServiceInterface {
virtual ~TestExtensionService();
// ExtensionServiceInterface implementation.
- virtual const ExtensionList* extensions() const OVERRIDE;
+ virtual const ExtensionSet* extensions() const OVERRIDE;
virtual PendingExtensionManager* pending_extension_manager() OVERRIDE;
virtual bool UpdateExtension(
diff --git a/chrome/browser/extensions/unpacked_installer.cc b/chrome/browser/extensions/unpacked_installer.cc
index eccf275..9bbea9a 100644
--- a/chrome/browser/extensions/unpacked_installer.cc
+++ b/chrome/browser/extensions/unpacked_installer.cc
@@ -194,15 +194,12 @@ void UnpackedInstaller::OnLoaded(
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!service_weak_.get())
return;
- const ExtensionList* disabled_extensions =
+ const ExtensionSet* disabled_extensions =
service_weak_->disabled_extensions();
if (service_weak_->show_extensions_prompts() &&
prompt_for_plugins_ &&
!extension->plugins().empty() &&
- std::find(disabled_extensions->begin(),
- disabled_extensions->end(),
- extension) !=
- disabled_extensions->end()) {
+ disabled_extensions->Contains(extension->id())) {
SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt(
service_weak_->profile(),
service_weak_,
diff --git a/chrome/browser/extensions/user_script_listener.cc b/chrome/browser/extensions/user_script_listener.cc
index 5a54e20..b169f12 100644
--- a/chrome/browser/extensions/user_script_listener.cc
+++ b/chrome/browser/extensions/user_script_listener.cc
@@ -200,7 +200,7 @@ void UserScriptListener::Observe(int type,
// Clear all our patterns and reregister all the still-loaded extensions.
URLPatterns new_patterns;
ExtensionService* service = profile->GetExtensionService();
- for (ExtensionList::const_iterator it = service->extensions()->begin();
+ for (ExtensionSet::const_iterator it = service->extensions()->begin();
it != service->extensions()->end(); ++it) {
if (*it != unloaded_extension)
CollectURLPatterns(*it, &new_patterns);
diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc
index f28c8d8..cbba08a 100644
--- a/chrome/browser/extensions/user_script_listener_unittest.cc
+++ b/chrome/browser/extensions/user_script_listener_unittest.cc
@@ -138,8 +138,8 @@ class UserScriptListenerTest
}
void UnloadTestExtension() {
- ASSERT_FALSE(service_->extensions()->empty());
- service_->UnloadExtension(service_->extensions()->at(0)->id(),
+ ASSERT_FALSE(service_->extensions()->is_empty());
+ service_->UnloadExtension((*service_->extensions()->begin())->id(),
extension_misc::UNLOAD_REASON_DISABLE);
}
diff --git a/chrome/browser/intents/web_intents_registry.cc b/chrome/browser/intents/web_intents_registry.cc
index 4e35219..5a8a567 100644
--- a/chrome/browser/intents/web_intents_registry.cc
+++ b/chrome/browser/intents/web_intents_registry.cc
@@ -81,9 +81,9 @@ void WebIntentsRegistry::OnWebDataServiceRequestDone(
// Loop over all intents in all extensions, collect ones matching the query.
if (extension_service_) {
- const ExtensionList* extensions = extension_service_->extensions();
+ const ExtensionSet* extensions = extension_service_->extensions();
if (extensions) {
- for (ExtensionList::const_iterator i(extensions->begin());
+ for (ExtensionSet::const_iterator i(extensions->begin());
i != extensions->end(); ++i) {
const IntentServiceList& intents((*i)->intents_services());
for (IntentServiceList::const_iterator j(intents.begin());
diff --git a/chrome/browser/intents/web_intents_registry_unittest.cc b/chrome/browser/intents/web_intents_registry_unittest.cc
index f6b20db..f25b802 100644
--- a/chrome/browser/intents/web_intents_registry_unittest.cc
+++ b/chrome/browser/intents/web_intents_registry_unittest.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/intents/web_intents_registry.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/extensions/extension_set.h"
#include "content/test/test_browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -21,49 +22,41 @@ using webkit_glue::WebIntentServiceData;
class MockExtensionService: public TestExtensionService {
public:
virtual ~MockExtensionService() {}
- MOCK_CONST_METHOD0(extensions, const ExtensionList*());
+ MOCK_CONST_METHOD0(extensions, const ExtensionSet*());
};
+namespace {
+
// TODO(groby): Unify loading functions with extension_manifest_unittest code.
-DictionaryValue* LoadManifestFile(const std::string& filename,
+DictionaryValue* LoadManifestFile(const FilePath& path,
std::string* error) {
- FilePath path;
- PathService::Get(chrome::DIR_TEST_DATA, &path);
- path = path.AppendASCII("extensions")
- .AppendASCII("manifest_tests")
- .AppendASCII(filename.c_str());
EXPECT_TRUE(file_util::PathExists(path));
-
JSONFileValueSerializer serializer(path);
return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error));
}
-namespace {
-
scoped_refptr<Extension> LoadExtensionWithLocation(
- DictionaryValue* value,
+ const std::string& name,
Extension::Location location,
bool strict_error_checks,
std::string* error) {
FilePath path;
PathService::Get(chrome::DIR_TEST_DATA, &path);
- path = path.AppendASCII("extensions").AppendASCII("manifest_tests");
+ path = path.AppendASCII("extensions")
+ .AppendASCII("manifest_tests")
+ .AppendASCII(name.c_str());
+ scoped_ptr<DictionaryValue> value(LoadManifestFile(path, error));
+ if (!value.get())
+ return NULL;
int flags = Extension::NO_FLAGS;
if (strict_error_checks)
flags |= Extension::STRICT_ERROR_CHECKS;
- return Extension::Create(path.DirName(), location, *value, flags, error);
-}
-
-scoped_refptr<Extension> LoadExtensionWithLocation(
- const std::string& name,
- Extension::Location location,
- bool strict_error_checks,
- std::string* error) {
- scoped_ptr<DictionaryValue> value(LoadManifestFile(name, error));
- if (!value.get())
- return NULL;
- return LoadExtensionWithLocation(value.get(), location,
- strict_error_checks, error);
+ return Extension::CreateWithId(path.DirName(),
+ location,
+ *value,
+ flags,
+ Extension::GenerateIdForPath(path),
+ error);
}
scoped_refptr<Extension> LoadExtension(const std::string& name,
@@ -114,7 +107,7 @@ class WebIntentsRegistryTest : public testing::Test {
content::TestBrowserThread db_thread_;
scoped_refptr<WebDataService> wds_;
MockExtensionService extension_service_;
- ExtensionList extensions_;
+ ExtensionSet extensions_;
WebIntentsRegistry registry_;
ScopedTempDir temp_dir_;
};
@@ -213,8 +206,9 @@ TEST_F(WebIntentsRegistryTest, GetAllIntents) {
}
TEST_F(WebIntentsRegistryTest, GetExtensionIntents) {
- extensions_.push_back(LoadAndExpectSuccess("intent_valid.json"));
- extensions_.push_back(LoadAndExpectSuccess("intent_valid_2.json"));
+ extensions_.Insert(LoadAndExpectSuccess("intent_valid.json"));
+ extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json"));
+ ASSERT_EQ(2U, extensions_.size());
TestConsumer consumer;
consumer.expected_id_ = registry_.GetAllIntentProviders(&consumer);
@@ -223,8 +217,9 @@ TEST_F(WebIntentsRegistryTest, GetExtensionIntents) {
}
TEST_F(WebIntentsRegistryTest, GetSomeExtensionIntents) {
- extensions_.push_back(LoadAndExpectSuccess("intent_valid.json"));
- extensions_.push_back(LoadAndExpectSuccess("intent_valid_2.json"));
+ extensions_.Insert(LoadAndExpectSuccess("intent_valid.json"));
+ extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json"));
+ ASSERT_EQ(2U, extensions_.size());
TestConsumer consumer;
consumer.expected_id_ = registry_.GetIntentProviders(
@@ -235,8 +230,9 @@ TEST_F(WebIntentsRegistryTest, GetSomeExtensionIntents) {
}
TEST_F(WebIntentsRegistryTest, GetIntentsFromMixedSources) {
- extensions_.push_back(LoadAndExpectSuccess("intent_valid.json"));
- extensions_.push_back(LoadAndExpectSuccess("intent_valid_2.json"));
+ extensions_.Insert(LoadAndExpectSuccess("intent_valid.json"));
+ extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json"));
+ ASSERT_EQ(2U, extensions_.size());
webkit_glue::WebIntentServiceData service;
service.service_url = GURL("http://somewhere.com/intent/edit.html");
diff --git a/chrome/browser/sync/test/integration/sync_extension_helper.cc b/chrome/browser/sync/test/integration/sync_extension_helper.cc
index be0d08b..08d1e8b 100644
--- a/chrome/browser/sync/test/integration/sync_extension_helper.cc
+++ b/chrome/browser/sync/test/integration/sync_extension_helper.cc
@@ -78,22 +78,22 @@ std::vector<std::string> SyncExtensionHelper::GetInstalledExtensionNames(
std::vector<std::string> names;
ExtensionService* extension_service = profile->GetExtensionService();
- const ExtensionList* extensions = extension_service->extensions();
- for (ExtensionList::const_iterator it = extensions->begin();
+ const ExtensionSet* extensions = extension_service->extensions();
+ for (ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
names.push_back((*it)->name());
}
- const ExtensionList* disabled_extensions =
+ const ExtensionSet* disabled_extensions =
extension_service->disabled_extensions();
- for (ExtensionList::const_iterator it = disabled_extensions->begin();
+ for (ExtensionSet::const_iterator it = disabled_extensions->begin();
it != disabled_extensions->end(); ++it) {
names.push_back((*it)->name());
}
- const ExtensionList* terminated_extensions =
+ const ExtensionSet* terminated_extensions =
extension_service->terminated_extensions();
- for (ExtensionList::const_iterator it = terminated_extensions->begin();
+ for (ExtensionSet::const_iterator it = terminated_extensions->begin();
it != terminated_extensions->end(); ++it) {
names.push_back((*it)->name());
}
@@ -180,8 +180,8 @@ SyncExtensionHelper::ExtensionStateMap
ExtensionService* extension_service = profile->GetExtensionService();
- const ExtensionList* extensions = extension_service->extensions();
- for (ExtensionList::const_iterator it = extensions->begin();
+ const ExtensionSet* extensions = extension_service->extensions();
+ for (ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
const std::string& id = (*it)->id();
extension_state_map[id].enabled_state = ExtensionState::ENABLED;
@@ -191,9 +191,9 @@ SyncExtensionHelper::ExtensionStateMap
<< profile_debug_name << " is enabled";
}
- const ExtensionList* disabled_extensions =
+ const ExtensionSet* disabled_extensions =
extension_service->disabled_extensions();
- for (ExtensionList::const_iterator it = disabled_extensions->begin();
+ for (ExtensionSet::const_iterator it = disabled_extensions->begin();
it != disabled_extensions->end(); ++it) {
const std::string& id = (*it)->id();
extension_state_map[id].enabled_state = ExtensionState::DISABLED;
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc
index 210e663..c4a62916 100644
--- a/chrome/browser/themes/theme_service.cc
+++ b/chrome/browser/themes/theme_service.cc
@@ -338,8 +338,8 @@ void ThemeService::RemoveUnusedThemes() {
return;
std::string current_theme = GetThemeID();
std::vector<std::string> remove_list;
- const ExtensionList* extensions = service->extensions();
- for (ExtensionList::const_iterator it = extensions->begin();
+ const ExtensionSet* extensions = service->extensions();
+ for (ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
if ((*it)->is_theme() && (*it)->id() != current_theme) {
remove_list.push_back((*it)->id());
diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc
index 173945f..d35cecb 100644
--- a/chrome/browser/ui/browser_browsertest.cc
+++ b/chrome/browser/ui/browser_browsertest.cc
@@ -164,11 +164,12 @@ class BrowserTest : public ExtensionBrowserTest {
// Returns the app extension aptly named "App Test".
const Extension* GetExtension() {
- const ExtensionList* extensions =
+ const ExtensionSet* extensions =
browser()->profile()->GetExtensionService()->extensions();
- for (size_t i = 0; i < extensions->size(); ++i) {
- if ((*extensions)[i]->name() == "App Test")
- return (*extensions)[i];
+ for (ExtensionSet::const_iterator it = extensions->begin();
+ it != extensions->end(); ++it) {
+ if ((*it)->name() == "App Test")
+ return *it;
}
NOTREACHED();
return NULL;
diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
index 400078e..b251cd3 100644
--- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
+++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
@@ -540,10 +540,12 @@ void LocationBarViewMac::RefreshPageActionDecorations() {
if (!service)
return;
+ // Find all the page actions.
std::vector<ExtensionAction*> page_actions;
- for (size_t i = 0; i < service->extensions()->size(); ++i) {
- if (service->extensions()->at(i)->page_action())
- page_actions.push_back(service->extensions()->at(i)->page_action());
+ for (ExtensionSet::const_iterator it = service->extensions()->begin();
+ it != service->extensions()->end(); ++it) {
+ if ((*it)->page_action())
+ page_actions.push_back((*it)->page_action());
}
// On startup we sometimes haven't loaded any extensions. This makes sure
diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
index 30a04f9..83407de 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
@@ -642,9 +642,10 @@ void LocationBarViewGtk::UpdatePageActions() {
return;
// Find all the page actions.
- for (size_t i = 0; i < service->extensions()->size(); ++i) {
- if (service->extensions()->at(i)->page_action())
- page_actions.push_back(service->extensions()->at(i)->page_action());
+ for (ExtensionSet::const_iterator it = service->extensions()->begin();
+ it != service->extensions()->end(); ++it) {
+ if ((*it)->page_action())
+ page_actions.push_back((*it)->page_action());
}
// Initialize on the first call, or re-inialize if more extensions have been
diff --git a/chrome/browser/ui/views/browser_actions_container_browsertest.cc b/chrome/browser/ui/views/browser_actions_container_browsertest.cc
index 08b6133..0b7b04a 100644
--- a/chrome/browser/ui/views/browser_actions_container_browsertest.cc
+++ b/chrome/browser/ui/views/browser_actions_container_browsertest.cc
@@ -242,17 +242,14 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, ForceHide) {
IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, TestCrash57536) {
LOG(INFO) << "Test starting\n" << std::flush;
- ExtensionService* service = browser()->profile()->GetExtensionService();
- const size_t size_before = service->extensions()->size();
-
LOG(INFO) << "Loading extension\n" << std::flush;
// Load extension A (contains browser action).
- ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
- .AppendASCII("browser_action")
- .AppendASCII("crash_57536")));
-
- const Extension* extension = service->extensions()->at(size_before);
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("api_test")
+ .AppendASCII("browser_action")
+ .AppendASCII("crash_57536"));
+ ASSERT_TRUE(extension);
LOG(INFO) << "Creating bitmap\n" << std::flush;
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index 848cc5c..f05ee66 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -925,9 +925,10 @@ void LocationBarView::RefreshPageActionViews() {
// Remember the previous visibility of the page actions so that we can
// notify when this changes.
std::vector<ExtensionAction*> page_actions;
- for (size_t i = 0; i < service->extensions()->size(); ++i) {
- if (service->extensions()->at(i)->page_action())
- page_actions.push_back(service->extensions()->at(i)->page_action());
+ for (ExtensionSet::const_iterator it = service->extensions()->begin();
+ it != service->extensions()->end(); ++it) {
+ if ((*it)->page_action())
+ page_actions.push_back((*it)->page_action());
}
// On startup we sometimes haven't loaded any extensions. This makes sure
diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
index 02752d8..424bc0e 100644
--- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
+++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
@@ -331,11 +331,12 @@ void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) {
AutoReset<bool> auto_reset(&ignore_changes_, true);
ListValue* list = new ListValue();
- const ExtensionList* extensions = extension_service_->extensions();
- ExtensionList::const_iterator it;
+ const ExtensionSet* extensions = extension_service_->extensions();
+ ExtensionSet::const_iterator it;
for (it = extensions->begin(); it != extensions->end(); ++it) {
- if (!IsAppExcludedFromList(*it)) {
- DictionaryValue* app_info = GetAppInfo(*it);
+ const Extension* extension = *it;
+ if (!IsAppExcludedFromList(extension)) {
+ DictionaryValue* app_info = GetAppInfo(extension);
list->Append(app_info);
} else {
// This is necessary because in some previous versions of chrome, we set a
@@ -343,8 +344,8 @@ void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) {
// and this fixes it. If we don't fix it, GetNaturalAppPageIndex() doesn't
// work. See http://crbug.com/98325
ExtensionPrefs* prefs = extension_service_->extension_prefs();
- if (prefs->GetPageIndex((*it)->id()) != -1)
- prefs->ClearPageIndex((*it)->id());
+ if (prefs->GetPageIndex(extension->id()) != -1)
+ prefs->ClearPageIndex(extension->id());
}
}
diff --git a/chrome/browser/ui/webui/options/extension_settings_handler.cc b/chrome/browser/ui/webui/options/extension_settings_handler.cc
index 6dff20f..222f713 100644
--- a/chrome/browser/ui/webui/options/extension_settings_handler.cc
+++ b/chrome/browser/ui/webui/options/extension_settings_handler.cc
@@ -150,8 +150,8 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData(
ExtensionWarningSet* warnings = extension_service_->extension_warnings();
- const ExtensionList* extensions = extension_service_->extensions();
- for (ExtensionList::const_iterator extension = extensions->begin();
+ const ExtensionSet* extensions = extension_service_->extensions();
+ for (ExtensionSet::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
if (ShouldShowExtension(*extension)) {
extensions_list->Append(CreateExtensionDetailValue(
@@ -163,7 +163,7 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData(
}
}
extensions = extension_service_->disabled_extensions();
- for (ExtensionList::const_iterator extension = extensions->begin();
+ for (ExtensionSet::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
if (ShouldShowExtension(*extension)) {
extensions_list->Append(CreateExtensionDetailValue(
@@ -176,7 +176,7 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData(
}
extensions = extension_service_->terminated_extensions();
std::vector<ExtensionPage> empty_pages;
- for (ExtensionList::const_iterator extension = extensions->begin();
+ for (ExtensionSet::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
if (ShouldShowExtension(*extension)) {
extensions_list->Append(CreateExtensionDetailValue(
diff --git a/chrome/browser/ui/webui/options/search_engine_manager_handler.cc b/chrome/browser/ui/webui/options/search_engine_manager_handler.cc
index e73b26a..1748e3a 100644
--- a/chrome/browser/ui/webui/options/search_engine_manager_handler.cc
+++ b/chrome/browser/ui/webui/options/search_engine_manager_handler.cc
@@ -143,8 +143,8 @@ void SearchEngineManagerHandler::OnModelChanged() {
ExtensionService* extension_service =
Profile::FromWebUI(web_ui_)->GetExtensionService();
if (extension_service) {
- const ExtensionList* extensions = extension_service->extensions();
- for (ExtensionList::const_iterator it = extensions->begin();
+ const ExtensionSet* extensions = extension_service->extensions();
+ for (ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
if ((*it)->omnibox_keyword().size() > 0)
keyword_list.Append(CreateDictionaryForExtension(*(*it)));
diff --git a/chrome/common/extensions/extension_set.cc b/chrome/common/extensions/extension_set.cc
index 0231115..c99220b 100644
--- a/chrome/common/extensions/extension_set.cc
+++ b/chrome/common/extensions/extension_set.cc
@@ -29,6 +29,10 @@ size_t ExtensionSet::size() const {
return extensions_.size();
}
+bool ExtensionSet::is_empty() const {
+ return extensions_.empty();
+}
+
bool ExtensionSet::Contains(const std::string& extension_id) const {
return extensions_.find(extension_id) != extensions_.end();
}
@@ -41,7 +45,11 @@ void ExtensionSet::Remove(const std::string& id) {
extensions_.erase(id);
}
-std::string ExtensionSet::GetIdByURL(const ExtensionURLInfo& info) const {
+void ExtensionSet::Clear() {
+ extensions_.clear();
+}
+
+std::string ExtensionSet::GetIDByURL(const ExtensionURLInfo& info) const {
DCHECK(!info.origin().isNull());
if (info.url().SchemeIs(chrome::kExtensionScheme))
diff --git a/chrome/common/extensions/extension_set.h b/chrome/common/extensions/extension_set.h
index 5ca0344..3407557 100644
--- a/chrome/common/extensions/extension_set.h
+++ b/chrome/common/extensions/extension_set.h
@@ -6,9 +6,9 @@
#define CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_
#pragma once
+#include <iterator>
#include <map>
#include <string>
-#include <vector>
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
@@ -44,17 +44,39 @@ class ExtensionSet {
public:
typedef std::pair<FilePath, std::string> ExtensionPathAndDefaultLocale;
typedef std::map<std::string, scoped_refptr<const Extension> > ExtensionMap;
- typedef ExtensionMap::const_iterator const_iterator;
+
+ // Iteration over the values of the map (given that it's an ExtensionSet,
+ // it should iterate like a set iterator).
+ class const_iterator :
+ public std::iterator<std::input_iterator_tag,
+ scoped_refptr<const Extension> > {
+ public:
+ const_iterator() {}
+ explicit const_iterator(ExtensionMap::const_iterator it) :
+ it_(it) {}
+ const_iterator& operator++() {
+ ++it_;
+ return *this;
+ }
+ const scoped_refptr<const Extension> operator*() {
+ return it_->second;
+ }
+ bool operator!=(const const_iterator& other) { return it_ != other.it_; }
+ bool operator==(const const_iterator& other) { return it_ == other.it_; }
+
+ private:
+ ExtensionMap::const_iterator it_;
+ };
ExtensionSet();
~ExtensionSet();
- // Gets the number of extensions contained.
size_t size() const;
+ bool is_empty() const;
// Iteration support.
- const_iterator begin() const { return extensions_.begin(); }
- const_iterator end() const { return extensions_.end(); }
+ const_iterator begin() const { return const_iterator(extensions_.begin()); }
+ const_iterator end() const { return const_iterator(extensions_.end()); }
// Returns true if the set contains the specified extension.
bool Contains(const std::string& id) const;
@@ -66,9 +88,12 @@ class ExtensionSet {
// Removes the specified extension.
void Remove(const std::string& id);
+ // Removes all extensions.
+ void Clear();
+
// Returns the extension ID, or empty if none. This includes web URLs that
// are part of an extension's web extent.
- std::string GetIdByURL(const ExtensionURLInfo& info) const;
+ std::string GetIDByURL(const ExtensionURLInfo& info) const;
// Returns the Extension, or NULL if none. This includes web URLs that are
// part of an extension's web extent.
diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc
index cc003fd..c33b488 100644
--- a/chrome/renderer/extensions/extension_dispatcher.cc
+++ b/chrome/renderer/extensions/extension_dispatcher.cc
@@ -293,7 +293,7 @@ void ExtensionDispatcher::DidCreateScriptContext(
extension_id = user_script_slave_->GetExtensionIdForIsolatedWorld(world_id);
} else {
GURL frame_url = UserScriptSlave::GetDataSourceURLForFrame(frame);
- extension_id = extensions_.GetIdByURL(
+ extension_id = extensions_.GetIDByURL(
ExtensionURLInfo(frame->document().securityOrigin(), frame_url));
}