summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-17 20:44:47 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-17 20:44:47 +0000
commitd6c1822152de516a1af54b388a40f95b2f6e0d23 (patch)
tree5ee72632e23bb98d9958d1d7b1589dab002c3749
parent85fdd735c44d3b16b831bd38ed70a6da18f7e986 (diff)
downloadchromium_src-d6c1822152de516a1af54b388a40f95b2f6e0d23.zip
chromium_src-d6c1822152de516a1af54b388a40f95b2f6e0d23.tar.gz
chromium_src-d6c1822152de516a1af54b388a40f95b2f6e0d23.tar.bz2
base::Bind: Convert FileUtilProxy::ReadCallback.
BUG=none TEST=none R=csilv@chromium.org Review URL: http://codereview.chromium.org/8294015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105905 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/file_util_proxy.cc17
-rw-r--r--base/file_util_proxy.h42
-rw-r--r--webkit/plugins/ppapi/ppb_file_io_impl.cc7
3 files changed, 31 insertions, 35 deletions
diff --git a/base/file_util_proxy.cc b/base/file_util_proxy.cc
index 771a5be..b1652c4 100644
--- a/base/file_util_proxy.cc
+++ b/base/file_util_proxy.cc
@@ -527,7 +527,7 @@ class RelayRead : public MessageLoopRelay {
RelayRead(base::PlatformFile file,
int64 offset,
int bytes_to_read,
- base::FileUtilProxy::ReadCallback* callback)
+ const base::FileUtilProxy::ReadCallback& callback)
: file_(file),
offset_(offset),
buffer_(new char[bytes_to_read]),
@@ -545,10 +545,8 @@ class RelayRead : public MessageLoopRelay {
}
virtual void RunCallback() {
- if (callback_) {
- callback_->Run(error_code(), buffer_.get(), bytes_read_);
- delete callback_;
- }
+ if (!callback_.is_null())
+ callback_.Run(error_code(), buffer_.get(), bytes_read_);
}
private:
@@ -556,7 +554,7 @@ class RelayRead : public MessageLoopRelay {
int64 offset_;
scoped_array<char> buffer_;
int bytes_to_read_;
- base::FileUtilProxy::ReadCallback* callback_;
+ base::FileUtilProxy::ReadCallback callback_;
int bytes_read_;
};
@@ -849,11 +847,10 @@ bool FileUtilProxy::Read(
PlatformFile file,
int64 offset,
int bytes_to_read,
- ReadCallback* callback) {
- if (bytes_to_read < 0) {
- delete callback;
+ const ReadCallback& callback) {
+ if (bytes_to_read < 0)
return false;
- }
+
return Start(FROM_HERE, message_loop_proxy,
new RelayRead(file, offset, bytes_to_read, callback));
}
diff --git a/base/file_util_proxy.h b/base/file_util_proxy.h
index 306d2e4..d86f797 100644
--- a/base/file_util_proxy.h
+++ b/base/file_util_proxy.h
@@ -52,26 +52,25 @@ class BASE_EXPORT FileUtilProxy {
GetFileInfoCallback;
typedef base::Callback<void(PlatformFileError /* error code */,
const std::vector<Entry>&)> ReadDirectoryCallback;
- typedef Callback3<PlatformFileError /* error code */,
- const char* /* data */,
- int /* bytes read/written */>::Type ReadCallback;
+ typedef base::Callback<void(PlatformFileError /* error code */,
+ const char* /* data */,
+ int /* bytes read/written */)> ReadCallback;
typedef Callback2<PlatformFileError /* error code */,
int /* bytes written */>::Type WriteCallback;
- // Creates or opens a file with the given flags. It is invalid to pass NULL
- // for the callback.
- // If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to create
- // a new file at the given |file_path| and calls back with
- // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists.
- // Takes ownership of |callback| and will delete it even on failure.
+ // Creates or opens a file with the given flags. It is invalid to pass a null
+ // callback. If PLATFORM_FILE_CREATE is set in |file_flags| it always tries to
+ // create a new file at the given |file_path| and calls back with
+ // PLATFORM_FILE_ERROR_FILE_EXISTS if the |file_path| already exists. Takes
+ // ownership of |callback| and will delete it even on failure.
static bool CreateOrOpen(scoped_refptr<MessageLoopProxy> message_loop_proxy,
const FilePath& file_path,
int file_flags,
const CreateOrOpenCallback& callback);
- // Creates a temporary file for writing. The path and an open file handle
- // are returned. It is invalid to pass NULL for the callback. The additional
- // file flags will be added on top of the default file flags which are:
+ // Creates a temporary file for writing. The path and an open file handle are
+ // returned. It is invalid to pass a null callback. The additional file flags
+ // will be added on top of the default file flags which are:
// base::PLATFORM_FILE_CREATE_ALWAYS
// base::PLATFORM_FILE_WRITE
// base::PLATFORM_FILE_TEMPORARY.
@@ -89,19 +88,18 @@ class BASE_EXPORT FileUtilProxy {
// Ensures that the given |file_path| exist. This creates a empty new file
// at |file_path| if the |file_path| does not exist.
- // If a new file han not existed and is created at the |file_path|,
- // |created| of the callback argument is set true and |error code|
- // is set PLATFORM_FILE_OK.
- // If the file already exists, |created| is set false and |error code|
- // is set PLATFORM_FILE_OK.
- // If the file hasn't existed but it couldn't be created for some other
- // reasons, |created| is set false and |error code| indicates the error.
+ // If a new file does not exist and is created at the |file_path|, |created|
+ // of the callback argument is set true and |error code| is set
+ // PLATFORM_FILE_OK. If the file already exists, |created| is set false and
+ // |error code| is set PLATFORM_FILE_OK. If the file hasn't existed but it
+ // couldn't be created for some other reasons, |created| is set false and
+ // |error code| indicates the error.
static bool EnsureFileExists(
scoped_refptr<MessageLoopProxy> message_loop_proxy,
const FilePath& file_path,
const EnsureFileExistsCallback& callback);
- // Retrieves the information about a file. It is invalid to pass NULL for the
+ // Retrieves the information about a file. It is invalid to pass a null
// callback.
static bool GetFileInfo(
scoped_refptr<MessageLoopProxy> message_loop_proxy,
@@ -161,13 +159,13 @@ class BASE_EXPORT FileUtilProxy {
StatusCallback* callback);
// Reads from a file. On success, the file pointer is moved to position
- // |offset + bytes_to_read| in the file. The callback can be NULL.
+ // |offset + bytes_to_read| in the file. The callback can be null.
static bool Read(
scoped_refptr<MessageLoopProxy> message_loop_proxy,
PlatformFile file,
int64 offset,
int bytes_to_read,
- ReadCallback* callback);
+ const ReadCallback& callback);
// Writes to a file. If |offset| is greater than the length of the file,
// |false| is returned. On success, the file pointer is moved to position
diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.cc b/webkit/plugins/ppapi/ppb_file_io_impl.cc
index 7cd8263..26f0154 100644
--- a/webkit/plugins/ppapi/ppb_file_io_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_io_impl.cc
@@ -176,9 +176,10 @@ int32_t PPB_FileIO_Impl::Read(int64_t offset,
return PP_ERROR_FAILED;
if (!base::FileUtilProxy::Read(
- plugin_delegate->GetFileThreadMessageLoopProxy(),
- file_, offset, bytes_to_read,
- callback_factory_.NewCallback(&PPB_FileIO_Impl::ReadCallback)))
+ plugin_delegate->GetFileThreadMessageLoopProxy(), file_, offset,
+ bytes_to_read,
+ base::Bind(&PPB_FileIO_Impl::ReadCallback,
+ weak_factory_.GetWeakPtr())))
return PP_ERROR_FAILED;
RegisterCallback(OPERATION_READ, callback, buffer);