diff options
author | rdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 17:46:28 +0000 |
---|---|---|
committer | rdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 17:46:28 +0000 |
commit | e50540ec88e9a2102a028336335fc8eb4ee026ee (patch) | |
tree | 97beeacad60484c512f1dea0e4de76f4c94b1edc | |
parent | 5d0801e33916634785e6d529e24a530f96462214 (diff) | |
download | chromium_src-e50540ec88e9a2102a028336335fc8eb4ee026ee.zip chromium_src-e50540ec88e9a2102a028336335fc8eb4ee026ee.tar.gz chromium_src-e50540ec88e9a2102a028336335fc8eb4ee026ee.tar.bz2 |
Fix DownloadCancelled test to be more precise about verifying requests cleared.
Review URL: http://codereview.chromium.org/8222005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106520 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/download/download_browsertest.cc | 16 | ||||
-rw-r--r-- | content/browser/net/url_request_slow_download_job.cc | 31 | ||||
-rw-r--r-- | content/browser/net/url_request_slow_download_job.h | 13 |
3 files changed, 39 insertions, 21 deletions
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index 440c1a4..2731a6c 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -446,7 +446,7 @@ class CancelTestDataCollector CancelTestDataCollector() : resource_dispatcher_host_( g_browser_process->resource_dispatcher_host()), - rdh_pending_requests_(0), + slow_download_job_pending_requests_(0), dfm_pending_downloads_(0) { } void WaitForDataCollected() { @@ -457,8 +457,11 @@ class CancelTestDataCollector ui_test_utils::RunMessageLoop(); } - int rdh_pending_requests() { return rdh_pending_requests_; } - int dfm_pending_downloads() { return dfm_pending_downloads_; } + int slow_download_job_pending_requests() const { + return slow_download_job_pending_requests_; + } + + int dfm_pending_downloads() const { return dfm_pending_downloads_; } protected: friend class base::RefCountedThreadSafe<CancelTestDataCollector>; @@ -469,7 +472,8 @@ class CancelTestDataCollector void IOInfoCollector() { download_file_manager_ = resource_dispatcher_host_->download_file_manager(); - rdh_pending_requests_ = resource_dispatcher_host_->pending_requests(); + slow_download_job_pending_requests_ = + URLRequestSlowDownloadJob::NumberOutstandingRequests(); BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, base::Bind(&CancelTestDataCollector::FileInfoCollector, this)); @@ -483,7 +487,7 @@ class CancelTestDataCollector ResourceDispatcherHost* resource_dispatcher_host_; DownloadFileManager* download_file_manager_; - int rdh_pending_requests_; + int slow_download_job_pending_requests_; int dfm_pending_downloads_; DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); @@ -1607,7 +1611,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { // Get the important info from other threads and check it. scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); info->WaitForDataCollected(); - EXPECT_EQ(0, info->rdh_pending_requests()); + EXPECT_EQ(0, info->slow_download_job_pending_requests()); EXPECT_EQ(0, info->dfm_pending_downloads()); // Using "DownloadItem::Remove" follows the discard dangerous download path, diff --git a/content/browser/net/url_request_slow_download_job.cc b/content/browser/net/url_request_slow_download_job.cc index 95806cb..a2bdf0ca 100644 --- a/content/browser/net/url_request_slow_download_job.cc +++ b/content/browser/net/url_request_slow_download_job.cc @@ -9,6 +9,7 @@ #include "base/message_loop.h" #include "base/stringprintf.h" #include "base/string_util.h" +#include "content/browser/browser_thread.h" #include "googleurl/src/gurl.h" #include "net/base/io_buffer.h" #include "net/http/http_response_headers.h" @@ -25,8 +26,8 @@ const char URLRequestSlowDownloadJob::kFinishDownloadUrl[] = const int URLRequestSlowDownloadJob::kFirstDownloadSize = 1024 * 35; const int URLRequestSlowDownloadJob::kSecondDownloadSize = 1024 * 10; -std::vector<URLRequestSlowDownloadJob*> - URLRequestSlowDownloadJob::kPendingRequests; +std::set<URLRequestSlowDownloadJob*> + URLRequestSlowDownloadJob::pending_requests_; void URLRequestSlowDownloadJob::Start() { MessageLoop::current()->PostTask( @@ -46,24 +47,31 @@ void URLRequestSlowDownloadJob::AddUrlHandler() { &URLRequestSlowDownloadJob::Factory); } -/*static */ +// static net::URLRequestJob* URLRequestSlowDownloadJob::Factory( net::URLRequest* request, const std::string& scheme) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); URLRequestSlowDownloadJob* job = new URLRequestSlowDownloadJob(request); if (request->url().spec() != kFinishDownloadUrl) - URLRequestSlowDownloadJob::kPendingRequests.push_back(job); + pending_requests_.insert(job); return job; } -/* static */ +// static +size_t URLRequestSlowDownloadJob::NumberOutstandingRequests() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + return pending_requests_.size(); +} + +// static void URLRequestSlowDownloadJob::FinishPendingRequests() { - typedef std::vector<URLRequestSlowDownloadJob*> JobList; - for (JobList::iterator it = kPendingRequests.begin(); it != - kPendingRequests.end(); ++it) { + typedef std::set<URLRequestSlowDownloadJob*> JobList; + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + for (JobList::iterator it = pending_requests_.begin(); it != + pending_requests_.end(); ++it) { (*it)->set_should_finish_download(); } - kPendingRequests.clear(); } URLRequestSlowDownloadJob::URLRequestSlowDownloadJob(net::URLRequest* request) @@ -146,7 +154,10 @@ void URLRequestSlowDownloadJob::GetResponseInfo(net::HttpResponseInfo* info) { GetResponseInfoConst(info); } -URLRequestSlowDownloadJob::~URLRequestSlowDownloadJob() {} +URLRequestSlowDownloadJob::~URLRequestSlowDownloadJob() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + pending_requests_.erase(this); +} // Private const version. void URLRequestSlowDownloadJob::GetResponseInfoConst( diff --git a/content/browser/net/url_request_slow_download_job.h b/content/browser/net/url_request_slow_download_job.h index b0f24e2..b5dc8a3 100644 --- a/content/browser/net/url_request_slow_download_job.h +++ b/content/browser/net/url_request_slow_download_job.h @@ -10,8 +10,8 @@ #define CONTENT_BROWSER_NET_URL_REQUEST_SLOW_DOWNLOAD_JOB_H_ #pragma once +#include <set> #include <string> -#include <vector> #include "base/task.h" #include "content/common/content_export.h" @@ -28,8 +28,6 @@ class URLRequestSlowDownloadJob : public net::URLRequestJob { CONTENT_EXPORT static const int kFirstDownloadSize; CONTENT_EXPORT static const int kSecondDownloadSize; - explicit URLRequestSlowDownloadJob(net::URLRequest* request); - // Timer callback, used to check to see if we should finish our download and // send the second chunk. void CheckDoneStatus(); @@ -43,18 +41,23 @@ class URLRequestSlowDownloadJob : public net::URLRequestJob { static net::URLRequestJob* Factory(net::URLRequest* request, const std::string& scheme); + // Returns the current number of URLRequestSlowDownloadJobs that have + // not yet completed. + static size_t NumberOutstandingRequests(); + // Adds the testing URLs to the net::URLRequestFilter. CONTENT_EXPORT static void AddUrlHandler(); private: + explicit URLRequestSlowDownloadJob(net::URLRequest* request); virtual ~URLRequestSlowDownloadJob(); void GetResponseInfoConst(net::HttpResponseInfo* info) const; // Mark all pending requests to be finished. We keep track of pending - // requests in |kPendingRequests|. + // requests in |pending_requests_|. static void FinishPendingRequests(); - static std::vector<URLRequestSlowDownloadJob*> kPendingRequests; + static std::set<URLRequestSlowDownloadJob*> pending_requests_; void StartAsync(); |