Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Unified Diff: net/url_request/url_request_file_dir_job.cc

Issue 5710002: Create base::WorkerPoolJob. Use it for HostResolverImpl and DirectoryLister. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/url_request/url_request_file_dir_job.cc
diff --git a/net/url_request/url_request_file_dir_job.cc b/net/url_request/url_request_file_dir_job.cc
index 553add8ee6c1e9eaa91881cb68d4e2c648e69a10..23b671e2d3a3202be79559fdba41fd838674d21b 100644
--- a/net/url_request/url_request_file_dir_job.cc
+++ b/net/url_request/url_request_file_dir_job.cc
@@ -12,6 +12,7 @@
#include "base/time.h"
#include "googleurl/src/gurl.h"
#include "net/base/io_buffer.h"
+#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/url_request/url_request.h"
@@ -19,11 +20,10 @@
#include <sys/stat.h>
#endif
-using std::string;
-
URLRequestFileDirJob::URLRequestFileDirJob(net::URLRequest* request,
const FilePath& dir_path)
- : net::URLRequestJob(request),
+ : URLRequestJob(request),
+ ALLOW_THIS_IN_INITIALIZER_LIST(lister_(dir_path, this)),
dir_path_(dir_path),
canceled_(false),
list_complete_(false),
@@ -34,8 +34,7 @@ URLRequestFileDirJob::URLRequestFileDirJob(net::URLRequest* request,
}
URLRequestFileDirJob::~URLRequestFileDirJob() {
- DCHECK(read_pending_ == false);
- DCHECK(lister_ == NULL);
+ DCHECK(!read_pending_);
}
void URLRequestFileDirJob::Start() {
@@ -48,36 +47,22 @@ void URLRequestFileDirJob::Start() {
}
void URLRequestFileDirJob::StartAsync() {
- DCHECK(!lister_);
-
- // TODO(willchan): This is stupid. We should tell |lister_| not to call us
- // back. Fix this stupidity.
-
- // AddRef so that *this* cannot be destroyed while the lister_
- // is trying to feed us data.
-
- AddRef();
- lister_ = new net::DirectoryLister(dir_path_, this);
- lister_->Start();
+ lister_.Start();
NotifyHeadersComplete();
}
void URLRequestFileDirJob::Kill() {
- if (canceled_)
- return;
-
- canceled_ = true;
-
- // Don't call CloseLister or dispatch an error to the net::URLRequest because
- // we want OnListDone to be called to also write the error to the output
- // stream. OnListDone will notify the net::URLRequest at this time.
- if (lister_)
- lister_->Cancel();
-
- net::URLRequestJob::Kill();
+ if (!is_done() && !list_complete_) {
+ lister_.Cancel();
+ read_pending_ = false;
+ list_complete_ = true;
+ }
+ DCHECK(!read_pending_);
+ DCHECK(list_complete_);
method_factory_.RevokeAll();
+ URLRequestJob::Kill();
}
bool URLRequestFileDirJob::ReadRawData(net::IOBuffer* buf, int buf_size,
@@ -99,19 +84,18 @@ bool URLRequestFileDirJob::ReadRawData(net::IOBuffer* buf, int buf_size,
return false;
}
-bool URLRequestFileDirJob::GetMimeType(string* mime_type) const {
+bool URLRequestFileDirJob::GetMimeType(std::string* mime_type) const {
*mime_type = "text/html";
return true;
}
-bool URLRequestFileDirJob::GetCharset(string* charset) {
+bool URLRequestFileDirJob::GetCharset(std::string* charset) {
// All the filenames are converted to UTF-8 before being added.
*charset = "utf-8";
return true;
}
-void URLRequestFileDirJob::OnListFile(
- const net::DirectoryLister::DirectoryListerData& data) {
+void URLRequestFileDirJob::OnListFile(const net::DirectoryLister::Data& data) {
// We wait to write out the header until we get the first file, so that we
// can catch errors from DirectoryLister and show an error page.
if (!wrote_header_) {
@@ -158,28 +142,13 @@ void URLRequestFileDirJob::OnListFile(
}
void URLRequestFileDirJob::OnListDone(int error) {
- CloseLister();
-
- if (canceled_) {
- read_pending_ = false;
- // No need for NotifyCanceled() since canceled_ is set inside Kill().
- } else if (error) {
+ if (error != net::OK) {
read_pending_ = false;
NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, error));
} else {
list_complete_ = true;
CompleteRead();
}
-
- Release(); // The Lister is finished; may delete *this*
-}
-
-void URLRequestFileDirJob::CloseLister() {
- if (lister_) {
- lister_->Cancel();
- lister_->set_delegate(NULL);
- lister_ = NULL;
- }
}
bool URLRequestFileDirJob::FillReadBuffer(char *buf, int buf_size,
« base/worker_pool_job_unittest.cc ('K') | « net/url_request/url_request_file_dir_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698