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

Unified Diff: content/common/net/url_fetcher.cc

Issue 8231004: Remaining cleanup (base::Bind): Replacing FileUtilProxy calls with new callback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: got it building Created 9 years, 2 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
Index: content/common/net/url_fetcher.cc
diff --git a/content/common/net/url_fetcher.cc b/content/common/net/url_fetcher.cc
index 677eafea55a83b79924fa38f23ba42be13576b97..9bb73c24c11c6b1fa95f56f35f8cfd42feb83cc8 100644
--- a/content/common/net/url_fetcher.cc
+++ b/content/common/net/url_fetcher.cc
@@ -6,12 +6,14 @@
#include <set>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "base/file_path.h"
#include "base/file_util_proxy.h"
#include "base/lazy_instance.h"
-#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/message_loop_proxy.h"
#include "base/platform_file.h"
#include "base/stl_util.h"
@@ -32,6 +34,9 @@
static const int kBufferSize = 4096;
const int URLFetcher::kInvalidHttpResponseCode = -1;
+using base::FileUtilProxy;
+using base::PlatformFileError;
+
class URLFetcher::Core
: public base::RefCountedThreadSafe<URLFetcher::Core>,
public net::URLRequest::Delegate {
@@ -146,9 +151,9 @@ class URLFetcher::Core
// if no error occurred.
base::PlatformFileError error_code_;
- // Callbacks are created for use with base::FileUtilProxy.
- base::ScopedCallbackFactory<URLFetcher::Core::TempFileWriter>
- callback_factory_;
+ // For file_util calls on the FileThread.
+ base::WeakPtrFactory<URLFetcher::Core::TempFileWriter>
+ weak_factory_;
// Message loop on which file opperations should happen.
scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy_;
@@ -160,6 +165,9 @@ class URLFetcher::Core
// Handle to the temp file.
base::PlatformFile temp_file_handle_;
+ // Bytes written by the last ContinueWrite.
+ int bytes_written_;
+
// We always append to the file. Track the total number of bytes
// written, so that writes know the offset to give.
int64 total_bytes_written_;
@@ -319,7 +327,7 @@ URLFetcher::Core::TempFileWriter::TempFileWriter(
scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy)
: core_(core),
error_code_(base::PLATFORM_FILE_OK),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
file_message_loop_proxy_(file_message_loop_proxy),
temp_file_handle_(base::kInvalidPlatformFileValue) {
}
@@ -331,11 +339,11 @@ URLFetcher::Core::TempFileWriter::~TempFileWriter() {
void URLFetcher::Core::TempFileWriter::CreateTempFile() {
DCHECK(core_->io_message_loop_proxy_->BelongsToCurrentThread());
CHECK(file_message_loop_proxy_.get());
- base::FileUtilProxy::CreateTemporary(
+ FileUtilProxy::CreateTemporary(
file_message_loop_proxy_,
0, // No additional file flags.
- callback_factory_.NewCallback(
- &URLFetcher::Core::TempFileWriter::DidCreateTempFile));
+ base::Bind(&URLFetcher::Core::TempFileWriter::DidCreateTempFile,
+ weak_factory_.GetWeakPtr()));
}
void URLFetcher::Core::TempFileWriter::DidCreateTempFile(
@@ -349,7 +357,7 @@ void URLFetcher::Core::TempFileWriter::DidCreateTempFile(
RemoveTempFile();
core_->delegate_loop_proxy_->PostTask(
FROM_HERE,
- NewRunnableMethod(core_, &Core::InformDelegateFetchIsComplete));
+ base::Bind(&Core::InformDelegateFetchIsComplete, core_));
return;
}
@@ -359,7 +367,7 @@ void URLFetcher::Core::TempFileWriter::DidCreateTempFile(
core_->io_message_loop_proxy_->PostTask(
FROM_HERE,
- NewRunnableMethod(core_, &Core::StartURLRequestWhenAppropriate));
+ base::Bind(&Core::StartURLRequestWhenAppropriate, core_));
}
void URLFetcher::Core::TempFileWriter::WriteBuffer(int num_bytes) {
@@ -383,7 +391,7 @@ void URLFetcher::Core::TempFileWriter::ContinueWrite(
RemoveTempFile();
core_->delegate_loop_proxy_->PostTask(
FROM_HERE,
- NewRunnableMethod(core_, &Core::InformDelegateFetchIsComplete));
+ base::Bind(&Core::InformDelegateFetchIsComplete, core_));
return;
}
@@ -392,14 +400,14 @@ void URLFetcher::Core::TempFileWriter::ContinueWrite(
pending_bytes_ -= bytes_written;
if (pending_bytes_ > 0) {
- base::FileUtilProxy::Write(
+ FileUtilProxy::Write(
file_message_loop_proxy_,
temp_file_handle_,
total_bytes_written_, // Append to the end
(core_->buffer_->data() + buffer_offset_),
pending_bytes_,
- callback_factory_.NewCallback(
- &URLFetcher::Core::TempFileWriter::ContinueWrite));
+ base::Bind(&URLFetcher::Core::TempFileWriter::ContinueWrite,
+ weak_factory_.GetWeakPtr()));
} else {
// Finished writing core_->buffer_ to the file. Read some more.
core_->ReadResponse();
@@ -421,11 +429,12 @@ void URLFetcher::Core::TempFileWriter::CloseTempFileAndCompleteRequest() {
DCHECK(core_->io_message_loop_proxy_->BelongsToCurrentThread());
if (temp_file_handle_ != base::kInvalidPlatformFileValue) {
- base::FileUtilProxy::Close(
+ FileUtilProxy::PostFileTaskAndReplyStatus<bool, PlatformFileError>(
file_message_loop_proxy_,
- temp_file_handle_,
- callback_factory_.NewCallback(
- &URLFetcher::Core::TempFileWriter::DidCloseTempFile));
+ FROM_HERE,
+ base::Bind(&base::ClosePlatformFile, temp_file_handle_),
+ base::Bind(&URLFetcher::Core::TempFileWriter::DidCloseTempFile,
+ weak_factory_.GetWeakPtr()));
temp_file_handle_ = base::kInvalidPlatformFileValue;
}
}
@@ -439,7 +448,7 @@ void URLFetcher::Core::TempFileWriter::DidCloseTempFile(
RemoveTempFile();
core_->delegate_loop_proxy_->PostTask(
FROM_HERE,
- NewRunnableMethod(core_, &Core::InformDelegateFetchIsComplete));
+ base::Bind(&Core::InformDelegateFetchIsComplete, core_));
return;
}
@@ -452,19 +461,19 @@ void URLFetcher::Core::TempFileWriter::RemoveTempFile() {
// Close the temp file if it is open.
if (temp_file_handle_ != base::kInvalidPlatformFileValue) {
- base::FileUtilProxy::Close(
- file_message_loop_proxy_,
- temp_file_handle_,
- NULL); // No callback: Ignore errors.
+ file_message_loop_proxy_->PostTask(
+ FROM_HERE,
+ base::IgnoreReturn(base::Callback<bool(void)>(
+ base::Bind(&base::ClosePlatformFile, temp_file_handle_))));
temp_file_handle_ = base::kInvalidPlatformFileValue;
}
if (!temp_file_.empty()) {
- base::FileUtilProxy::Delete(
- file_message_loop_proxy_,
- temp_file_,
- false, // No need to recurse, as the path is to a file.
- NULL); // No callback: Ignore errors.
+ file_message_loop_proxy_->PostTask(
+ FROM_HERE,
+ base::IgnoreReturn(base::Callback<bool(void)>(
+ base::Bind(&file_util::Delete, temp_file_,
+ false /* recursive */))));
DisownTempFile();
}
}
@@ -566,7 +575,7 @@ void URLFetcher::Core::Start() {
io_message_loop_proxy_->PostTask(
FROM_HERE,
- NewRunnableMethod(this, &Core::StartOnIOThread));
+ base::Bind(&Core::StartOnIOThread, this));
}
void URLFetcher::Core::StartOnIOThread() {

Powered by Google App Engine
This is Rietveld 408576698