From d85cf074f2186dbe1cf8a9db5d89a2b817ffb0e1 Mon Sep 17 00:00:00 2001 From: "jam@chromium.org" <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> Date: Tue, 27 Oct 2009 03:59:31 +0000 Subject: Simplify threading in browser thread by making only ChromeThread deal with different thread lifetimes.The rest of the code doesn't get MessageLoop pointers since they're not thread-safe and instead just call PostTask on ChromeThread. If the target thread is not alive, then the task is simply deleted.In a followup change, I'll remove any remaining MessageLoop* caching. With this change, there's little to be gained by caching since no locks are involved if the target MessageLoop is guaranteed to outlive the current thread (inferred automatically by the order of the chrome_threads_ array).BUG=25354 Review URL: http://codereview.chromium.org/306032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30163 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/user_data_manager.cc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'chrome/browser/user_data_manager.cc') diff --git a/chrome/browser/user_data_manager.cc b/chrome/browser/user_data_manager.cc index 5e9e0e6..bd2ba88 100644 --- a/chrome/browser/user_data_manager.cc +++ b/chrome/browser/user_data_manager.cc @@ -210,8 +210,7 @@ void UserDataManager::LaunchChromeForProfile(int index) const { void UserDataManager::GetProfiles(std::vector<std::wstring>* profiles) const { // This function should be called on the file thread. - DCHECK(MessageLoop::current() == - ChromeThread::GetMessageLoop(ChromeThread::FILE)); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); file_util::FileEnumerator file_enum( FilePath::FromWStringHack(user_data_root_), false, file_util::FileEnumerator::DIRECTORIES); @@ -281,9 +280,8 @@ void GetProfilesHelper::GetProfiles(MessageLoop* target_loop) { message_loop_ = MessageLoop::current(); } DCHECK(message_loop_); - MessageLoop* file_loop = ChromeThread::GetMessageLoop(ChromeThread::FILE); - file_loop->PostTask( - FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(this, &GetProfilesHelper::GetProfilesFromManager)); } @@ -294,8 +292,7 @@ void GetProfilesHelper::OnDelegateDeleted() { void GetProfilesHelper::GetProfilesFromManager() { // This function should be called on the file thread. - DCHECK(MessageLoop::current() == - ChromeThread::GetMessageLoop(ChromeThread::FILE)); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); // If the delegate is gone by now, no need to do any work. if (!delegate_) -- cgit v1.1