diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-03 23:12:42 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-03 23:12:42 +0000 |
commit | 79084c2d01586797f762cbb308cb2c204dd9a164 (patch) | |
tree | de83878b22e4641589e8d7ea8bc0fe020c429876 /chrome/browser/download | |
parent | 755bbc4326d8c6c05900d681e232ec7b069e25c2 (diff) | |
download | chromium_src-79084c2d01586797f762cbb308cb2c204dd9a164.zip chromium_src-79084c2d01586797f762cbb308cb2c204dd9a164.tar.gz chromium_src-79084c2d01586797f762cbb308cb2c204dd9a164.tar.bz2 |
Last patch in removing MessageLoop* caching.
BUG=25354
Review URL: http://codereview.chromium.org/353015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30881 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/download_request_manager.cc | 28 | ||||
-rw-r--r-- | chrome/browser/download/download_request_manager.h | 8 | ||||
-rw-r--r-- | chrome/browser/download/download_request_manager_unittest.cc | 8 |
3 files changed, 19 insertions, 25 deletions
diff --git a/chrome/browser/download/download_request_manager.cc b/chrome/browser/download/download_request_manager.cc index 98a20ff..bcb4214 100644 --- a/chrome/browser/download/download_request_manager.cc +++ b/chrome/browser/download/download_request_manager.cc @@ -4,8 +4,7 @@ #include "chrome/browser/download/download_request_manager.h" -#include "base/message_loop.h" -#include "base/thread.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/download/download_request_infobar_delegate.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" @@ -152,10 +151,7 @@ void DownloadRequestManager::TabDownloadState::NotifyCallbacks(bool allow) { // DownloadRequestManager ------------------------------------------------------ -DownloadRequestManager::DownloadRequestManager(MessageLoop* io_loop, - MessageLoop* ui_loop) - : io_loop_(io_loop), - ui_loop_(ui_loop) { +DownloadRequestManager::DownloadRequestManager() { } DownloadRequestManager::~DownloadRequestManager() { @@ -175,8 +171,9 @@ void DownloadRequestManager::CanDownloadOnIOThread(int render_process_host_id, Callback* callback) { // This is invoked on the IO thread. Schedule the task to run on the UI // thread so that we can query UI state. - DCHECK(!io_loop_ || io_loop_ == MessageLoop::current()); - ui_loop_->PostTask(FROM_HERE, + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, NewRunnableMethod(this, &DownloadRequestManager::CanDownload, render_process_host_id, render_view_id, callback)); } @@ -215,7 +212,7 @@ DownloadRequestManager::TabDownloadState* DownloadRequestManager:: void DownloadRequestManager::CanDownload(int render_process_host_id, int render_view_id, Callback* callback) { - DCHECK(!ui_loop_ || MessageLoop::current() == ui_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); TabContents* originating_tab = tab_util::GetTabContentsByID(render_process_host_id, render_view_id); @@ -265,18 +262,15 @@ void DownloadRequestManager::CanDownloadImpl( void DownloadRequestManager::ScheduleNotification(Callback* callback, bool allow) { - if (io_loop_) { - io_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &DownloadRequestManager::NotifyCallback, - callback, allow)); - } else { - NotifyCallback(callback, allow); - } + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod( + this, &DownloadRequestManager::NotifyCallback, callback, allow)); } void DownloadRequestManager::NotifyCallback(Callback* callback, bool allow) { // We better be on the IO thread now. - DCHECK(!io_loop_ || MessageLoop::current() == io_loop_); + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (allow) callback->ContinueDownload(); else diff --git a/chrome/browser/download/download_request_manager.h b/chrome/browser/download/download_request_manager.h index 8844de7..8e120bb 100644 --- a/chrome/browser/download/download_request_manager.h +++ b/chrome/browser/download/download_request_manager.h @@ -14,7 +14,6 @@ #include "chrome/common/notification_registrar.h" class DownloadRequestInfoBarDelegate; -class MessageLoop; class NavigationController; class TabContents; @@ -148,7 +147,7 @@ class DownloadRequestManager : DISALLOW_COPY_AND_ASSIGN(TabDownloadState); }; - DownloadRequestManager(MessageLoop* io_loop, MessageLoop* ui_loop); + DownloadRequestManager(); ~DownloadRequestManager(); // Returns the download status for a page. This does not change the state in @@ -215,11 +214,6 @@ class DownloadRequestManager : // ALLOW_ONE_DOWNLOAD. void Remove(TabDownloadState* state); - // Two threads we use. NULL during testing, in which case messages are - // dispatched immediately. - MessageLoop* io_loop_; - MessageLoop* ui_loop_; - // Maps from tab to download state. The download state for a tab only exists // if the state is other than ALLOW_ONE_DOWNLOAD. Similarly once the state // transitions from anything but ALLOW_ONE_DOWNLOAD back to ALLOW_ONE_DOWNLOAD diff --git a/chrome/browser/download/download_request_manager_unittest.cc b/chrome/browser/download/download_request_manager_unittest.cc index a9f6382..c55bea4 100644 --- a/chrome/browser/download/download_request_manager_unittest.cc +++ b/chrome/browser/download/download_request_manager_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/download/download_request_manager.h" #include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "chrome/browser/tab_contents/navigation_controller.h" @@ -12,13 +13,15 @@ class DownloadRequestManagerTest : public RenderViewHostTestHarness, public DownloadRequestManager::Callback { public: + DownloadRequestManagerTest() : io_thread_(ChromeThread::IO, &message_loop_) {} + virtual void SetUp() { RenderViewHostTestHarness::SetUp(); allow_download_ = true; ask_allow_count_ = cancel_count_ = continue_count_ = 0; - download_request_manager_ = new DownloadRequestManager(NULL, NULL); + download_request_manager_ = new DownloadRequestManager(); test_delegate_.reset(new DownloadRequestManagerTestDelegate(this)); DownloadRequestManager::SetTestingDelegate(test_delegate_.get()); } @@ -39,6 +42,7 @@ class DownloadRequestManagerTest void CanDownload() { download_request_manager_->CanDownloadImpl( controller().tab_contents(), this); + message_loop_.RunAllPending(); } bool ShouldAllowDownload() { @@ -75,6 +79,8 @@ class DownloadRequestManagerTest // Number of times ShouldAllowDownload was invoked. int ask_allow_count_; + + ChromeThread io_thread_; }; TEST_F(DownloadRequestManagerTest, Allow) { |