summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-02 05:59:37 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-02 05:59:37 +0000
commit6fad26338ed6119903826156f307e20fe6657c31 (patch)
tree5c6baed35fce907a0cea47ed6091c941db8ebfd1 /chrome
parentf75c8f13b967b01babc9454506e9d2ed00519e39 (diff)
downloadchromium_src-6fad26338ed6119903826156f307e20fe6657c31.zip
chromium_src-6fad26338ed6119903826156f307e20fe6657c31.tar.gz
chromium_src-6fad26338ed6119903826156f307e20fe6657c31.tar.bz2
Third patch in getting rid of caching MessageLoop pointers and always using ChromeThread instead.
BUG=25354 Review URL: http://codereview.chromium.org/342068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30687 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/history_contents_provider_unittest.cc6
-rw-r--r--chrome/browser/autocomplete/history_url_provider_unittest.cc9
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data_unittest.cc18
-rw-r--r--chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc10
-rw-r--r--chrome/browser/bookmarks/bookmark_html_writer.cc12
-rw-r--r--chrome/browser/bookmarks/bookmark_html_writer.h9
-rw-r--r--chrome/browser/bookmarks/bookmark_html_writer_unittest.cc7
-rw-r--r--chrome/browser/bookmarks/bookmark_index_unittest.cc3
-rw-r--r--chrome/browser/bookmarks/bookmark_model_unittest.cc6
-rw-r--r--chrome/browser/bookmarks/bookmark_storage.cc45
-rw-r--r--chrome/browser/bookmarks/bookmark_storage.h15
-rw-r--r--chrome/browser/bookmarks/bookmark_table_model_unittest.cc10
-rw-r--r--chrome/browser/browser_about_handler.cc7
-rw-r--r--chrome/browser/browser_commands_unittest.cc3
-rw-r--r--chrome/browser/browser_main.cc3
-rw-r--r--chrome/browser/browser_process_impl.cc2
-rw-r--r--chrome/browser/browser_shutdown.cc6
-rw-r--r--chrome/browser/browsing_data_remover.cc24
-rw-r--r--chrome/browser/chrome_plugin_host.cc4
-rw-r--r--chrome/browser/cocoa/browser_test_helper.h7
-rw-r--r--chrome/browser/debugger/devtools_protocol_handler.cc33
-rw-r--r--chrome/browser/debugger/devtools_protocol_handler.h2
-rw-r--r--chrome/browser/dom_ui/new_tab_ui_uitest.cc2
-rw-r--r--chrome/browser/dom_ui/shown_sections_handler_unittest.cc2
-rw-r--r--chrome/browser/extensions/extension_updater_unittest.cc2
-rw-r--r--chrome/browser/extensions/extensions_service_unittest.cc2
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk_unittest.cc9
-rw-r--r--chrome/browser/gtk/bookmark_editor_gtk_unittest.cc9
-rw-r--r--chrome/browser/gtk/bookmark_manager_gtk.cc5
-rw-r--r--chrome/browser/gtk/dialogs_gtk.cc7
-rw-r--r--chrome/browser/jankometer.cc10
-rw-r--r--chrome/browser/memory_details.cc12
-rw-r--r--chrome/browser/memory_details.h3
-rw-r--r--chrome/browser/memory_details_linux.cc6
-rw-r--r--chrome/browser/memory_details_win.cc7
-rw-r--r--chrome/browser/metrics/metrics_service_uitest.cc3
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc16
-rw-r--r--chrome/browser/net/dns_global.cc2
-rw-r--r--chrome/browser/net/dns_master.cc42
-rw-r--r--chrome/browser/net/dns_master.h11
-rw-r--r--chrome/browser/net/dns_master_unittest.cc37
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc35
-rw-r--r--chrome/browser/printing/print_dialog_gtk.cc8
-rw-r--r--chrome/browser/printing/print_dialog_gtk.h6
-rw-r--r--chrome/browser/profile.cc51
-rw-r--r--chrome/browser/profile_manager.cc10
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc6
-rw-r--r--chrome/browser/renderer_host/buffered_resource_handler.cc37
-rw-r--r--chrome/browser/renderer_host/buffered_resource_handler.h9
-rw-r--r--chrome/browser/renderer_host/render_widget_helper.cc47
-rw-r--r--chrome/browser/renderer_host/render_widget_helper.h4
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_win.cc4
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc23
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h1
-rw-r--r--chrome/browser/renderer_host/resource_message_filter_gtk.cc34
-rw-r--r--chrome/browser/renderer_host/resource_message_filter_mac.mm4
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page.cc16
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc7
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_service.cc11
-rw-r--r--chrome/browser/spellcheck_unittest.cc28
-rw-r--r--chrome/browser/spellchecker.cc136
-rw-r--r--chrome/browser/spellchecker.h12
-rw-r--r--chrome/browser/strict_transport_security_persister.cc18
-rw-r--r--chrome/browser/strict_transport_security_persister.h12
-rw-r--r--chrome/browser/sync/profile_sync_service_unittest.cc8
-rw-r--r--chrome/browser/sync/sync_setup_wizard.cc20
-rw-r--r--chrome/browser/sync/sync_setup_wizard_unittest.cc8
-rw-r--r--chrome/browser/tab_contents/interstitial_page.cc17
-rw-r--r--chrome/browser/tab_contents/web_contents_unittest.cc2
-rw-r--r--chrome/browser/task_manager.cc18
-rw-r--r--chrome/browser/task_manager_resource_providers.cc9
-rw-r--r--chrome/browser/views/about_network_dialog.cc8
-rw-r--r--chrome/browser/views/bookmark_context_menu_test.cc7
-rw-r--r--chrome/browser/views/bookmark_editor_view_unittest.cc10
-rw-r--r--chrome/browser/views/bookmark_manager_view.cc6
-rw-r--r--chrome/browser/visitedlink_master.cc63
-rw-r--r--chrome/browser/visitedlink_master.h27
-rw-r--r--chrome/browser/visitedlink_perftest.cc10
-rw-r--r--chrome/browser/visitedlink_unittest.cc21
-rw-r--r--chrome/browser/web_resource/web_resource_service.cc4
-rw-r--r--chrome/browser/web_resource/web_resource_service.h6
-rw-r--r--chrome/browser/worker_host/worker_process_host.cc8
-rw-r--r--chrome/browser/worker_host/worker_service.cc7
-rw-r--r--chrome/browser/worker_host/worker_service.h7
-rw-r--r--chrome/common/histogram_synchronizer.cc16
-rw-r--r--chrome/common/important_file_writer.cc14
-rw-r--r--chrome/common/important_file_writer.h9
-rw-r--r--chrome/common/important_file_writer_unittest.cc31
-rw-r--r--chrome/common/pref_member_unittest.cc6
-rw-r--r--chrome/common/pref_service.cc6
-rw-r--r--chrome/common/pref_service.h11
-rw-r--r--chrome/common/pref_service_unittest.cc20
-rw-r--r--chrome/test/in_process_browser_test.cc4
-rw-r--r--chrome/test/reliability/page_load_test.cc2
-rw-r--r--chrome/test/testing_profile.h2
95 files changed, 618 insertions, 716 deletions
diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
index 84dde8f..1afbd88 100644
--- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
@@ -7,6 +7,7 @@
#include "base/string_util.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/history_contents_provider.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/history/history.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -29,6 +30,9 @@ struct TestEntry {
class HistoryContentsProviderTest : public testing::Test,
public ACProviderListener {
public:
+ HistoryContentsProviderTest()
+ : ui_thread_(ChromeThread::UI, &message_loop_),
+ file_thread_(ChromeThread::FILE, &message_loop_) {}
void RunQuery(const AutocompleteInput& input,
bool minimal_changes) {
@@ -87,6 +91,8 @@ class HistoryContentsProviderTest : public testing::Test,
}
MessageLoopForUI message_loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
std::wstring history_dir_;
diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc
index d06c543..6254e7f 100644
--- a/chrome/browser/autocomplete/history_url_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc
@@ -8,6 +8,7 @@
#include "base/string_util.h"
#include "chrome/browser/autocomplete/history_url_provider.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/history/history.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -94,6 +95,11 @@ static TestURLInfo test_db[] = {
class HistoryURLProviderTest : public testing::Test,
public ACProviderListener {
+ public:
+ HistoryURLProviderTest()
+ : ui_thread_(ChromeThread::UI, &message_loop_),
+ file_thread_(ChromeThread::FILE, &message_loop_) {}
+
// ACProviderListener
virtual void OnProviderUpdate(bool updated_matches);
@@ -114,6 +120,8 @@ class HistoryURLProviderTest : public testing::Test,
size_t num_results);
MessageLoopForUI message_loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
ACMatches matches_;
scoped_ptr<TestingProfile> profile_;
HistoryService* history_service_;
@@ -130,6 +138,7 @@ void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) {
void HistoryURLProviderTest::SetUp() {
profile_.reset(new TestingProfile());
profile_->CreateBookmarkModel(true);
+ profile_->BlockUntilBookmarkModelLoaded();
profile_->CreateHistoryService(true);
history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
diff --git a/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc b/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc
index 77d999a..55fc3b59 100644
--- a/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc
@@ -4,14 +4,26 @@
#include "app/os_exchange_data.h"
#include "app/os_exchange_data_provider_win.h"
+#include "base/message_loop.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/bookmarks/bookmark_drag_data.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/test/testing_profile.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
-typedef testing::Test BookmarkDragDataTest;
+class BookmarkDragDataTest : public testing::Test {
+ public:
+ BookmarkDragDataTest()
+ : ui_thread_(ChromeThread::UI, &loop_),
+ file_thread_(ChromeThread::FILE, &loop_) { }
+
+ private:
+ MessageLoop loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
+};
namespace {
@@ -59,6 +71,7 @@ TEST_F(BookmarkDragDataTest, URL) {
// Write a single node representing a URL to the clipboard.
TestingProfile profile;
profile.CreateBookmarkModel(false);
+ profile.BlockUntilBookmarkModelLoaded();
profile.SetID(L"id");
BookmarkModel* model = profile.GetBookmarkModel();
const BookmarkNode* root = model->GetBookmarkBarNode();
@@ -101,6 +114,7 @@ TEST_F(BookmarkDragDataTest, URL) {
TEST_F(BookmarkDragDataTest, Group) {
TestingProfile profile;
profile.CreateBookmarkModel(false);
+ profile.BlockUntilBookmarkModelLoaded();
profile.SetID(L"id");
BookmarkModel* model = profile.GetBookmarkModel();
const BookmarkNode* root = model->GetBookmarkBarNode();
@@ -140,6 +154,7 @@ TEST_F(BookmarkDragDataTest, GroupWithChild) {
TestingProfile profile;
profile.SetID(L"id");
profile.CreateBookmarkModel(false);
+ profile.BlockUntilBookmarkModelLoaded();
BookmarkModel* model = profile.GetBookmarkModel();
const BookmarkNode* root = model->GetBookmarkBarNode();
const BookmarkNode* group = model->AddGroup(root, 0, L"g1");
@@ -178,6 +193,7 @@ TEST_F(BookmarkDragDataTest, MultipleNodes) {
TestingProfile profile;
profile.SetID(L"id");
profile.CreateBookmarkModel(false);
+ profile.BlockUntilBookmarkModelLoaded();
BookmarkModel* model = profile.GetBookmarkModel();
const BookmarkNode* root = model->GetBookmarkBarNode();
const BookmarkNode* group = model->AddGroup(root, 0, L"g1");
diff --git a/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc b/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc
index ddefae0..2f9b3b5 100644
--- a/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc
@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/message_loop.h"
#include "base/string_util.h"
#include "chrome/browser/bookmarks/bookmark_folder_tree_model.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/test/testing_profile.h"
#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -31,12 +33,15 @@ class BookmarkFolderTreeModelTest : public testing::Test,
added_count_(0),
removed_count_(0),
changed_count_(0),
- reordered_count_(0) {
+ reordered_count_(0),
+ ui_thread_(ChromeThread::UI, &loop_),
+ file_thread_(ChromeThread::FILE, &loop_) {
}
virtual void SetUp() {
profile_.reset(new TestingProfile());
profile_->CreateBookmarkModel(true);
+ profile_->BlockUntilBookmarkModelLoaded();
// Populate with some default data.
const BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode();
bookmark_model()->AddURL(bb, 0, L"url1", url1_);
@@ -112,6 +117,9 @@ class BookmarkFolderTreeModelTest : public testing::Test,
int removed_count_;
int reordered_count_;
scoped_ptr<TestingProfile> profile_;
+ MessageLoop loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
};
// Verifies the root node has 4 nodes, and the contents of the bookmark bar
diff --git a/chrome/browser/bookmarks/bookmark_html_writer.cc b/chrome/browser/bookmarks/bookmark_html_writer.cc
index a684562..2dccfef 100644
--- a/chrome/browser/bookmarks/bookmark_html_writer.cc
+++ b/chrome/browser/bookmarks/bookmark_html_writer.cc
@@ -14,6 +14,7 @@
#include "base/values.h"
#include "chrome/browser/bookmarks/bookmark_codec.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/history/history_types.h"
#include "grit/generated_resources.h"
#include "net/base/escape.h"
@@ -316,18 +317,13 @@ class Writer : public Task {
} // namespace
-void WriteBookmarks(MessageLoop* thread,
- BookmarkModel* model,
- const FilePath& path) {
+void WriteBookmarks(BookmarkModel* model, const FilePath& path) {
// BookmarkModel isn't thread safe (nor would we want to lock it down
// for the duration of the write), as such we make a copy of the
// BookmarkModel using BookmarkCodec then write from that.
BookmarkCodec codec;
- scoped_ptr<Writer> writer(new Writer(codec.Encode(model), path));
- if (thread)
- thread->PostTask(FROM_HERE, writer.release());
- else
- writer->Run();
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE, new Writer(codec.Encode(model), path));
}
} // namespace bookmark_html_writer
diff --git a/chrome/browser/bookmarks/bookmark_html_writer.h b/chrome/browser/bookmarks/bookmark_html_writer.h
index 97ff5731..e7202de 100644
--- a/chrome/browser/bookmarks/bookmark_html_writer.h
+++ b/chrome/browser/bookmarks/bookmark_html_writer.h
@@ -12,14 +12,11 @@ class MessageLoop;
namespace bookmark_html_writer {
// Writes the bookmarks out in the 'bookmarks.html' format understood by
-// Firefox and IE. The results are written to the file at |path|.
-// If |thread| is non-null, writing is done on that thread, otherwise
-// writing is synchronous.
+// Firefox and IE. The results are written to the file at |path|. The file
+// thread is used.
//
// TODO(sky): need a callback on failure.
-void WriteBookmarks(MessageLoop* thread,
- BookmarkModel* model,
- const FilePath& path);
+void WriteBookmarks(BookmarkModel* model, const FilePath& path);
}
diff --git a/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc b/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc
index 526b5d3..7d3b772 100644
--- a/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_html_writer_unittest.cc
@@ -6,12 +6,14 @@
#include "app/l10n_util.h"
#include "base/file_util.h"
+#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/time.h"
#include "base/i18n/time_formatting.h"
#include "chrome/browser/bookmarks/bookmark_html_writer.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/importer/firefox2_importer.h"
#include "grit/generated_resources.h"
@@ -149,7 +151,10 @@ TEST_F(BookmarkHTMLWriterTest, Test) {
url4, t4);
// Write to a temp file.
- bookmark_html_writer::WriteBookmarks(NULL, &model, path_);
+ MessageLoop message_loop;
+ ChromeThread fake_file_thread(ChromeThread::FILE, &message_loop);
+ bookmark_html_writer::WriteBookmarks(&model, path_);
+ message_loop.RunAllPending();
// Read the bookmarks back in.
std::vector<ProfileWriter::BookmarkEntry> parsed_bookmarks;
diff --git a/chrome/browser/bookmarks/bookmark_index_unittest.cc b/chrome/browser/bookmarks/bookmark_index_unittest.cc
index 102a734..9ef6907 100644
--- a/chrome/browser/bookmarks/bookmark_index_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_index_unittest.cc
@@ -9,6 +9,7 @@
#include "base/string_util.h"
#include "chrome/browser/bookmarks/bookmark_index.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/history/history_database.h"
#include "chrome/browser/history/in_memory_database.h"
#include "chrome/browser/history/query_parser.h"
@@ -212,6 +213,8 @@ TEST_F(BookmarkIndexTest, GetResultsSortedByTypedCount) {
// This ensures MessageLoop::current() will exist, which is needed by
// TestingProfile::BlockUntilHistoryProcessesPendingRequests().
MessageLoop loop(MessageLoop::TYPE_DEFAULT);
+ ChromeThread ui_thread(ChromeThread::UI, &loop);
+ ChromeThread file_thread(ChromeThread::FILE, &loop);
TestingProfile profile;
profile.CreateHistoryService(true);
diff --git a/chrome/browser/bookmarks/bookmark_model_unittest.cc b/chrome/browser/bookmarks/bookmark_model_unittest.cc
index 5eb240e..d511530 100644
--- a/chrome/browser/bookmarks/bookmark_model_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_model_unittest.cc
@@ -562,6 +562,10 @@ static void PopulateBookmarkNode(TestNode* parent,
class BookmarkModelTestWithProfile : public testing::Test,
public BookmarkModelObserver {
public:
+ BookmarkModelTestWithProfile()
+ : ui_thread_(ChromeThread::UI, &message_loop_),
+ file_thread_(ChromeThread::FILE, &message_loop_) {}
+
virtual void SetUp() {
}
@@ -652,6 +656,8 @@ class BookmarkModelTestWithProfile : public testing::Test,
const BookmarkNode* node) {}
MessageLoopForUI message_loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
};
// Creates a set of nodes in the bookmark bar model, then recreates the
diff --git a/chrome/browser/bookmarks/bookmark_storage.cc b/chrome/browser/bookmarks/bookmark_storage.cc
index 10f79ff..387fa71 100644
--- a/chrome/browser/bookmarks/bookmark_storage.cc
+++ b/chrome/browser/bookmarks/bookmark_storage.cc
@@ -7,12 +7,10 @@
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/histogram.h"
-#include "base/message_loop.h"
-#include "base/thread.h"
#include "base/time.h"
#include "chrome/browser/bookmarks/bookmark_codec.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
-#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/profile.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/json_value_serializer.h"
@@ -65,11 +63,9 @@ class FileDeleteTask : public Task {
class BookmarkStorage::LoadTask : public Task {
public:
LoadTask(const FilePath& path,
- MessageLoop* loop,
BookmarkStorage* storage,
LoadDetails* details)
: path_(path),
- loop_(loop),
storage_(storage),
details_(details) {
}
@@ -103,13 +99,11 @@ class BookmarkStorage::LoadTask : public Task {
}
}
- if (loop_) {
- loop_->PostTask(FROM_HERE, NewRunnableMethod(
- storage_.get(), &BookmarkStorage::OnLoadFinished,
- bookmark_file_exists, path_));
- } else {
- storage_->OnLoadFinished(bookmark_file_exists, path_);
- }
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ storage_.get(), &BookmarkStorage::OnLoadFinished,
+ bookmark_file_exists, path_));
}
private:
@@ -125,7 +119,6 @@ class BookmarkStorage::LoadTask : public Task {
}
const FilePath path_;
- MessageLoop* loop_;
scoped_refptr<BookmarkStorage> storage_;
LoadDetails* details_;
@@ -137,13 +130,12 @@ class BookmarkStorage::LoadTask : public Task {
BookmarkStorage::BookmarkStorage(Profile* profile, BookmarkModel* model)
: profile_(profile),
model_(model),
- backend_thread_(g_browser_process->file_thread()),
- writer_(profile->GetPath().Append(chrome::kBookmarksFileName),
- backend_thread_),
+ writer_(profile->GetPath().Append(chrome::kBookmarksFileName)),
tmp_history_path_(
profile->GetPath().Append(chrome::kHistoryBookmarksFileName)) {
writer_.set_commit_interval(base::TimeDelta::FromMilliseconds(kSaveDelayMS));
- RunTaskOnBackendThread(new BackupTask(writer_.path()));
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE, new BackupTask(writer_.path()));
}
BookmarkStorage::~BookmarkStorage() {
@@ -159,11 +151,8 @@ void BookmarkStorage::LoadBookmarks(LoadDetails* details) {
}
void BookmarkStorage::DoLoadBookmarks(const FilePath& path) {
- Task* task = new LoadTask(path,
- backend_thread() ? MessageLoop::current() : NULL,
- this,
- details_.get());
- RunTaskOnBackendThread(task);
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE, new LoadTask(path, this, details_.get()));
}
void BookmarkStorage::MigrateFromHistory() {
@@ -238,7 +227,8 @@ void BookmarkStorage::OnLoadFinished(bool file_exists, const FilePath& path) {
SaveNow();
// Clean up after migration from history.
- RunTaskOnBackendThread(new FileDeleteTask(tmp_history_path_));
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE, new FileDeleteTask(tmp_history_path_));
}
}
@@ -270,12 +260,3 @@ bool BookmarkStorage::SaveNow() {
writer_.WriteNow(data);
return true;
}
-
-void BookmarkStorage::RunTaskOnBackendThread(Task* task) const {
- if (backend_thread()) {
- backend_thread()->message_loop()->PostTask(FROM_HERE, task);
- } else {
- task->Run();
- delete task;
- }
-}
diff --git a/chrome/browser/bookmarks/bookmark_storage.h b/chrome/browser/bookmarks/bookmark_storage.h
index 3b83468..d41b2c5 100644
--- a/chrome/browser/bookmarks/bookmark_storage.h
+++ b/chrome/browser/bookmarks/bookmark_storage.h
@@ -19,10 +19,6 @@ class Profile;
class Task;
class Value;
-namespace base {
-class Thread;
-}
-
// BookmarkStorage handles reading/write the bookmark bar model. The
// BookmarkModel uses the BookmarkStorage to load bookmarks from disk, as well
// as notifying the BookmarkStorage every time the model changes.
@@ -143,23 +139,12 @@ class BookmarkStorage : public NotificationObserver,
// Returns true on successful serialization.
bool SaveNow();
- // Runs task on backend thread (or on current thread if backend thread
- // is NULL). Takes ownership of |task|.
- void RunTaskOnBackendThread(Task* task) const;
-
- // Returns the thread the backend is run on.
- const base::Thread* backend_thread() const { return backend_thread_; }
-
// Keep the pointer to profile, we may need it for migration from history.
Profile* profile_;
// The model. The model is NULL once BookmarkModelDeleted has been invoked.
BookmarkModel* model_;
- // Thread read/writing is run on. This comes from the profile, and is null
- // during testing.
- const base::Thread* backend_thread_;
-
// Helper to write bookmark data safely.
ImportantFileWriter writer_;
diff --git a/chrome/browser/bookmarks/bookmark_table_model_unittest.cc b/chrome/browser/bookmarks/bookmark_table_model_unittest.cc
index 54ee29e..5cc3d6d 100644
--- a/chrome/browser/bookmarks/bookmark_table_model_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_table_model_unittest.cc
@@ -3,9 +3,11 @@
// found in the LICENSE file.
#include "app/table_model_observer.h"
+#include "base/message_loop.h"
#include "base/string_util.h"
#include "base/time.h"
#include "chrome/browser/bookmarks/bookmark_table_model.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/test/testing_profile.h"
#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -32,12 +34,15 @@ class BookmarkTableModelTest : public testing::Test,
changed_count_(0),
item_changed_count_(0),
added_count_(0),
- removed_count_(0) {
+ removed_count_(0),
+ ui_thread_(ChromeThread::UI, &loop_),
+ file_thread_(ChromeThread::FILE, &loop_) {
}
virtual void SetUp() {
profile_.reset(new TestingProfile());
profile_->CreateBookmarkModel(true);
+ profile_->BlockUntilBookmarkModelLoaded();
// Populate with some default data.
Time t0 = Time::Now();
const BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode();
@@ -110,6 +115,9 @@ class BookmarkTableModelTest : public testing::Test,
int added_count_;
int removed_count_;
scoped_ptr<TestingProfile> profile_;
+ MessageLoop loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
};
// Verifies the count when showing various nodes.
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc
index 370cfa0..c478945 100644
--- a/chrome/browser/browser_about_handler.cc
+++ b/chrome/browser/browser_about_handler.cc
@@ -21,6 +21,7 @@
#include "base/tracked_objects.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/memory_details.h"
#include "chrome/browser/net/dns_global.h"
@@ -567,8 +568,10 @@ AboutSource::AboutSource()
about_source = this;
// Add us to the global URL handler on the IO thread.
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(Singleton<ChromeURLDataManager>().get(),
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ Singleton<ChromeURLDataManager>().get(),
&ChromeURLDataManager::AddDataSource, this));
}
diff --git a/chrome/browser/browser_commands_unittest.cc b/chrome/browser/browser_commands_unittest.cc
index 144263b..3ed2adc 100644
--- a/chrome/browser/browser_commands_unittest.cc
+++ b/chrome/browser/browser_commands_unittest.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/common/url_constants.h"
@@ -78,6 +79,8 @@ TEST_F(BrowserCommandsTest, DuplicateTab) {
}
TEST_F(BrowserCommandsTest, BookmarkCurrentPage) {
+ ChromeThread ui_loop(ChromeThread::UI, MessageLoop::current());
+ ChromeThread file_loop(ChromeThread::FILE, MessageLoop::current());
// We use profile() here, since it's a TestingProfile.
profile()->CreateBookmarkModel(true);
profile()->BlockUntilBookmarkModelLoaded();
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index df1947f..a3e5f8b 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -443,8 +443,7 @@ int BrowserMain(const MainFunctionParams& parameters) {
parsed_command_line.HasSwitch(switches::kParentProfile)) {
FilePath parent_profile = FilePath::FromWStringHack(
parsed_command_line.GetSwitchValue(switches::kParentProfile));
- PrefService parent_local_state(parent_profile,
- g_browser_process->file_thread());
+ PrefService parent_local_state(parent_profile);
parent_local_state.RegisterStringPref(prefs::kApplicationLocale,
std::wstring());
// Right now, we only inherit the locale setting from the parent profile.
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 2195f42..af54bb5 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -397,7 +397,7 @@ void BrowserProcessImpl::CreateLocalState() {
FilePath local_state_path;
PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
- local_state_.reset(new PrefService(local_state_path, file_thread()));
+ local_state_.reset(new PrefService(local_state_path));
}
#if defined(OS_WIN)
diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc
index 120bcaf..0b6d680 100644
--- a/chrome/browser/browser_shutdown.cc
+++ b/chrome/browser/browser_shutdown.cc
@@ -14,6 +14,7 @@
#include "base/time.h"
#include "base/waitable_event.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/first_run.h"
#include "chrome/browser/jankometer.h"
@@ -90,10 +91,9 @@ FilePath GetShutdownMsPath() {
void Shutdown() {
// Unload plugins. This needs to happen on the IO thread.
- if (g_browser_process->io_thread()) {
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
NewRunnableFunction(&ChromePluginLib::UnloadAllPlugins));
- }
// WARNING: During logoff/shutdown (WM_ENDSESSION) we may not have enough
// time to get here. If you have something that *must* happen on end session,
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc
index 5cfe415..aef400a 100644
--- a/chrome/browser/browsing_data_remover.cc
+++ b/chrome/browser/browsing_data_remover.cc
@@ -5,7 +5,6 @@
#include "chrome/browser/browsing_data_remover.h"
#include "chrome/browser/chrome_thread.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/profile.h"
@@ -133,18 +132,17 @@ void BrowsingDataRemover::Remove(int remove_mask) {
if (remove_mask & REMOVE_CACHE) {
// Invoke ClearBrowsingDataView::ClearCache on the IO thread.
- base::Thread* thread = g_browser_process->io_thread();
- if (thread) {
- waiting_for_clear_cache_ = true;
- UserMetrics::RecordAction(L"ClearBrowsingData_Cache", profile_);
- thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this,
- &BrowsingDataRemover::ClearCacheOnIOThread,
- profile_->GetRequestContext(),
- delete_begin_,
- delete_end_,
- MessageLoop::current()));
- }
+ waiting_for_clear_cache_ = true;
+ UserMetrics::RecordAction(L"ClearBrowsingData_Cache", profile_);
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &BrowsingDataRemover::ClearCacheOnIOThread,
+ profile_->GetRequestContext(),
+ delete_begin_,
+ delete_end_,
+ MessageLoop::current()));
}
NotifyAndDeleteIfDone();
diff --git a/chrome/browser/chrome_plugin_host.cc b/chrome/browser/chrome_plugin_host.cc
index 5b09fd8..defc466 100644
--- a/chrome/browser/chrome_plugin_host.cc
+++ b/chrome/browser/chrome_plugin_host.cc
@@ -17,6 +17,7 @@
#include "base/singleton.h"
#include "base/string_util.h"
#include "chrome/browser/browser_list.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/chrome_plugin_browsing_context.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/dom_ui/html_dialog_ui.h"
@@ -817,7 +818,8 @@ void CPHandleCommand(int command, CPCommandInterface* data,
// brain trying to compile the Tuple3 ctor. This cast works.
int32 context_as_int32 = static_cast<int32>(context);
// Plugins can only be accessed on the IO thread.
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
NewRunnableFunction(PluginCommandHandler::HandleCommand,
command, data, context_as_int32));
}
diff --git a/chrome/browser/cocoa/browser_test_helper.h b/chrome/browser/cocoa/browser_test_helper.h
index bf3ffa7..772a1bb 100644
--- a/chrome/browser/cocoa/browser_test_helper.h
+++ b/chrome/browser/cocoa/browser_test_helper.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_COCOA_BROWSER_TEST_HELPER_H_
#include "chrome/browser/browser.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/profile.h"
#include "chrome/test/testing_profile.h"
@@ -18,7 +19,9 @@
// navigation_controller_unittest.cc, ..
class BrowserTestHelper {
public:
- BrowserTestHelper() {
+ BrowserTestHelper()
+ : ui_thread_(ChromeThread::UI, &message_loop_),
+ file_thread_(ChromeThread::FILE, &message_loop_) {
profile_.reset(new TestingProfile());
profile_->CreateBookmarkModel(true);
profile_->BlockUntilBookmarkModelLoaded();
@@ -32,6 +35,8 @@ class BrowserTestHelper {
scoped_ptr<TestingProfile> profile_;
scoped_ptr<Browser> browser_;
MessageLoopForUI message_loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
};
#endif // CHROME_BROWSER_COCOA_BROWSER_TEST_HELPER_H_
diff --git a/chrome/browser/debugger/devtools_protocol_handler.cc b/chrome/browser/debugger/devtools_protocol_handler.cc
index 39f3dea..d88aad0 100644
--- a/chrome/browser/debugger/devtools_protocol_handler.cc
+++ b/chrome/browser/debugger/devtools_protocol_handler.cc
@@ -5,8 +5,7 @@
#include "chrome/browser/debugger/devtools_protocol_handler.h"
#include "base/logging.h"
-#include "base/thread.h"
-#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/debugger/inspectable_tab_proxy.h"
#include "chrome/browser/debugger/devtools_remote_message.h"
#include "chrome/browser/debugger/devtools_remote_listen_socket.h"
@@ -16,8 +15,6 @@ DevToolsProtocolHandler::DevToolsProtocolHandler(int port)
: port_(port),
connection_(NULL),
server_(NULL) {
- ui_loop_ = MessageLoop::current();
- io_loop_ = g_browser_process->io_thread()->message_loop();
inspectable_tab_proxy_.reset(new InspectableTabProxy);
}
@@ -28,8 +25,9 @@ DevToolsProtocolHandler::~DevToolsProtocolHandler() {
}
void DevToolsProtocolHandler::Start() {
- io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &DevToolsProtocolHandler::Init));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &DevToolsProtocolHandler::Init));
}
void DevToolsProtocolHandler::Init() {
@@ -38,8 +36,9 @@ void DevToolsProtocolHandler::Init() {
}
void DevToolsProtocolHandler::Stop() {
- io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &DevToolsProtocolHandler::Teardown));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &DevToolsProtocolHandler::Teardown));
tool_to_listener_map_.clear(); // Releases all scoped_refptr's to listeners
}
@@ -73,9 +72,11 @@ void DevToolsProtocolHandler::HandleMessage(
NOTREACHED(); // an unsupported tool, bail out
return;
}
- DCHECK(MessageLoop::current() == io_loop_);
- ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- it->second.get(), &DevToolsRemoteListener::HandleMessage, message));
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ it->second.get(), &DevToolsRemoteListener::HandleMessage, message));
}
void DevToolsProtocolHandler::Send(const DevToolsRemoteMessage& message) {
@@ -86,7 +87,7 @@ void DevToolsProtocolHandler::Send(const DevToolsRemoteMessage& message) {
void DevToolsProtocolHandler::DidAccept(ListenSocket *server,
ListenSocket *connection) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (connection_ == NULL) {
connection_ = connection;
connection_->AddRef();
@@ -100,7 +101,7 @@ void DevToolsProtocolHandler::DidRead(ListenSocket *connection,
}
void DevToolsProtocolHandler::DidClose(ListenSocket *sock) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DCHECK(connection_ == sock);
connection_ = NULL;
sock->Release();
@@ -108,7 +109,9 @@ void DevToolsProtocolHandler::DidClose(ListenSocket *sock) {
end = tool_to_listener_map_.end();
it != end;
++it) {
- ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- it->second.get(), &DevToolsRemoteListener::OnConnectionLost));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ it->second.get(), &DevToolsRemoteListener::OnConnectionLost));
}
}
diff --git a/chrome/browser/debugger/devtools_protocol_handler.h b/chrome/browser/debugger/devtools_protocol_handler.h
index 7c1d5e0..41b2869 100644
--- a/chrome/browser/debugger/devtools_protocol_handler.h
+++ b/chrome/browser/debugger/devtools_protocol_handler.h
@@ -69,8 +69,6 @@ class DevToolsProtocolHandler
void Init();
void Teardown();
int port_;
- MessageLoop* ui_loop_;
- MessageLoop* io_loop_;
ToolToListenerMap tool_to_listener_map_;
scoped_refptr<ListenSocket> connection_;
scoped_refptr<DevToolsRemoteListenSocket> server_;
diff --git a/chrome/browser/dom_ui/new_tab_ui_uitest.cc b/chrome/browser/dom_ui/new_tab_ui_uitest.cc
index 5779b96e..83a5ef7 100644
--- a/chrome/browser/dom_ui/new_tab_ui_uitest.cc
+++ b/chrome/browser/dom_ui/new_tab_ui_uitest.cc
@@ -60,7 +60,7 @@ TEST_F(NewTabUITest, NTPHasThumbnails) {
}
TEST_F(NewTabUITest, UpdateUserPrefsVersion) {
- PrefService prefs(FilePath(), NULL);
+ PrefService prefs((FilePath()));
// Does the migration
NewTabUI::RegisterUserPrefs(&prefs);
diff --git a/chrome/browser/dom_ui/shown_sections_handler_unittest.cc b/chrome/browser/dom_ui/shown_sections_handler_unittest.cc
index a3c4429..6b77e01 100644
--- a/chrome/browser/dom_ui/shown_sections_handler_unittest.cc
+++ b/chrome/browser/dom_ui/shown_sections_handler_unittest.cc
@@ -14,7 +14,7 @@ class ShownSectionsHandlerTest : public testing::Test {
};
TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) {
- PrefService pref(FilePath(), NULL);
+ PrefService pref((FilePath()));
// Set an *old* value
pref.RegisterIntegerPref(prefs::kNTPShownSections, 0);
diff --git a/chrome/browser/extensions/extension_updater_unittest.cc b/chrome/browser/extensions/extension_updater_unittest.cc
index bcb9287..2765b40 100644
--- a/chrome/browser/extensions/extension_updater_unittest.cc
+++ b/chrome/browser/extensions/extension_updater_unittest.cc
@@ -74,7 +74,7 @@ class ScopedTempPrefService {
// problem when different tests are running in parallel.
temp_dir_.CreateUniqueTempDir();
FilePath pref_file = temp_dir_.path().AppendASCII("prefs");
- prefs_.reset(new PrefService(pref_file, NULL));
+ prefs_.reset(new PrefService(pref_file));
}
~ScopedTempPrefService() {}
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index f31a298..3ca4b95 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -210,7 +210,7 @@ class ExtensionsServiceTest
virtual void InitializeExtensionsService(const FilePath& pref_file,
const FilePath& extensions_install_dir) {
- prefs_.reset(new PrefService(pref_file, NULL));
+ prefs_.reset(new PrefService(pref_file));
profile_.reset(new TestingProfile());
service_ = new ExtensionsService(profile_.get(),
CommandLine::ForCurrentProcess(),
diff --git a/chrome/browser/gtk/bookmark_bar_gtk_unittest.cc b/chrome/browser/gtk/bookmark_bar_gtk_unittest.cc
index 87fb647..59c6172 100644
--- a/chrome/browser/gtk/bookmark_bar_gtk_unittest.cc
+++ b/chrome/browser/gtk/bookmark_bar_gtk_unittest.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/gtk/bookmark_bar_gtk.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/gtk/tabstrip_origin_provider.h"
#include "base/task.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -21,9 +22,12 @@ class EmptyTabstripOriginProvider : public TabstripOriginProvider {
class BookmarkBarGtkUnittest : public ::testing::Test {
protected:
- BookmarkBarGtkUnittest() {
+ BookmarkBarGtkUnittest()
+ : ui_thread_(ChromeThread::UI, &message_loop_),
+ file_thread_(ChromeThread::FILE, &message_loop_) {
profile_.reset(new TestingProfile());
profile_->CreateBookmarkModel(true);
+ profile_->BlockUntilBookmarkModelLoaded();
browser_.reset(new Browser(Browser::TYPE_NORMAL, profile_.get()));
origin_provider_.reset(new EmptyTabstripOriginProvider);
@@ -35,6 +39,9 @@ class BookmarkBarGtkUnittest : public ::testing::Test {
scoped_ptr<Browser> browser_;
scoped_ptr<TabstripOriginProvider> origin_provider_;
scoped_ptr<BookmarkBarGtk> bookmark_bar_;
+ MessageLoopForUI message_loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
};
TEST_F(BookmarkBarGtkUnittest, DisplaysHelpMessageOnEmpty) {
diff --git a/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc b/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc
index de03a51..4945715 100644
--- a/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc
+++ b/chrome/browser/gtk/bookmark_editor_gtk_unittest.cc
@@ -6,6 +6,7 @@
#include "base/string_util.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/gtk/bookmark_editor_gtk.h"
#include "chrome/browser/gtk/bookmark_tree_model.h"
@@ -25,13 +26,17 @@ using bookmark_utils::GetTitleFromTreeIter;
// BookmarkModel class to GTK's native GtkTreeStore.
class BookmarkEditorGtkTest : public testing::Test {
public:
- BookmarkEditorGtkTest() : model_(NULL) {
+ BookmarkEditorGtkTest()
+ : ui_thread_(ChromeThread::UI, &message_loop_),
+ file_thread_(ChromeThread::FILE, &message_loop_),
+ model_(NULL) {
}
virtual void SetUp() {
profile_.reset(new TestingProfile());
profile_->set_has_history_service(true);
profile_->CreateBookmarkModel(true);
+ profile_->BlockUntilBookmarkModelLoaded();
model_ = profile_->GetBookmarkModel();
@@ -43,6 +48,8 @@ class BookmarkEditorGtkTest : public testing::Test {
protected:
MessageLoopForUI message_loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
BookmarkModel* model_;
scoped_ptr<TestingProfile> profile_;
diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc
index ee3eb75..efe338e 100644
--- a/chrome/browser/gtk/bookmark_manager_gtk.cc
+++ b/chrome/browser/gtk/bookmark_manager_gtk.cc
@@ -1407,10 +1407,7 @@ void BookmarkManagerGtk::FileSelected(const FilePath& path,
profile_info, profile_,
new ImportObserverImpl(profile()), false);
} else if (id == IDS_BOOKMARK_MANAGER_EXPORT_MENU) {
- if (g_browser_process->io_thread()) {
- bookmark_html_writer::WriteBookmarks(
- g_browser_process->io_thread()->message_loop(), model_, path);
- }
+ bookmark_html_writer::WriteBookmarks(model_, path);
} else {
NOTREACHED();
}
diff --git a/chrome/browser/gtk/dialogs_gtk.cc b/chrome/browser/gtk/dialogs_gtk.cc
index 79baf3d..fe934c0 100644
--- a/chrome/browser/gtk/dialogs_gtk.cc
+++ b/chrome/browser/gtk/dialogs_gtk.cc
@@ -15,6 +15,7 @@
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/shell_dialogs.h"
#include "grit/generated_resources.h"
@@ -148,10 +149,8 @@ FilePath* SelectFileDialogImpl::last_opened_path_ = NULL;
// static
SelectFileDialog* SelectFileDialog::Create(Listener* listener) {
- DCHECK(MessageLoop::current() !=
- g_browser_process->io_thread()->message_loop());
- DCHECK(MessageLoop::current() !=
- g_browser_process->file_thread()->message_loop());
+ DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::IO));
+ DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::FILE));
return new SelectFileDialogImpl(listener);
}
diff --git a/chrome/browser/jankometer.cc b/chrome/browser/jankometer.cc
index 7cdbe3a..c5c78b07 100644
--- a/chrome/browser/jankometer.cc
+++ b/chrome/browser/jankometer.cc
@@ -18,6 +18,7 @@
#include "base/watchdog.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/common/chrome_switches.h"
#if defined(OS_LINUX)
@@ -249,12 +250,9 @@ void InstallJankometer(const CommandLine& parsed_command_line) {
TimeDelta::FromMilliseconds(kMaxIOMessageDelayMs),
io_watchdog_enabled);
io_observer->AddRef();
- base::Thread* io_thread = g_browser_process->io_thread();
- if (io_thread) {
- io_thread->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(io_observer,
- &JankObserver::AttachToCurrentThread));
- }
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(io_observer, &JankObserver::AttachToCurrentThread));
}
void UninstallJankometer() {
diff --git a/chrome/browser/memory_details.cc b/chrome/browser/memory_details.cc
index eed3bc9..4ea4444 100644
--- a/chrome/browser/memory_details.cc
+++ b/chrome/browser/memory_details.cc
@@ -8,7 +8,6 @@
#include "base/file_version_info.h"
#include "base/process_util.h"
#include "base/string_util.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/renderer_host/backing_store_manager.h"
#include "chrome/browser/renderer_host/render_process_host.h"
@@ -37,14 +36,13 @@
//
void MemoryDetails::StartFetch() {
- ui_loop_ = MessageLoop::current();
-
- DCHECK(ui_loop_ != g_browser_process->io_thread()->message_loop());
- DCHECK(ui_loop_ != g_browser_process->file_thread()->message_loop());
+ DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::IO));
+ DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::FILE));
// In order to process this request, we need to use the plugin information.
// However, plugin process information is only available from the IO thread.
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnIOThread));
}
@@ -72,7 +70,7 @@ void MemoryDetails::CollectChildInfoOnIOThread() {
}
void MemoryDetails::CollectChildInfoOnUIThread() {
- DCHECK(MessageLoop::current() == ui_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
#if defined(OS_LINUX)
const pid_t zygote_pid = Singleton<ZygoteHost>()->pid();
diff --git a/chrome/browser/memory_details.h b/chrome/browser/memory_details.h
index 5e155a1..b92fbae 100644
--- a/chrome/browser/memory_details.h
+++ b/chrome/browser/memory_details.h
@@ -11,8 +11,6 @@
#include "base/ref_counted.h"
#include "chrome/common/child_process_info.h"
-class MessageLoop;
-
// We collect data about each browser process. A browser may
// have multiple processes (of course!). Even IE has multiple
// processes these days.
@@ -117,7 +115,6 @@ class MemoryDetails : public base::RefCountedThreadSafe<MemoryDetails> {
ProcessData* ChromeBrowser();
std::vector<ProcessData> process_data_;
- MessageLoop* ui_loop_;
DISALLOW_EVIL_CONSTRUCTORS(MemoryDetails);
};
diff --git a/chrome/browser/memory_details_linux.cc b/chrome/browser/memory_details_linux.cc
index 0c815ab..1308fb8 100644
--- a/chrome/browser/memory_details_linux.cc
+++ b/chrome/browser/memory_details_linux.cc
@@ -58,8 +58,7 @@ static const struct {
{ "", MAX_BROWSERS },
};
-MemoryDetails::MemoryDetails()
- : ui_loop_(NULL) {
+MemoryDetails::MemoryDetails() {
}
ProcessData* MemoryDetails::ChromeBrowser() {
@@ -252,6 +251,7 @@ void MemoryDetails::CollectProcessData(
}
// Finally return to the browser thread.
- ui_loop_->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnUIThread));
}
diff --git a/chrome/browser/memory_details_win.cc b/chrome/browser/memory_details_win.cc
index db5cce0..34beb3e 100644
--- a/chrome/browser/memory_details_win.cc
+++ b/chrome/browser/memory_details_win.cc
@@ -8,7 +8,6 @@
#include "app/l10n_util.h"
#include "base/file_version_info.h"
#include "base/string_util.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/renderer_host/backing_store_manager.h"
#include "chrome/browser/renderer_host/render_process_host.h"
@@ -34,8 +33,7 @@ enum {
// These entries must match the ordering for MemoryDetails::BrowserProcess.
static ProcessData g_process_template[MAX_BROWSERS];
-MemoryDetails::MemoryDetails()
- : ui_loop_(NULL) {
+MemoryDetails::MemoryDetails() {
static const std::wstring google_browser_name =
l10n_util::GetString(IDS_PRODUCT_NAME);
ProcessData g_process_template[MAX_BROWSERS] = {
@@ -150,6 +148,7 @@ void MemoryDetails::CollectProcessData(
} while (::Process32Next(snapshot, &process_entry));
// Finally return to the browser thread.
- ui_loop_->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnUIThread));
}
diff --git a/chrome/browser/metrics/metrics_service_uitest.cc b/chrome/browser/metrics/metrics_service_uitest.cc
index da25d8e..5127208 100644
--- a/chrome/browser/metrics/metrics_service_uitest.cc
+++ b/chrome/browser/metrics/metrics_service_uitest.cc
@@ -52,8 +52,7 @@ class MetricsServiceTest : public UITest {
FilePath local_state_path = user_data_dir()
.Append(chrome::kLocalStateFilename);
- PrefService* local_state(new PrefService(local_state_path, NULL));
- return local_state;
+ return new PrefService(local_state_path);
}
};
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 7730127..dec67cb 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -118,6 +118,9 @@ static net::ProxyConfigService* CreateProxyConfigService(
if (!proxy_config_from_cmd_line.get()) {
// Use system settings.
+ // TODO(port): the IO and FILE message loops are only used by Linux. Can
+ // that code be moved to chrome/browser instead of being in net, so that it
+ // can use ChromeThread instead of raw MessageLoop pointers? See bug 25354.
return net::ProxyService::CreateSystemProxyConfigService(
g_browser_process->io_thread()->message_loop(),
g_browser_process->file_thread()->message_loop());
@@ -667,7 +670,8 @@ void ChromeURLRequestContextGetter::Observe(NotificationType type,
if (*pref_name_in == prefs::kAcceptLanguages) {
std::string accept_language =
WideToASCII(prefs->GetString(prefs::kAcceptLanguages));
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
NewRunnableMethod(
this,
&ChromeURLRequestContextGetter::OnAcceptLanguageChange,
@@ -675,7 +679,8 @@ void ChromeURLRequestContextGetter::Observe(NotificationType type,
} else if (*pref_name_in == prefs::kCookieBehavior) {
net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt(
prefs_->GetInteger(prefs::kCookieBehavior));
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
NewRunnableMethod(
this,
&ChromeURLRequestContextGetter::OnCookiePolicyChange,
@@ -683,7 +688,8 @@ void ChromeURLRequestContextGetter::Observe(NotificationType type,
} else if (*pref_name_in == prefs::kDefaultCharset) {
std::string default_charset =
WideToASCII(prefs->GetString(prefs::kDefaultCharset));
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
NewRunnableMethod(
this,
&ChromeURLRequestContextGetter::OnDefaultCharsetChange,
@@ -869,8 +875,8 @@ net::CookieStore* ChromeURLRequestContextGetter::GetCookieStore() {
base::WaitableEvent completion(false, false);
net::CookieStore* result = NULL;
- g_browser_process->io_thread()->message_loop()->PostTask(
- FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
NewRunnableMethod(this,
&ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper,
&completion,
diff --git a/chrome/browser/net/dns_global.cc b/chrome/browser/net/dns_global.cc
index 7813f77..d70a3a0 100644
--- a/chrome/browser/net/dns_global.cc
+++ b/chrome/browser/net/dns_global.cc
@@ -13,7 +13,6 @@
#include "base/thread.h"
#include "base/values.h"
#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/dns_host_info.h"
#include "chrome/browser/net/referrer.h"
#include "chrome/browser/profile.h"
@@ -422,7 +421,6 @@ void InitDnsPrefetch(TimeDelta max_queue_delay, size_t max_concurrent,
// Have the DnsMaster issue resolve requests through a global HostResolver
// that is shared by the main URLRequestContext, and lives on the IO thread.
dns_master = new DnsMaster(GetGlobalHostResolver(),
- g_browser_process->io_thread()->message_loop(),
max_queue_delay, max_concurrent);
dns_master->AddRef();
// We did the initialization, so we should prime the pump, and set up
diff --git a/chrome/browser/net/dns_master.cc b/chrome/browser/net/dns_master.cc
index b30793f..91e2d1f 100644
--- a/chrome/browser/net/dns_master.cc
+++ b/chrome/browser/net/dns_master.cc
@@ -10,11 +10,11 @@
#include "base/compiler_specific.h"
#include "base/histogram.h"
-#include "base/message_loop.h"
#include "base/lock.h"
#include "base/stats_counters.h"
#include "base/string_util.h"
#include "base/time.h"
+#include "chrome/browser/chrome_thread.h"
#include "net/base/address_list.h"
#include "net/base/completion_callback.h"
#include "net/base/host_resolver.h"
@@ -70,15 +70,13 @@ class DnsMaster::LookupRequest {
};
DnsMaster::DnsMaster(net::HostResolver* host_resolver,
- MessageLoop* host_resolver_loop,
TimeDelta max_queue_delay,
size_t max_concurrent)
: peak_pending_lookups_(0),
shutdown_(false),
max_concurrent_lookups_(max_concurrent),
max_queue_delay_(max_queue_delay),
- host_resolver_(host_resolver),
- host_resolver_loop_(host_resolver_loop) {
+ host_resolver_(host_resolver) {
}
DnsMaster::~DnsMaster() {
@@ -101,11 +99,13 @@ void DnsMaster::ResolveList(const NameList& hostnames,
DnsHostInfo::ResolutionMotivation motivation) {
AutoLock auto_lock(lock_);
- // We need to run this on |host_resolver_loop_| since we may access
+ // We need to run this on the IO thread since we may access
// |host_resolver_| which is not thread safe.
- if (MessageLoop::current() != host_resolver_loop_) {
- host_resolver_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &DnsMaster::ResolveList, hostnames, motivation));
+ if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this, &DnsMaster::ResolveList, hostnames, motivation));
return;
}
@@ -122,11 +122,12 @@ void DnsMaster::Resolve(const std::string& hostname,
return;
AutoLock auto_lock(lock_);
- // We need to run this on |host_resolver_loop_| since we may access
+ // We need to run this on the IO thread since we may access
// |host_resolver_| which is not thread safe.
- if (MessageLoop::current() != host_resolver_loop_) {
- host_resolver_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &DnsMaster::Resolve, hostname, motivation));
+ if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &DnsMaster::Resolve, hostname, motivation));
return;
}
@@ -205,11 +206,12 @@ void DnsMaster::NonlinkNavigation(const GURL& referrer,
void DnsMaster::NavigatingTo(const std::string& host_name) {
AutoLock auto_lock(lock_);
- // We need to run this on |host_resolver_loop_| since we may access
+ // We need to run this on the IO thread since we may access
// |host_resolver_| which is not thread safe.
- if (MessageLoop::current() != host_resolver_loop_) {
- host_resolver_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &DnsMaster::NavigatingTo, host_name));
+ if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &DnsMaster::NavigatingTo, host_name));
return;
}
@@ -414,9 +416,9 @@ DnsHostInfo* DnsMaster::PreLockedResolve(
}
void DnsMaster::PreLockedScheduleLookups() {
- // We need to run this on |host_resolver_loop_| since we may access
- // |host_resolver_| which is not thread safe.
- DCHECK_EQ(MessageLoop::current(), host_resolver_loop_);
+ // We need to run this on the IO thread since we may access |host_resolver_|
+ // which is not thread safe.
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
while (!work_queue_.IsEmpty() &&
pending_lookups_.size() < max_concurrent_lookups_) {
@@ -466,7 +468,7 @@ bool DnsMaster::PreLockedCongestionControlPerformed(DnsHostInfo* info) {
void DnsMaster::OnLookupFinished(LookupRequest* request,
const std::string& hostname, bool found) {
- DCHECK_EQ(MessageLoop::current(), host_resolver_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
AutoLock auto_lock(lock_); // For map access (changing info values).
PrelockedLookupFinished(request, hostname, found);
diff --git a/chrome/browser/net/dns_master.h b/chrome/browser/net/dns_master.h
index 1bf87d0..451e9ed 100644
--- a/chrome/browser/net/dns_master.h
+++ b/chrome/browser/net/dns_master.h
@@ -32,8 +32,6 @@ namespace net {
class HostResolver;
}
-class MessageLoop;
-
namespace chrome_browser_net {
typedef chrome_common_net::NameList NameList;
@@ -42,9 +40,9 @@ typedef std::map<std::string, DnsHostInfo> Results;
class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> {
public:
// |max_concurrent| specifies how many concurrent (paralell) prefetches will
- // be performed. Host lookups will be issued on the |host_resolver_loop|
- // thread, using the |host_resolver| instance.
- DnsMaster(net::HostResolver* host_resolver, MessageLoop* host_resolver_loop,
+ // be performed. Host lookups will be issued on the IO thread, using the
+ // |host_resolver| instance.
+ DnsMaster(net::HostResolver* host_resolver,
TimeDelta max_queue_delay_ms, size_t max_concurrent);
~DnsMaster();
@@ -236,9 +234,8 @@ class DnsMaster : public base::RefCountedThreadSafe<DnsMaster> {
const TimeDelta max_queue_delay_;
// The host resovler we warm DNS entries for. The resolver (which is not
- // thread safe) should be accessed only on |host_resolver_loop_|.
+ // thread safe) should be accessed only on the IO thread.
scoped_refptr<net::HostResolver> host_resolver_;
- MessageLoop* host_resolver_loop_;
DISALLOW_COPY_AND_ASSIGN(DnsMaster);
};
diff --git a/chrome/browser/net/dns_master_unittest.cc b/chrome/browser/net/dns_master_unittest.cc
index fc8b796d..249956d 100644
--- a/chrome/browser/net/dns_master_unittest.cc
+++ b/chrome/browser/net/dns_master_unittest.cc
@@ -12,6 +12,7 @@
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/timer.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/dns_global.h"
#include "chrome/browser/net/dns_host_info.h"
#include "chrome/common/net/dns.h"
@@ -59,7 +60,8 @@ class WaitForResolutionHelper {
class DnsMasterTest : public testing::Test {
public:
DnsMasterTest()
- : host_resolver_(new net::MockCachingHostResolver()),
+ : io_thread_(ChromeThread::IO, &loop_),
+ host_resolver_(new net::MockCachingHostResolver()),
default_max_queueing_delay_(TimeDelta::FromMilliseconds(
DnsPrefetcherInit::kMaxQueueingDelayMs)) {
}
@@ -91,7 +93,8 @@ class DnsMasterTest : public testing::Test {
// IMPORTANT: do not move this below |host_resolver_|; the host resolver
// must not outlive the message loop, otherwise bad things can happen
// (like posting to a deleted message loop).
- MessageLoop loop;
+ MessageLoop loop_;
+ ChromeThread io_thread_;
protected:
scoped_refptr<net::MockCachingHostResolver> host_resolver_;
@@ -105,15 +108,13 @@ class DnsMasterTest : public testing::Test {
TEST_F(DnsMasterTest, StartupShutdownTest) {
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- MessageLoop::current(), default_max_queueing_delay_,
- DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
testing_master->Shutdown();
}
TEST_F(DnsMasterTest, BenefitLookupTest) {
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- MessageLoop::current(), default_max_queueing_delay_,
- DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
std::string goog("www.google.com"),
goog2("gmail.google.com.com"),
@@ -177,8 +178,7 @@ TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) {
host_resolver_->Reset(resolver_proc);
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- MessageLoop::current(), default_max_queueing_delay_,
- DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
std::string localhost("127.0.0.1");
NameList names;
@@ -201,8 +201,7 @@ TEST_F(DnsMasterTest, ShutdownWhenResolutionIsPendingTest) {
TEST_F(DnsMasterTest, SingleLookupTest) {
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- MessageLoop::current(), default_max_queueing_delay_,
- DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
std::string goog("www.google.com");
@@ -231,8 +230,7 @@ TEST_F(DnsMasterTest, ConcurrentLookupTest) {
host_resolver_->rules()->AddSimulatedFailure("*.notfound");
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- MessageLoop::current(), default_max_queueing_delay_,
- DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
std::string goog("www.google.com"),
goog2("gmail.google.com.com"),
@@ -280,8 +278,7 @@ TEST_F(DnsMasterTest, MassiveConcurrentLookupTest) {
host_resolver_->rules()->AddSimulatedFailure("*.notfound");
scoped_refptr<DnsMaster> testing_master = new DnsMaster(host_resolver_,
- MessageLoop::current(), default_max_queueing_delay_,
- DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
NameList names;
for (int i = 0; i < 100; i++)
@@ -385,8 +382,7 @@ int GetLatencyFromSerialization(const std::string& motivation,
// Make sure nil referral lists really have no entries, and no latency listed.
TEST_F(DnsMasterTest, ReferrerSerializationNilTest) {
scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_,
- MessageLoop::current(), default_max_queueing_delay_,
- DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
ListValue referral_list;
master->SerializeReferrers(&referral_list);
EXPECT_EQ(0U, referral_list.GetSize());
@@ -401,8 +397,7 @@ TEST_F(DnsMasterTest, ReferrerSerializationNilTest) {
// serialization without being changed.
TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) {
scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_,
- MessageLoop::current(), default_max_queueing_delay_,
- DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
std::string motivation_hostname = "www.google.com";
std::string subresource_hostname = "icons.google.com";
const int kLatency = 3;
@@ -426,8 +421,7 @@ TEST_F(DnsMasterTest, ReferrerSerializationSingleReferrerTest) {
// Make sure the Trim() functionality works as expected.
TEST_F(DnsMasterTest, ReferrerSerializationTrimTest) {
scoped_refptr<DnsMaster> master = new DnsMaster(host_resolver_,
- MessageLoop::current(), default_max_queueing_delay_,
- DnsPrefetcherInit::kMaxConcurrentLookups);
+ default_max_queueing_delay_, DnsPrefetcherInit::kMaxConcurrentLookups);
std::string motivation_hostname = "www.google.com";
std::string icon_subresource_hostname = "icons.google.com";
std::string img_subresource_hostname = "img.google.com";
@@ -556,7 +550,4 @@ TEST_F(DnsMasterTest, PriorityQueueReorderTest) {
EXPECT_TRUE(queue.IsEmpty());
}
-
-
-
} // namespace chrome_browser_net
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index 08e0d2b..1cd0b31 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -10,7 +10,6 @@
#include "base/string_util.h"
#include "base/thread.h"
#include "chrome/browser/browser_list.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_object_proxy.h"
@@ -116,12 +115,10 @@ class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
if (!action_taken_)
UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1);
- base::Thread* io_thread = g_browser_process->io_thread();
- if (io_thread && io_thread->message_loop()) {
- io_thread->message_loop()->PostTask(FROM_HERE,
- new NotificationPermissionCallbackTask(process_id_, route_id_,
- callback_context_));
- }
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ new NotificationPermissionCallbackTask(
+ process_id_, route_id_, callback_context_));
delete this;
}
@@ -221,13 +218,11 @@ void DesktopNotificationService::GrantPermission(const GURL& origin) {
prefs->ScheduleSavePersistentPrefs();
// Schedule a cache update on the IO thread.
- base::Thread* io_thread = g_browser_process->io_thread();
- if (io_thread && io_thread->message_loop()) {
- io_thread->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(prefs_cache_.get(),
- &NotificationsPrefsCache::CacheAllowedOrigin,
- origin));
- }
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ prefs_cache_.get(), &NotificationsPrefsCache::CacheAllowedOrigin,
+ origin));
}
void DesktopNotificationService::DenyPermission(const GURL& origin) {
@@ -244,13 +239,11 @@ void DesktopNotificationService::DenyPermission(const GURL& origin) {
prefs->ScheduleSavePersistentPrefs();
// Schedule a cache update on the IO thread.
- base::Thread* io_thread = g_browser_process->io_thread();
- if (io_thread && io_thread->message_loop()) {
- io_thread->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(prefs_cache_.get(),
- &NotificationsPrefsCache::CacheDeniedOrigin,
- origin));
- }
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ prefs_cache_.get(), &NotificationsPrefsCache::CacheDeniedOrigin,
+ origin));
}
void DesktopNotificationService::RequestPermission(
diff --git a/chrome/browser/printing/print_dialog_gtk.cc b/chrome/browser/printing/print_dialog_gtk.cc
index 7536a59..b35da24 100644
--- a/chrome/browser/printing/print_dialog_gtk.cc
+++ b/chrome/browser/printing/print_dialog_gtk.cc
@@ -10,9 +10,9 @@
#include "base/file_util.h"
#include "base/logging.h"
-#include "base/message_loop.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/tab_contents/tab_contents.h"
@@ -58,9 +58,9 @@ class PdfUnsupportedInfoBarDelegate : public LinkInfoBarDelegate {
} // namespace
// static
-void PrintDialogGtk::CreatePrintDialogForPdf(const FilePath& path,
- MessageLoop* loop) {
- loop->PostTask(FROM_HERE,
+void PrintDialogGtk::CreatePrintDialogForPdf(const FilePath& path) {
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
NewRunnableFunction(&PrintDialogGtk::CreateDialogImpl, path));
}
diff --git a/chrome/browser/printing/print_dialog_gtk.h b/chrome/browser/printing/print_dialog_gtk.h
index 7f9cc7f..589af80 100644
--- a/chrome/browser/printing/print_dialog_gtk.h
+++ b/chrome/browser/printing/print_dialog_gtk.h
@@ -11,16 +11,14 @@
#include "base/file_path.h"
class Browser;
-class MessageLoop;
typedef struct _GtkPrintJob GtkPrintJob;
// Currently this dialog only allows the user to choose a printer.
class PrintDialogGtk {
public:
- // Called on the IO thread. Posts the dialog creation action on the given
- // loop.
- static void CreatePrintDialogForPdf(const FilePath& path, MessageLoop* loop);
+ // Called on the IO thread.
+ static void CreatePrintDialogForPdf(const FilePath& path);
private:
explicit PrintDialogGtk(const FilePath& path_to_pdf);
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index cafba63..aba64c5 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -13,8 +13,8 @@
#include "base/string_util.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_list.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_theme_provider.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/extensions/extension_devtools_manager.h"
#include "chrome/browser/extensions/extension_message_service.h"
@@ -132,8 +132,7 @@ static void CleanupRequestContext(ChromeURLRequestContextGetter* context) {
context->CleanupOnUIThread();
// Clean up request context on IO thread.
- g_browser_process->io_thread()->message_loop()->ReleaseSoon(FROM_HERE,
- context);
+ ChromeThread::ReleaseSoon(ChromeThread::IO, FROM_HERE, context);
}
}
@@ -695,10 +694,7 @@ void ProfileImpl::InitWebResources() {
if (web_resource_service_)
return; // Already initialized.
- web_resource_service_ = new WebResourceService(
- this,
- g_browser_process->file_thread()->message_loop());
-
+ web_resource_service_ = new WebResourceService(this);
web_resource_service_->StartAfterDelay();
}
@@ -814,8 +810,7 @@ Profile* ProfileImpl::GetOriginalProfile() {
VisitedLinkMaster* ProfileImpl::GetVisitedLinkMaster() {
if (!visited_link_master_.get()) {
scoped_ptr<VisitedLinkMaster> visited_links(
- new VisitedLinkMaster(g_browser_process->file_thread(),
- visited_link_event_listener_.get(), this));
+ new VisitedLinkMaster(visited_link_event_listener_.get(), this));
if (!visited_links->Init())
return NULL;
visited_link_master_.swap(visited_links);
@@ -857,8 +852,7 @@ net::StrictTransportSecurityState*
if (!strict_transport_security_state_.get()) {
strict_transport_security_state_ = new net::StrictTransportSecurityState();
strict_transport_security_persister_ = new StrictTransportSecurityPersister(
- strict_transport_security_state_.get(),
- g_browser_process->file_thread(), path_);
+ strict_transport_security_state_.get(), path_);
}
return strict_transport_security_state_.get();
@@ -866,8 +860,7 @@ net::StrictTransportSecurityState*
PrefService* ProfileImpl::GetPrefs() {
if (!prefs_.get()) {
- prefs_.reset(new PrefService(GetPrefFilePath(),
- g_browser_process->file_thread()));
+ prefs_.reset(new PrefService(GetPrefFilePath()));
// The Profile class and ProfileManager class may read some prefs so
// register known prefs as soon as possible.
@@ -1268,31 +1261,23 @@ void ProfileImpl::ReinitializeSpellChecker() {
}
void ProfileImpl::NotifySpellCheckerChanged() {
- // The I/O thread may be NULL during testing.
- base::Thread* io_thread = g_browser_process->io_thread();
- if (io_thread) { // Notify resource message filters.
- SpellcheckerReinitializedDetails scoped_spellchecker;
- scoped_spellchecker.spellchecker = spellchecker_;
- io_thread->message_loop()->PostTask(FROM_HERE,
- new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
- }
+ SpellcheckerReinitializedDetails scoped_spellchecker;
+ scoped_spellchecker.spellchecker = spellchecker_;
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ new NotifySpellcheckerChangeTask(this, scoped_spellchecker));
}
void ProfileImpl::DeleteSpellCheckerImpl(bool notify) {
- if (spellchecker_) {
- // The spellchecker must be deleted on the I/O thread.
- // The I/O thread may be NULL during testing.
- base::Thread* io_thread = g_browser_process->io_thread();
- if (io_thread)
- io_thread->message_loop()->ReleaseSoon(FROM_HERE, spellchecker_);
- else // during testing, we don't have an I/O thread
- spellchecker_->Release();
+ if (!spellchecker_)
+ return;
- spellchecker_ = NULL;
+ // The spellchecker must be deleted on the I/O thread.
+ ChromeThread::ReleaseSoon(ChromeThread::IO, FROM_HERE, spellchecker_);
+ spellchecker_ = NULL;
- if (notify)
- NotifySpellCheckerChanged();
- }
+ if (notify)
+ NotifySpellCheckerChanged();
}
SpellChecker* ProfileImpl::GetSpellChecker() {
diff --git a/chrome/browser/profile_manager.cc b/chrome/browser/profile_manager.cc
index 4526911..2a20bdc 100644
--- a/chrome/browser/profile_manager.cc
+++ b/chrome/browser/profile_manager.cc
@@ -221,16 +221,18 @@ void ProfileManager::OnSuspend() {
DCHECK(CalledOnValidThread());
for (const_iterator i(begin()); i != end(); ++i) {
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableFunction(&ProfileManager::SuspendProfile, *i));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableFunction(&ProfileManager::SuspendProfile, *i));
}
}
void ProfileManager::OnResume() {
DCHECK(CalledOnValidThread());
for (const_iterator i(begin()); i != end(); ++i) {
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableFunction(&ProfileManager::ResumeProfile, *i));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableFunction(&ProfileManager::ResumeProfile, *i));
}
}
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index 38e163b..076b803 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -404,11 +404,11 @@ void BrowserRenderProcessHost::WidgetHidden() {
}
void BrowserRenderProcessHost::AddWord(const string16& word) {
- base::Thread* io_thread = g_browser_process->io_thread();
SpellChecker* spellchecker = profile()->GetSpellChecker();
if (spellchecker) {
- io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- spellchecker, &SpellChecker::AddWord, word));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(spellchecker, &SpellChecker::AddWord, word));
}
}
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.cc b/chrome/browser/renderer_host/buffered_resource_handler.cc
index 45dec61..33e6489 100644
--- a/chrome/browser/renderer_host/buffered_resource_handler.cc
+++ b/chrome/browser/renderer_host/buffered_resource_handler.cc
@@ -404,8 +404,7 @@ bool BufferedResourceHandler::ShouldWaitForPlugins() {
AddRef();
ChromeThread::PostTask(
ChromeThread::FILE, FROM_HERE,
- NewRunnableFunction(&BufferedResourceHandler::LoadPlugins,
- this, host_->ui_loop()));
+ NewRunnableFunction(&BufferedResourceHandler::LoadPlugins, this));
return true;
}
@@ -469,34 +468,26 @@ bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) {
GURL(), type, allow_wildcard, &info, NULL);
}
-void BufferedResourceHandler::LoadPlugins(BufferedResourceHandler* handler,
- MessageLoop* main_message_loop) {
+void BufferedResourceHandler::LoadPlugins(BufferedResourceHandler* handler) {
std::vector<WebPluginInfo> plugins;
NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins);
- // Note, we want to get to the IO thread now, but the file thread outlives it
- // so we can't post a task to it directly as it might be in the middle of
- // destruction. So hop through the main thread, where the destruction of the
- // IO thread happens and hence no race conditions exist.
- main_message_loop->PostTask(FROM_HERE,
- NewRunnableFunction(&BufferedResourceHandler::NotifyPluginsLoaded,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableFunction(&BufferedResourceHandler::OnPluginsLoaded,
handler));
}
-void BufferedResourceHandler::NotifyPluginsLoaded(
+void BufferedResourceHandler::OnPluginsLoaded(
BufferedResourceHandler* handler) {
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(handler, &BufferedResourceHandler::OnPluginsLoaded));
-}
-
-void BufferedResourceHandler::OnPluginsLoaded() {
- wait_for_plugins_ = false;
- if (request_) {
+ handler->wait_for_plugins_ = false;
+ if (handler->request_) {
ResourceDispatcherHostRequestInfo* info =
- ResourceDispatcherHost::InfoForRequest(request_);
- host_->PauseRequest(info->child_id(), info->request_id(), false);
- if (!CompleteResponseStarted(info->request_id(), false))
- host_->CancelRequest(info->child_id(), info->request_id(), false);
+ ResourceDispatcherHost::InfoForRequest(handler->request_);
+ handler->host_->PauseRequest(info->child_id(), info->request_id(), false);
+ if (!handler->CompleteResponseStarted(info->request_id(), false))
+ handler->host_->CancelRequest(
+ info->child_id(), info->request_id(), false);
}
- Release();
+ handler->Release();
}
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.h b/chrome/browser/renderer_host/buffered_resource_handler.h
index 919a675..fa0e249 100644
--- a/chrome/browser/renderer_host/buffered_resource_handler.h
+++ b/chrome/browser/renderer_host/buffered_resource_handler.h
@@ -62,15 +62,10 @@ class BufferedResourceHandler : public ResourceHandler {
bool ShouldDownload(bool* need_plugin_list);
// Called on the file thread to load the list of plugins.
- static void LoadPlugins(BufferedResourceHandler* handler,
- MessageLoop* main_message_loop);
-
- // Runs on the main thread to notify the IO thread that plugins have been
- // loaded. This is needed since the file thread outlives the IO thread.
- static void NotifyPluginsLoaded(BufferedResourceHandler* handler);
+ static void LoadPlugins(BufferedResourceHandler* handler);
// Called on the IO thread once the list of plugins has been loaded.
- void OnPluginsLoaded();
+ static void OnPluginsLoaded(BufferedResourceHandler* handler);
scoped_refptr<ResourceHandler> real_handler_;
scoped_refptr<ResourceResponse> response_;
diff --git a/chrome/browser/renderer_host/render_widget_helper.cc b/chrome/browser/renderer_host/render_widget_helper.cc
index 6534edf..51a533f 100644
--- a/chrome/browser/renderer_host/render_widget_helper.cc
+++ b/chrome/browser/renderer_host/render_widget_helper.cc
@@ -6,7 +6,7 @@
#include "base/eintr_wrapper.h"
#include "base/thread.h"
-#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
@@ -45,7 +45,6 @@ class RenderWidgetHelper::PaintMsgProxy : public Task {
RenderWidgetHelper::RenderWidgetHelper()
: render_process_id_(-1),
- ui_loop_(MessageLoop::current()),
#if defined(OS_WIN)
event_(CreateEvent(NULL, FALSE /* auto-reset */, FALSE, NULL)),
#elif defined(OS_POSIX)
@@ -76,22 +75,23 @@ int RenderWidgetHelper::GetNextRoutingID() {
}
void RenderWidgetHelper::CancelResourceRequests(int render_widget_id) {
- if (g_browser_process->io_thread() && render_process_id_ != -1) {
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(this,
- &RenderWidgetHelper::OnCancelResourceRequests,
- render_widget_id));
- }
+ if (render_process_id_ == -1)
+ return;
+
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this,
+ &RenderWidgetHelper::OnCancelResourceRequests,
+ render_widget_id));
}
void RenderWidgetHelper::CrossSiteClosePageACK(
const ViewMsg_ClosePage_Params& params) {
- if (g_browser_process->io_thread()) {
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(this,
- &RenderWidgetHelper::OnCrossSiteClosePageACK,
- params));
- }
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this,
+ &RenderWidgetHelper::OnCrossSiteClosePageACK,
+ params));
}
bool RenderWidgetHelper::WaitForPaintMsg(int render_widget_id,
@@ -161,7 +161,7 @@ void RenderWidgetHelper::DidReceivePaintMsg(const IPC::Message& msg) {
event_.Signal();
// The proxy will be deleted when it is run as a task.
- ui_loop_->PostTask(FROM_HERE, proxy);
+ ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, proxy);
}
void RenderWidgetHelper::OnDiscardPaintMsg(PaintMsgProxy* proxy) {
@@ -209,8 +209,10 @@ void RenderWidgetHelper::CreateNewWindow(int opener_id,
resource_dispatcher_host_->BlockRequestsForRoute(
render_process_id_, *route_id);
- ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RenderWidgetHelper::OnCreateWindowOnUI, opener_id, *route_id));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ this, &RenderWidgetHelper::OnCreateWindowOnUI, opener_id, *route_id));
}
void RenderWidgetHelper::OnCreateWindowOnUI(int opener_id, int route_id) {
@@ -218,7 +220,8 @@ void RenderWidgetHelper::OnCreateWindowOnUI(int opener_id, int route_id) {
if (host)
host->CreateNewWindow(route_id);
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
NewRunnableMethod(this, &RenderWidgetHelper::OnCreateWindowOnIO,
route_id));
}
@@ -232,9 +235,11 @@ void RenderWidgetHelper::CreateNewWidget(int opener_id,
bool activatable,
int* route_id) {
*route_id = GetNextRoutingID();
- ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &RenderWidgetHelper::OnCreateWidgetOnUI, opener_id, *route_id,
- activatable));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ this, &RenderWidgetHelper::OnCreateWidgetOnUI, opener_id, *route_id,
+ activatable));
}
void RenderWidgetHelper::OnCreateWidgetOnUI(
diff --git a/chrome/browser/renderer_host/render_widget_helper.h b/chrome/browser/renderer_host/render_widget_helper.h
index 2b3b445..d3593da 100644
--- a/chrome/browser/renderer_host/render_widget_helper.h
+++ b/chrome/browser/renderer_host/render_widget_helper.h
@@ -23,7 +23,6 @@ namespace base {
class TimeDelta;
}
-class MessageLoop;
class ResourceDispatcherHost;
struct ViewMsg_ClosePage_Params;
@@ -120,8 +119,6 @@ class RenderWidgetHelper :
// Called on the IO thread when a PaintRect message is received.
void DidReceivePaintMsg(const IPC::Message& msg);
- MessageLoop* ui_loop() { return ui_loop_; }
-
void CreateNewWindow(int opener_id,
bool user_gesture,
base::ProcessHandle render_process,
@@ -184,7 +181,6 @@ class RenderWidgetHelper :
Lock pending_paints_lock_;
int render_process_id_;
- MessageLoop* ui_loop_;
// Event used to implement WaitForPaintMsg.
base::WaitableEvent event_;
diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc
index f10f728..f97d249 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_win.cc
+++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc
@@ -18,6 +18,7 @@
#include "chrome/browser/browser_accessibility_manager.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_trial.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/plugin_process_host.h"
#include "chrome/browser/renderer_host/backing_store.h"
#include "chrome/browser/renderer_host/render_process_host.h"
@@ -411,7 +412,8 @@ HWND RenderWidgetHostViewWin::ReparentWindow(HWND window) {
0, 0, 0, 0, ::GetParent(window), 0, GetModuleHandle(NULL), 0);
DCHECK(parent);
::SetParent(window, parent);
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
new NotifyPluginProcessHostTask(window, parent));
return parent;
}
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 4d0d451..c4ccda3 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -234,8 +234,7 @@ void ResourceMessageFilter::OnChannelConnected(int32 peer_pid) {
// this object for sending messages.
audio_renderer_host_->IPCChannelConnected(id(), handle(), this);
- WorkerService::GetInstance()->Initialize(
- resource_dispatcher_host_, ui_loop());
+ WorkerService::GetInstance()->Initialize(resource_dispatcher_host_);
appcache_dispatcher_host_->Initialize(this, id(), handle());
socket_stream_dispatcher_host_->Initialize(this, id());
dom_storage_dispatcher_host_->Init(handle());
@@ -430,8 +429,9 @@ void ResourceMessageFilter::OnReceiveContextMenuMsg(const IPC::Message& msg) {
// Create a new ViewHostMsg_ContextMenu message.
const ViewHostMsg_ContextMenu context_menu_message(msg.routing_id(), params);
- ui_loop()->PostTask(FROM_HERE, new ContextMenuMessageDispatcher(
- id(), context_menu_message));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ new ContextMenuMessageDispatcher(id(), context_menu_message));
}
// Called on the IPC thread:
@@ -456,10 +456,6 @@ URLRequestContext* ResourceMessageFilter::GetRequestContext(
return request_context->GetURLRequestContext();
}
-MessageLoop* ResourceMessageFilter::ui_loop() {
- return render_widget_helper_->ui_loop();
-}
-
void ResourceMessageFilter::OnMsgCreateWindow(
int opener_id, bool user_gesture, int* route_id) {
render_widget_helper_->CreateNewWindow(opener_id,
@@ -704,7 +700,8 @@ void ResourceMessageFilter::OnClipboardWriteObjects(
Clipboard::DuplicateRemoteHandles(handle(), long_living_objects);
#endif
- ui_loop()->PostTask(FROM_HERE, new WriteClipboardTask(long_living_objects));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE, new WriteClipboardTask(long_living_objects));
}
#if !defined(OS_LINUX)
@@ -823,8 +820,9 @@ void ResourceMessageFilter::OnResourceTypeStats(
static_cast<int>(stats.fonts.size / 1024));
// We need to notify the TaskManager of these statistics from the UI
// thread.
- ui_loop()->PostTask(
- FROM_HERE, NewRunnableFunction(
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableFunction(
&ResourceMessageFilter::OnResourceTypeStatsOnUIThread,
stats,
base::GetProcId(handle())));
@@ -1170,7 +1168,8 @@ void ResourceMessageFilter::OnKeygen(uint32 key_size_index,
#if defined(USE_TCMALLOC)
void ResourceMessageFilter::OnRendererTcmalloc(base::ProcessId pid,
const std::string& output) {
- ui_loop()->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
NewRunnableFunction(AboutTcmallocRendererCallback, pid, output));
}
#endif
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index 1a91466..1c3d520 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -108,7 +108,6 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
ResourceDispatcherHost* resource_dispatcher_host() {
return resource_dispatcher_host_;
}
- MessageLoop* ui_loop();
bool off_the_record() { return off_the_record_; }
CallbackWithReturnValue<int>::Type* next_route_id_callback() {
return next_route_id_callback_.get();
diff --git a/chrome/browser/renderer_host/resource_message_filter_gtk.cc b/chrome/browser/renderer_host/resource_message_filter_gtk.cc
index f8c8986..5ed8fb0 100644
--- a/chrome/browser/renderer_host/resource_message_filter_gtk.cc
+++ b/chrome/browser/renderer_host/resource_message_filter_gtk.cc
@@ -248,33 +248,41 @@ void ResourceMessageFilter::OnGetRootWindowRect(gfx::NativeViewId view,
void ResourceMessageFilter::OnClipboardIsFormatAvailable(
Clipboard::FormatType format, Clipboard::Buffer buffer,
IPC::Message* reply_msg) {
- ui_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::DoOnClipboardIsFormatAvailable, format,
- buffer, reply_msg));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ this, &ResourceMessageFilter::DoOnClipboardIsFormatAvailable, format,
+ buffer, reply_msg));
}
// Called on the IO thread.
void ResourceMessageFilter::OnClipboardReadText(Clipboard::Buffer buffer,
IPC::Message* reply_msg) {
- ui_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::DoOnClipboardReadText, buffer,
- reply_msg));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ this, &ResourceMessageFilter::DoOnClipboardReadText, buffer,
+ reply_msg));
}
// Called on the IO thread.
void ResourceMessageFilter::OnClipboardReadAsciiText(Clipboard::Buffer buffer,
IPC::Message* reply_msg) {
- ui_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::DoOnClipboardReadAsciiText, buffer,
- reply_msg));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ this, &ResourceMessageFilter::DoOnClipboardReadAsciiText, buffer,
+ reply_msg));
}
// Called on the IO thread.
void ResourceMessageFilter::OnClipboardReadHTML(Clipboard::Buffer buffer,
IPC::Message* reply_msg) {
- ui_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ResourceMessageFilter::DoOnClipboardReadHTML, buffer,
- reply_msg));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ this, &ResourceMessageFilter::DoOnClipboardReadHTML, buffer,
+ reply_msg));
}
// Called on the IO thread.
@@ -298,7 +306,7 @@ void ResourceMessageFilter::OnTempFileForPrintingWritten(int fd_in_browser) {
}
#if defined(TOOLKIT_GTK)
- PrintDialogGtk::CreatePrintDialogForPdf(it->second, ui_loop());
+ PrintDialogGtk::CreatePrintDialogForPdf(it->second);
#else
NOTIMPLEMENTED();
#endif
diff --git a/chrome/browser/renderer_host/resource_message_filter_mac.mm b/chrome/browser/renderer_host/resource_message_filter_mac.mm
index f7687c9..ef83622 100644
--- a/chrome/browser/renderer_host/resource_message_filter_mac.mm
+++ b/chrome/browser/renderer_host/resource_message_filter_mac.mm
@@ -8,6 +8,7 @@
#include "base/message_loop.h"
#include "base/sys_string_conversions.h"
+#include "chrome/browser/chrome_thread.h"
#import "chrome/browser/cocoa/find_pasteboard.h"
// The number of utf16 code units that will be written to the find pasteboard,
@@ -35,7 +36,8 @@ void ResourceMessageFilter::OnClipboardFindPboardWriteString(
NSString* nsText = base::SysUTF16ToNSString(text);
if (nsText) {
// FindPasteboard must be used on the UI thread.
- ui_loop()->PostTask(FROM_HERE, new WriteFindPboardTask(nsText));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE, new WriteFindPboardTask(nsText));
}
}
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
index b66df16..399d16c 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
@@ -11,7 +11,7 @@
#include "base/histogram.h"
#include "base/string_util.h"
#include "base/values.h"
-#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/dom_operation_notification_details.h"
#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/google_util.h"
@@ -437,15 +437,11 @@ void SafeBrowsingBlockingPage::NotifySafeBrowsingService(
SafeBrowsingService* sb_service,
const UnsafeResourceList& unsafe_resources,
bool proceed) {
- MessageLoop* message_loop;
- if (g_browser_process->io_thread())
- message_loop = g_browser_process->io_thread()->message_loop();
- else // For unit-tests, just post on the current thread.
- message_loop = MessageLoop::current();
-
- message_loop->PostTask(FROM_HERE, NewRunnableMethod(
- sb_service, &SafeBrowsingService::OnBlockingPageDone, unsafe_resources,
- proceed));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ sb_service, &SafeBrowsingService::OnBlockingPageDone,
+ unsafe_resources, proceed));
}
// static
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
index b664718..b3463e3 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/common/render_messages.h"
@@ -73,7 +74,8 @@ class SafeBrowsingBlockingPageTest : public RenderViewHostTestHarness,
CANCEL
};
- SafeBrowsingBlockingPageTest() {
+ SafeBrowsingBlockingPageTest()
+ : io_thread_(ChromeThread::IO, MessageLoop::current()) {
ResetUserResponse();
service_ = new SafeBrowsingService();
}
@@ -157,6 +159,7 @@ class SafeBrowsingBlockingPageTest : public RenderViewHostTestHarness,
UserResponse user_response_;
scoped_refptr<SafeBrowsingService> service_;
TestSafeBrowsingBlockingPageFactory factory_;
+ ChromeThread io_thread_;
};
// Tests showing a blocking page for a malware page and not proceeding.
@@ -169,6 +172,8 @@ TEST_F(SafeBrowsingBlockingPageTest, MalwarePageDontProceed) {
SafeBrowsingBlockingPage* sb_interstitial = GetSafeBrowsingBlockingPage();
ASSERT_TRUE(sb_interstitial);
+ MessageLoop::current()->RunAllPending();
+
// Simulate the user clicking "don't proceed".
DontProceedThroughInterstitial(sb_interstitial);
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc
index 09912f2..260c592 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc
@@ -258,13 +258,10 @@ void SafeBrowsingService::DoDisplayBlockingPage(
// Just act as "Don't Proceed" was chosen.
std::vector<UnsafeResource> resources;
resources.push_back(resource);
- MessageLoop* message_loop;
- if (g_browser_process->io_thread())
- message_loop = g_browser_process->io_thread()->message_loop();
- else // For unit-tests, just post on the current thread.
- message_loop = MessageLoop::current();
- message_loop->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SafeBrowsingService::OnBlockingPageDone, resources, false));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this, &SafeBrowsingService::OnBlockingPageDone, resources, false));
return;
}
diff --git a/chrome/browser/spellcheck_unittest.cc b/chrome/browser/spellcheck_unittest.cc
index d57f15c..b50f802 100644
--- a/chrome/browser/spellcheck_unittest.cc
+++ b/chrome/browser/spellcheck_unittest.cc
@@ -8,6 +8,7 @@
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/sys_string_conversions.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/spellchecker.h"
#include "chrome/browser/spellchecker_platform_engine.h"
#include "chrome/common/chrome_paths.h"
@@ -19,8 +20,17 @@ const FilePath::CharType kTempCustomDictionaryFile[] =
} // namespace
class SpellCheckTest : public testing::Test {
- private:
+ public:
+ SpellCheckTest()
+ : file_thread_(ChromeThread::FILE, &message_loop_),
+ io_thread_(ChromeThread::IO, &message_loop_) {}
+
+ protected:
MessageLoop message_loop_;
+
+ private:
+ ChromeThread file_thread_;
+ ChromeThread io_thread_; // To keep DCHECKs inside spell checker happy.
};
// Represents a special initialization function used only for the unit tests
@@ -271,6 +281,8 @@ TEST_F(SpellCheckTest, SpellCheckStrings_EN_US) {
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
hunspell_directory, "en-US", NULL, FilePath()));
+ spell_checker->Initialize();
+ message_loop_.RunAllPending();
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
size_t input_length = 0;
@@ -616,6 +628,8 @@ TEST_F(SpellCheckTest, SpellCheckSuggestions_EN_US) {
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
hunspell_directory, "en-US", NULL, FilePath()));
+ spell_checker->Initialize();
+ message_loop_.RunAllPending();
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
std::vector<string16> suggestions;
@@ -889,6 +903,8 @@ TEST_F(SpellCheckTest, SpellCheckText) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
hunspell_directory, kTestCases[i].language, NULL, FilePath()));
+ spell_checker->Initialize();
+ message_loop_.RunAllPending();
size_t input_length = 0;
if (kTestCases[i].input != NULL)
@@ -926,6 +942,8 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckAddToDictionary_EN_US) {
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
hunspell_directory, "en-US", NULL, custom_dictionary_file));
+ spell_checker->Initialize();
+ message_loop_.RunAllPending();
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
// Add the word to spellchecker.
@@ -954,6 +972,8 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckAddToDictionary_EN_US) {
// Now initialize another spellchecker to see that AddToWord is permanent.
scoped_refptr<SpellChecker> spell_checker_new(new SpellChecker(
hunspell_directory, "en-US", NULL, custom_dictionary_file));
+ spell_checker->Initialize();
+ message_loop_.RunAllPending();
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
// Now check whether it is added to Spellchecker.
@@ -997,6 +1017,8 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckSuggestionsAddToDictionary_EN_US) {
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
hunspell_directory, "en-US", NULL, custom_dictionary_file));
+ spell_checker->Initialize();
+ message_loop_.RunAllPending();
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
// Add the word to spellchecker.
@@ -1083,6 +1105,8 @@ TEST_F(SpellCheckTest, GetAutoCorrectionWord_EN_US) {
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
hunspell_directory, "en-US", NULL, FilePath()));
spell_checker->EnableAutoSpellCorrect(true);
+ spell_checker->Initialize();
+ message_loop_.RunAllPending();
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
string16 misspelled_word(UTF8ToUTF16(kTestCases[i].input));
@@ -1118,6 +1142,8 @@ TEST_F(SpellCheckTest, IgnoreWords_EN_US) {
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
hunspell_directory, "en-US", NULL, FilePath()));
+ spell_checker->Initialize();
+ message_loop_.RunAllPending();
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
string16 word(UTF8ToUTF16(kTestCases[i].input));
diff --git a/chrome/browser/spellchecker.cc b/chrome/browser/spellchecker.cc
index c3829b3..b674ed8 100644
--- a/chrome/browser/spellchecker.cc
+++ b/chrome/browser/spellchecker.cc
@@ -13,8 +13,6 @@
#include "base/path_service.h"
#include "base/stats_counters.h"
#include "base/string_util.h"
-#include "base/thread.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/url_fetcher.h"
#include "chrome/browser/profile.h"
@@ -95,59 +93,15 @@ bool SaveBufferToFile(const std::string& data,
} // namespace
-// This is a helper class which acts as a proxy for invoking a task from the
-// file loop back to the IO loop. Invoking a task from file loop to the IO
-// loop directly is not safe as during browser shutdown, the IO loop tears
-// down before the file loop. To avoid a crash, this object is invoked in the
-// UI loop from the file loop, from where it gets the IO thread directly from
-// g_browser_process and invokes the given task in the IO loop if it is not
-// NULL. This object also takes ownership of the given task.
-class UIProxyForIOTask : public Task {
- public:
- explicit UIProxyForIOTask(Task* callback_task, SpellChecker* spellchecker)
- : callback_task_(callback_task),
- spellchecker_(spellchecker) {
- }
-
- private:
- void Run();
-
- Task* callback_task_;
- // The SpellChecker that invoked the file loop task. May be NULL. If not
- // NULL, then we will Release() on it if we don't run |callback_task_|. This
- // balances any refs the spellchecker might have had outstanding which it
- // would have Released() when |callback_task_| was run.
- SpellChecker* spellchecker_;
- DISALLOW_COPY_AND_ASSIGN(UIProxyForIOTask);
-};
-
-void UIProxyForIOTask::Run() {
- // This has been invoked in the UI thread.
- base::Thread* io_thread = g_browser_process->io_thread();
- if (io_thread) { // io_thread has not been torn down yet.
- MessageLoop* io_loop = io_thread->message_loop();
- io_loop->PostTask(FROM_HERE, callback_task_);
- } else {
- if (spellchecker_)
- spellchecker_->Release();
- delete callback_task_;
- }
-
- callback_task_ = NULL;
-}
-
// Design: The spellchecker initializes hunspell_ in the Initialize() method.
// This is done using the dictionary file on disk, e.g. "en-US_1_1.bdic".
// Initialization of hunspell_ is held off during this process. If the
// dictionary is not available, we first attempt to download and save it. After
// the dictionary is downloaded and saved to disk (or the attempt to do so
-// fails)), corresponding flags are set
-// in spellchecker - in the IO thread. Since IO thread goes first during closing
-// of browser, a proxy task |UIProxyForIOTask| is created in the UI thread,
-// which obtains the IO thread independently and invokes the task in the IO
-// thread if it's not NULL. After the flags are cleared, a (final) attempt is
-// made to initialize hunspell_. If it fails even then (dictionary could not
-// download), no more attempts are made to initialize it.
+// fails)), corresponding flags are set in spellchecker - in the IO thread.
+// After the flags are cleared, a (final) attempt is made to initialize
+// hunspell_. If it fails even then (dictionary could not download), no more
+// attempts are made to initialize it.
class SaveDictionaryTask : public Task {
public:
SaveDictionaryTask(Task* on_dictionary_save_complete_callback_task,
@@ -201,13 +155,12 @@ void SaveDictionaryTask::Run() {
// Set Flag that dictionary is not downloading anymore.
ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- new UIProxyForIOTask(on_dictionary_save_complete_callback_task_, NULL));
+ ChromeThread::IO, FROM_HERE, on_dictionary_save_complete_callback_task_);
}
// Design: this task tries to read the dictionary from disk and load it into
// memory. It is executed on the file thread, and posts the results back to
-// the IO thread (via the UI thread---see UIProxyForIOTask).
+// the IO thread.
// The task first checks for the existence of the dictionary in one of the two
// given locations. If it does not exist, the task informs the SpellChecker,
// which will try to download the directory and run a new ReadDictionaryTask.
@@ -265,21 +218,11 @@ class ReadDictionaryTask : public Task {
private:
void Finish(bool file_existed) {
- Task* task = NewRunnableMethod(spellchecker_, &SpellChecker::HunspellInited,
- hunspell_, bdict_file_, file_existed);
- if (spellchecker_->file_loop_) {
- // We were called on the file loop. Post back to the IO loop.
- // If this never gets posted to the IO loop, then we will leak |hunspell_|
- // and |bdict_file_|. But that can only happen during shutdown, so it's
- // not worth caring about.
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- new UIProxyForIOTask(task, spellchecker_));
- } else {
- // We were called directly (e.g., during testing). Run the task directly.
- task->Run();
- delete task;
- }
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ spellchecker_, &SpellChecker::HunspellInited, hunspell_,
+ bdict_file_, file_existed));
}
// The SpellChecker we are working for. We are guaranteed to be outlived
@@ -470,9 +413,7 @@ SpellChecker::SpellChecker(const FilePath& dict_dir,
custom_dictionary_file_name_(custom_dictionary_file_name),
tried_to_init_(false),
language_(language),
- worker_loop_(NULL),
tried_to_download_dictionary_file_(false),
- file_loop_(NULL),
request_context_getter_(request_context_getter),
obtaining_dictionary_(false),
auto_spell_correct_turned_on_(false),
@@ -492,11 +433,6 @@ SpellChecker::SpellChecker(const FilePath& dict_dir,
// Get the corresponding BDIC file name.
bdic_file_name_ = GetVersionedFileName(language, dict_dir).BaseName();
- // Get File Loop - hunspell gets initialized here.
- base::Thread* file_thread = g_browser_process->file_thread();
- if (file_thread)
- file_loop_ = file_thread->message_loop();
-
// Get the path to the custom dictionary file.
if (custom_dictionary_file_name_.empty()) {
FilePath personal_file_directory;
@@ -511,11 +447,7 @@ SpellChecker::SpellChecker(const FilePath& dict_dir,
}
SpellChecker::~SpellChecker() {
- // This must be deleted on the I/O thread (see the header). This is the same
- // thread that SpellCheckWord is called on, so we verify that they were all
- // the same thread.
- if (worker_loop_)
- DCHECK(MessageLoop::current() == worker_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
}
void SpellChecker::StartDictionaryDownload(const FilePath& file_name) {
@@ -558,8 +490,10 @@ void SpellChecker::OnURLFetchComplete(const URLFetcher* source,
FilePath fallback_file_name = user_data_dir.Append(bdic_file_name_);
Task* dic_task = method_factory_.
NewRunnableMethod(&SpellChecker::OnDictionarySaveComplete);
- file_loop_->PostTask(FROM_HERE, new SaveDictionaryTask(dic_task,
- first_attempt_file_name, fallback_file_name, data));
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
+ new SaveDictionaryTask(
+ dic_task, first_attempt_file_name, fallback_file_name, data));
}
void SpellChecker::OnDictionarySaveComplete() {
@@ -571,10 +505,7 @@ void SpellChecker::OnDictionarySaveComplete() {
// Initialize SpellChecker. In this method, if the dictionary is not present
// in the local disk, it is fetched asynchronously.
bool SpellChecker::Initialize() {
- if (!worker_loop_)
- worker_loop_ = MessageLoop::current();
- else
- DCHECK(worker_loop_ == MessageLoop::current());
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
// Return false if the dictionary files are downloading.
if (obtaining_dictionary_)
@@ -606,17 +537,12 @@ bool SpellChecker::Initialize() {
FilePath dictionary_file_name_usr = GetVersionedFileName(language_,
dict_dir_userdata);
- // Balances Release() in HunspellInited(), or in UIProxyForIOTask if the IO
- // thread is torn down before the ReadDictionaryTask calls us back.
+ // Balances Release() in HunspellInited().
AddRef();
- Task* task = new ReadDictionaryTask(this,
- dictionary_file_name_app, dictionary_file_name_usr);
- if (file_loop_) {
- file_loop_->PostTask(FROM_HERE, task);
- } else {
- task->Run();
- delete task;
- }
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
+ new ReadDictionaryTask(
+ this, dictionary_file_name_app, dictionary_file_name_usr));
return hunspell_.get() != NULL;
}
@@ -624,7 +550,7 @@ bool SpellChecker::Initialize() {
void SpellChecker::HunspellInited(Hunspell* hunspell,
file_util::MemoryMappedFile* bdict_file,
bool file_existed) {
- DCHECK(worker_loop_ == MessageLoop::current());
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (file_existed)
tried_to_init_ = true;
@@ -655,7 +581,7 @@ void SpellChecker::HunspellInited(Hunspell* hunspell,
void SpellChecker::DoDictionaryDownload() {
// Download the dictionary file.
- if (file_loop_ && request_context_getter_) {
+ if (request_context_getter_) {
if (!tried_to_download_dictionary_file_) {
FilePath dictionary_file_name_app = GetVersionedFileName(language_,
given_dictionary_directory_);
@@ -750,8 +676,7 @@ bool SpellChecker::SpellCheckWord(
DCHECK(misspelling_start && misspelling_len) << "Out vars must be given.";
// This must always be called on the same thread (normally the I/O thread).
- if (worker_loop_)
- DCHECK(MessageLoop::current() == worker_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
// Check if the platform spellchecker is being used.
if (!is_using_platform_spelling_engine_) {
@@ -850,14 +775,9 @@ void SpellChecker::AddWord(const string16& word) {
}
// Now add the word to the custom dictionary file.
- Task* write_word_task =
- new AddWordToCustomDictionaryTask(custom_dictionary_file_name_, word);
- if (file_loop_) {
- file_loop_->PostTask(FROM_HERE, write_word_task);
- } else {
- write_word_task->Run();
- delete write_word_task;
- }
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
+ new AddWordToCustomDictionaryTask(custom_dictionary_file_name_, word));
}
bool SpellChecker::CheckSpelling(const string16& word_to_check, int tag) {
diff --git a/chrome/browser/spellchecker.h b/chrome/browser/spellchecker.h
index 295ab43..26315d8 100644
--- a/chrome/browser/spellchecker.h
+++ b/chrome/browser/spellchecker.h
@@ -25,7 +25,6 @@ class FilePath;
class Hunspell;
class PrefService;
class Profile;
-class MessageLoop;
class URLFetcher;
class URLRequestContextGetter;
@@ -116,6 +115,14 @@ class SpellChecker : public base::RefCountedThreadSafe<SpellChecker>,
private:
friend class ReadDictionaryTask;
+ FRIEND_TEST(SpellCheckTest, SpellCheckStrings_EN_US);
+ FRIEND_TEST(SpellCheckTest, SpellCheckSuggestions_EN_US);
+ FRIEND_TEST(SpellCheckTest, SpellCheckText);
+ FRIEND_TEST(SpellCheckTest, DISABLED_SpellCheckAddToDictionary_EN_US);
+ FRIEND_TEST(SpellCheckTest,
+ DISABLED_SpellCheckSuggestionsAddToDictionary_EN_US);
+ FRIEND_TEST(SpellCheckTest, GetAutoCorrectionWord_EN_US);
+ FRIEND_TEST(SpellCheckTest, IgnoreWords_EN_US);
// URLFetcher::Delegate implementation. Called when we finish downloading the
// spellcheck dictionary; saves the dictionary to disk.
@@ -206,9 +213,6 @@ class SpellChecker : public base::RefCountedThreadSafe<SpellChecker>,
// Flag indicating whether we tried to download the dictionary file.
bool tried_to_download_dictionary_file_;
- // File Thread Message Loop.
- MessageLoop* file_loop_;
-
// Used for requests. MAY BE NULL which means don't try to download.
URLRequestContextGetter* request_context_getter_;
diff --git a/chrome/browser/strict_transport_security_persister.cc b/chrome/browser/strict_transport_security_persister.cc
index 310cf23..52fc611 100644
--- a/chrome/browser/strict_transport_security_persister.cc
+++ b/chrome/browser/strict_transport_security_persister.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,25 +8,22 @@
#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/path_service.h"
-#include "base/thread.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/common/chrome_paths.h"
#include "net/base/strict_transport_security_state.h"
StrictTransportSecurityPersister::StrictTransportSecurityPersister(
net::StrictTransportSecurityState* state,
- base::Thread* file_thread,
const FilePath& profile_path)
: state_is_dirty_(false),
strict_transport_security_state_(state),
- file_thread_(file_thread),
state_file_(profile_path.Append(
FILE_PATH_LITERAL("StrictTransportSecurity"))) {
state->SetDelegate(this);
Task* task = NewRunnableMethod(this,
&StrictTransportSecurityPersister::LoadState);
- file_thread->message_loop()->PostDelayedTask(FROM_HERE, task,
- 1000 /* 1 second */);
+ ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE, task, 1000);
}
StrictTransportSecurityPersister::~StrictTransportSecurityPersister() {
@@ -34,9 +31,8 @@ StrictTransportSecurityPersister::~StrictTransportSecurityPersister() {
}
void StrictTransportSecurityPersister::LoadState() {
- // Runs on |file_thread_|
AutoLock locked_(lock_);
- DCHECK(file_thread_->message_loop() == MessageLoop::current());
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
std::string state;
if (!file_util::ReadFileToString(state_file_, &state))
@@ -57,15 +53,13 @@ void StrictTransportSecurityPersister::StateIsDirty(
Task* task = NewRunnableMethod(this,
&StrictTransportSecurityPersister::SerialiseState);
- file_thread_->message_loop()->PostDelayedTask(FROM_HERE, task,
- 1000 /* 1 second */);
+ ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE, task, 1000);
state_is_dirty_ = true;
}
void StrictTransportSecurityPersister::SerialiseState() {
- // Runs on |file_thread_|
AutoLock locked_(lock_);
- DCHECK(file_thread_->message_loop() == MessageLoop::current());
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
DCHECK(state_is_dirty_);
state_is_dirty_ = false;
diff --git a/chrome/browser/strict_transport_security_persister.h b/chrome/browser/strict_transport_security_persister.h
index 28c4139..5accc9e 100644
--- a/chrome/browser/strict_transport_security_persister.h
+++ b/chrome/browser/strict_transport_security_persister.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,7 +22,7 @@
// StrictTransportSecurityState calls...
// StrictTransportSecurityPersister::StateIsDirty
// since the callback isn't allowed to block or reenter, we schedule a Task
-// on |file_thread_| after some small amount of time
+// on the file thread after some small amount of time
//
// ...
//
@@ -35,16 +35,12 @@
#include "base/ref_counted.h"
#include "net/base/strict_transport_security_state.h"
-namespace base {
-class Thread;
-}
class StrictTransportSecurityPersister :
public base::RefCountedThreadSafe<StrictTransportSecurityPersister>,
public net::StrictTransportSecurityState::Delegate {
public:
StrictTransportSecurityPersister(net::StrictTransportSecurityState* state,
- base::Thread* file_thread,
const FilePath& profile_path);
~StrictTransportSecurityPersister();
@@ -67,10 +63,6 @@ class StrictTransportSecurityPersister :
scoped_refptr<net::StrictTransportSecurityState>
strict_transport_security_state_;
-
- // This is a thread which can perform file access.
- base::Thread* const file_thread_;
-
// The path to the file in which we store the serialised state.
const FilePath state_file_;
};
diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc
index 30fea8b..8d2f535 100644
--- a/chrome/browser/sync/profile_sync_service_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_unittest.cc
@@ -11,6 +11,7 @@
#include "base/string_util.h"
#include "base/string16.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/model_associator.h"
@@ -267,7 +268,10 @@ class ProfileSyncServiceTest : public testing::Test {
protected:
enum LoadOption { LOAD_FROM_STORAGE, DELETE_EXISTING_STORAGE };
enum SaveOption { SAVE_TO_STORAGE, DONT_SAVE_TO_STORAGE };
- ProfileSyncServiceTest() : model_(NULL) {
+ ProfileSyncServiceTest()
+ : ui_thread_(ChromeThread::UI, &message_loop_),
+ file_thread_(ChromeThread::FILE, &message_loop_),
+ model_(NULL) {
profile_.reset(new TestingProfile());
profile_->set_has_history_service(true);
}
@@ -464,6 +468,8 @@ class ProfileSyncServiceTest : public testing::Test {
// avoid leaking the ProfileSyncService (the PostTask will retain the callee
// and caller until the task is run).
MessageLoop message_loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
scoped_ptr<ProfileSyncService> service_;
scoped_ptr<TestingProfile> profile_;
diff --git a/chrome/browser/sync/sync_setup_wizard.cc b/chrome/browser/sync/sync_setup_wizard.cc
index 35e05f5..2e4664d 100644
--- a/chrome/browser/sync/sync_setup_wizard.cc
+++ b/chrome/browser/sync/sync_setup_wizard.cc
@@ -9,7 +9,7 @@
#include "base/singleton.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
-#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/sync_setup_flow.h"
@@ -137,14 +137,16 @@ void SyncResourcesSource::StartDataRequest(const std::string& path_raw,
SyncSetupWizard::SyncSetupWizard(ProfileSyncService* service)
: service_(service),
flow_container_(new SyncSetupFlowContainer()) {
- // Register data sources for HTML content we require.
- // g_browser_process and/or io_thread may not exist during testing.
- if (g_browser_process && g_browser_process->io_thread()) {
- // Add our network layer data source for 'cloudy' URLs.
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(Singleton<ChromeURLDataManager>().get(),
- &ChromeURLDataManager::AddDataSource,
- new SyncResourcesSource()));
+ // Add our network layer data source for 'cloudy' URLs.
+ SyncResourcesSource* sync_source = new SyncResourcesSource();
+ bool posted = ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(Singleton<ChromeURLDataManager>().get(),
+ &ChromeURLDataManager::AddDataSource,
+ sync_source));
+ if (!posted) {
+ sync_source->AddRef();
+ sync_source->Release(); // Keep Valgrind happy in unit tests.
}
}
diff --git a/chrome/browser/sync/sync_setup_wizard_unittest.cc b/chrome/browser/sync/sync_setup_wizard_unittest.cc
index 10f5a7a..2cc16bf 100644
--- a/chrome/browser/sync/sync_setup_wizard_unittest.cc
+++ b/chrome/browser/sync/sync_setup_wizard_unittest.cc
@@ -141,7 +141,11 @@ class TestBrowserWindowForWizardTest : public TestBrowserWindow {
class SyncSetupWizardTest : public BrowserWithTestWindowTest {
public:
- SyncSetupWizardTest() : test_window_(NULL), wizard_(NULL) { }
+ SyncSetupWizardTest()
+ : ui_thread_(ChromeThread::UI, MessageLoop::current()),
+ file_thread_(ChromeThread::FILE, MessageLoop::current()),
+ test_window_(NULL),
+ wizard_(NULL) { }
virtual ~SyncSetupWizardTest() { }
virtual void SetUp() {
set_profile(new TestingProfileWithSyncService());
@@ -164,6 +168,8 @@ class SyncSetupWizardTest : public BrowserWithTestWindowTest {
wizard_.reset();
}
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
TestBrowserWindowForWizardTest* test_window_;
scoped_ptr<SyncSetupWizard> wizard_;
ProfileSyncServiceForWizardTest* service_;
diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc
index 3a6b7c6..075c809 100644
--- a/chrome/browser/tab_contents/interstitial_page.cc
+++ b/chrome/browser/tab_contents/interstitial_page.cc
@@ -10,6 +10,7 @@
#include "base/thread.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/dom_operation_notification_details.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
@@ -495,16 +496,16 @@ void InterstitialPage::TakeActionOnResourceDispatcher(
// The tab might not have a render_view_host if it was closed (in which case,
// we have taken care of the blocked requests when processing
// NOTIFY_RENDER_WIDGET_HOST_DESTROYED.
- // Also we need to test there is an IO thread, as when unit-tests we don't
- // have one.
+ // Also we need to test there is a ResourceDispatcherHost, as when unit-tests
+ // we don't have one.
RenderViewHost* rvh = RenderViewHost::FromID(original_child_id_,
original_rvh_id_);
- if (rvh && g_browser_process->io_thread()) {
- g_browser_process->io_thread()->message_loop()->PostTask(
- FROM_HERE, new ResourceRequestTask(original_child_id_,
- original_rvh_id_,
- action));
- }
+ if (!rvh || !g_browser_process->resource_dispatcher_host())
+ return;
+
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ new ResourceRequestTask(original_child_id_, original_rvh_id_, action));
}
// static
diff --git a/chrome/browser/tab_contents/web_contents_unittest.cc b/chrome/browser/tab_contents/web_contents_unittest.cc
index c99a8a8..509e295 100644
--- a/chrome/browser/tab_contents/web_contents_unittest.cc
+++ b/chrome/browser/tab_contents/web_contents_unittest.cc
@@ -50,7 +50,7 @@ class TabContentsTestingProfile : public TestingProfile {
source_path = source_path.AppendASCII("profiles")
.AppendASCII("chrome_prefs").AppendASCII("Preferences");
- prefs_.reset(new PrefService(source_path, NULL));
+ prefs_.reset(new PrefService(source_path));
Profile::RegisterUserPrefs(prefs_.get());
browser::RegisterAllPrefs(prefs_.get(), prefs_.get());
}
diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc
index cb68301..3085964 100644
--- a/chrome/browser/task_manager.cc
+++ b/chrome/browser/task_manager.cc
@@ -13,8 +13,8 @@
#include "base/string_util.h"
#include "base/thread.h"
#include "chrome/browser/browser_list.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/url_request_tracking.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
@@ -436,10 +436,10 @@ void TaskManagerModel::StartUpdating() {
// Register jobs notifications so we can compute network usage (it must be
// done from the IO thread).
- base::Thread* thread = g_browser_process->io_thread();
- if (thread)
- thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &TaskManagerModel::RegisterForJobDoneNotifications));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this, &TaskManagerModel::RegisterForJobDoneNotifications));
// Notify resource providers that we are updating.
for (ResourceProviderList::iterator iter = providers_.begin();
@@ -459,10 +459,10 @@ void TaskManagerModel::StopUpdating() {
}
// Unregister jobs notification (must be done from the IO thread).
- base::Thread* thread = g_browser_process->io_thread();
- if (thread)
- thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &TaskManagerModel::UnregisterForJobDoneNotifications));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this, &TaskManagerModel::UnregisterForJobDoneNotifications));
}
void TaskManagerModel::AddResourceProvider(
diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc
index b9fe366..7606672 100644
--- a/chrome/browser/task_manager_resource_providers.cc
+++ b/chrome/browser/task_manager_resource_providers.cc
@@ -25,6 +25,7 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_list.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/profile_manager.h"
@@ -362,9 +363,11 @@ void TaskManagerChildProcessResourceProvider::StartUpdating() {
NotificationService::AllSources());
// Get the existing plugins
- MessageLoop* io_loop_ = g_browser_process->io_thread()->message_loop();
- io_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &TaskManagerChildProcessResourceProvider::RetrieveChildProcessInfo));
}
void TaskManagerChildProcessResourceProvider::StopUpdating() {
diff --git a/chrome/browser/views/about_network_dialog.cc b/chrome/browser/views/about_network_dialog.cc
index 3d3a972..0883b31 100644
--- a/chrome/browser/views/about_network_dialog.cc
+++ b/chrome/browser/views/about_network_dialog.cc
@@ -6,7 +6,7 @@
#include "base/string_util.h"
#include "base/thread.h"
-#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_job_tracker.h"
@@ -96,10 +96,8 @@ JobTracker::~JobTracker() {
// main thread:
void JobTracker::InvokeOnIOThread(void (JobTracker::*m)()) {
- base::Thread* thread = g_browser_process->io_thread();
- if (!thread)
- return;
- thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, m));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE, NewRunnableMethod(this, m));
}
// main thread:
diff --git a/chrome/browser/views/bookmark_context_menu_test.cc b/chrome/browser/views/bookmark_context_menu_test.cc
index 97e222f..b33745b 100644
--- a/chrome/browser/views/bookmark_context_menu_test.cc
+++ b/chrome/browser/views/bookmark_context_menu_test.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/views/bookmark_context_menu.h"
#include "chrome/browser/profile.h"
#include "chrome/common/pref_names.h"
@@ -37,7 +38,9 @@ class TestingPageNavigator : public PageNavigator {
class BookmarkContextMenuTest : public testing::Test {
public:
BookmarkContextMenuTest()
- : model_(NULL) {
+ : ui_thread_(ChromeThread::UI, &message_loop_),
+ file_thread_(ChromeThread::FILE, &message_loop_),
+ model_(NULL) {
}
virtual void SetUp() {
@@ -66,6 +69,8 @@ class BookmarkContextMenuTest : public testing::Test {
protected:
MessageLoopForUI message_loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
scoped_ptr<TestingProfile> profile_;
BookmarkModel* model_;
TestingPageNavigator navigator_;
diff --git a/chrome/browser/views/bookmark_editor_view_unittest.cc b/chrome/browser/views/bookmark_editor_view_unittest.cc
index 9e2ae40..a43a928 100644
--- a/chrome/browser/views/bookmark_editor_view_unittest.cc
+++ b/chrome/browser/views/bookmark_editor_view_unittest.cc
@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/message_loop.h"
#include "base/string_util.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/views/bookmark_editor_view.h"
#include "chrome/common/pref_names.h"
@@ -18,7 +20,10 @@ using base::TimeDelta;
// it with test data.
class BookmarkEditorViewTest : public testing::Test {
public:
- BookmarkEditorViewTest() : model_(NULL) {
+ BookmarkEditorViewTest()
+ : model_(NULL),
+ ui_thread_(ChromeThread::UI, &message_loop_),
+ file_thread_(ChromeThread::FILE, &message_loop_) {
}
virtual void SetUp() {
@@ -27,6 +32,7 @@ class BookmarkEditorViewTest : public testing::Test {
profile_->CreateBookmarkModel(true);
model_ = profile_->GetBookmarkModel();
+ profile_->BlockUntilBookmarkModelLoaded();
AddTestData();
}
@@ -117,6 +123,8 @@ class BookmarkEditorViewTest : public testing::Test {
}
scoped_ptr<BookmarkEditorView> editor_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
};
// Makes sure the tree model matches that of the bookmark bar model.
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc
index 5cb0375..978eb43 100644
--- a/chrome/browser/views/bookmark_manager_view.cc
+++ b/chrome/browser/views/bookmark_manager_view.cc
@@ -604,11 +604,7 @@ void BookmarkManagerView::FileSelected(const FilePath& path,
profile_info, profile_,
new ImportObserverImpl(profile()), false);
} else if (id == IDS_BOOKMARK_MANAGER_EXPORT_MENU) {
- if (g_browser_process->io_thread()) {
- bookmark_html_writer::WriteBookmarks(
- g_browser_process->io_thread()->message_loop(), GetBookmarkModel(),
- path);
- }
+ bookmark_html_writer::WriteBookmarks(GetBookmarkModel(), path);
} else {
NOTREACHED();
}
diff --git a/chrome/browser/visitedlink_master.cc b/chrome/browser/visitedlink_master.cc
index 1036bb6..8bbe926 100644
--- a/chrome/browser/visitedlink_master.cc
+++ b/chrome/browser/visitedlink_master.cc
@@ -24,7 +24,6 @@
#include "base/rand_util.h"
#include "base/stack_container.h"
#include "base/string_util.h"
-#include "base/thread.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/profile.h"
@@ -190,9 +189,6 @@ class VisitedLinkMaster::TableBuilder
// Owner of this object. MAY ONLY BE ACCESSED ON THE MAIN THREAD!
VisitedLinkMaster* master_;
- // The thread the visited link master is on where we will notify it.
- MessageLoop* main_message_loop_;
-
// Indicates whether the operation has failed or not.
bool success_;
@@ -205,19 +201,17 @@ class VisitedLinkMaster::TableBuilder
// VisitedLinkMaster ----------------------------------------------------------
-VisitedLinkMaster::VisitedLinkMaster(base::Thread* file_thread,
- Listener* listener,
+VisitedLinkMaster::VisitedLinkMaster(Listener* listener,
Profile* profile) {
- InitMembers(file_thread, listener, profile);
+ InitMembers(listener, profile);
}
-VisitedLinkMaster::VisitedLinkMaster(base::Thread* file_thread,
- Listener* listener,
+VisitedLinkMaster::VisitedLinkMaster(Listener* listener,
HistoryService* history_service,
bool suppress_rebuild,
const FilePath& filename,
int32 default_table_size) {
- InitMembers(file_thread, listener, NULL);
+ InitMembers(listener, NULL);
database_name_override_ = filename;
table_size_override_ = default_table_size;
@@ -236,16 +230,9 @@ VisitedLinkMaster::~VisitedLinkMaster() {
FreeURLTable();
}
-void VisitedLinkMaster::InitMembers(base::Thread* file_thread,
- Listener* listener,
- Profile* profile) {
+void VisitedLinkMaster::InitMembers(Listener* listener, Profile* profile) {
DCHECK(listener);
- if (file_thread)
- file_thread_ = file_thread->message_loop();
- else
- file_thread_ = NULL;
-
listener_ = listener;
file_ = NULL;
shared_memory_ = NULL;
@@ -553,13 +540,8 @@ bool VisitedLinkMaster::WriteFullTable() {
hash_table_, table_length_ * sizeof(Fingerprint));
// The hash table may have shrunk, so make sure this is the end.
- if (file_thread_) {
- AsyncSetEndOfFile* setter = new AsyncSetEndOfFile(file_);
- file_thread_->PostTask(FROM_HERE, setter);
- } else {
- TruncateFile(file_);
- }
-
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE, new AsyncSetEndOfFile(file_));
return true;
}
@@ -754,14 +736,11 @@ void VisitedLinkMaster::FreeURLTable() {
delete shared_memory_;
shared_memory_ = NULL;
}
- if (file_) {
- if (file_thread_) {
- AsyncCloseHandle* closer = new AsyncCloseHandle(file_);
- file_thread_->PostTask(FROM_HERE, closer);
- } else {
- fclose(file_);
- }
- }
+ if (!file_)
+ return;
+
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE, new AsyncCloseHandle(file_));
}
bool VisitedLinkMaster::ResizeTableIfNecessary() {
@@ -941,15 +920,9 @@ void VisitedLinkMaster::WriteToFile(FILE* file,
posted_asynchronous_operation_ = true;
#endif
- if (file_thread_) {
- // Send the write to the other thread for execution to avoid blocking.
- AsyncWriter* writer = new AsyncWriter(file, offset, data, data_size);
- file_thread_->PostTask(FROM_HERE, writer);
- } else {
- // When there is no I/O thread, we are probably running in unit test mode,
- // just do the write synchronously.
- AsyncWriter::WriteToFile(file, offset, data, data_size);
- }
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
+ new AsyncWriter(file, offset, data, data_size));
}
void VisitedLinkMaster::WriteUsedItemCountToFile() {
@@ -1000,7 +973,6 @@ VisitedLinkMaster::TableBuilder::TableBuilder(
VisitedLinkMaster* master,
const uint8 salt[LINK_SALT_LENGTH])
: master_(master),
- main_message_loop_(MessageLoop::current()),
success_(true) {
fingerprints_.reserve(4096);
memcpy(salt_, salt, sizeof(salt));
@@ -1025,8 +997,9 @@ void VisitedLinkMaster::TableBuilder::OnComplete(bool success) {
// Marshal to the main thread to notify the VisitedLinkMaster that the
// rebuild is complete.
- main_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
- &TableBuilder::OnCompleteMainThread));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &TableBuilder::OnCompleteMainThread));
}
void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() {
diff --git a/chrome/browser/visitedlink_master.h b/chrome/browser/visitedlink_master.h
index 3355436..b42bedd 100644
--- a/chrome/browser/visitedlink_master.h
+++ b/chrome/browser/visitedlink_master.h
@@ -23,16 +23,12 @@ class GURL;
class MessageLoop;
class Profile;
-namespace base {
-class Thread;
-} // namespace base
-
// Controls the link coloring database. The master controls all writing to the
// database as well as disk I/O. There should be only one master.
//
-// This class will optionally defer writing operations to another thread. This
-// means that after class destruction, the file may still be open since
-// operations are pending on another thread.
+// This class will defer writing operations to the file thread. This means that
+// class destruction, the file may still be open since operations are pending on
+// another thread.
class VisitedLinkMaster : public VisitedLinkCommon {
public:
// Listens to the link coloring database events. The master is given this
@@ -54,12 +50,8 @@ class VisitedLinkMaster : public VisitedLinkCommon {
virtual void Reset() = 0;
};
- // The |file_thread| may be NULL, in which case write operations will be
- // synchronous.
// The |listener| may not be NULL.
- VisitedLinkMaster(base::Thread* file_thread,
- Listener* listener,
- Profile* profile);
+ VisitedLinkMaster(Listener* listener, Profile* profile);
// In unit test mode, we allow the caller to optionally specify the database
// filename so that it can be run from a unit test. The directory where this
@@ -76,8 +68,7 @@ class VisitedLinkMaster : public VisitedLinkCommon {
// When |suppress_rebuild| is set, we'll not attempt to load data from
// history if the file can't be loaded. This should generally be set for
// testing except when you want to test the rebuild process explicitly.
- VisitedLinkMaster(base::Thread* file_thread,
- Listener* listener,
+ VisitedLinkMaster(Listener* listener,
HistoryService* history_service,
bool suppress_rebuild,
const FilePath& filename,
@@ -168,9 +159,7 @@ class VisitedLinkMaster : public VisitedLinkCommon {
static const size_t kBigDeleteThreshold;
// Backend for the constructors initializing the members.
- void InitMembers(base::Thread* file_thread,
- Listener* listener,
- Profile* profile);
+ void InitMembers(Listener* listener, Profile* profile);
// If a rebuild is in progress, we save the URL in the temporary list.
// Otherwise, we add this to the table. Returns the index of the
@@ -325,10 +314,6 @@ class VisitedLinkMaster : public VisitedLinkCommon {
bool posted_asynchronous_operation_;
#endif
- // The thread where we do write operations from to avoid synchronous I/O on
- // the main thread. This may be NULL, which indicates synchronous I/O.
- MessageLoop* file_thread_;
-
// Reference to the user profile that this object belongs to
// (it knows the path to where the data is stored)
Profile* profile_;
diff --git a/chrome/browser/visitedlink_perftest.cc b/chrome/browser/visitedlink_perftest.cc
index b38a953..a21848d 100644
--- a/chrome/browser/visitedlink_perftest.cc
+++ b/chrome/browser/visitedlink_perftest.cc
@@ -90,7 +90,7 @@ class VisitedLink : public testing::Test {
// useful to make another set of tests to test these things in isolation.
TEST_F(VisitedLink, TestAddAndQuery) {
// init
- VisitedLinkMaster master(NULL, DummyVisitedLinkEventListener::GetInstance(),
+ VisitedLinkMaster master(DummyVisitedLinkEventListener::GetInstance(),
NULL, true, FilePath(db_name_), 0);
ASSERT_TRUE(master.Init());
@@ -121,7 +121,7 @@ TEST_F(VisitedLink, TestLoad) {
{
PerfTimeLogger table_initialization_timer("Table_initialization");
- VisitedLinkMaster master(NULL, DummyVisitedLinkEventListener::GetInstance(),
+ VisitedLinkMaster master(DummyVisitedLinkEventListener::GetInstance(),
NULL, true, FilePath(db_name_), 0);
// time init with empty table
@@ -160,8 +160,7 @@ TEST_F(VisitedLink, TestLoad) {
{
PerfTimer cold_timer;
- VisitedLinkMaster master(NULL,
- DummyVisitedLinkEventListener::GetInstance(),
+ VisitedLinkMaster master(DummyVisitedLinkEventListener::GetInstance(),
NULL,
true,
FilePath(db_name_),
@@ -177,8 +176,7 @@ TEST_F(VisitedLink, TestLoad) {
{
PerfTimer hot_timer;
- VisitedLinkMaster master(NULL,
- DummyVisitedLinkEventListener::GetInstance(),
+ VisitedLinkMaster master(DummyVisitedLinkEventListener::GetInstance(),
NULL,
true,
FilePath(db_name_),
diff --git a/chrome/browser/visitedlink_unittest.cc b/chrome/browser/visitedlink_unittest.cc
index 7b238f6..d8906f7 100644
--- a/chrome/browser/visitedlink_unittest.cc
+++ b/chrome/browser/visitedlink_unittest.cc
@@ -12,6 +12,7 @@
#include "base/process_util.h"
#include "base/shared_memory.h"
#include "base/string_util.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/visitedlink_master.h"
#include "chrome/browser/visitedlink_event_listener.h"
#include "chrome/browser/renderer_host/browser_render_process_host.h"
@@ -71,6 +72,9 @@ class TrackingVisitedLinkEventListener : public VisitedLinkMaster::Listener {
class VisitedLinkTest : public testing::Test {
protected:
+ VisitedLinkTest()
+ : ui_thread_(ChromeThread::UI, &message_loop_),
+ file_thread_(ChromeThread::FILE, &message_loop_) {}
// Initialize the history system. This should be called before InitVisited().
bool InitHistory() {
history_service_ = new HistoryService;
@@ -84,7 +88,7 @@ class VisitedLinkTest : public testing::Test {
// the VisitedLinkMaster constructor.
bool InitVisited(int initial_size, bool suppress_rebuild) {
// Initialize the visited link system.
- master_.reset(new VisitedLinkMaster(NULL, &listener_, history_service_,
+ master_.reset(new VisitedLinkMaster(&listener_, history_service_,
suppress_rebuild, visited_file_,
initial_size));
return master_->Init();
@@ -170,6 +174,8 @@ class VisitedLinkTest : public testing::Test {
}
MessageLoop message_loop_;
+ ChromeThread ui_thread_;
+ ChromeThread file_thread_;
// Filenames for the services;
FilePath history_dir_;
@@ -452,8 +458,7 @@ class VisitCountingProfile : public TestingProfile {
virtual VisitedLinkMaster* GetVisitedLinkMaster() {
if (!visited_link_master_.get()) {
- visited_link_master_.reset(
- new VisitedLinkMaster(NULL, event_listener_, this));
+ visited_link_master_.reset(new VisitedLinkMaster(event_listener_, this));
visited_link_master_->Init();
}
return visited_link_master_.get();
@@ -570,7 +575,14 @@ class VisitedLinkRenderProcessHostFactory
class VisitedLinkEventsTest : public RenderViewHostTestHarness {
public:
- VisitedLinkEventsTest() : RenderViewHostTestHarness() {}
+ VisitedLinkEventsTest()
+ : RenderViewHostTestHarness(),
+ file_thread_(ChromeThread::FILE, &message_loop_) {}
+ ~VisitedLinkEventsTest() {
+ // This ends up using the file thread to schedule the delete.
+ profile_.reset();
+ message_loop_.RunAllPending();
+ }
virtual void SetFactoryMode() {}
virtual void SetUp() {
SetFactoryMode();
@@ -596,6 +608,7 @@ class VisitedLinkEventsTest : public RenderViewHostTestHarness {
private:
scoped_ptr<VisitedLinkEventListener> event_listener_;
+ ChromeThread file_thread_;
DISALLOW_COPY_AND_ASSIGN(VisitedLinkEventsTest);
};
diff --git a/chrome/browser/web_resource/web_resource_service.cc b/chrome/browser/web_resource/web_resource_service.cc
index 4a6683c..80805f2 100644
--- a/chrome/browser/web_resource/web_resource_service.cc
+++ b/chrome/browser/web_resource/web_resource_service.cc
@@ -196,11 +196,9 @@ const wchar_t* WebResourceService::kDefaultResourceServer =
const char* WebResourceService::kResourceDirectoryName =
"Resources";
-WebResourceService::WebResourceService(Profile* profile,
- MessageLoop* backend_loop) :
+WebResourceService::WebResourceService(Profile* profile) :
prefs_(profile->GetPrefs()),
web_resource_dir_(profile->GetPath().AppendASCII(kResourceDirectoryName)),
- backend_loop_(backend_loop),
in_fetch_(false) {
Init();
}
diff --git a/chrome/browser/web_resource/web_resource_service.h b/chrome/browser/web_resource/web_resource_service.h
index 41f75f1..14c04cf 100644
--- a/chrome/browser/web_resource/web_resource_service.h
+++ b/chrome/browser/web_resource/web_resource_service.h
@@ -16,8 +16,7 @@ class Profile;
class WebResourceService
: public UtilityProcessHost::Client {
public:
- WebResourceService(Profile* profile,
- MessageLoop* backend_loop);
+ WebResourceService(Profile* profile);
~WebResourceService();
// Sleep until cache needs to be updated, but always for at least 5 seconds
@@ -61,9 +60,6 @@ class WebResourceService
// Server from which we are currently pulling web resource data.
std::wstring web_resource_server_;
- // Whenever we update resource cache, schedule another task.
- MessageLoop* backend_loop_;
-
WebResourceFetcher* web_resource_fetcher_;
ResourceDispatcherHost* resource_dispatcher_host_;
diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc
index 54446b3..eb6d2fe 100644
--- a/chrome/browser/worker_host/worker_process_host.cc
+++ b/chrome/browser/worker_host/worker_process_host.cc
@@ -16,7 +16,7 @@
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_util.h"
-#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/child_process_security_policy.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
@@ -77,10 +77,10 @@ WorkerProcessHost::~WorkerProcessHost() {
NotificationService::NoDetails());
// If we crashed, tell the RenderViewHost.
- MessageLoop* ui_loop = WorkerService::GetInstance()->ui_loop();
for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) {
- ui_loop->PostTask(FROM_HERE, new WorkerCrashTask(
- i->renderer_id, i->render_view_route_id));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ new WorkerCrashTask(i->renderer_id, i->render_view_route_id));
}
ChildProcessSecurityPolicy::GetInstance()->Remove(id());
diff --git a/chrome/browser/worker_host/worker_service.cc b/chrome/browser/worker_host/worker_service.cc
index d37314b..a54bb2a 100644
--- a/chrome/browser/worker_host/worker_service.cc
+++ b/chrome/browser/worker_host/worker_service.cc
@@ -28,8 +28,7 @@ WorkerService* WorkerService::GetInstance() {
WorkerService::WorkerService()
: next_worker_route_id_(0),
- resource_dispatcher_host_(NULL),
- ui_loop_(NULL) {
+ resource_dispatcher_host_(NULL) {
// Receive a notification if a message filter or WorkerProcessHost is deleted.
registrar_.Add(this, NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN,
NotificationService::AllSources());
@@ -38,10 +37,8 @@ WorkerService::WorkerService()
NotificationService::AllSources());
}
-void WorkerService::Initialize(ResourceDispatcherHost* rdh,
- MessageLoop* ui_loop) {
+void WorkerService::Initialize(ResourceDispatcherHost* rdh) {
resource_dispatcher_host_ = rdh;
- ui_loop_ = ui_loop;
}
WorkerService::~WorkerService() {
diff --git a/chrome/browser/worker_host/worker_service.h b/chrome/browser/worker_host/worker_service.h
index a3e71031..0bd6f58 100644
--- a/chrome/browser/worker_host/worker_service.h
+++ b/chrome/browser/worker_host/worker_service.h
@@ -14,8 +14,6 @@
#include "googleurl/src/gurl.h"
#include "ipc/ipc_message.h"
-
-class MessageLoop;
class WorkerProcessHost;
class ResourceDispatcherHost;
@@ -25,7 +23,7 @@ class WorkerService : public NotificationObserver {
static WorkerService* GetInstance();
// Initialize the WorkerService. OK to be called multiple times.
- void Initialize(ResourceDispatcherHost* rdh, MessageLoop* ui_loop);
+ void Initialize(ResourceDispatcherHost* rdh);
// Creates a dedicated worker. Returns true on success.
bool CreateDedicatedWorker(const GURL &url,
@@ -42,8 +40,6 @@ class WorkerService : public NotificationObserver {
// forwarded to the worker process.
void ForwardMessage(const IPC::Message& message, int sender_id);
- MessageLoop* ui_loop() { return ui_loop_; }
-
int next_worker_route_id() { return ++next_worker_route_id_; }
// TODO(dimich): This code assumes there is 1 worker per worker process, which
@@ -95,7 +91,6 @@ class WorkerService : public NotificationObserver {
NotificationRegistrar registrar_;
int next_worker_route_id_;
ResourceDispatcherHost* resource_dispatcher_host_;
- MessageLoop* ui_loop_;
WorkerProcessHost::Instances queued_workers_;
diff --git a/chrome/common/histogram_synchronizer.cc b/chrome/common/histogram_synchronizer.cc
index cc20c41..2a7e09a 100644
--- a/chrome/common/histogram_synchronizer.cc
+++ b/chrome/common/histogram_synchronizer.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,7 +7,7 @@
#include "base/histogram.h"
#include "base/logging.h"
#include "base/thread.h"
-#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/common/render_messages.h"
@@ -97,8 +97,10 @@ void HistogramSynchronizer::FetchRendererHistogramsAsynchronously(
}
// callback_task_ member can only be accessed on IO thread.
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(current_synchronizer,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ current_synchronizer,
&HistogramSynchronizer::SetCallbackTaskToCallAfterGettingHistograms,
callback_thread,
callback_task));
@@ -114,8 +116,10 @@ void HistogramSynchronizer::FetchRendererHistogramsAsynchronously(
}
// Post a task that would be called after waiting for wait_time.
- g_browser_process->io_thread()->message_loop()->PostDelayedTask(FROM_HERE,
- NewRunnableMethod(current_synchronizer,
+ ChromeThread::PostDelayedTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ current_synchronizer,
&HistogramSynchronizer::ForceHistogramSynchronizationDoneCallback,
sequence_number),
wait_time);
diff --git a/chrome/common/important_file_writer.cc b/chrome/common/important_file_writer.cc
index 86a7b7d..1759116 100644
--- a/chrome/common/important_file_writer.cc
+++ b/chrome/common/important_file_writer.cc
@@ -16,6 +16,7 @@
#include "base/task.h"
#include "base/thread.h"
#include "base/time.h"
+#include "chrome/browser/chrome_thread.h"
using base::TimeDelta;
@@ -82,10 +83,8 @@ class WriteToDiskTask : public Task {
} // namespace
-ImportantFileWriter::ImportantFileWriter(const FilePath& path,
- const base::Thread* backend_thread)
+ImportantFileWriter::ImportantFileWriter(const FilePath& path)
: path_(path),
- backend_thread_(backend_thread),
serializer_(NULL),
commit_interval_(TimeDelta::FromMilliseconds(kDefaultCommitIntervalMs)) {
DCHECK(CalledOnValidThread());
@@ -109,13 +108,8 @@ void ImportantFileWriter::WriteNow(const std::string& data) {
if (HasPendingWrite())
timer_.Stop();
- Task* task = new WriteToDiskTask(path_, data);
- if (backend_thread_) {
- backend_thread_->message_loop()->PostTask(FROM_HERE, task);
- } else {
- task->Run();
- delete task;
- }
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE, new WriteToDiskTask(path_, data));
}
void ImportantFileWriter::ScheduleWrite(DataSerializer* serializer) {
diff --git a/chrome/common/important_file_writer.h b/chrome/common/important_file_writer.h
index 623322a..bdf2223 100644
--- a/chrome/common/important_file_writer.h
+++ b/chrome/common/important_file_writer.h
@@ -48,11 +48,9 @@ class ImportantFileWriter : public NonThreadSafe {
};
// Initialize the writer.
- // |path| is the name of file to write. Disk operations will be executed on
- // |backend_thread|, or current thread if |backend_thread| is NULL.
- //
+ // |path| is the name of file to write.
// All non-const methods, ctor and dtor must be called on the same thread.
- ImportantFileWriter(const FilePath& path, const base::Thread* backend_thread);
+ ImportantFileWriter(const FilePath& path);
// You have to ensure that there are no pending writes at the moment
// of destruction.
@@ -91,9 +89,6 @@ class ImportantFileWriter : public NonThreadSafe {
// Path being written to.
const FilePath path_;
- // Thread on which disk operation run. NULL means no separate thread is used.
- const base::Thread* backend_thread_;
-
// Timer used to schedule commit after ScheduleWrite.
base::OneShotTimer<ImportantFileWriter> timer_;
diff --git a/chrome/common/important_file_writer_unittest.cc b/chrome/common/important_file_writer_unittest.cc
index e4ce5f0..b3fee0d 100644
--- a/chrome/common/important_file_writer_unittest.cc
+++ b/chrome/common/important_file_writer_unittest.cc
@@ -12,6 +12,7 @@
#include "base/scoped_temp_dir.h"
#include "base/thread.h"
#include "base/time.h"
+#include "chrome/browser/chrome_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -42,6 +43,7 @@ class DataSerializer : public ImportantFileWriter::DataSerializer {
class ImportantFileWriterTest : public testing::Test {
public:
+ ImportantFileWriterTest() : file_thread_(ChromeThread::FILE, &loop_) { }
virtual void SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
file_ = temp_dir_.path().AppendASCII("test-file");
@@ -49,35 +51,25 @@ class ImportantFileWriterTest : public testing::Test {
protected:
FilePath file_;
+ MessageLoop loop_;
private:
- MessageLoop loop_;
+ ChromeThread file_thread_;
ScopedTempDir temp_dir_;
};
-TEST_F(ImportantFileWriterTest, WithoutBackendThread) {
- ImportantFileWriter writer(file_, NULL);
- EXPECT_FALSE(file_util::PathExists(writer.path()));
- writer.WriteNow("foo");
- ASSERT_TRUE(file_util::PathExists(writer.path()));
- EXPECT_EQ("foo", GetFileContent(writer.path()));
-}
-
-TEST_F(ImportantFileWriterTest, WithBackendThread) {
- base::Thread thread("file_writer_test");
- ASSERT_TRUE(thread.Start());
-
- ImportantFileWriter writer(file_, &thread);
+TEST_F(ImportantFileWriterTest, Basic) {
+ ImportantFileWriter writer(file_);
EXPECT_FALSE(file_util::PathExists(writer.path()));
writer.WriteNow("foo");
- thread.Stop(); // Blocks until all tasks are executed.
+ loop_.RunAllPending();
ASSERT_TRUE(file_util::PathExists(writer.path()));
EXPECT_EQ("foo", GetFileContent(writer.path()));
}
TEST_F(ImportantFileWriterTest, ScheduleWrite) {
- ImportantFileWriter writer(file_, NULL);
+ ImportantFileWriter writer(file_);
writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25));
EXPECT_FALSE(writer.HasPendingWrite());
DataSerializer serializer("foo");
@@ -92,19 +84,22 @@ TEST_F(ImportantFileWriterTest, ScheduleWrite) {
}
TEST_F(ImportantFileWriterTest, DoScheduledWrite) {
- ImportantFileWriter writer(file_, NULL);
+ ImportantFileWriter writer(file_);
EXPECT_FALSE(writer.HasPendingWrite());
DataSerializer serializer("foo");
writer.ScheduleWrite(&serializer);
EXPECT_TRUE(writer.HasPendingWrite());
writer.DoScheduledWrite();
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ new MessageLoop::QuitTask(), 100);
+ MessageLoop::current()->Run();
EXPECT_FALSE(writer.HasPendingWrite());
ASSERT_TRUE(file_util::PathExists(writer.path()));
EXPECT_EQ("foo", GetFileContent(writer.path()));
}
TEST_F(ImportantFileWriterTest, BatchingWrites) {
- ImportantFileWriter writer(file_, NULL);
+ ImportantFileWriter writer(file_);
writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25));
DataSerializer foo("foo"), bar("bar"), baz("baz");
writer.ScheduleWrite(&foo);
diff --git a/chrome/common/pref_member_unittest.cc b/chrome/common/pref_member_unittest.cc
index 7fe9c6d..bf9cc39 100644
--- a/chrome/common/pref_member_unittest.cc
+++ b/chrome/common/pref_member_unittest.cc
@@ -50,7 +50,7 @@ class PrefMemberTestClass : public NotificationObserver {
} // anonymous namespace
TEST(PrefMemberTest, BasicGetAndSet) {
- PrefService prefs(FilePath(), NULL);
+ PrefService prefs((FilePath()));
RegisterTestPrefs(&prefs);
// Test bool
@@ -140,7 +140,7 @@ TEST(PrefMemberTest, BasicGetAndSet) {
TEST(PrefMemberTest, TwoPrefs) {
// Make sure two RealPrefMembers stay in sync.
- PrefService prefs(FilePath(), NULL);
+ PrefService prefs((FilePath()));
RegisterTestPrefs(&prefs);
RealPrefMember pref1;
@@ -160,7 +160,7 @@ TEST(PrefMemberTest, TwoPrefs) {
}
TEST(PrefMemberTest, Observer) {
- PrefService prefs(FilePath(), NULL);
+ PrefService prefs((FilePath()));
RegisterTestPrefs(&prefs);
PrefMemberTestClass test_obj(&prefs);
diff --git a/chrome/common/pref_service.cc b/chrome/common/pref_service.cc
index 989d438..691fb77 100644
--- a/chrome/common/pref_service.cc
+++ b/chrome/common/pref_service.cc
@@ -10,7 +10,6 @@
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
-#include "base/thread.h"
#include "build/build_config.h"
#include "chrome/common/json_value_serializer.h"
#include "chrome/common/notification_service.h"
@@ -61,11 +60,10 @@ Value* CreateLocaleDefaultValue(Value::ValueType type, int message_id) {
} // namespace
-PrefService::PrefService(const FilePath& pref_filename,
- const base::Thread* backend_thread)
+PrefService::PrefService(const FilePath& pref_filename)
: persistent_(new DictionaryValue),
transient_(new DictionaryValue),
- writer_(pref_filename, backend_thread) {
+ writer_(pref_filename) {
ReloadPersistentPrefs();
}
diff --git a/chrome/common/pref_service.h b/chrome/common/pref_service.h
index c4f7ce6..110a515 100644
--- a/chrome/common/pref_service.h
+++ b/chrome/common/pref_service.h
@@ -28,10 +28,6 @@
class NotificationObserver;
class Preference;
-namespace base {
-class Thread;
-}
-
class PrefService : public NonThreadSafe,
public ImportantFileWriter::DataSerializer {
public:
@@ -77,11 +73,8 @@ class PrefService : public NonThreadSafe,
};
// |pref_filename| is the path to the prefs file we will try to load or save
- // to. Saves will be executed on |backend_thread|. It should be the file
- // thread in Chrome. You can pass NULL for unit tests, and then no separate
- // thread will be used.
- PrefService(const FilePath& pref_filename,
- const base::Thread* backend_thread);
+ // to. Saves will be executed on the file thread.
+ explicit PrefService(const FilePath& pref_filename);
~PrefService();
// Reloads the data from file. This should only be called when the importer
diff --git a/chrome/common/pref_service_unittest.cc b/chrome/common/pref_service_unittest.cc
index 29b4b09..29b19c3 100644
--- a/chrome/common/pref_service_unittest.cc
+++ b/chrome/common/pref_service_unittest.cc
@@ -4,7 +4,9 @@
#include "app/test/data/resource.h"
#include "base/file_util.h"
+#include "base/message_loop.h"
#include "base/path_service.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/json_value_serializer.h"
#include "chrome/common/notification_service.h"
@@ -81,7 +83,7 @@ TEST_F(PrefServiceTest, Basic) {
{
// Test that it fails on nonexistent file.
FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
- PrefService prefs(bogus_input_file, NULL);
+ PrefService prefs(bogus_input_file);
EXPECT_FALSE(prefs.ReloadPersistentPrefs());
}
@@ -91,7 +93,7 @@ TEST_F(PrefServiceTest, Basic) {
// Test that the persistent value can be loaded.
FilePath input_file = test_dir_.AppendASCII("write.json");
ASSERT_TRUE(file_util::PathExists(input_file));
- PrefService prefs(input_file, NULL);
+ PrefService prefs(input_file);
ASSERT_TRUE(prefs.ReloadPersistentPrefs());
// Register test prefs.
@@ -141,10 +143,14 @@ TEST_F(PrefServiceTest, Basic) {
EXPECT_EQ(some_path.value(), prefs.GetFilePath(kSomeDirectory).value());
// Serialize and compare to expected output.
+ // SavePersistentPrefs uses ImportantFileWriter which needs a file thread.
+ MessageLoop message_loop;
+ ChromeThread file_thread(ChromeThread::FILE, &message_loop);
FilePath output_file = test_dir_.AppendASCII("write.json");
FilePath golden_output_file = data_dir_.AppendASCII("write.golden.json");
ASSERT_TRUE(file_util::PathExists(golden_output_file));
ASSERT_TRUE(prefs.SavePersistentPrefs());
+ MessageLoop::current()->RunAllPending();
EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, output_file));
ASSERT_TRUE(file_util::Delete(output_file, false));
}
@@ -159,7 +165,7 @@ TEST_F(PrefServiceTest, Overlay) {
std::wstring transient_string(L"transient");
FilePath persistent_file = data_dir_.AppendASCII("overlay.json");
- PrefService prefs(persistent_file, NULL);
+ PrefService prefs(persistent_file);
EXPECT_TRUE(prefs.ReloadPersistentPrefs());
Value* transient_value;
@@ -286,7 +292,7 @@ TEST_F(PrefServiceTest, Observers) {
FilePath input_file = data_dir_.AppendASCII("read.json");
EXPECT_TRUE(file_util::PathExists(input_file));
- PrefService prefs(input_file, NULL);
+ PrefService prefs(input_file);
EXPECT_TRUE(prefs.ReloadPersistentPrefs());
@@ -329,7 +335,7 @@ TEST_F(PrefServiceTest, Observers) {
// TODO(port): port this test to POSIX.
#if defined(OS_WIN)
TEST_F(PrefServiceTest, LocalizedPrefs) {
- PrefService prefs(FilePath(), NULL);
+ PrefService prefs((FilePath()));
const wchar_t kBoolean[] = L"boolean";
const wchar_t kInteger[] = L"integer";
const wchar_t kString[] = L"string";
@@ -352,7 +358,7 @@ TEST_F(PrefServiceTest, LocalizedPrefs) {
#endif
TEST_F(PrefServiceTest, NoObserverFire) {
- PrefService prefs(FilePath(), NULL);
+ PrefService prefs((FilePath()));
const wchar_t pref_name[] = L"homepage";
prefs.RegisterStringPref(pref_name, L"");
@@ -387,7 +393,7 @@ TEST_F(PrefServiceTest, NoObserverFire) {
}
TEST_F(PrefServiceTest, HasPrefPath) {
- PrefService prefs(FilePath(), NULL);
+ PrefService prefs((FilePath()));
const wchar_t path[] = L"fake.path";
diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc
index d4028db..4b5f205 100644
--- a/chrome/test/in_process_browser_test.cc
+++ b/chrome/test/in_process_browser_test.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/profile_manager.h"
@@ -220,7 +221,8 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
#endif
CHECK(PathService::Override(base::FILE_EXE, chrome_path));
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
NewRunnableFunction(chrome_browser_net::SetUrlRequestMocksEnabled, true));
browser_ = CreateBrowser(profile);
diff --git a/chrome/test/reliability/page_load_test.cc b/chrome/test/reliability/page_load_test.cc
index 4df7423..ffaa63a 100644
--- a/chrome/test/reliability/page_load_test.cc
+++ b/chrome/test/reliability/page_load_test.cc
@@ -539,7 +539,7 @@ class PageLoadTest : public UITest {
FilePath local_state_path = user_data_dir()
.Append(chrome::kLocalStateFilename);
- PrefService* local_state(new PrefService(local_state_path, NULL));
+ PrefService* local_state(new PrefService(local_state_path));
return local_state;
}
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index adbb7dd4..61083af 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -114,7 +114,7 @@ class TestingProfile : public Profile {
if (!prefs_.get()) {
FilePath prefs_filename =
path_.Append(FILE_PATH_LITERAL("TestPreferences"));
- prefs_.reset(new PrefService(prefs_filename, NULL));
+ prefs_.reset(new PrefService(prefs_filename));
Profile::RegisterUserPrefs(prefs_.get());
browser::RegisterAllPrefs(prefs_.get(), prefs_.get());
}