0

Revert 113047 - Make ExtensionService use ExtensionSet.

It broke ExtensionManagementApiBrowserTest.LaunchApp.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113071 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
yoz@chromium.org
2011-12-06 00:18:55 +00:00
parent 5ffbf69700
commit 1234043654
53 changed files with 490 additions and 504 deletions
chrome
browser
common
renderer

@ -98,9 +98,9 @@ void ExtensionAppProvider::RefreshAppList() {
ExtensionService* extension_service = profile_->GetExtensionService();
if (!extension_service)
return; // During testing, there is no extension service.
const ExtensionSet* extensions = extension_service->extensions();
const ExtensionList* extensions = extension_service->extensions();
extension_apps_.clear();
for (ExtensionSet::const_iterator app = extensions->begin();
for (ExtensionList::const_iterator app = extensions->begin();
app != extensions->end(); ++app) {
if ((*app)->is_app() && (*app)->GetFullLaunchURL().is_valid()) {
if (profile_->IsOffTheRecord() &&

@ -2017,11 +2017,11 @@ namespace {
// as identified from a given list of extensions. The caller takes ownership
// of the created vector.
std::vector<DictionaryValue*>* GetAppInfoFromExtensions(
const ExtensionSet* extensions,
const ExtensionList* extensions,
ExtensionService* ext_service) {
std::vector<DictionaryValue*>* apps_list =
new std::vector<DictionaryValue*>();
for (ExtensionSet::const_iterator ext = extensions->begin();
for (ExtensionList::const_iterator ext = extensions->begin();
ext != extensions->end(); ++ext) {
// Only return information about extensions that are actually apps.
if ((*ext)->is_app()) {
@ -2089,7 +2089,7 @@ NTPInfoObserver::NTPInfoObserver(
}
// Process enabled extensions.
ListValue* apps_list = new ListValue();
const ExtensionSet* extensions = ext_service->extensions();
const ExtensionList* extensions = ext_service->extensions();
std::vector<DictionaryValue*>* enabled_apps = GetAppInfoFromExtensions(
extensions, ext_service);
for (std::vector<DictionaryValue*>::const_iterator app =
@ -2099,7 +2099,7 @@ NTPInfoObserver::NTPInfoObserver(
}
delete enabled_apps;
// Process disabled extensions.
const ExtensionSet* disabled_extensions = ext_service->disabled_extensions();
const ExtensionList* disabled_extensions = ext_service->disabled_extensions();
std::vector<DictionaryValue*>* disabled_apps = GetAppInfoFromExtensions(
disabled_extensions, ext_service);
for (std::vector<DictionaryValue*>::const_iterator app =
@ -2109,7 +2109,7 @@ NTPInfoObserver::NTPInfoObserver(
}
delete disabled_apps;
// Process terminated extensions.
const ExtensionSet* terminated_extensions =
const ExtensionList* terminated_extensions =
ext_service->terminated_extensions();
std::vector<DictionaryValue*>* terminated_apps = GetAppInfoFromExtensions(
terminated_extensions, ext_service);

@ -4379,8 +4379,8 @@ void TestingAutomationProvider::GetExtensionsInfo(
}
scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
ListValue* extensions_values = new ListValue;
const ExtensionSet* extensions = service->extensions();
const ExtensionSet* disabled_extensions = service->disabled_extensions();
const ExtensionList* extensions = service->extensions();
const ExtensionList* disabled_extensions = service->disabled_extensions();
ExtensionList all;
all.insert(all.end(),
extensions->begin(),

@ -71,9 +71,9 @@ class BackgroundApplicationListModel::Application
namespace {
void GetServiceApplications(ExtensionService* service,
ExtensionList* applications_result) {
const ExtensionSet* extensions = service->extensions();
const ExtensionList* extensions = service->extensions();
for (ExtensionSet::const_iterator cursor = extensions->begin();
for (ExtensionList::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 (ExtensionSet::const_iterator cursor = extensions->begin();
for (ExtensionList::const_iterator cursor = extensions->begin();
cursor != extensions->end();
++cursor) {
const Extension* extension = *cursor;

@ -60,11 +60,8 @@ 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;
@ -108,7 +105,7 @@ TEST_F(BackgroundApplicationListModelTest, ExplicitTest) {
ASSERT_TRUE(service);
ASSERT_TRUE(service->is_ready());
ASSERT_TRUE(service->extensions());
ASSERT_TRUE(service->extensions()->is_empty());
ASSERT_TRUE(service->extensions()->empty());
scoped_ptr<BackgroundApplicationListModel> model(
new BackgroundApplicationListModel(profile_.get()));
ASSERT_EQ(0U, model->size());
@ -174,7 +171,7 @@ TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) {
ASSERT_TRUE(service);
ASSERT_TRUE(service->is_ready());
ASSERT_TRUE(service->extensions());
ASSERT_TRUE(service->extensions()->is_empty());
ASSERT_TRUE(service->extensions()->empty());
scoped_ptr<BackgroundApplicationListModel> model(
new BackgroundApplicationListModel(profile_.get()));
ASSERT_EQ(0U, model->size());
@ -313,7 +310,7 @@ TEST_F(BackgroundApplicationListModelTest, RandomTest) {
ASSERT_TRUE(service);
ASSERT_TRUE(service->is_ready());
ASSERT_TRUE(service->extensions());
ASSERT_TRUE(service->extensions()->is_empty());
ASSERT_TRUE(service->extensions()->empty());
scoped_ptr<BackgroundApplicationListModel> model(
new BackgroundApplicationListModel(profile_.get()));
ASSERT_EQ(0U, model->size());

@ -418,9 +418,9 @@ void BackgroundContentsService::LoadBackgroundContentsFromDictionary(
void BackgroundContentsService::LoadBackgroundContentsFromManifests(
Profile* profile) {
const ExtensionSet* extensions =
const ExtensionList* extensions =
profile->GetExtensionService()->extensions();
ExtensionSet::const_iterator iter = extensions->begin();
ExtensionList::const_iterator iter = extensions->begin();
for (; iter != extensions->end(); ++iter) {
const Extension* extension = *iter;
if (extension->is_hosted_app() &&

@ -414,9 +414,9 @@ void DevToolsWindow::AddDevToolsExtensionsToClient() {
if (!extension_service)
return;
const ExtensionSet* extensions = extension_service->extensions();
const ExtensionList* extensions = extension_service->extensions();
for (ExtensionSet::const_iterator extension = extensions->begin();
for (ExtensionList::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
if ((*extension)->devtools_url().is_empty())
continue;

@ -316,15 +316,12 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoDragging) {
const size_t size_before = service->extensions()->size();
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);
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")));
// Test that there are 3 browser actions in the toolbar.
ASSERT_EQ(size_before + 3, service->extensions()->size());
@ -332,8 +329,10 @@ 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(extension_a->id(), true);
service->extension_prefs()->SetIsIncognitoEnabled(extension_c->id(), true);
service->extension_prefs()->SetIsIncognitoEnabled(
service->extensions()->at(size_before)->id(), true);
service->extension_prefs()->SetIsIncognitoEnabled(
service->extensions()->at(size_before + 2)->id(), true);
Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
Browser* incognito_browser = Browser::Create(incognito_profile);
@ -356,7 +355,8 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoDragging) {
// regular and incognito mode.
// ABC -> CAB
service->toolbar_model()->MoveBrowserAction(extension_c, 0);
service->toolbar_model()->MoveBrowserAction(
service->extensions()->at(size_before + 2), 0);
EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0));
EXPECT_EQ(kTooltipA, GetBrowserActionsBar().GetTooltip(1));
@ -366,7 +366,8 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoDragging) {
EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1));
// CAB -> CBA
service->toolbar_model()->MoveBrowserAction(extension_b, 1);
service->toolbar_model()->MoveBrowserAction(
service->extensions()->at(size_before + 1), 1);
EXPECT_EQ(kTooltipC, GetBrowserActionsBar().GetTooltip(0));
EXPECT_EQ(kTooltipB, GetBrowserActionsBar().GetTooltip(1));

@ -11,7 +11,6 @@
#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"
@ -21,7 +20,7 @@ namespace {
class MockExtensionService : public TestExtensionService {
private:
bool ready_;
ExtensionSet extension_set_;
ExtensionList extension_list_;
public:
MockExtensionService() : ready_(false) {
@ -29,30 +28,37 @@ class MockExtensionService : public TestExtensionService {
virtual void AddExtension(const Extension* extension) OVERRIDE {
// ExtensionService must become the owner of the extension object.
extension_set_.Insert(extension);
extension_list_.push_back(extension);
}
virtual void UnloadExtension(
const std::string& extension_id,
extension_misc::UnloadedExtensionReason reason) OVERRIDE {
// Remove the extension with the matching id.
extension_set_.Remove(extension_id);
for (ExtensionList::iterator it = extension_list_.begin();
it != extension_list_.end();
++it) {
if ((*it)->id() == extension_id) {
extension_list_.erase(it);
return;
}
}
}
virtual bool is_ready() OVERRIDE {
return ready_;
}
virtual const ExtensionSet* extensions() const OVERRIDE {
return &extension_set_;
virtual const ExtensionList* extensions() const OVERRIDE {
return &extension_list_;
}
void set_ready(bool ready) {
ready_ = ready;
}
void clear_extensions() {
extension_set_.Clear();
void clear_extension_list() {
extension_list_.clear();
}
};
@ -211,7 +217,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_extensions();
extension_service_.clear_extension_list();
component_loader_.Add(manifest_contents_, extension_path_);
component_loader_.LoadAll();
@ -231,7 +237,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_extensions();
extension_service_.clear_extension_list();
component_loader_.ClearAllRegistered();
component_loader_.AddDefaultComponentExtensions();
component_loader_.LoadAll();

@ -202,29 +202,28 @@ bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name,
}
}
// Test that exactly one extension is loaded, and return it.
// Test that exactly one extension loaded.
const Extension* ExtensionApiTest::GetSingleLoadedExtension() {
ExtensionService* service = browser()->profile()->GetExtensionService();
const Extension* extension = NULL;
for (ExtensionSet::const_iterator it = service->extensions()->begin();
it != service->extensions()->end(); ++it) {
int found_extension_index = -1;
for (size_t i = 0; i < service->extensions()->size(); ++i) {
// Ignore any component extensions. They are automatically loaded into all
// profiles and aren't the extension we're looking for here.
if ((*it)->location() == Extension::COMPONENT)
if (service->extensions()->at(i)->location() == Extension::COMPONENT)
continue;
if (extension != NULL) {
// TODO(yoz): this is misleading; it counts component extensions.
if (found_extension_index != -1) {
message_ = base::StringPrintf(
"Expected only one extension to be present. Found %u.",
static_cast<unsigned>(service->extensions()->size()));
return NULL;
}
extension = *it;
found_extension_index = static_cast<int>(i);
}
const Extension* extension = service->extensions()->at(found_extension_index);
if (!extension) {
message_ = "extension pointer is NULL.";
return NULL;

@ -72,13 +72,13 @@ const Extension* ExtensionBrowserTest::LoadExtensionWithOptions(
ui_test_utils::RunMessageLoop();
}
// Find the loaded extension by its path. See crbug.com/59531 for why
// we cannot just use last_loaded_extension_id_.
// Find the extension by iterating backwards since it is likely last.
FilePath extension_path = path;
file_util::AbsolutePath(&extension_path);
const Extension* extension = NULL;
for (ExtensionSet::const_iterator iter = service->extensions()->begin();
iter != service->extensions()->end(); ++iter) {
for (ExtensionList::const_reverse_iterator iter =
service->extensions()->rbegin();
iter != service->extensions()->rend(); ++iter) {
if ((*iter)->path() == extension_path) {
extension = *iter;
break;
@ -296,9 +296,8 @@ const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
<< " num after: " << base::IntToString(num_after)
<< " Installed extensions follow:";
for (ExtensionSet::const_iterator it = service->extensions()->begin();
it != service->extensions()->end(); ++it)
VLOG(1) << " " << (*it)->id();
for (size_t i = 0; i < service->extensions()->size(); ++i)
VLOG(1) << " " << (*service->extensions())[i]->id();
VLOG(1) << "Errors follow:";
const std::vector<std::string>* errors =

@ -212,30 +212,29 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionRefreshCrash) {
FilePath base_path = test_data_dir_.AppendASCII("browsertest")
.AppendASCII("crash_44415");
// Load extension A.
const Extension* extensionA = LoadExtension(base_path.AppendASCII("ExtA"));
ASSERT_TRUE(extensionA);
ASSERT_TRUE(LoadExtension(base_path.AppendASCII("ExtA")));
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.
const Extension* extensionB = LoadExtension(base_path.AppendASCII("ExtB"));
ASSERT_TRUE(extensionB);
ASSERT_TRUE(LoadExtension(base_path.AppendASCII("ExtB")));
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()->GetByID(idA);
extensionA = service->extensions()->at(size_before + 1);
LOG(INFO) << "Reload extension A done: "
<< (base::TimeTicks::Now() - start_time).InMilliseconds()
@ -279,10 +278,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"));
const Extension* extension = LoadExtension(extension_path);
ASSERT_TRUE(extension);
ASSERT_TRUE(LoadExtension(extension_path));
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());
@ -303,8 +302,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) {
FilePath extension_path(test_data_dir_.AppendASCII("browsertest")
.AppendASCII("title_localized_pa"));
const Extension* extension = LoadExtension(extension_path);
ASSERT_TRUE(extension);
ASSERT_TRUE(LoadExtension(extension_path));
// Any navigation prompts the location bar to load the page action.
GURL url = test_server()->GetURL(kLocalization);
@ -312,6 +310,7 @@ 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());
@ -388,7 +387,6 @@ 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,
@ -398,9 +396,12 @@ 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, extension_id));
ui_test_utils::NavigateToURL(browser, GetFeedUrl(server, url, true, id));
TabContents* tab = browser->GetSelectedTabContents();
ASSERT_TRUE(ValidatePageElement(tab,
@ -424,12 +425,10 @@ void NavigateToFeedAndValidate(net::TestServer* server,
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed1) {
ASSERT_TRUE(test_server()->Start());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
NavigateToFeedAndValidate(test_server(), kValidFeed1, browser(), id, true,
NavigateToFeedAndValidate(test_server(), kValidFeed1, browser(), true,
"Feed for MyFeedTitle",
"Title 1",
"Desc",
@ -439,12 +438,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed1) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed2) {
ASSERT_TRUE(test_server()->Start());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
NavigateToFeedAndValidate(test_server(), kValidFeed2, browser(), id, true,
NavigateToFeedAndValidate(test_server(), kValidFeed2, browser(), true,
"Feed for MyFeed2",
"My item title1",
"This is a summary.",
@ -454,12 +451,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed2) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed3) {
ASSERT_TRUE(test_server()->Start());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
NavigateToFeedAndValidate(test_server(), kValidFeed3, browser(), id, true,
NavigateToFeedAndValidate(test_server(), kValidFeed3, browser(), true,
"Feed for Google Code buglist rss feed",
"My dear title",
"My dear content",
@ -469,12 +464,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed3) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed4) {
ASSERT_TRUE(test_server()->Start());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
NavigateToFeedAndValidate(test_server(), kValidFeed4, browser(), id, true,
NavigateToFeedAndValidate(test_server(), kValidFeed4, browser(), true,
"Feed for Title chars <script> %23 stop",
"Title chars %23 stop",
"My dear content %23 stop",
@ -484,14 +477,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed4) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed0) {
ASSERT_TRUE(test_server()->Start());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
// Try a feed with a link with an onclick handler (before r27440 this would
// trigger a NOTREACHED).
NavigateToFeedAndValidate(test_server(), kValidFeed0, browser(), id, true,
NavigateToFeedAndValidate(test_server(), kValidFeed0, browser(), true,
"Feed for MyFeedTitle",
"Title 1",
"Desc VIDEO",
@ -501,13 +492,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed0) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed5) {
ASSERT_TRUE(test_server()->Start());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
// Feed with valid but mostly empty xml.
NavigateToFeedAndValidate(test_server(), kValidFeed5, browser(), id, true,
NavigateToFeedAndValidate(test_server(), kValidFeed5, browser(), true,
"Feed for Unknown feed name",
"element 'anchor_0' not found",
"element 'desc_0' not found",
@ -517,13 +506,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed5) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed6) {
ASSERT_TRUE(test_server()->Start());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
// Feed that is technically invalid but still parseable.
NavigateToFeedAndValidate(test_server(), kValidFeed6, browser(), id, true,
NavigateToFeedAndValidate(test_server(), kValidFeed6, browser(), true,
"Feed for MyFeedTitle",
"Title 1",
"Desc",
@ -533,13 +520,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedValidFeed6) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed1) {
ASSERT_TRUE(test_server()->Start());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
// Try an empty feed.
NavigateToFeedAndValidate(test_server(), kInvalidFeed1, browser(), id, false,
NavigateToFeedAndValidate(test_server(), kInvalidFeed1, browser(), false,
"Feed for Unknown feed name",
"element 'anchor_0' not found",
"element 'desc_0' not found",
@ -549,13 +534,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed1) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed2) {
ASSERT_TRUE(test_server()->Start());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
// Try a garbage feed.
NavigateToFeedAndValidate(test_server(), kInvalidFeed2, browser(), id, false,
NavigateToFeedAndValidate(test_server(), kInvalidFeed2, browser(), false,
"Feed for Unknown feed name",
"element 'anchor_0' not found",
"element 'desc_0' not found",
@ -565,13 +548,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed2) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed3) {
ASSERT_TRUE(test_server()->Start());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
// Try a feed that doesn't exist.
NavigateToFeedAndValidate(test_server(), "foo.xml", browser(), id, false,
NavigateToFeedAndValidate(test_server(), "foo.xml", browser(), false,
"Feed for Unknown feed name",
"element 'anchor_0' not found",
"element 'desc_0' not found",
@ -581,10 +562,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed3) {
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeedInvalidFeed4) {
ASSERT_TRUE(test_server()->Start());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
// 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
@ -593,29 +572,25 @@ 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(), id, 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(), 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());
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(extension);
std::string id = extension->id();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
// Valid feed but containing no links.
NavigateToFeedAndValidate(
test_server(), kValidFeedNoLinks, browser(), id, true,
"Feed for MyFeedTitle",
"Title with no link",
"Desc",
"No error");
NavigateToFeedAndValidate(test_server(), kValidFeedNoLinks, browser(), true,
"Feed for MyFeedTitle",
"Title with no link",
"Desc",
"No error");
}
// Tests that an error raised during an async function still fires
@ -747,8 +722,7 @@ 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();
const Extension* extension = LoadExtension(extension_dir);
ASSERT_TRUE(extension);
ASSERT_TRUE(LoadExtension(extension_dir));
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.
@ -768,7 +742,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MAYBE_PluginLoadUnload) {
EXPECT_TRUE(result);
EXPECT_EQ(size_before + 1, service->extensions()->size());
UnloadExtension(extension->id());
UnloadExtension(service->extensions()->at(size_before)->id());
EXPECT_EQ(size_before, service->extensions()->size());
// Now the plugin should be unloaded, and the page should be broken.
@ -810,11 +784,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();
const Extension* extension = LoadExtension(extension_dir);
ASSERT_TRUE(extension);
ASSERT_TRUE(LoadExtension(extension_dir));
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();
@ -851,11 +825,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.
const Extension* extension =
InstallExtension(test_data_dir_.AppendASCII("options.crx"), 1);
ASSERT_TRUE(extension);
ASSERT_TRUE(InstallExtension(test_data_dir_.AppendASCII("options.crx"), 1));
ExtensionService* service = browser()->profile()->GetExtensionService();
ASSERT_EQ(1u, service->extensions()->size());
const ExtensionList* extensions = service->extensions();
ASSERT_EQ(1u, extensions->size());
const Extension* extension = extensions->at(0);
// Go to the Extension Settings page and click the Options button.
ui_test_utils::NavigateToURL(

@ -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 ExtensionSet* extensions =
const ExtensionList* extensions =
browser()->profile()->GetExtensionService()->extensions();
ExtensionSet::const_iterator i;
ExtensionList::const_iterator i;
for (i = extensions->begin(); i != extensions->end(); ++i) {
if ((*i)->name() == name) {
return *i;

@ -62,10 +62,12 @@ class ExtensionCrashRecoveryTest : public ExtensionBrowserTest {
return balloons.size();
}
void CrashExtension(std::string extension_id) {
void CrashExtension(size_t index) {
ASSERT_LT(index, GetExtensionService()->extensions()->size());
const Extension* extension =
GetExtensionService()->extensions()->GetByID(extension_id);
GetExtensionService()->extensions()->at(index);
ASSERT_TRUE(extension);
std::string extension_id(extension->id());
ExtensionHost* extension_host = GetExtensionProcessManager()->
GetBackgroundHostForExtension(extension_id);
ASSERT_TRUE(extension_host);
@ -79,36 +81,43 @@ class ExtensionCrashRecoveryTest : public ExtensionBrowserTest {
GetBackgroundHostForExtension(extension_id));
}
void CheckExtensionConsistency(std::string extension_id) {
void CheckExtensionConsistency(size_t index) {
ASSERT_LT(index, GetExtensionService()->extensions()->size());
const Extension* extension =
GetExtensionService()->extensions()->GetByID(extension_id);
GetExtensionService()->extensions()->at(index);
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 Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("common").AppendASCII("background_page"));
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();
ASSERT_TRUE(extension);
first_extension_id_ = extension->id();
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(size_before);
}
void LoadSecondExtension() {
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("install").AppendASCII("install"));
int offset = GetExtensionService()->extensions()->size();
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("install").AppendASCII("install")));
const Extension* extension =
GetExtensionService()->extensions()->at(offset);
ASSERT_TRUE(extension);
second_extension_id_ = extension->id();
CheckExtensionConsistency(second_extension_id_);
CheckExtensionConsistency(offset);
}
std::string first_extension_id_;
@ -120,14 +129,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) {
const size_t crash_size_before =
GetExtensionService()->terminated_extensions()->size();
LoadTestExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
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(first_extension_id_);
CheckExtensionConsistency(size_before);
ASSERT_EQ(crash_size_before,
GetExtensionService()->terminated_extensions()->size());
}
@ -137,7 +146,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CloseAndReload) {
const size_t crash_size_before =
GetExtensionService()->terminated_extensions()->size();
LoadTestExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
ASSERT_EQ(crash_size_before + 1,
@ -147,7 +156,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CloseAndReload) {
ReloadExtension(first_extension_id_);
SCOPED_TRACE("after reloading");
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(size_before);
ASSERT_EQ(crash_size_before,
GetExtensionService()->terminated_extensions()->size());
}
@ -155,13 +164,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(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
ReloadExtension(first_extension_id_);
SCOPED_TRACE("after reloading");
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(size_before);
TabContents* current_tab = browser()->GetSelectedTabContents();
ASSERT_TRUE(current_tab);
@ -175,7 +184,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
ReloadIndependentlyChangeTabs) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
TabContents* original_tab = browser()->GetSelectedTabContents();
@ -192,7 +201,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
ReloadExtension(first_extension_id_);
SCOPED_TRACE("after reloading");
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(size_before);
// The balloon should automatically hide after the extension is successfully
// reloaded.
@ -203,7 +212,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
ReloadIndependentlyNavigatePage) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
TabContents* current_tab = browser()->GetSelectedTabContents();
@ -219,7 +228,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
ReloadExtension(first_extension_id_);
SCOPED_TRACE("after reloading");
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(size_before);
// The balloon should automatically hide after the extension is successfully
// reloaded.
@ -240,7 +249,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(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
}
@ -248,26 +257,26 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashFirst) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
LoadSecondExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
AcceptNotification(0);
SCOPED_TRACE("after clicking the balloon");
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(second_extension_id_);
CheckExtensionConsistency(size_before);
CheckExtensionConsistency(size_before + 1);
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashSecond) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
LoadSecondExtension();
CrashExtension(second_extension_id_);
CrashExtension(size_before + 1);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
AcceptNotification(0);
SCOPED_TRACE("after clicking the balloon");
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(second_extension_id_);
CheckExtensionConsistency(size_before);
CheckExtensionConsistency(size_before + 1);
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
@ -277,11 +286,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
GetExtensionService()->terminated_extensions()->size();
LoadTestExtension();
LoadSecondExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
ASSERT_EQ(crash_size_before + 1,
GetExtensionService()->terminated_extensions()->size());
CrashExtension(second_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
ASSERT_EQ(crash_size_before + 2,
GetExtensionService()->terminated_extensions()->size());
@ -289,37 +298,37 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
{
SCOPED_TRACE("first balloon");
AcceptNotification(0);
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(size_before);
}
{
SCOPED_TRACE("second balloon");
AcceptNotification(0);
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(second_extension_id_);
CheckExtensionConsistency(size_before);
CheckExtensionConsistency(size_before + 1);
}
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsOneByOne) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
LoadSecondExtension();
CrashExtension(second_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
{
SCOPED_TRACE("first balloon");
AcceptNotification(0);
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(size_before);
}
{
SCOPED_TRACE("second balloon");
AcceptNotification(0);
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(second_extension_id_);
CheckExtensionConsistency(size_before);
CheckExtensionConsistency(size_before + 1);
}
}
@ -339,10 +348,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
MAYBE_TwoExtensionsShutdownWhileCrashed) {
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
LoadSecondExtension();
CrashExtension(second_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
}
@ -351,9 +360,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
LoadSecondExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
CrashExtension(second_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
// Accept notification 1 before canceling notification 0.
@ -364,7 +373,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
SCOPED_TRACE("balloons done");
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
CheckExtensionConsistency(second_extension_id_);
EXPECT_EQ(second_extension_id_,
GetExtensionService()->extensions()->at(size_before)->id());
CheckExtensionConsistency(size_before);
}
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
@ -372,9 +383,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
const size_t size_before = GetExtensionService()->extensions()->size();
LoadTestExtension();
LoadSecondExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
CrashExtension(second_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
{
@ -386,14 +397,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(first_extension_id_);
CheckExtensionConsistency(size_before);
}
{
SCOPED_TRACE("second: balloon");
AcceptNotification(0);
CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(second_extension_id_);
CheckExtensionConsistency(size_before);
CheckExtensionConsistency(size_before + 1);
}
}
@ -403,7 +414,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) {
GetExtensionService()->terminated_extensions()->size();
LoadTestExtension();
LoadSecondExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
ASSERT_EQ(crash_size_before + 1,
GetExtensionService()->terminated_extensions()->size());
@ -432,7 +443,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, MAYBE_CrashAndUnloadAll) {
GetExtensionService()->terminated_extensions()->size();
LoadTestExtension();
LoadSecondExtension();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
ASSERT_EQ(crash_size_before + 1,
GetExtensionService()->terminated_extensions()->size());
@ -460,7 +471,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
GURL("chrome-extension://" + first_extension_id_ + "/background.html"));
const int tabs_before = tab_strip->count();
CrashExtension(first_extension_id_);
CrashExtension(size_before);
// Tab should still be open, and extension should be crashed.
EXPECT_EQ(tabs_before, tab_strip->count());
@ -477,8 +488,6 @@ 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());
}

@ -130,10 +130,10 @@ bool GetFileBrowserHandlers(Profile* profile,
if (!service)
return false; // In unit-tests, we may not have an ExtensionService.
for (ExtensionSet::const_iterator iter = service->extensions()->begin();
for (ExtensionList::const_iterator iter = service->extensions()->begin();
iter != service->extensions()->end();
++iter) {
const Extension* extension = *iter;
const Extension* extension = iter->get();
if (!extension->file_browser_handlers())
continue;

@ -138,11 +138,11 @@ bool ExtensionInfoMap::SecurityOriginHasAPIPermission(
process_map_.Contains(id, process_id);
}
ExtensionSet::const_iterator i = extensions_.begin();
ExtensionSet::ExtensionMap::const_iterator i = extensions_.begin();
for (; i != extensions_.end(); ++i) {
if ((*i)->web_extent().MatchesSecurityOrigin(origin) &&
process_map_.Contains((*i)->id(), process_id) &&
(*i)->HasAPIPermission(permission)) {
if (i->second->web_extent().MatchesSecurityOrigin(origin) &&
process_map_.Contains(i->first, process_id) &&
i->second->HasAPIPermission(permission)) {
return true;
}
}

@ -123,10 +123,10 @@ static DictionaryValue* CreateExtensionInfo(const Extension& extension,
}
static void AddExtensionInfo(ListValue* list,
const ExtensionSet& extensions,
const ExtensionList& extensions,
bool enabled,
ExtensionPrefs* prefs) {
for (ExtensionSet::const_iterator i = extensions.begin();
for (ExtensionList::const_iterator i = extensions.begin();
i != extensions.end(); ++i) {
const Extension& extension = **i;

@ -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()->is_empty());
ASSERT_TRUE(service->disabled_extensions()->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()->is_empty());
ASSERT_TRUE(service->disabled_extensions()->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()->is_empty());
ASSERT_TRUE(service->disabled_extensions()->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()->is_empty());
ASSERT_TRUE(service->disabled_extensions()->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()->is_empty());
EXPECT_TRUE(service->disabled_extensions()->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()->is_empty());
EXPECT_TRUE(service->disabled_extensions()->empty());
}

@ -114,16 +114,15 @@ IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, MAYBE_OverrideHistory) {
// Regression test for http://crbug.com/41442.
IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, ShouldNotCreateDuplicateEntries) {
const Extension* extension =
LoadExtension(test_data_dir_.AppendASCII("override/history"));
ASSERT_TRUE(extension);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("override/history")));
// 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(),
extension->GetChromeURLOverrides());
browser()->profile()->GetExtensionService()->extensions()->back()->
GetChromeURLOverrides());
}
ASSERT_TRUE(CheckHistoryOverridesContainsNoDupes());
@ -161,9 +160,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, OverrideKeyboard) {
}
// Load the failing version. This should take precedence.
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("override").AppendASCII("keyboard_fails"));
ASSERT_TRUE(extension);
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("override").AppendASCII("keyboard_fails")));
{
ResultCatcher catcher;
NavigateToKeyboard();
@ -171,7 +169,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionOverrideTest, OverrideKeyboard) {
}
// Unload the failing version. We should be back to passing now.
UnloadExtension(extension->id());
const ExtensionList *extensions =
browser()->profile()->GetExtensionService()->extensions();
UnloadExtension((*extensions->rbegin())->id());
{
ResultCatcher catcher;
NavigateToKeyboard();

@ -309,8 +309,8 @@ void ExtensionPreferenceEventRouter::OnPrefChanged(
ExtensionEventRouter* router = profile_->GetExtensionEventRouter();
if (!router || !router->HasEventListener(event_name))
return;
const ExtensionSet* extensions = extension_service->extensions();
for (ExtensionSet::const_iterator it = extensions->begin();
const ExtensionList* extensions = extension_service->extensions();
for (ExtensionList::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
std::string extension_id = (*it)->id();
// TODO(bauerb): Only iterate over registered event listeners.

@ -74,8 +74,8 @@ static void CreateBackgroundHostForExtensionLoad(
}
static void CreateBackgroundHostsForProfileStartup(
ExtensionProcessManager* manager, const ExtensionSet* extensions) {
for (ExtensionSet::const_iterator extension = extensions->begin();
ExtensionProcessManager* manager, const ExtensionList* extensions) {
for (ExtensionList::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
CreateBackgroundHostForExtensionLoad(manager, *extension);
}

@ -444,15 +444,15 @@ ExtensionService::ExtensionService(Profile* profile,
install_directory_.value().length(), 0, 500, 100);
}
const ExtensionSet* ExtensionService::extensions() const {
const ExtensionList* ExtensionService::extensions() const {
return &extensions_;
}
const ExtensionSet* ExtensionService::disabled_extensions() const {
const ExtensionList* ExtensionService::disabled_extensions() const {
return &disabled_extensions_;
}
const ExtensionSet* ExtensionService::terminated_extensions() const {
const ExtensionList* ExtensionService::terminated_extensions() const {
return &terminated_extensions_;
}
@ -766,11 +766,14 @@ bool ExtensionService::UninstallExtension(
bool ExtensionService::IsExtensionEnabled(
const std::string& extension_id) const {
if (extensions_.Contains(extension_id) ||
terminated_extensions_.Contains(extension_id))
const Extension* extension =
GetExtensionByIdInternal(extension_id, true, false, true);
if (extension)
return true;
if (disabled_extensions_.Contains(extension_id))
extension =
GetExtensionByIdInternal(extension_id, false, true, false);
if (extension)
return false;
// If the extension hasn't been loaded yet, check the prefs for it. Assume
@ -800,8 +803,11 @@ void ExtensionService::EnableExtension(const std::string& extension_id) {
return;
// Move it over to the enabled list.
extensions_.Insert(make_scoped_refptr(extension));
disabled_extensions_.Remove(extension->id());
extensions_.push_back(make_scoped_refptr(extension));
ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
disabled_extensions_.end(),
extension);
disabled_extensions_.erase(iter);
// Make sure any browser action contained within it is not hidden.
extension_prefs_->SetBrowserActionVisibility(extension, true);
@ -831,11 +837,18 @@ void ExtensionService::DisableExtension(const std::string& extension_id) {
return;
// Move it over to the disabled list.
disabled_extensions_.Insert(make_scoped_refptr(extension));
if (extensions_.Contains(extension->id()))
extensions_.Remove(extension->id());
else
terminated_extensions_.Remove(extension->id());
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);
}
NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE);
@ -1102,7 +1115,7 @@ void ExtensionService::UpdateExtensionBlacklist(
extension_prefs_->UpdateBlacklist(blacklist_set);
std::vector<std::string> to_be_removed;
// Loop current extensions, unload installed extensions.
for (ExtensionSet::const_iterator iter = extensions_.begin();
for (ExtensionList::const_iterator iter = extensions_.begin();
iter != extensions_.end(); ++iter) {
const Extension* extension = (*iter);
if (blacklist_set.find(extension->id()) != blacklist_set.end()) {
@ -1145,7 +1158,7 @@ ExtensionUpdater* ExtensionService::updater() {
void ExtensionService::CheckAdminBlacklist() {
std::vector<std::string> to_be_removed;
// Loop through extensions list, unload installed extensions.
for (ExtensionSet::const_iterator iter = extensions_.begin();
for (ExtensionList::const_iterator iter = extensions_.begin();
iter != extensions_.end(); ++iter) {
const Extension* extension = (*iter);
if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id(),
@ -1346,10 +1359,10 @@ SyncError ExtensionService::ProcessSyncChanges(
}
void ExtensionService::GetSyncDataListHelper(
const ExtensionSet& extensions,
const ExtensionList& extensions,
const SyncBundle& bundle,
std::vector<ExtensionSyncData>* sync_data_list) const {
for (ExtensionSet::const_iterator it = extensions.begin();
for (ExtensionList::const_iterator it = extensions.begin();
it != extensions.end(); ++it) {
const Extension& extension = **it;
if (bundle.filter(extension) &&
@ -1480,7 +1493,8 @@ void ExtensionService::SetIsIncognitoEnabled(
extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
bool extension_is_enabled = extensions_.Contains(extension->id());
bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(),
extension) != extensions_.end();
// 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.
@ -1557,7 +1571,8 @@ void ExtensionService::SetAllowFileAccess(const Extension* extension,
extension_prefs_->SetAllowFileAccess(extension->id(), allow);
bool extension_is_enabled = extensions_.Contains(extension->id());
bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(),
extension) != extensions_.end();
if (extension_is_enabled)
ReloadExtension(extension->id());
}
@ -1661,9 +1676,12 @@ void ExtensionService::IdentifyAlertableExtensions() {
scoped_ptr<ExtensionGlobalError> global_error(
new ExtensionGlobalError(AsWeakPtr()));
bool needs_alert = false;
for (ExtensionSet::const_iterator iter = extensions_.begin();
for (ExtensionList::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());
@ -1763,10 +1781,13 @@ void ExtensionService::UnloadExtension(
// Clean up runtime data.
extension_runtime_data_.erase(extension_id);
if (disabled_extensions_.Contains(extension->id())) {
ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
disabled_extensions_.end(),
extension.get());
if (iter != disabled_extensions_.end()) {
UnloadedExtensionInfo details(extension, reason);
details.already_disabled = true;
disabled_extensions_.Remove(extension->id());
disabled_extensions_.erase(iter);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_UNLOADED,
content::Source<Profile>(profile_),
@ -1778,8 +1799,10 @@ if (disabled_extensions_.Contains(extension->id())) {
return;
}
// Remove the extension from our list.
extensions_.Remove(extension->id());
iter = std::find(extensions_.begin(), extensions_.end(), extension.get());
// Remove the extension from our list.
extensions_.erase(iter);
NotifyExtensionUnloaded(extension.get(), reason);
}
@ -1788,9 +1811,10 @@ void ExtensionService::UnloadAllExtensions() {
profile_->GetExtensionSpecialStoragePolicy()->
RevokeRightsForAllExtensions();
extensions_.Clear();
disabled_extensions_.Clear();
terminated_extensions_.Clear();
extensions_.clear();
disabled_extensions_.clear();
terminated_extension_ids_.clear();
terminated_extensions_.clear();
extension_runtime_data_.clear();
// TODO(erikkay) should there be a notification for this? We can't use
@ -1874,10 +1898,10 @@ void ExtensionService::AddExtension(const Extension* extension) {
bool disabled = extension_prefs_->IsExtensionDisabled(extension->id());
if (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.
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.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
content::Source<Profile>(profile_),
@ -1886,7 +1910,7 @@ void ExtensionService::AddExtension(const Extension* extension) {
return;
}
extensions_.Insert(scoped_extension);
extensions_.push_back(scoped_extension);
SyncExtensionChangeIfNeeded(*extension);
NotifyExtensionLoaded(extension);
IdentifyAlertableExtensions();
@ -1998,11 +2022,10 @@ void ExtensionService::InitializePermissions(const Extension* extension) {
void ExtensionService::UpdateActiveExtensionsInCrashReporter() {
std::set<std::string> extension_ids;
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());
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());
}
child_process_logging::SetActiveExtensions(extension_ids);
@ -2095,33 +2118,51 @@ const Extension* ExtensionService::GetExtensionByIdInternal(
bool include_terminated) const {
std::string lowercase_id = StringToLowerASCII(id);
if (include_enabled) {
const Extension* extension = extensions_.GetByID(lowercase_id);
if (extension)
return extension;
for (ExtensionList::const_iterator iter = extensions_.begin();
iter != extensions_.end(); ++iter) {
if ((*iter)->id() == lowercase_id)
return *iter;
}
}
if (include_disabled) {
const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
if (extension)
return extension;
for (ExtensionList::const_iterator iter = disabled_extensions_.begin();
iter != disabled_extensions_.end(); ++iter) {
if ((*iter)->id() == lowercase_id)
return *iter;
}
}
if (include_terminated) {
const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
if (extension)
return extension;
for (ExtensionList::const_iterator iter = terminated_extensions_.begin();
iter != terminated_extensions_.end(); ++iter) {
if ((*iter)->id() == lowercase_id)
return *iter;
}
}
return NULL;
}
void ExtensionService::TrackTerminatedExtension(const Extension* extension) {
if (!terminated_extensions_.Contains(extension->id()))
terminated_extensions_.Insert(make_scoped_refptr(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?
// 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);
terminated_extensions_.Remove(lowercase_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;
}
}
}
const Extension* ExtensionService::GetTerminatedExtension(
@ -2144,22 +2185,18 @@ const Extension* ExtensionService::GetExtensionByURL(const GURL& url) {
}
const Extension* ExtensionService::GetExtensionByWebExtent(const GURL& url) {
// 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;
for (size_t i = 0; i < extensions_.size(); ++i) {
if (extensions_[i]->web_extent().MatchesURL(url))
return extensions_[i];
}
return NULL;
}
const Extension* ExtensionService::GetDisabledExtensionByWebExtent(
const GURL& url) {
// 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;
for (size_t i = 0; i < disabled_extensions_.size(); ++i) {
if (disabled_extensions_[i]->web_extent().MatchesURL(url))
return disabled_extensions_[i];
}
return NULL;
}
@ -2180,11 +2217,9 @@ bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) {
const Extension* ExtensionService::GetExtensionByOverlappingWebExtent(
const URLPatternSet& extent) {
// 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;
for (size_t i = 0; i < extensions_.size(); ++i) {
if (extensions_[i]->web_extent().OverlapsWith(extent))
return extensions_[i];
}
return NULL;
@ -2319,9 +2354,9 @@ void ExtensionService::Observe(int type,
// Loaded extensions.
std::vector<ExtensionMsg_Loaded_Params> loaded_extensions;
for (ExtensionSet::const_iterator iter = extensions_.begin();
iter != extensions_.end(); ++iter) {
loaded_extensions.push_back(ExtensionMsg_Loaded_Params(*iter));
for (size_t i = 0; i < extensions_.size(); ++i) {
loaded_extensions.push_back(
ExtensionMsg_Loaded_Params(extensions_[i]));
}
process->Send(new ExtensionMsg_Loaded(loaded_extensions));
break;
@ -2372,7 +2407,7 @@ bool ExtensionService::HasApps() const {
ExtensionIdSet ExtensionService::GetAppIds() const {
ExtensionIdSet result;
for (ExtensionSet::const_iterator it = extensions_.begin();
for (ExtensionList::const_iterator it = extensions_.begin();
it != extensions_.end(); ++it) {
if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT)
result.insert((*it)->id());

@ -41,7 +41,6 @@
#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"
@ -87,7 +86,7 @@ class ExtensionServiceInterface : public SyncableService {
typedef bool (*ExtensionFilter)(const Extension&);
virtual ~ExtensionServiceInterface() {}
virtual const ExtensionSet* extensions() const = 0;
virtual const ExtensionList* extensions() const = 0;
virtual PendingExtensionManager* pending_extension_manager() = 0;
// Install an update. Return true if the install can be started.
@ -193,9 +192,9 @@ class ExtensionService
virtual ~ExtensionService();
// Gets the list of currently installed extensions.
virtual const ExtensionSet* extensions() const OVERRIDE;
const ExtensionSet* disabled_extensions() const;
const ExtensionSet* terminated_extensions() const;
virtual const ExtensionList* extensions() const OVERRIDE;
const ExtensionList* disabled_extensions() const;
const ExtensionList* terminated_extensions() const;
// Gets the object managing the set of pending extensions.
virtual PendingExtensionManager* pending_extension_manager() OVERRIDE;
@ -631,7 +630,7 @@ class ExtensionService
// Appends sync data objects for every extension in |extensions|
// that passes |filter|.
void GetSyncDataListHelper(
const ExtensionSet& extensions,
const ExtensionList& extensions,
const SyncBundle& bundle,
std::vector<ExtensionSyncData>* sync_data_list) const;
@ -691,13 +690,16 @@ class ExtensionService
// The current list of installed extensions.
// TODO(aa): This should use chrome/common/extensions/extension_set.h.
ExtensionSet extensions_;
ExtensionList extensions_;
// The list of installed extensions that have been disabled.
ExtensionSet disabled_extensions_;
ExtensionList disabled_extensions_;
// The list of installed extensions that have been terminated.
ExtensionSet terminated_extensions_;
ExtensionList terminated_extensions_;
// Used to quickly check if an extension was terminated.
std::set<std::string> terminated_extension_ids_;
// Hold the set of pending extensions.
PendingExtensionManager pending_extension_manager_;

@ -1874,7 +1874,7 @@ TEST_F(ExtensionServiceTest, UpdateApps) {
TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
InitializeEmptyExtensionService();
InitializeRequestContext();
EXPECT_TRUE(service_->extensions()->is_empty());
EXPECT_TRUE(service_->extensions()->empty());
int pref_count = 0;
@ -1925,7 +1925,7 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
InitializeEmptyExtensionService();
InitializeRequestContext();
EXPECT_TRUE(service_->extensions()->is_empty());
EXPECT_TRUE(service_->extensions()->empty());
int pref_count = 0;
@ -1954,7 +1954,7 @@ TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
UninstallExtension(id2, false);
EXPECT_TRUE(service_->extensions()->is_empty());
EXPECT_TRUE(service_->extensions()->empty());
EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
IsStorageProtected(origin1));
EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
@ -2675,18 +2675,18 @@ TEST_F(ExtensionServiceTest, DisableExtension) {
InitializeEmptyExtensionService();
InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
EXPECT_FALSE(service_->extensions()->is_empty());
EXPECT_FALSE(service_->extensions()->empty());
EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
EXPECT_TRUE(service_->disabled_extensions()->is_empty());
EXPECT_TRUE(service_->disabled_extensions()->empty());
// Disable it.
service_->DisableExtension(good_crx);
EXPECT_TRUE(service_->extensions()->is_empty());
EXPECT_TRUE(service_->extensions()->empty());
EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
EXPECT_FALSE(service_->GetExtensionById(good_crx, false));
EXPECT_FALSE(service_->disabled_extensions()->is_empty());
EXPECT_FALSE(service_->disabled_extensions()->empty());
}
TEST_F(ExtensionServiceTest, DisableTerminatedExtension) {
@ -2701,7 +2701,7 @@ TEST_F(ExtensionServiceTest, DisableTerminatedExtension) {
EXPECT_FALSE(service_->GetTerminatedExtension(good_crx));
EXPECT_TRUE(service_->GetExtensionById(good_crx, true));
EXPECT_FALSE(service_->disabled_extensions()->is_empty());
EXPECT_FALSE(service_->disabled_extensions()->empty());
}
// Tests disabling all extensions (simulating --disable-extensions flag).

@ -83,9 +83,8 @@ class ExtensionStartupTestBase : public InProcessBrowserTest {
// Count the number of non-component extensions.
int found_extensions = 0;
for (ExtensionSet::const_iterator it = service->extensions()->begin();
it != service->extensions()->end(); ++it)
if ((*it)->location() != Extension::COMPONENT)
for (size_t i = 0; i < service->extensions()->size(); i++)
if (service->extensions()->at(i)->location() != Extension::COMPONENT)
found_extensions++;
ASSERT_EQ(static_cast<uint32>(num_expected_extensions),
@ -164,25 +163,17 @@ 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 (ExtensionSet::const_iterator it = service->extensions()->begin();
it != service->extensions()->end(); ++it) {
if ((*it)->location() == Extension::COMPONENT)
for (size_t i = 0; i < service->extensions()->size(); ++i) {
if (service->extensions()->at(i)->location() == Extension::COMPONENT)
continue;
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();
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();
}
}
TestInjection(false, false);

@ -98,9 +98,9 @@ void ExtensionTabHelper::DidNavigateMainFrame(
if (!service)
return;
for (ExtensionSet::const_iterator it = service->extensions()->begin();
it != service->extensions()->end(); ++it) {
ExtensionAction* browser_action = (*it)->browser_action();
for (size_t i = 0; i < service->extensions()->size(); ++i) {
ExtensionAction* browser_action =
service->extensions()->at(i)->browser_action();
if (browser_action) {
browser_action->ClearAllValuesForTab(
wrapper_->restore_tab_helper()->session_id().id());
@ -110,7 +110,8 @@ void ExtensionTabHelper::DidNavigateMainFrame(
content::NotificationService::NoDetails());
}
ExtensionAction* page_action = (*it)->page_action();
ExtensionAction* page_action =
service->extensions()->at(i)->page_action();
if (page_action) {
page_action->ClearAllValuesForTab(
wrapper_->restore_tab_helper()->session_id().id());

@ -181,9 +181,8 @@ void ExtensionToolbarModel::InitializeExtensionList() {
ExtensionList unsorted;
// Create the lists.
for (ExtensionSet::const_iterator it = service_->extensions()->begin();
it != service_->extensions()->end(); ++it) {
const Extension* extension = *it;
for (size_t i = 0; i < service_->extensions()->size(); ++i) {
const Extension* extension = service_->extensions()->at(i);
if (!extension->browser_action())
continue;
if (!service_->GetBrowserActionVisibility(extension))

@ -28,8 +28,8 @@ void GetExtensionVoices(Profile* profile, ListValue* result_voices) {
ExtensionEventRouter* event_router = profile->GetExtensionEventRouter();
DCHECK(event_router);
const ExtensionSet* extensions = service->extensions();
ExtensionSet::const_iterator iter;
const ExtensionList* extensions = service->extensions();
ExtensionList::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 ExtensionSet* extensions = service->extensions();
ExtensionSet::const_iterator iter;
const ExtensionList* extensions = service->extensions();
ExtensionList::const_iterator iter;
for (iter = extensions->begin(); iter != extensions->end(); ++iter) {
const Extension* extension = *iter;

@ -1025,8 +1025,8 @@ void ExtensionUpdater::CheckNow() {
}
}
const ExtensionSet* extensions = service_->extensions();
for (ExtensionSet::const_iterator iter = extensions->begin();
const ExtensionList* extensions = service_->extensions();
for (ExtensionList::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

@ -153,10 +153,16 @@ class ServiceForManifestTests : public MockService {
virtual const Extension* GetExtensionById(
const std::string& id, bool include_disabled) const OVERRIDE {
return extensions_.GetByID(id);
for (ExtensionList::const_iterator iter = extensions_.begin();
iter != extensions_.end(); ++iter) {
if ((*iter)->id() == id) {
return *iter;
}
}
return NULL;
}
virtual const ExtensionSet* extensions() const OVERRIDE {
virtual const ExtensionList* extensions() const OVERRIDE {
return &extensions_;
}
@ -165,14 +171,11 @@ class ServiceForManifestTests : public MockService {
}
void set_extensions(ExtensionList extensions) {
for (ExtensionList::const_iterator it = extensions.begin();
it != extensions.end(); ++it) {
extensions_.Insert(*it);
}
extensions_ = extensions;
}
private:
ExtensionSet extensions_;
ExtensionList extensions_;
};
class ServiceForDownloadTests : public MockService {

@ -1697,9 +1697,9 @@ void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host) {
bool adblock = false;
bool adblock_plus = false;
bool other = false;
const ExtensionSet* extensions =
const ExtensionList* extensions =
profile->GetExtensionService()->extensions();
for (ExtensionSet::const_iterator it = extensions->begin();
for (ExtensionList::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
if (profile->GetExtensionService()->HasUsedWebRequest(*it)) {
if ((*it)->name().find("Adblock Plus") != std::string::npos) {

@ -181,8 +181,8 @@ void InstalledLoader::LoadAllExtensions() {
int theme_count = 0;
int page_action_count = 0;
int browser_action_count = 0;
const ExtensionSet* extensions = extension_service_->extensions();
ExtensionSet::const_iterator ex;
const ExtensionList* extensions = extension_service_->extensions();
ExtensionList::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, "Extensions.Permissions_Load");
ex->get(), "Extensions.Permissions_Load");
}
UMA_HISTOGRAM_COUNTS_100("Extensions.LoadApp",
app_user_count + app_external_count);

@ -127,9 +127,9 @@ class NetworkDelayListenerTest
void LoadTestExtension1() {
LoadTestExtension(kTestExtensionId1);
ASSERT_FALSE(service_->extensions()->is_empty());
extension1_ = service_->extensions()->GetByID(kTestExtensionId1);
ASSERT_TRUE(extension1_);
ASSERT_FALSE(service_->extensions()->empty());
extension1_ = service_->extensions()->at(0).get();
ASSERT_FALSE(extension1_ == NULL);
}
void SendExtensionLoadedNotification(const Extension* extension) {
@ -197,9 +197,8 @@ TEST_F(NetworkDelayListenerTest, TwoBlockingExtensions) {
LoadTestExtension1();
LoadTestExtension(kTestExtensionId2);
ASSERT_EQ(2u, service_->extensions()->size());
const Extension* extension2 =
service_->extensions()->GetByID(kTestExtensionId2);
ASSERT_TRUE(extension2);
const Extension* extension2 = service_->extensions()->at(1).get();
ASSERT_FALSE(extension2 == NULL);
TestDelegate delegate;
scoped_ptr<TestURLRequest> request(StartTestRequest(&delegate, kTestUrl));
@ -232,7 +231,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()->is_empty());
ASSERT_FALSE(service_->extensions()->empty());
TestDelegate delegate;
scoped_ptr<TestURLRequest> request(StartTestRequest(&delegate, kTestUrl));

@ -9,7 +9,7 @@
TestExtensionService::~TestExtensionService() {}
const ExtensionSet* TestExtensionService::extensions() const {
const ExtensionList* TestExtensionService::extensions() const {
ADD_FAILURE();
return NULL;
}

@ -21,7 +21,7 @@ class TestExtensionService : public ExtensionServiceInterface {
virtual ~TestExtensionService();
// ExtensionServiceInterface implementation.
virtual const ExtensionSet* extensions() const OVERRIDE;
virtual const ExtensionList* extensions() const OVERRIDE;
virtual PendingExtensionManager* pending_extension_manager() OVERRIDE;
virtual bool UpdateExtension(

@ -194,12 +194,15 @@ void UnpackedInstaller::OnLoaded(
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!service_weak_.get())
return;
const ExtensionSet* disabled_extensions =
const ExtensionList* disabled_extensions =
service_weak_->disabled_extensions();
if (service_weak_->show_extensions_prompts() &&
prompt_for_plugins_ &&
!extension->plugins().empty() &&
disabled_extensions->Contains(extension->id())) {
std::find(disabled_extensions->begin(),
disabled_extensions->end(),
extension) !=
disabled_extensions->end()) {
SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt(
service_weak_->profile(),
service_weak_,

@ -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 (ExtensionSet::const_iterator it = service->extensions()->begin();
for (ExtensionList::const_iterator it = service->extensions()->begin();
it != service->extensions()->end(); ++it) {
if (*it != unloaded_extension)
CollectURLPatterns(*it, &new_patterns);

@ -138,8 +138,8 @@ class UserScriptListenerTest
}
void UnloadTestExtension() {
ASSERT_FALSE(service_->extensions()->is_empty());
service_->UnloadExtension((*service_->extensions()->begin())->id(),
ASSERT_FALSE(service_->extensions()->empty());
service_->UnloadExtension(service_->extensions()->at(0)->id(),
extension_misc::UNLOAD_REASON_DISABLE);
}

@ -81,9 +81,9 @@ void WebIntentsRegistry::OnWebDataServiceRequestDone(
// Loop over all intents in all extensions, collect ones matching the query.
if (extension_service_) {
const ExtensionSet* extensions = extension_service_->extensions();
const ExtensionList* extensions = extension_service_->extensions();
if (extensions) {
for (ExtensionSet::const_iterator i(extensions->begin());
for (ExtensionList::const_iterator i(extensions->begin());
i != extensions->end(); ++i) {
const IntentServiceList& intents((*i)->intents_services());
for (IntentServiceList::const_iterator j(intents.begin());

@ -11,7 +11,6 @@
#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"
@ -22,17 +21,37 @@ using webkit_glue::WebIntentServiceData;
class MockExtensionService: public TestExtensionService {
public:
virtual ~MockExtensionService() {}
MOCK_CONST_METHOD0(extensions, const ExtensionSet*());
MOCK_CONST_METHOD0(extensions, const ExtensionList*());
};
// TODO(groby): Unify loading functions with extension_manifest_unittest code.
DictionaryValue* LoadManifestFile(const std::string& filename,
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 {
// TODO(groby): Unify loading functions with extension_manifest_unittest code.
DictionaryValue* LoadManifestFile(const FilePath& path,
std::string* error) {
EXPECT_TRUE(file_util::PathExists(path));
JSONFileValueSerializer serializer(path);
return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error));
scoped_refptr<Extension> LoadExtensionWithLocation(
DictionaryValue* value,
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");
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(
@ -40,23 +59,11 @@ scoped_refptr<Extension> LoadExtensionWithLocation(
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")
.AppendASCII(name.c_str());
scoped_ptr<DictionaryValue> value(LoadManifestFile(path, error));
scoped_ptr<DictionaryValue> value(LoadManifestFile(name, error));
if (!value.get())
return NULL;
int flags = Extension::NO_FLAGS;
if (strict_error_checks)
flags |= Extension::STRICT_ERROR_CHECKS;
return Extension::CreateWithId(path.DirName(),
location,
*value,
flags,
Extension::GenerateIdForPath(path),
error);
return LoadExtensionWithLocation(value.get(), location,
strict_error_checks, error);
}
scoped_refptr<Extension> LoadExtension(const std::string& name,
@ -107,7 +114,7 @@ class WebIntentsRegistryTest : public testing::Test {
content::TestBrowserThread db_thread_;
scoped_refptr<WebDataService> wds_;
MockExtensionService extension_service_;
ExtensionSet extensions_;
ExtensionList extensions_;
WebIntentsRegistry registry_;
ScopedTempDir temp_dir_;
};
@ -206,9 +213,8 @@ TEST_F(WebIntentsRegistryTest, GetAllIntents) {
}
TEST_F(WebIntentsRegistryTest, GetExtensionIntents) {
extensions_.Insert(LoadAndExpectSuccess("intent_valid.json"));
extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json"));
ASSERT_EQ(2U, extensions_.size());
extensions_.push_back(LoadAndExpectSuccess("intent_valid.json"));
extensions_.push_back(LoadAndExpectSuccess("intent_valid_2.json"));
TestConsumer consumer;
consumer.expected_id_ = registry_.GetAllIntentProviders(&consumer);
@ -217,9 +223,8 @@ TEST_F(WebIntentsRegistryTest, GetExtensionIntents) {
}
TEST_F(WebIntentsRegistryTest, GetSomeExtensionIntents) {
extensions_.Insert(LoadAndExpectSuccess("intent_valid.json"));
extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json"));
ASSERT_EQ(2U, extensions_.size());
extensions_.push_back(LoadAndExpectSuccess("intent_valid.json"));
extensions_.push_back(LoadAndExpectSuccess("intent_valid_2.json"));
TestConsumer consumer;
consumer.expected_id_ = registry_.GetIntentProviders(
@ -230,9 +235,8 @@ TEST_F(WebIntentsRegistryTest, GetSomeExtensionIntents) {
}
TEST_F(WebIntentsRegistryTest, GetIntentsFromMixedSources) {
extensions_.Insert(LoadAndExpectSuccess("intent_valid.json"));
extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json"));
ASSERT_EQ(2U, extensions_.size());
extensions_.push_back(LoadAndExpectSuccess("intent_valid.json"));
extensions_.push_back(LoadAndExpectSuccess("intent_valid_2.json"));
webkit_glue::WebIntentServiceData service;
service.service_url = GURL("http://somewhere.com/intent/edit.html");

@ -78,22 +78,22 @@ std::vector<std::string> SyncExtensionHelper::GetInstalledExtensionNames(
std::vector<std::string> names;
ExtensionService* extension_service = profile->GetExtensionService();
const ExtensionSet* extensions = extension_service->extensions();
for (ExtensionSet::const_iterator it = extensions->begin();
const ExtensionList* extensions = extension_service->extensions();
for (ExtensionList::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
names.push_back((*it)->name());
}
const ExtensionSet* disabled_extensions =
const ExtensionList* disabled_extensions =
extension_service->disabled_extensions();
for (ExtensionSet::const_iterator it = disabled_extensions->begin();
for (ExtensionList::const_iterator it = disabled_extensions->begin();
it != disabled_extensions->end(); ++it) {
names.push_back((*it)->name());
}
const ExtensionSet* terminated_extensions =
const ExtensionList* terminated_extensions =
extension_service->terminated_extensions();
for (ExtensionSet::const_iterator it = terminated_extensions->begin();
for (ExtensionList::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 ExtensionSet* extensions = extension_service->extensions();
for (ExtensionSet::const_iterator it = extensions->begin();
const ExtensionList* extensions = extension_service->extensions();
for (ExtensionList::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 ExtensionSet* disabled_extensions =
const ExtensionList* disabled_extensions =
extension_service->disabled_extensions();
for (ExtensionSet::const_iterator it = disabled_extensions->begin();
for (ExtensionList::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;

@ -338,8 +338,8 @@ void ThemeService::RemoveUnusedThemes() {
return;
std::string current_theme = GetThemeID();
std::vector<std::string> remove_list;
const ExtensionSet* extensions = service->extensions();
for (ExtensionSet::const_iterator it = extensions->begin();
const ExtensionList* extensions = service->extensions();
for (ExtensionList::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
if ((*it)->is_theme() && (*it)->id() != current_theme) {
remove_list.push_back((*it)->id());

@ -164,12 +164,11 @@ class BrowserTest : public ExtensionBrowserTest {
// Returns the app extension aptly named "App Test".
const Extension* GetExtension() {
const ExtensionSet* extensions =
const ExtensionList* extensions =
browser()->profile()->GetExtensionService()->extensions();
for (ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
if ((*it)->name() == "App Test")
return *it;
for (size_t i = 0; i < extensions->size(); ++i) {
if ((*extensions)[i]->name() == "App Test")
return (*extensions)[i];
}
NOTREACHED();
return NULL;

@ -540,12 +540,10 @@ void LocationBarViewMac::RefreshPageActionDecorations() {
if (!service)
return;
// Find all the page actions.
std::vector<ExtensionAction*> page_actions;
for (ExtensionSet::const_iterator it = service->extensions()->begin();
it != service->extensions()->end(); ++it) {
if ((*it)->page_action())
page_actions.push_back((*it)->page_action());
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());
}
// On startup we sometimes haven't loaded any extensions. This makes sure

@ -642,10 +642,9 @@ void LocationBarViewGtk::UpdatePageActions() {
return;
// Find all the page actions.
for (ExtensionSet::const_iterator it = service->extensions()->begin();
it != service->extensions()->end(); ++it) {
if ((*it)->page_action())
page_actions.push_back((*it)->page_action());
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());
}
// Initialize on the first call, or re-inialize if more extensions have been

@ -242,14 +242,17 @@ 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).
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("crash_57536"));
ASSERT_TRUE(extension);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("crash_57536")));
const Extension* extension = service->extensions()->at(size_before);
LOG(INFO) << "Creating bitmap\n" << std::flush;

@ -925,10 +925,9 @@ 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 (ExtensionSet::const_iterator it = service->extensions()->begin();
it != service->extensions()->end(); ++it) {
if ((*it)->page_action())
page_actions.push_back((*it)->page_action());
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());
}
// On startup we sometimes haven't loaded any extensions. This makes sure

@ -326,12 +326,11 @@ void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) {
AutoReset<bool> auto_reset(&ignore_changes_, true);
ListValue* list = new ListValue();
const ExtensionSet* extensions = extension_service_->extensions();
ExtensionSet::const_iterator it;
const ExtensionList* extensions = extension_service_->extensions();
ExtensionList::const_iterator it;
for (it = extensions->begin(); it != extensions->end(); ++it) {
const Extension* extension = *it;
if (!IsAppExcludedFromList(extension)) {
DictionaryValue* app_info = GetAppInfo(extension);
if (!IsAppExcludedFromList(*it)) {
DictionaryValue* app_info = GetAppInfo(*it);
list->Append(app_info);
} else {
// This is necessary because in some previous versions of chrome, we set a
@ -339,8 +338,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(extension->id()) != -1)
prefs->ClearPageIndex(extension->id());
if (prefs->GetPageIndex((*it)->id()) != -1)
prefs->ClearPageIndex((*it)->id());
}
}

@ -150,8 +150,8 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData(
ExtensionWarningSet* warnings = extension_service_->extension_warnings();
const ExtensionSet* extensions = extension_service_->extensions();
for (ExtensionSet::const_iterator extension = extensions->begin();
const ExtensionList* extensions = extension_service_->extensions();
for (ExtensionList::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 (ExtensionSet::const_iterator extension = extensions->begin();
for (ExtensionList::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 (ExtensionSet::const_iterator extension = extensions->begin();
for (ExtensionList::const_iterator extension = extensions->begin();
extension != extensions->end(); ++extension) {
if (ShouldShowExtension(*extension)) {
extensions_list->Append(CreateExtensionDetailValue(

@ -143,8 +143,8 @@ void SearchEngineManagerHandler::OnModelChanged() {
ExtensionService* extension_service =
Profile::FromWebUI(web_ui_)->GetExtensionService();
if (extension_service) {
const ExtensionSet* extensions = extension_service->extensions();
for (ExtensionSet::const_iterator it = extensions->begin();
const ExtensionList* extensions = extension_service->extensions();
for (ExtensionList::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
if ((*it)->omnibox_keyword().size() > 0)
keyword_list.Append(CreateDictionaryForExtension(*(*it)));

@ -29,10 +29,6 @@ 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();
}
@ -45,11 +41,7 @@ void ExtensionSet::Remove(const std::string& id) {
extensions_.erase(id);
}
void ExtensionSet::Clear() {
extensions_.clear();
}
std::string ExtensionSet::GetIDByURL(const ExtensionURLInfo& info) const {
std::string ExtensionSet::GetIdByURL(const ExtensionURLInfo& info) const {
DCHECK(!info.origin().isNull());
if (info.url().SchemeIs(chrome::kExtensionScheme))

@ -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,39 +44,17 @@ class ExtensionSet {
public:
typedef std::pair<FilePath, std::string> ExtensionPathAndDefaultLocale;
typedef std::map<std::string, scoped_refptr<const Extension> > ExtensionMap;
// 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_;
};
typedef ExtensionMap::const_iterator const_iterator;
ExtensionSet();
~ExtensionSet();
// Gets the number of extensions contained.
size_t size() const;
bool is_empty() const;
// Iteration support.
const_iterator begin() const { return const_iterator(extensions_.begin()); }
const_iterator end() const { return const_iterator(extensions_.end()); }
const_iterator begin() const { return extensions_.begin(); }
const_iterator end() const { return extensions_.end(); }
// Returns true if the set contains the specified extension.
bool Contains(const std::string& id) const;
@ -88,12 +66,9 @@ 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.

@ -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));
}