summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/extensions/extension_process_manager.cc23
-rw-r--r--chrome/browser/extensions/extension_shelf_model_unittest.cc25
-rw-r--r--chrome/browser/extensions/extensions_service.cc23
-rw-r--r--chrome/browser/extensions/extensions_service.h8
-rw-r--r--chrome/browser/profile.cc4
-rw-r--r--chrome/browser/profile.h1
-rw-r--r--chrome/browser/views/extensions/extension_view.cc3
7 files changed, 52 insertions, 35 deletions
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index 774d3a9e..e655057 100644
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -25,19 +25,22 @@ static void CreateBackgroundHosts(
ExtensionProcessManager::ExtensionProcessManager(Profile* profile)
: browsing_instance_(new BrowsingInstance(profile)) {
+ registrar_.Add(this, NotificationType::EXTENSIONS_READY,
+ NotificationService::AllSources());
registrar_.Add(this, NotificationType::EXTENSIONS_LOADED,
NotificationService::AllSources());
registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
NotificationService::AllSources());
- if (profile->GetExtensionsService())
- CreateBackgroundHosts(this, profile->GetExtensionsService()->extensions());
+ ExtensionsService* service = profile->GetExtensionsService();
+ if (service && service->is_ready())
+ CreateBackgroundHosts(this, service->extensions());
}
ExtensionProcessManager::~ExtensionProcessManager() {
// Copy all_hosts_ to avoid iterator invalidation issues.
- ExtensionHostSet to_delete(all_hosts_.begin(),
- all_hosts_.end());
+ ExtensionHostSet to_delete(background_hosts_.begin(),
+ background_hosts_.end());
ExtensionHostSet::iterator iter;
for (iter = to_delete.begin(); iter != to_delete.end(); ++iter)
delete *iter;
@@ -85,9 +88,17 @@ void ExtensionProcessManager::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
switch (type.value) {
+ case NotificationType::EXTENSIONS_READY:
+ CreateBackgroundHosts(this,
+ Source<ExtensionsService>(source).ptr()->extensions());
+ break;
+
case NotificationType::EXTENSIONS_LOADED: {
- const ExtensionList* extensions = Details<ExtensionList>(details).ptr();
- CreateBackgroundHosts(this, extensions);
+ ExtensionsService* service = Source<ExtensionsService>(source).ptr();
+ if (service->is_ready()) {
+ const ExtensionList* extensions = Details<ExtensionList>(details).ptr();
+ CreateBackgroundHosts(this, extensions);
+ }
break;
}
diff --git a/chrome/browser/extensions/extension_shelf_model_unittest.cc b/chrome/browser/extensions/extension_shelf_model_unittest.cc
index 80da55d..eaddab8 100644
--- a/chrome/browser/extensions/extension_shelf_model_unittest.cc
+++ b/chrome/browser/extensions/extension_shelf_model_unittest.cc
@@ -16,7 +16,7 @@
namespace {
// The extension we're using as our test case.
-const char* kExtensionId = "fc6f6ba6693faf6773c13701019f2e7a12f0febe";
+const char* kExtensionId = "behllobkkfkfnphdnhnkndlbkcpglgmj";
}; // namespace
@@ -40,16 +40,6 @@ class ExtensionShelfModelTest : public InProcessBrowserTest,
InProcessBrowserTest::SetUp();
}
- virtual void TearDown() {
- // Tear down |model_| manually here rather than in the destructor or with
- // a scoped_ptr. Since it uses NotificationRegistrar, it needs to clean up
- // before the rest of InProcessBrowserTest.
- model_->RemoveObserver(this);
- delete model_;
- model_ = NULL;
- InProcessBrowserTest::TearDown();
- }
-
virtual void SetUpCommandLine(CommandLine* command_line) {
command_line->AppendSwitch(switches::kEnableExtensions);
}
@@ -83,13 +73,12 @@ class ExtensionShelfModelTest : public InProcessBrowserTest,
int moved_count_;
};
-// TODO(erikkay): http://crbug.com/15080 Disabled because it fails.
-IN_PROC_BROWSER_TEST_F(ExtensionShelfModelTest, DISABLED_Basic) {
+IN_PROC_BROWSER_TEST_F(ExtensionShelfModelTest, Basic) {
// Get the path to our extension.
FilePath path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
path = path.AppendASCII("extensions").
- AppendASCII("good").AppendASCII("extension1").AppendASCII("1");
+ AppendASCII("good").AppendASCII(kExtensionId).AppendASCII("1.0.0.0");
ASSERT_TRUE(file_util::DirectoryExists(path)); // sanity check
// Wait for the extension to load and grab a pointer to it.
@@ -113,4 +102,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionShelfModelTest, DISABLED_Basic) {
EXPECT_EQ(one, model_->ToolstripAt(0));
EXPECT_EQ(1, model_->count());
EXPECT_EQ(removed_count_, 1);
+
+ // Tear down |model_| manually here rather than in the destructor or with
+ // a scoped_ptr. InProcessBrowserTest doesn't give us a chance to clean
+ // up before the browser and all of its services have been shut down,
+ // and |model_| depends on these existing.
+ model_->RemoveObserver(this);
+ delete model_;
+ model_ = NULL;
}
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 48dc8d8..affb542 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -215,6 +215,7 @@ ExtensionsService::ExtensionsService(Profile* profile,
MessageLoop* frontend_loop,
MessageLoop* backend_loop)
: extension_prefs_(new ExtensionPrefs(profile->GetPrefs())),
+ extension_process_manager_(new ExtensionProcessManager(profile)),
backend_loop_(backend_loop),
install_directory_(profile->GetPath().AppendASCII(kInstallDirectoryName)),
extensions_enabled_(false),
@@ -244,6 +245,7 @@ void ExtensionsService::SetExtensionsEnabled(bool enabled) {
}
void ExtensionsService::Init() {
+ DCHECK(!ready_);
DCHECK(extensions_.size() == 0);
// Start up the extension event routers.
@@ -354,7 +356,7 @@ void ExtensionsService::UnloadExtension(const std::string& extension_id) {
// Tell other services the extension is gone.
NotificationService::current()->Notify(NotificationType::EXTENSION_UNLOADED,
- NotificationService::AllSources(),
+ Source<ExtensionsService>(this),
Details<Extension>(extension));
delete extension;
@@ -362,14 +364,13 @@ void ExtensionsService::UnloadExtension(const std::string& extension_id) {
void ExtensionsService::UnloadAllExtensions() {
ExtensionList::iterator iter;
- for (iter = extensions_.begin(); iter != extensions_.end(); ++iter) {
- // Tell other services the extension is gone.
- NotificationService::current()->Notify(NotificationType::EXTENSION_UNLOADED,
- NotificationService::AllSources(),
- Details<Extension>(*iter));
+ for (iter = extensions_.begin(); iter != extensions_.end(); ++iter)
delete *iter;
- }
extensions_.clear();
+
+ // TODO(erikkay) should there be a notification for this? We can't use
+ // EXTENSION_UNLOADED since that implies that the extension has been disabled
+ // or uninstalled, and UnloadAll is just part of shutdown.
}
void ExtensionsService::ReloadExtensions() {
@@ -428,7 +429,7 @@ void ExtensionsService::OnExtensionsLoaded(ExtensionList* new_extensions) {
if (enabled_extensions.size()) {
NotificationService::current()->Notify(
NotificationType::EXTENSIONS_LOADED,
- NotificationService::AllSources(),
+ Source<ExtensionsService>(this),
Details<ExtensionList>(&enabled_extensions));
}
}
@@ -443,12 +444,12 @@ void ExtensionsService::OnExtensionInstalled(const FilePath& path,
if (extension->IsTheme()) {
NotificationService::current()->Notify(
NotificationType::THEME_INSTALLED,
- NotificationService::AllSources(),
+ Source<ExtensionsService>(this),
Details<Extension>(extension));
} else {
NotificationService::current()->Notify(
NotificationType::EXTENSION_INSTALLED,
- NotificationService::AllSources(),
+ Source<ExtensionsService>(this),
Details<Extension>(extension));
}
}
@@ -474,7 +475,7 @@ void ExtensionsService::OnExtensionOverinstallAttempted(const std::string& id,
if (extension && extension->IsTheme()) {
NotificationService::current()->Notify(
NotificationType::THEME_INSTALLED,
- NotificationService::AllSources(),
+ Source<ExtensionsService>(this),
Details<Extension>(extension));
}
}
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index fd4ddb7..653c29d 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -18,6 +18,7 @@
#include "base/tuple.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_prefs.h"
+#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/external_extension_provider.h"
#include "chrome/common/extensions/extension.h"
@@ -161,6 +162,10 @@ class ExtensionsService
ExtensionPrefs* extension_prefs() { return extension_prefs_.get(); }
+ ExtensionProcessManager* extension_process_manager() {
+ return extension_process_manager_.get();
+ }
+
// Whether the extension service is ready.
bool is_ready() { return ready_; }
@@ -197,6 +202,9 @@ class ExtensionsService
// Preferences for the owning profile.
scoped_ptr<ExtensionPrefs> extension_prefs_;
+ // Controls how the various extension processes get created and destroyed.
+ scoped_ptr<ExtensionProcessManager> extension_process_manager_;
+
// The message loop to use with the backend.
MessageLoop* backend_loop_;
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index 5c9f977..c76b2f5 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -434,8 +434,6 @@ ProfileImpl::ProfileImpl(const FilePath& path)
TimeDelta::FromMilliseconds(kCreateSessionServiceDelayMS), this,
&ProfileImpl::EnsureSessionServiceCreated);
- extension_process_manager_.reset(new ExtensionProcessManager(this));
-
PrefService* prefs = GetPrefs();
prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
@@ -651,7 +649,7 @@ UserScriptMaster* ProfileImpl::GetUserScriptMaster() {
}
ExtensionProcessManager* ProfileImpl::GetExtensionProcessManager() {
- return extension_process_manager_.get();
+ return extensions_service_->extension_process_manager();
}
SSLHostState* ProfileImpl::GetSSLHostState() {
diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h
index 1501462..57f3bad 100644
--- a/chrome/browser/profile.h
+++ b/chrome/browser/profile.h
@@ -401,7 +401,6 @@ class ProfileImpl : public Profile,
scoped_ptr<VisitedLinkMaster> visited_link_master_;
scoped_refptr<ExtensionsService> extensions_service_;
scoped_refptr<UserScriptMaster> user_script_master_;
- scoped_ptr<ExtensionProcessManager> extension_process_manager_;
scoped_ptr<SSLHostState> ssl_host_state_;
scoped_ptr<net::ForceTLSState> force_tls_state_;
scoped_ptr<PrefService> prefs_;
diff --git a/chrome/browser/views/extensions/extension_view.cc b/chrome/browser/views/extensions/extension_view.cc
index 2050aa0..120fb3c 100644
--- a/chrome/browser/views/extensions/extension_view.cc
+++ b/chrome/browser/views/extensions/extension_view.cc
@@ -20,6 +20,9 @@ ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser)
}
ExtensionView::~ExtensionView() {
+ View* parent = GetParent();
+ if (parent)
+ parent->RemoveChildView(this);
CleanUp();
}