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

Unified Diff: net/url_request/url_fetcher_core.cc

Issue 10915307: URLFetcher uses a TaskRunner instead of a message loop. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Changes to url_fetcher.h Created 8 years, 3 months 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
« no previous file with comments | « net/url_request/url_fetcher_core.h ('k') | net/url_request/url_fetcher_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_fetcher_core.cc
diff --git a/net/url_request/url_fetcher_core.cc b/net/url_request/url_fetcher_core.cc
index 043d220a5880607f78e8394b8fe6ff8138bf06b9..40385491007f1a208ff7e31436a1b62ec29f2251 100644
--- a/net/url_request/url_fetcher_core.cc
+++ b/net/url_request/url_fetcher_core.cc
@@ -56,7 +56,7 @@ void URLFetcherCore::Registry::CancelAll() {
URLFetcherCore::FileWriter::FileWriter(
URLFetcherCore* core,
- scoped_refptr<base::SingleThreadTaskRunner> file_task_runner)
+ scoped_refptr<base::TaskRunner> file_task_runner)
: core_(core),
error_code_(base::PLATFORM_FILE_OK),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
@@ -65,7 +65,7 @@ URLFetcherCore::FileWriter::FileWriter(
}
URLFetcherCore::FileWriter::~FileWriter() {
- RemoveFile();
+ CloseAndDeleteFile();
}
void URLFetcherCore::FileWriter::CreateFileAtPath(
@@ -124,7 +124,7 @@ void URLFetcherCore::FileWriter::ContinueWrite(
if (base::PLATFORM_FILE_OK != error_code) {
error_code_ = error_code;
- RemoveFile();
+ CloseAndDeleteFile();
core_->delegate_task_runner_->PostTask(
FROM_HERE,
base::Bind(&URLFetcherCore::InformDelegateFetchIsComplete, core_));
@@ -171,24 +171,32 @@ void URLFetcherCore::FileWriter::CloseFileAndCompleteRequest() {
}
}
-void URLFetcherCore::FileWriter::RemoveFile() {
+void URLFetcherCore::FileWriter::CloseAndDeleteFile() {
DCHECK(core_->network_task_runner_->BelongsToCurrentThread());
- // Close the file if it is open.
- if (file_handle_ != base::kInvalidPlatformFileValue) {
- base::FileUtilProxy::Close(
- file_task_runner_, file_handle_,
- base::FileUtilProxy::StatusCallback()); // No callback: Ignore errors.
- file_handle_ = base::kInvalidPlatformFileValue;
+ if (file_handle_ == base::kInvalidPlatformFileValue) {
+ DeleteFile(base::PLATFORM_FILE_OK);
+ return;
}
+ // Close the file if it is open.
+ base::FileUtilProxy::Close(
+ file_task_runner_, file_handle_,
+ base::Bind(&URLFetcherCore::FileWriter::DeleteFile,
+ weak_factory_.GetWeakPtr()));
+ file_handle_ = base::kInvalidPlatformFileValue;
+}
- if (!file_path_.empty()) {
- base::FileUtilProxy::Delete(
- file_task_runner_, file_path_,
- false, // No need to recurse, as the path is to a file.
- base::FileUtilProxy::StatusCallback()); // No callback: Ignore errors.
- DisownFile();
- }
+void URLFetcherCore::FileWriter::DeleteFile(
+ base::PlatformFileError error_code) {
+ DCHECK(core_->network_task_runner_->BelongsToCurrentThread());
+ if (file_path_.empty())
+ return;
+
+ base::FileUtilProxy::Delete(
+ file_task_runner_, file_path_,
+ false, // No need to recurse, as the path is to a file.
+ base::FileUtilProxy::StatusCallback());
+ DisownFile();
}
void URLFetcherCore::FileWriter::DidCreateFile(
@@ -214,7 +222,7 @@ void URLFetcherCore::FileWriter::DidCreateFileInternal(
if (base::PLATFORM_FILE_OK != error_code) {
error_code_ = error_code;
- RemoveFile();
+ CloseAndDeleteFile();
core_->delegate_task_runner_->PostTask(
FROM_HERE,
base::Bind(&URLFetcherCore::InformDelegateFetchIsComplete, core_));
@@ -236,7 +244,7 @@ void URLFetcherCore::FileWriter::DidCloseFile(
if (base::PLATFORM_FILE_OK != error_code) {
error_code_ = error_code;
- RemoveFile();
+ CloseAndDeleteFile();
core_->delegate_task_runner_->PostTask(
FROM_HERE,
base::Bind(&URLFetcherCore::InformDelegateFetchIsComplete, core_));
@@ -412,7 +420,7 @@ base::TimeDelta URLFetcherCore::GetBackoffDelay() const {
void URLFetcherCore::SaveResponseToFileAtPath(
const FilePath& file_path,
- scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) {
+ scoped_refptr<base::TaskRunner> file_task_runner) {
DCHECK(delegate_task_runner_->BelongsToCurrentThread());
file_task_runner_ = file_task_runner;
response_destination_ = URLFetcherCore::PERMANENT_FILE;
@@ -420,7 +428,7 @@ void URLFetcherCore::SaveResponseToFileAtPath(
}
void URLFetcherCore::SaveResponseToTemporaryFile(
- scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) {
+ scoped_refptr<base::TaskRunner> file_task_runner) {
DCHECK(delegate_task_runner_->BelongsToCurrentThread());
file_task_runner_ = file_task_runner;
response_destination_ = URLFetcherCore::TEMP_FILE;
« no previous file with comments | « net/url_request/url_fetcher_core.h ('k') | net/url_request/url_fetcher_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698