diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-28 20:31:58 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-28 20:31:58 +0000 |
commit | fae20799882ef797ae9cb5a169c3a60680fa66c2 (patch) | |
tree | aa54776c6e6b1b95fb1ad7737440c82c022eff01 /chrome | |
parent | 419834aa659b728039d8dd398f7156b823f572d8 (diff) | |
download | chromium_src-fae20799882ef797ae9cb5a169c3a60680fa66c2.zip chromium_src-fae20799882ef797ae9cb5a169c3a60680fa66c2.tar.gz chromium_src-fae20799882ef797ae9cb5a169c3a60680fa66c2.tar.bz2 |
First of several patches to get rid of MessageLoop caching now that we have ChromeThread::PostTask.
BUG=25354
Review URL: http://codereview.chromium.org/342020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30383 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/automation/automation_profile_impl.cc | 4 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 4 | ||||
-rw-r--r-- | chrome/browser/browser_process.h | 6 | ||||
-rw-r--r-- | chrome/browser/cocoa/web_drop_target_unittest.mm | 1 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_dom_handler.cc | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_ui.cc | 5 | ||||
-rw-r--r-- | chrome/browser/dom_ui/filebrowse_ui.cc | 18 | ||||
-rw-r--r-- | chrome/browser/dom_ui/history_ui.cc | 18 | ||||
-rw-r--r-- | chrome/browser/dom_ui/most_visited_handler.cc | 26 | ||||
-rw-r--r-- | chrome/browser/dom_ui/new_tab_ui.cc | 39 | ||||
-rw-r--r-- | chrome/browser/dom_ui/print_ui.cc | 8 | ||||
-rw-r--r-- | chrome/browser/download/download_file.cc | 131 | ||||
-rw-r--r-- | chrome/browser/download/download_file.h | 17 | ||||
-rw-r--r-- | chrome/browser/renderer_host/download_resource_handler.cc | 15 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.cc | 3 | ||||
-rw-r--r-- | chrome/browser/renderer_host/test/test_render_view_host.cc | 2 | ||||
-rw-r--r-- | chrome/browser/renderer_host/test/test_render_view_host.h | 3 |
17 files changed, 153 insertions, 151 deletions
diff --git a/chrome/browser/automation/automation_profile_impl.cc b/chrome/browser/automation/automation_profile_impl.cc index d1f0750..50cb650 100644 --- a/chrome/browser/automation/automation_profile_impl.cc +++ b/chrome/browser/automation/automation_profile_impl.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "chrome/browser/automation/automation_profile_impl.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/test/automation/automation_messages.h" @@ -149,8 +150,7 @@ 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); } } // namespace diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index fcd8d81..68c6041 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -28,6 +28,7 @@ #include "chrome/browser/blocked_popup_container.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_window.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_operation_notification_details.h" #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/download/download_manager.h" @@ -1274,7 +1275,8 @@ void AutomationProvider::SetProxyConfig(const std::string& new_proxy_config) { } DCHECK(context_getter); - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, new SetProxyConfigTask(context_getter, new_proxy_config)); } diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h index 6d96e3a..ff1361b 100644 --- a/chrome/browser/browser_process.h +++ b/chrome/browser/browser_process.h @@ -71,7 +71,11 @@ class BrowserProcess { // Returns the thread that we perform I/O coordination on (network requests, // communication with renderers, etc. - // NOTE: need to check the return value for NULL. + // NOTE: You should ONLY use this to pass to IPC or other objects which must + // need a MessageLoop*. If you just want to post a task, use + // ChromeThread::PostTask (or other variants) as they take care of checking + // that a thread is still alive, race conditions, lifetime differences etc. + // If you still must use this, need to check the return value for NULL. virtual base::Thread* io_thread() = 0; // Returns the thread that we perform random file operations on. For code diff --git a/chrome/browser/cocoa/web_drop_target_unittest.mm b/chrome/browser/cocoa/web_drop_target_unittest.mm index 7dd02de..45bae3e 100644 --- a/chrome/browser/cocoa/web_drop_target_unittest.mm +++ b/chrome/browser/cocoa/web_drop_target_unittest.mm @@ -14,7 +14,6 @@ class WebDropTargetTest : public RenderViewHostTestHarness { public: WebDropTargetTest() { - RenderViewHostTestHarness::SetUp(); drop_target_.reset([[WebDropTarget alloc] initWithTabContents:contents()]); } diff --git a/chrome/browser/dom_ui/downloads_dom_handler.cc b/chrome/browser/dom_ui/downloads_dom_handler.cc index bdaddd7..7b77915 100644 --- a/chrome/browser/dom_ui/downloads_dom_handler.cc +++ b/chrome/browser/dom_ui/downloads_dom_handler.cc @@ -11,6 +11,7 @@ #include "base/thread.h" #include "base/values.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/dom_ui/fileicon_source.h" #include "chrome/browser/metrics/user_metrics.h" @@ -51,7 +52,8 @@ DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) : search_text_(), download_manager_(dlm) { // Create our fileicon data source. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, NewRunnableMethod(&chrome_url_data_manager, &ChromeURLDataManager::AddDataSource, new FileIconSource())); diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc index 3de6f5a..ee17102 100644 --- a/chrome/browser/dom_ui/downloads_ui.cc +++ b/chrome/browser/dom_ui/downloads_ui.cc @@ -9,7 +9,7 @@ #include "base/string_piece.h" #include "base/thread.h" #include "base/values.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/dom_ui/downloads_dom_handler.h" #include "chrome/browser/download/download_manager.h" @@ -132,7 +132,8 @@ DownloadsUI::DownloadsUI(TabContents* contents) : DOMUI(contents) { DownloadsUIHTMLSource* html_source = new DownloadsUIHTMLSource(); // Set up the chrome://downloads/ source. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, NewRunnableMethod(&chrome_url_data_manager, &ChromeURLDataManager::AddDataSource, html_source)); diff --git a/chrome/browser/dom_ui/filebrowse_ui.cc b/chrome/browser/dom_ui/filebrowse_ui.cc index eacf872..bcd0aff 100644 --- a/chrome/browser/dom_ui/filebrowse_ui.cc +++ b/chrome/browser/dom_ui/filebrowse_ui.cc @@ -14,7 +14,7 @@ #include "base/time.h" #include "base/values.h" #include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/history/history_types.h" @@ -133,10 +133,12 @@ FileBrowseHandler::~FileBrowseHandler() { DOMMessageHandler* FileBrowseHandler::Attach(DOMUI* dom_ui) { // Create our favicon data source. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, - &ChromeURLDataManager::AddDataSource, - new DOMUIFavIconSource(dom_ui->GetProfile()))); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + &chrome_url_data_manager, + &ChromeURLDataManager::AddDataSource, + new DOMUIFavIconSource(dom_ui->GetProfile()))); return DOMMessageHandler::Attach(dom_ui); } @@ -248,8 +250,10 @@ FileBrowseUI::FileBrowseUI(TabContents* contents) : DOMUI(contents) { FileBrowseUIHTMLSource* html_source = new FileBrowseUIHTMLSource(); // Set up the chrome://filebrowse/ source. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + &chrome_url_data_manager, &ChromeURLDataManager::AddDataSource, html_source)); } diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc index 7c2b916..5e78bbe 100644 --- a/chrome/browser/dom_ui/history_ui.cc +++ b/chrome/browser/dom_ui/history_ui.cc @@ -14,7 +14,7 @@ #include "base/time.h" #include "base/values.h" #include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/history/history_types.h" @@ -110,10 +110,12 @@ BrowsingHistoryHandler::~BrowsingHistoryHandler() { DOMMessageHandler* BrowsingHistoryHandler::Attach(DOMUI* dom_ui) { // Create our favicon data source. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, - &ChromeURLDataManager::AddDataSource, - new DOMUIFavIconSource(dom_ui->GetProfile()))); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + &chrome_url_data_manager, + &ChromeURLDataManager::AddDataSource, + new DOMUIFavIconSource(dom_ui->GetProfile()))); // Get notifications when history is cleared. registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, @@ -368,8 +370,10 @@ HistoryUI::HistoryUI(TabContents* contents) : DOMUI(contents) { HistoryUIHTMLSource* html_source = new HistoryUIHTMLSource(); // Set up the chrome://history/ source. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + &chrome_url_data_manager, &ChromeURLDataManager::AddDataSource, html_source)); } diff --git a/chrome/browser/dom_ui/most_visited_handler.cc b/chrome/browser/dom_ui/most_visited_handler.cc index 4c3c3f3..0142c18 100644 --- a/chrome/browser/dom_ui/most_visited_handler.cc +++ b/chrome/browser/dom_ui/most_visited_handler.cc @@ -9,11 +9,11 @@ #include "base/string_util.h" #include "base/thread.h" #include "base/values.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" #include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h" #include "chrome/browser/dom_ui/new_tab_ui.h" -#include "chrome/browser/browser_process.h" #include "chrome/browser/history/page_usage_data.h" #include "chrome/browser/history/history.h" #include "chrome/browser/profile.h" @@ -55,19 +55,17 @@ DOMMessageHandler* MostVisitedHandler::Attach(DOMUI* dom_ui) { GetMutableDictionary(prefs::kNTPMostVisitedURLsBlacklist); pinned_urls_ = dom_ui->GetProfile()->GetPrefs()-> GetMutableDictionary(prefs::kNTPMostVisitedPinnedURLs); - // Set up our sources for thumbnail and favicon data. Since we may be in - // testing mode with no I/O thread, only add our handler when an I/O thread - // exists. Ownership is passed to the ChromeURLDataManager. - if (g_browser_process->io_thread()) { - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, - &ChromeURLDataManager::AddDataSource, - new DOMUIThumbnailSource(dom_ui->GetProfile()))); - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, - &ChromeURLDataManager::AddDataSource, - new DOMUIFavIconSource(dom_ui->GetProfile()))); - } + // Set up our sources for thumbnail and favicon data. + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(&chrome_url_data_manager, + &ChromeURLDataManager::AddDataSource, + new DOMUIThumbnailSource(dom_ui->GetProfile()))); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(&chrome_url_data_manager, + &ChromeURLDataManager::AddDataSource, + new DOMUIFavIconSource(dom_ui->GetProfile()))); // Get notifications when history is cleared. registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc index 76c44ae..6d34031 100644 --- a/chrome/browser/dom_ui/new_tab_ui.cc +++ b/chrome/browser/dom_ui/new_tab_ui.cc @@ -18,7 +18,7 @@ #include "base/string_piece.h" #include "base/thread.h" #include "chrome/browser/browser.h" -#include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/dom_ui_theme_source.h" #include "chrome/browser/dom_ui/most_visited_handler.h" #include "chrome/browser/dom_ui/new_tab_page_sync_handler.h" @@ -548,9 +548,10 @@ NewTabUI::NewTabUI(TabContents* contents) IncognitoTabHTMLSource* html_source = new IncognitoTabHTMLSource( GetProfile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar)); - - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + &chrome_url_data_manager, &ChromeURLDataManager::AddDataSource, html_source)); } else { @@ -569,15 +570,14 @@ NewTabUI::NewTabUI(TabContents* contents) AddMessageHandler((new NewTabPageSetHomepageHandler())->Attach(this)); - // In testing mode there may not be an I/O thread. - if (g_browser_process->io_thread()) { - InitializeCSSCaches(); - NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()); - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, - &ChromeURLDataManager::AddDataSource, - html_source)); - } + InitializeCSSCaches(); + NewTabHTMLSource* html_source = new NewTabHTMLSource(GetProfile()); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + &chrome_url_data_manager, + &ChromeURLDataManager::AddDataSource, + html_source)); } // Listen for theme installation. @@ -614,13 +614,12 @@ void NewTabUI::Observe(NotificationType type, } void NewTabUI::InitializeCSSCaches() { - // In testing mode there may not be an I/O thread. - if (g_browser_process->io_thread()) { - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, - &ChromeURLDataManager::AddDataSource, - new DOMUIThemeSource(GetProfile()))); - } + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + &chrome_url_data_manager, + &ChromeURLDataManager::AddDataSource, + new DOMUIThemeSource(GetProfile()))); } // static diff --git a/chrome/browser/dom_ui/print_ui.cc b/chrome/browser/dom_ui/print_ui.cc index 56514f9a..3821b98 100644 --- a/chrome/browser/dom_ui/print_ui.cc +++ b/chrome/browser/dom_ui/print_ui.cc @@ -9,7 +9,7 @@ #include "base/message_loop.h" #include "base/thread.h" #include "base/values.h" -#include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/url_constants.h" @@ -26,8 +26,10 @@ PrintUI::PrintUI(TabContents* contents) : DOMUI(contents) { PrintUIHTMLSource* html_source = new PrintUIHTMLSource(); // Set up the print:url source. - g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(&chrome_url_data_manager, + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + &chrome_url_data_manager, &ChromeURLDataManager::AddDataSource, html_source)); } diff --git a/chrome/browser/download/download_file.cc b/chrome/browser/download/download_file.cc index 48d7b31..575da50 100644 --- a/chrome/browser/download/download_file.cc +++ b/chrome/browser/download/download_file.cc @@ -11,7 +11,7 @@ #include "base/task.h" #include "base/thread.h" #include "build/build_config.h" -#include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/profile.h" @@ -159,12 +159,8 @@ void DownloadFile::AnnotateWithSourceInformation() { // DownloadFileManager implementation ------------------------------------------ -DownloadFileManager::DownloadFileManager(MessageLoop* ui_loop, - ResourceDispatcherHost* rdh) +DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh) : next_id_(0), - ui_loop_(ui_loop), - file_loop_(NULL), - io_loop_(NULL), resource_dispatcher_host_(rdh) { } @@ -174,24 +170,19 @@ DownloadFileManager::~DownloadFileManager() { ui_progress_.clear(); } -void DownloadFileManager::Initialize() { - io_loop_ = g_browser_process->io_thread()->message_loop(); - file_loop_ = g_browser_process->file_thread()->message_loop(); -} - // Called during the browser shutdown process to clean up any state (open files, // timers) that live on the download_thread_. void DownloadFileManager::Shutdown() { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); StopUpdateTimer(); - file_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &DownloadFileManager::OnShutdown)); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod(this, &DownloadFileManager::OnShutdown)); } // Cease download thread operations. void DownloadFileManager::OnShutdown() { - DCHECK(MessageLoop::current() == file_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); // Delete any partial downloads during shutdown. for (DownloadFileMap::iterator it = downloads_.begin(); it != downloads_.end(); ++it) { @@ -211,7 +202,7 @@ DownloadFile* DownloadFileManager::LookupDownload(int id) { // The UI progress is updated on the file thread and removed on the UI thread. void DownloadFileManager::RemoveDownloadFromUIProgress(int id) { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); AutoLock lock(progress_lock_); if (ui_progress_.find(id) != ui_progress_.end()) ui_progress_.erase(id); @@ -220,7 +211,7 @@ void DownloadFileManager::RemoveDownloadFromUIProgress(int id) { // Throttle updates to the UI thread by only posting update notifications at a // regularly controlled interval. void DownloadFileManager::StartUpdateTimer() { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); if (!update_timer_.IsRunning()) { update_timer_.Start(base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), this, &DownloadFileManager::UpdateInProgressDownloads); @@ -228,14 +219,14 @@ void DownloadFileManager::StartUpdateTimer() { } void DownloadFileManager::StopUpdateTimer() { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); update_timer_.Stop(); } // Called on the IO thread once the ResourceDispatcherHost has decided that a // request is a download. int DownloadFileManager::GetNextId() { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); return next_id_++; } @@ -245,7 +236,7 @@ int DownloadFileManager::GetNextId() { // to create a DownloadFile, then passes 'info' to the UI thread where it is // finally consumed and deleted. void DownloadFileManager::StartDownload(DownloadCreateInfo* info) { - DCHECK(MessageLoop::current() == file_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); DCHECK(info); DownloadFile* download = new DownloadFile(info); @@ -273,10 +264,9 @@ void DownloadFileManager::StartDownload(DownloadCreateInfo* info) { ui_progress_[info->download_id] = info->received_bytes; } - ui_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &DownloadFileManager::OnStartDownload, - info)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod(this, &DownloadFileManager::OnStartDownload, info)); } // We don't forward an update to the UI thread here, since we want to throttle @@ -285,7 +275,7 @@ void DownloadFileManager::StartDownload(DownloadCreateInfo* info) { // thread gets the cancel message: we just delete the data since the // DownloadFile has been deleted. void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) { - DCHECK(MessageLoop::current() == file_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); std::vector<DownloadBuffer::Contents> contents; { AutoLock auto_lock(buffer->lock); @@ -308,18 +298,18 @@ void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) { } void DownloadFileManager::DownloadFinished(int id, DownloadBuffer* buffer) { - DCHECK(MessageLoop::current() == file_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); delete buffer; DownloadFileMap::iterator it = downloads_.find(id); if (it != downloads_.end()) { DownloadFile* download = it->second; download->set_in_progress(false); - ui_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &DownloadFileManager::OnDownloadFinished, - id, - download->bytes_so_far())); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod( + this, &DownloadFileManager::OnDownloadFinished, + id, download->bytes_so_far())); // We need to keep the download around until the UI thread has finalized // the name. @@ -330,15 +320,16 @@ void DownloadFileManager::DownloadFinished(int id, DownloadBuffer* buffer) { } if (downloads_.empty()) - ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &DownloadFileManager::StopUpdateTimer)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod(this, &DownloadFileManager::StopUpdateTimer)); } // This method will be sent via a user action, or shutdown on the UI thread, and // run on the download thread. Since this message has been sent from the UI // thread, the download may have already completed and won't exist in our map. void DownloadFileManager::CancelDownload(int id) { - DCHECK(MessageLoop::current() == file_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); DownloadFileMap::iterator it = downloads_.find(id); if (it != downloads_.end()) { DownloadFile* download = it->second; @@ -346,10 +337,11 @@ void DownloadFileManager::CancelDownload(int id) { download->Cancel(); - ui_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &DownloadFileManager::RemoveDownloadFromUIProgress, - download->id())); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod( + this, &DownloadFileManager::RemoveDownloadFromUIProgress, + download->id())); if (download->path_renamed()) { downloads_.erase(it); @@ -357,15 +349,17 @@ void DownloadFileManager::CancelDownload(int id) { } } - if (downloads_.empty()) - ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &DownloadFileManager::StopUpdateTimer)); + if (downloads_.empty()) { + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod(this, &DownloadFileManager::StopUpdateTimer)); + } } // Our periodic timer has fired so send the UI thread updates on all in progress // downloads. void DownloadFileManager::UpdateInProgressDownloads() { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); AutoLock lock(progress_lock_); ProgressMap::iterator it = ui_progress_.begin(); for (; it != ui_progress_.end(); ++it) { @@ -383,7 +377,7 @@ void DownloadFileManager::UpdateInProgressDownloads() { // TODO(paulg): When implementing download restart via the Downloads tab, // there will be no 'render_process_id' or 'render_view_id'. void DownloadFileManager::OnStartDownload(DownloadCreateInfo* info) { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); DownloadManager* manager = DownloadManagerFromRenderIds(info->child_id, info->render_view_id); if (!manager) { @@ -423,7 +417,7 @@ void DownloadFileManager::OnStartDownload(DownloadCreateInfo* info) { // tracking entries. void DownloadFileManager::OnDownloadFinished(int id, int64 bytes_so_far) { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); DownloadManager* manager = LookupManager(id); if (manager) manager->DownloadFinished(id, bytes_so_far); @@ -438,10 +432,9 @@ void DownloadFileManager::DownloadUrl( int render_process_host_id, int render_view_id, URLRequestContextGetter* request_context_getter) { - DCHECK(MessageLoop::current() == ui_loop_); - base::Thread* thread = g_browser_process->io_thread(); - if (thread) { - thread->message_loop()->PostTask(FROM_HERE, + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, NewRunnableMethod(this, &DownloadFileManager::OnDownloadUrl, url, @@ -450,12 +443,11 @@ void DownloadFileManager::DownloadUrl( render_process_host_id, render_view_id, request_context_getter)); - } } // Relate a download ID to its owning DownloadManager. DownloadManager* DownloadFileManager::LookupManager(int download_id) { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); DownloadManagerMap::iterator it = managers_.find(download_id); if (it != managers_.end()) return it->second; @@ -467,7 +459,7 @@ DownloadManager* DownloadFileManager::LookupManager(int download_id) { // one download (id) and remove it from the set, and remove the set if it // becomes empty. void DownloadFileManager::RemoveDownload(int id, DownloadManager* manager) { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); if (manager) { RequestMap::iterator it = requests_.find(manager); if (it != requests_.end()) { @@ -505,7 +497,7 @@ DownloadManager* DownloadFileManager::DownloadManagerFromRenderIds( // Called by DownloadManagers in their destructor, and only on the UI thread. void DownloadFileManager::RemoveDownloadManager(DownloadManager* manager) { - DCHECK(MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); DCHECK(manager); RequestMap::iterator it = requests_.find(manager); if (it == requests_.end()) @@ -535,7 +527,7 @@ void DownloadFileManager::OnDownloadUrl( int render_process_host_id, int render_view_id, URLRequestContextGetter* request_context_getter) { - DCHECK(MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); URLRequestContext* context = request_context_getter->GetURLRequestContext(); context->set_referrer_charset(referrer_charset); @@ -554,7 +546,7 @@ void DownloadFileManager::OnDownloadUrl( // TODO(paulg): File 'stat' operations. #if !defined(OS_MACOSX) void DownloadFileManager::OnShowDownloadInShell(const FilePath& full_path) { - DCHECK(MessageLoop::current() == file_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); platform_util::ShowItemInFolder(full_path); } #endif @@ -566,7 +558,7 @@ void DownloadFileManager::OnShowDownloadInShell(const FilePath& full_path) { void DownloadFileManager::OnOpenDownloadInShell(const FilePath& full_path, const GURL& url, gfx::NativeView parent_window) { - DCHECK(MessageLoop::current() == file_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); #if defined(OS_WIN) if (NULL != parent_window) { win_util::SaferOpenItemViaShell(parent_window, L"", full_path, @@ -584,7 +576,7 @@ void DownloadFileManager::OnOpenDownloadInShell(const FilePath& full_path, void DownloadFileManager::OnFinalDownloadName(int id, const FilePath& full_path, DownloadManager* manager) { - DCHECK(MessageLoop::current() == file_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); DownloadFileMap::iterator it = downloads_.find(id); if (it == downloads_.end()) return; @@ -598,21 +590,20 @@ void DownloadFileManager::OnFinalDownloadName(int id, // http://crbug.com/13120 for details. download->AnnotateWithSourceInformation(); #endif - ui_loop_->PostTask(FROM_HERE, - NewRunnableMethod(manager, - &DownloadManager::DownloadRenamedToFinalName, - id, - full_path)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod( + manager, &DownloadManager::DownloadRenamedToFinalName, id, + full_path)); } else { // Error. Between the time the UI thread generated 'full_path' to the time // this code runs, something happened that prevents us from renaming. DownloadManagerMap::iterator dmit = managers_.find(download->id()); if (dmit != managers_.end()) { DownloadManager* dlm = dmit->second; - ui_loop_->PostTask(FROM_HERE, - NewRunnableMethod(dlm, - &DownloadManager::DownloadCancelled, - id)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod(dlm, &DownloadManager::DownloadCancelled, id)); } else { ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, @@ -630,9 +621,11 @@ void DownloadFileManager::OnFinalDownloadName(int id, delete download; } - if (downloads_.empty()) - ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &DownloadFileManager::StopUpdateTimer)); + if (downloads_.empty()) { + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod(this, &DownloadFileManager::StopUpdateTimer)); + } } // static diff --git a/chrome/browser/download/download_file.h b/chrome/browser/download/download_file.h index 2e24a17..ef367ce 100644 --- a/chrome/browser/download/download_file.h +++ b/chrome/browser/download/download_file.h @@ -60,7 +60,6 @@ class IOBuffer; } struct DownloadCreateInfo; class DownloadManager; -class MessageLoop; class ResourceDispatcherHost; class URLRequestContextGetter; @@ -168,11 +167,10 @@ class DownloadFile { class DownloadFileManager : public base::RefCountedThreadSafe<DownloadFileManager> { public: - DownloadFileManager(MessageLoop* ui_loop, ResourceDispatcherHost* rdh); + DownloadFileManager(ResourceDispatcherHost* rdh); ~DownloadFileManager(); - // Lifetime management functions, called on the UI thread. - void Initialize(); + // Called on shutdown on the UI thread. void Shutdown(); // Called on the IO thread @@ -232,8 +230,6 @@ class DownloadFileManager // Timer notifications. void UpdateInProgressDownloads(); - MessageLoop* file_loop() const { return file_loop_; } - // Called by the download manager to delete non validated dangerous downloads. static void DeleteFile(const FilePath& path); @@ -266,15 +262,6 @@ class DownloadFileManager // Throttle updates to the UI thread. base::RepeatingTimer<DownloadFileManager> update_timer_; - // The MessageLoop that the DownloadManagers live on. - MessageLoop* ui_loop_; - - // The MessageLoop that the this objects primarily operates on. - MessageLoop* file_loop_; - - // Used only for DCHECKs! - MessageLoop* io_loop_; - ResourceDispatcherHost* resource_dispatcher_host_; // Tracking which DownloadManager to send data to, called only on UI thread. diff --git a/chrome/browser/renderer_host/download_resource_handler.cc b/chrome/browser/renderer_host/download_resource_handler.cc index 8ac8ac0..f232771 100644 --- a/chrome/browser/renderer_host/download_resource_handler.cc +++ b/chrome/browser/renderer_host/download_resource_handler.cc @@ -5,6 +5,7 @@ #include "chrome/browser/renderer_host/download_resource_handler.h" #include "base/logging.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/download/download_file.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" @@ -69,10 +70,10 @@ bool DownloadResourceHandler::OnResponseStarted(int request_id, info->save_as = save_as_; info->is_dangerous = false; info->referrer_charset = request_->context()->referrer_charset(); - download_manager_->file_loop()->PostTask(FROM_HERE, - NewRunnableMethod(download_manager_, - &DownloadFileManager::StartDownload, - info)); + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod( + download_manager_, &DownloadFileManager::StartDownload, info)); return true; } @@ -104,7 +105,8 @@ bool DownloadResourceHandler::OnReadCompleted(int request_id, int* bytes_read) { read_buffer_.swap(&buffer); buffer_->contents.push_back(std::make_pair(buffer, *bytes_read)); if (need_update) { - download_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(download_manager_, &DownloadFileManager::UpdateDownload, download_id_, @@ -123,7 +125,8 @@ bool DownloadResourceHandler::OnResponseCompleted( int request_id, const URLRequestStatus& status, const std::string& security_info) { - download_manager_->file_loop()->PostTask(FROM_HERE, + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, NewRunnableMethod(download_manager_, &DownloadFileManager::DownloadFinished, download_id_, diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 0a495df8..85935c3 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -254,7 +254,7 @@ ResourceDispatcherHost::ResourceDispatcherHost(MessageLoop* io_loop) : ui_loop_(MessageLoop::current()), io_loop_(io_loop), ALLOW_THIS_IN_INITIALIZER_LIST( - download_file_manager_(new DownloadFileManager(ui_loop_, this))), + download_file_manager_(new DownloadFileManager(this))), download_request_manager_(new DownloadRequestManager(io_loop, ui_loop_)), ALLOW_THIS_IN_INITIALIZER_LIST( save_file_manager_(new SaveFileManager(ui_loop_, io_loop, this))), @@ -296,7 +296,6 @@ ResourceDispatcherHost::~ResourceDispatcherHost() { void ResourceDispatcherHost::Initialize() { DCHECK(MessageLoop::current() == ui_loop_); - download_file_manager_->Initialize(); safe_browsing_->Initialize(io_loop_); io_loop_->PostTask( FROM_HERE, diff --git a/chrome/browser/renderer_host/test/test_render_view_host.cc b/chrome/browser/renderer_host/test/test_render_view_host.cc index 712d967..72a0c6b 100644 --- a/chrome/browser/renderer_host/test/test_render_view_host.cc +++ b/chrome/browser/renderer_host/test/test_render_view_host.cc @@ -104,6 +104,8 @@ void RenderViewHostTestHarness::SetUp() { SiteInstance* instance = SiteInstance::CreateSiteInstance(profile_.get()); contents_.reset(new TestTabContents(profile_.get(), instance)); + + user_data_manager_.reset(UserDataManager::Create()); } void RenderViewHostTestHarness::TearDown() { diff --git a/chrome/browser/renderer_host/test/test_render_view_host.h b/chrome/browser/renderer_host/test/test_render_view_host.h index cc707f8..bd83b0e 100644 --- a/chrome/browser/renderer_host/test/test_render_view_host.h +++ b/chrome/browser/renderer_host/test/test_render_view_host.h @@ -14,6 +14,7 @@ #include "chrome/browser/renderer_host/render_view_host_factory.h" #include "chrome/browser/renderer_host/site_instance.h" #include "chrome/browser/tab_contents/test_tab_contents.h" +#include "chrome/browser/user_data_manager.h" #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" @@ -254,6 +255,8 @@ class RenderViewHostTestHarness : public testing::Test { scoped_ptr<TestTabContents> contents_; + scoped_ptr<UserDataManager> user_data_manager_; + DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestHarness); }; |