summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-27 03:59:31 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-27 03:59:31 +0000
commitd85cf074f2186dbe1cf8a9db5d89a2b817ffb0e1 (patch)
treee03156e3142955f7cf637fe404a1ce2c6f7aaaf4 /chrome/browser/extensions
parent76a188be4e3ddc42c42beabfeeeb618b2adae11e (diff)
downloadchromium_src-d85cf074f2186dbe1cf8a9db5d89a2b817ffb0e1.zip
chromium_src-d85cf074f2186dbe1cf8a9db5d89a2b817ffb0e1.tar.gz
chromium_src-d85cf074f2186dbe1cf8a9db5d89a2b817ffb0e1.tar.bz2
Simplify threading in browser thread by making only ChromeThread deal with different thread lifetimes.The rest of the code doesn't get MessageLoop pointers since they're not thread-safe and instead just call PostTask on ChromeThread. If the target thread is not alive, then the task is simply deleted.In a followup change, I'll remove any remaining MessageLoop* caching. With this change, there's little to be gained by caching since no locks are involved if the target MessageLoop is guaranteed to outlive the current thread (inferred automatically by the order of the chrome_threads_ array).BUG=25354
Review URL: http://codereview.chromium.org/306032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30163 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/autoupdate_interceptor.cc7
-rw-r--r--chrome/browser/extensions/extension_disabled_infobar_delegate.cc3
-rw-r--r--chrome/browser/extensions/extension_message_service.cc6
-rw-r--r--chrome/browser/extensions/extension_updater_unittest.cc34
-rw-r--r--chrome/browser/extensions/extensions_ui.cc4
-rw-r--r--chrome/browser/extensions/file_reader.cc3
-rw-r--r--chrome/browser/extensions/pack_extension_job.cc11
-rw-r--r--chrome/browser/extensions/pack_extension_job.h4
-rw-r--r--chrome/browser/extensions/sandboxed_extension_unpacker.cc6
-rw-r--r--chrome/browser/extensions/user_script_listener_unittest.cc5
10 files changed, 49 insertions, 34 deletions
diff --git a/chrome/browser/extensions/autoupdate_interceptor.cc b/chrome/browser/extensions/autoupdate_interceptor.cc
index b908133..f8f9bfd 100644
--- a/chrome/browser/extensions/autoupdate_interceptor.cc
+++ b/chrome/browser/extensions/autoupdate_interceptor.cc
@@ -68,8 +68,7 @@ void AutoUpdateInterceptor::SetResponse(const std::string url,
void AutoUpdateInterceptor::SetResponseOnIOThread(const std::string url,
const FilePath& path) {
- MessageLoop* io_loop = ChromeThread::GetMessageLoop(ChromeThread::IO);
- io_loop->PostTask(FROM_HERE,
- NewRunnableMethod(this, &AutoUpdateInterceptor::SetResponse,
- url, path));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &AutoUpdateInterceptor::SetResponse, url, path));
}
diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
index 8e4de1a..64a1534 100644
--- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
+++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
@@ -33,7 +33,8 @@ class ExtensionDisabledDialogDelegate
install_icon_resource_ =
extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE);
- ChromeThread::GetMessageLoop(ChromeThread::FILE)->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
NewRunnableMethod(this, &ExtensionDisabledDialogDelegate::Start));
}
diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc
index 9107c4b..cd011f1 100644
--- a/chrome/browser/extensions/extension_message_service.cc
+++ b/chrome/browser/extensions/extension_message_service.cc
@@ -198,8 +198,7 @@ int ExtensionMessageService::OpenChannelToExtension(
int routing_id, const std::string& source_extension_id,
const std::string& target_extension_id,
const std::string& channel_name, ResourceMessageFilter* source) {
- DCHECK_EQ(MessageLoop::current(),
- ChromeThread::GetMessageLoop(ChromeThread::IO));
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
// Create a channel ID for both sides of the channel.
int port1_id = -1;
@@ -222,8 +221,7 @@ int ExtensionMessageService::OpenChannelToTab(int routing_id,
const std::string& extension_id,
const std::string& channel_name,
ResourceMessageFilter* source) {
- DCHECK_EQ(MessageLoop::current(),
- ChromeThread::GetMessageLoop(ChromeThread::IO));
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
// Create a channel ID for both sides of the channel.
int port1_id = -1;
diff --git a/chrome/browser/extensions/extension_updater_unittest.cc b/chrome/browser/extensions/extension_updater_unittest.cc
index 69f2460..600ae71 100644
--- a/chrome/browser/extensions/extension_updater_unittest.cc
+++ b/chrome/browser/extensions/extension_updater_unittest.cc
@@ -9,6 +9,7 @@
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/thread.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/extensions/extension_updater.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/net/test_url_fetcher_factory.h"
@@ -234,9 +235,12 @@ class ExtensionUpdaterTest : public testing::Test {
service.set_extensions(tmp);
// Setup and start the updater.
+ MessageLoop message_loop;
+ ChromeThread io_thread(ChromeThread::IO);
+ io_thread.Start();
+
TestURLFetcherFactory factory;
URLFetcher::set_factory(&factory);
- MessageLoop message_loop;
ScopedTempPrefService prefs;
scoped_refptr<ExtensionUpdater> updater =
new ExtensionUpdater(&service, prefs.get(), 60*60*24, NULL, NULL);
@@ -277,9 +281,12 @@ class ExtensionUpdaterTest : public testing::Test {
ServiceForManifestTests service;
// Setup and start the updater.
+ MessageLoop message_loop;
+ ChromeThread io_thread(ChromeThread::IO);
+ io_thread.Start();
+
TestURLFetcherFactory factory;
URLFetcher::set_factory(&factory);
- MessageLoop message_loop;
ScopedTempPrefService prefs;
scoped_refptr<ExtensionUpdater> updater =
new ExtensionUpdater(&service, prefs.get(), 60*60*24, NULL, NULL);
@@ -349,15 +356,16 @@ class ExtensionUpdaterTest : public testing::Test {
}
static void TestMultipleManifestDownloading() {
+ MessageLoop ui_loop;
+ ChromeThread file_thread(ChromeThread::FILE);
+ file_thread.Start();
+ ChromeThread io_thread(ChromeThread::IO);
+ io_thread.Start();
+
TestURLFetcherFactory factory;
TestURLFetcher* fetcher = NULL;
URLFetcher::set_factory(&factory);
ServiceForDownloadTests service;
- MessageLoop ui_loop;
- base::Thread file_thread("File Thread");
- ASSERT_TRUE(file_thread.Start());
- base::Thread io_thread("IO Thread");
- ASSERT_TRUE(io_thread.Start());
ScopedTempPrefService prefs;
scoped_refptr<ExtensionUpdater> updater =
new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs,
@@ -410,8 +418,10 @@ class ExtensionUpdaterTest : public testing::Test {
static void TestSingleExtensionDownloading() {
MessageLoop ui_loop;
- base::Thread file_thread("File Thread");
- ASSERT_TRUE(file_thread.Start());
+ ChromeThread file_thread(ChromeThread::FILE);
+ file_thread.Start();
+ ChromeThread io_thread(ChromeThread::IO);
+ io_thread.Start();
TestURLFetcherFactory factory;
TestURLFetcher* fetcher = NULL;
@@ -457,6 +467,9 @@ class ExtensionUpdaterTest : public testing::Test {
static void TestBlacklistDownloading() {
MessageLoop message_loop;
+ ChromeThread io_thread(ChromeThread::IO);
+ io_thread.Start();
+
TestURLFetcherFactory factory;
TestURLFetcher* fetcher = NULL;
URLFetcher::set_factory(&factory);
@@ -501,6 +514,9 @@ class ExtensionUpdaterTest : public testing::Test {
static void TestMultipleExtensionDownloading() {
MessageLoopForUI message_loop;
+ ChromeThread io_thread(ChromeThread::IO);
+ io_thread.Start();
+
TestURLFetcherFactory factory;
TestURLFetcher* fetcher = NULL;
URLFetcher::set_factory(&factory);
diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc
index 7bae618..ef05466 100644
--- a/chrome/browser/extensions/extensions_ui.cc
+++ b/chrome/browser/extensions/extensions_ui.cc
@@ -10,7 +10,6 @@
#include "base/thread.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/debugger/devtools_manager.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
#include "chrome/browser/extensions/extension_message_service.h"
@@ -265,8 +264,7 @@ void ExtensionsDOMHandler::HandlePackMessage(const Value* value) {
return;
}
- pack_job_ = new PackExtensionJob(this, root_directory, key_file,
- ChromeThread::GetMessageLoop(ChromeThread::FILE));
+ pack_job_ = new PackExtensionJob(this, root_directory, key_file);
}
void ExtensionsDOMHandler::OnPackSuccess(const FilePath& crx_file,
diff --git a/chrome/browser/extensions/file_reader.cc b/chrome/browser/extensions/file_reader.cc
index 955e664..e848c2e 100644
--- a/chrome/browser/extensions/file_reader.cc
+++ b/chrome/browser/extensions/file_reader.cc
@@ -16,7 +16,8 @@ FileReader::FileReader(const ExtensionResource& resource, Callback* callback)
}
void FileReader::Start() {
- ChromeThread::GetMessageLoop(ChromeThread::FILE)->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
NewRunnableMethod(this, &FileReader::ReadFileOnBackgroundThread));
}
diff --git a/chrome/browser/extensions/pack_extension_job.cc b/chrome/browser/extensions/pack_extension_job.cc
index c9c26cf..497f1d1 100644
--- a/chrome/browser/extensions/pack_extension_job.cc
+++ b/chrome/browser/extensions/pack_extension_job.cc
@@ -7,16 +7,17 @@
#include "base/message_loop.h"
#include "base/string_util.h"
#include "base/task.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/extensions/extension_creator.h"
PackExtensionJob::PackExtensionJob(Client* client,
const FilePath& root_directory,
- const FilePath& key_file,
- MessageLoop* file_loop)
- : ui_loop_(MessageLoop::current()), file_loop_(file_loop), client_(client),
+ const FilePath& key_file)
+ : ui_loop_(MessageLoop::current()), client_(client),
root_directory_(root_directory), key_file_(key_file) {
- file_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &PackExtensionJob::RunOnFileThread));
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
+ NewRunnableMethod(this, &PackExtensionJob::RunOnFileThread));
}
void PackExtensionJob::ClearClient() {
diff --git a/chrome/browser/extensions/pack_extension_job.h b/chrome/browser/extensions/pack_extension_job.h
index 8c3cf26..b82e9d0 100644
--- a/chrome/browser/extensions/pack_extension_job.h
+++ b/chrome/browser/extensions/pack_extension_job.h
@@ -27,8 +27,7 @@ class PackExtensionJob : public base::RefCountedThreadSafe<PackExtensionJob> {
PackExtensionJob(Client* client,
const FilePath& root_directory,
- const FilePath& key_file,
- MessageLoop* file_loop);
+ const FilePath& key_file);
// The client should call this when it is destroyed to prevent
// PackExtensionJob from attempting to access it.
@@ -40,7 +39,6 @@ class PackExtensionJob : public base::RefCountedThreadSafe<PackExtensionJob> {
void ReportFailureOnUIThread(const std::string& error);
MessageLoop* ui_loop_;
- MessageLoop* file_loop_;
Client* client_;
FilePath root_directory_;
FilePath key_file_;
diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker.cc b/chrome/browser/extensions/sandboxed_extension_unpacker.cc
index 8756450..d3d9f61 100644
--- a/chrome/browser/extensions/sandboxed_extension_unpacker.cc
+++ b/chrome/browser/extensions/sandboxed_extension_unpacker.cc
@@ -73,8 +73,10 @@ void SandboxedExtensionUnpacker::Start() {
#endif
if (use_utility_process) {
- ChromeThread::GetMessageLoop(ChromeThread::IO)->PostTask(FROM_HERE,
- NewRunnableMethod(this,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this,
&SandboxedExtensionUnpacker::StartProcessOnIOThread,
temp_crx_path));
} else {
diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc
index fff1002..59357de 100644
--- a/chrome/browser/extensions/user_script_listener_unittest.cc
+++ b/chrome/browser/extensions/user_script_listener_unittest.cc
@@ -7,6 +7,7 @@
#include "base/message_loop.h"
#include "base/thread.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/common/chrome_paths.h"
@@ -41,9 +42,9 @@ class MockUserScriptMaster : public UserScriptMaster {
}
};
-class MockIOThread : public base::Thread {
+class MockIOThread : public ChromeThread {
public:
- MockIOThread() : base::Thread("IO") {}
+ MockIOThread() : ChromeThread(ChromeThread::IO) {}
virtual ~MockIOThread() { Stop(); }
private: