summaryrefslogtreecommitdiffstats
path: root/net/url_request
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 19:50:34 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 19:50:34 +0000
commit05a81418486624a13eb7961963fe5bb07ff03806 (patch)
treefc8f5ebd45addfca4f370238ff0cb0239e3005e6 /net/url_request
parent8a6e41619ddac0aa52625ff425b574142fd96ba1 (diff)
downloadchromium_src-05a81418486624a13eb7961963fe5bb07ff03806.zip
chromium_src-05a81418486624a13eb7961963fe5bb07ff03806.tar.gz
chromium_src-05a81418486624a13eb7961963fe5bb07ff03806.tar.bz2
Fix DirectoryLister not to require refcounting.
Also prevent DirectoryLister from blocking the IO thread when cancelled (blocked on joining file IO thread). Allows us to remove refcounting from URLRequestFileDirJob. BUG=65331 TEST=Browse to file:/// and make sure it still works. Test cancellation by closing the tab. Review URL: http://codereview.chromium.org/6898047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83193 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request')
-rw-r--r--net/url_request/url_request_file_dir_job.cc46
-rw-r--r--net/url_request/url_request_file_dir_job.h4
2 files changed, 11 insertions, 39 deletions
diff --git a/net/url_request/url_request_file_dir_job.cc b/net/url_request/url_request_file_dir_job.cc
index 1cc15be..c47e800 100644
--- a/net/url_request/url_request_file_dir_job.cc
+++ b/net/url_request/url_request_file_dir_job.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -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"
@@ -24,6 +25,7 @@ namespace net {
URLRequestFileDirJob::URLRequestFileDirJob(URLRequest* request,
const FilePath& dir_path)
: URLRequestJob(request),
+ ALLOW_THIS_IN_INITIALIZER_LIST(lister_(dir_path, this)),
dir_path_(dir_path),
canceled_(false),
list_complete_(false),
@@ -34,17 +36,7 @@ URLRequestFileDirJob::URLRequestFileDirJob(URLRequest* request,
}
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 DirectoryLister(dir_path_, this);
- lister_->Start();
+ lister_.Start();
NotifyHeadersComplete();
}
@@ -64,11 +56,8 @@ void URLRequestFileDirJob::Kill() {
canceled_ = true;
- // Don't call CloseLister or dispatch an error to the URLRequest because
- // we want OnListDone to be called to also write the error to the output
- // stream. OnListDone will notify the URLRequest at this time.
- if (lister_)
- lister_->Cancel();
+ if (!list_complete_)
+ lister_.Cancel();
URLRequestJob::Kill();
@@ -153,34 +142,17 @@ 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) {
+ DCHECK(!canceled_);
+ if (error != OK) {
read_pending_ = false;
NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, error));
} else {
list_complete_ = true;
CompleteRead();
}
-
- Release(); // The Lister is finished; may delete *this*
-}
-
-URLRequestFileDirJob::~URLRequestFileDirJob() {
- DCHECK(read_pending_ == false);
- DCHECK(lister_ == NULL);
}
-void URLRequestFileDirJob::CloseLister() {
- if (lister_) {
- lister_->Cancel();
- lister_->set_delegate(NULL);
- lister_ = NULL;
- }
-}
+URLRequestFileDirJob::~URLRequestFileDirJob() {}
void URLRequestFileDirJob::CompleteRead() {
if (read_pending_) {
diff --git a/net/url_request/url_request_file_dir_job.h b/net/url_request/url_request_file_dir_job.h
index f938417..ffc34bc 100644
--- a/net/url_request/url_request_file_dir_job.h
+++ b/net/url_request/url_request_file_dir_job.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -51,7 +51,7 @@ class URLRequestFileDirJob
// Fills a buffer with the output.
bool FillReadBuffer(char *buf, int buf_size, int *bytes_read);
- scoped_refptr<DirectoryLister> lister_;
+ DirectoryLister lister_;
FilePath dir_path_;
std::string data_;
bool canceled_;