base::Bind: Convert FileUtilProxy::GetFileInfoCallback.
BUG=none TEST=none R=csilv@chromium.org Review URL: http://codereview.chromium.org/8315012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105888 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -469,10 +469,10 @@ class RelayReadDirectory : public MessageLoopRelay {
|
||||
class RelayGetFileInfo : public MessageLoopRelay {
|
||||
public:
|
||||
RelayGetFileInfo(const FilePath& file_path,
|
||||
base::FileUtilProxy::GetFileInfoCallback* callback)
|
||||
const base::FileUtilProxy::GetFileInfoCallback& callback)
|
||||
: callback_(callback),
|
||||
file_path_(file_path) {
|
||||
DCHECK(callback);
|
||||
DCHECK_EQ(false, callback.is_null());
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -486,12 +486,11 @@ class RelayGetFileInfo : public MessageLoopRelay {
|
||||
}
|
||||
|
||||
virtual void RunCallback() {
|
||||
callback_->Run(error_code(), file_info_);
|
||||
delete callback_;
|
||||
callback_.Run(error_code(), file_info_);
|
||||
}
|
||||
|
||||
private:
|
||||
base::FileUtilProxy::GetFileInfoCallback* callback_;
|
||||
base::FileUtilProxy::GetFileInfoCallback callback_;
|
||||
FilePath file_path_;
|
||||
base::PlatformFileInfo file_info_;
|
||||
};
|
||||
@ -500,10 +499,10 @@ class RelayGetFileInfoFromPlatformFile : public MessageLoopRelay {
|
||||
public:
|
||||
RelayGetFileInfoFromPlatformFile(
|
||||
base::PlatformFile file,
|
||||
base::FileUtilProxy::GetFileInfoCallback* callback)
|
||||
const base::FileUtilProxy::GetFileInfoCallback& callback)
|
||||
: callback_(callback),
|
||||
file_(file) {
|
||||
DCHECK(callback);
|
||||
DCHECK_EQ(false, callback.is_null());
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -513,12 +512,11 @@ class RelayGetFileInfoFromPlatformFile : public MessageLoopRelay {
|
||||
}
|
||||
|
||||
virtual void RunCallback() {
|
||||
callback_->Run(error_code(), file_info_);
|
||||
delete callback_;
|
||||
callback_.Run(error_code(), file_info_);
|
||||
}
|
||||
|
||||
private:
|
||||
base::FileUtilProxy::GetFileInfoCallback* callback_;
|
||||
base::FileUtilProxy::GetFileInfoCallback callback_;
|
||||
base::PlatformFile file_;
|
||||
base::PlatformFileInfo file_info_;
|
||||
};
|
||||
@ -774,7 +772,7 @@ bool FileUtilProxy::EnsureFileExists(
|
||||
bool FileUtilProxy::GetFileInfo(
|
||||
scoped_refptr<MessageLoopProxy> message_loop_proxy,
|
||||
const FilePath& file_path,
|
||||
GetFileInfoCallback* callback) {
|
||||
const GetFileInfoCallback& callback) {
|
||||
return Start(FROM_HERE, message_loop_proxy, new RelayGetFileInfo(
|
||||
file_path, callback));
|
||||
}
|
||||
@ -783,7 +781,7 @@ bool FileUtilProxy::GetFileInfo(
|
||||
bool FileUtilProxy::GetFileInfoFromPlatformFile(
|
||||
scoped_refptr<MessageLoopProxy> message_loop_proxy,
|
||||
PlatformFile file,
|
||||
GetFileInfoCallback* callback) {
|
||||
const GetFileInfoCallback& callback) {
|
||||
return Start(FROM_HERE, message_loop_proxy,
|
||||
new RelayGetFileInfoFromPlatformFile(file, callback));
|
||||
}
|
||||
|
@ -47,9 +47,9 @@ class BASE_EXPORT FileUtilProxy {
|
||||
FilePath)> CreateTemporaryCallback;
|
||||
typedef base::Callback<void(PlatformFileError /* error code */,
|
||||
bool /* created */)> EnsureFileExistsCallback;
|
||||
typedef Callback2<PlatformFileError /* error code */,
|
||||
const PlatformFileInfo& /* file_info */
|
||||
>::Type GetFileInfoCallback;
|
||||
typedef base::Callback<void(PlatformFileError /* error code */,
|
||||
const PlatformFileInfo& /* file_info */)>
|
||||
GetFileInfoCallback;
|
||||
typedef Callback2<PlatformFileError /* error code */,
|
||||
const std::vector<Entry>&>::Type ReadDirectoryCallback;
|
||||
typedef Callback3<PlatformFileError /* error code */,
|
||||
@ -106,12 +106,12 @@ class BASE_EXPORT FileUtilProxy {
|
||||
static bool GetFileInfo(
|
||||
scoped_refptr<MessageLoopProxy> message_loop_proxy,
|
||||
const FilePath& file_path,
|
||||
GetFileInfoCallback* callback);
|
||||
const GetFileInfoCallback& callback);
|
||||
|
||||
static bool GetFileInfoFromPlatformFile(
|
||||
scoped_refptr<MessageLoopProxy> message_loop_proxy,
|
||||
PlatformFile file,
|
||||
GetFileInfoCallback* callback);
|
||||
const GetFileInfoCallback& callback);
|
||||
|
||||
static bool ReadDirectory(scoped_refptr<MessageLoopProxy> message_loop_proxy,
|
||||
const FilePath& file_path,
|
||||
|
@ -52,7 +52,6 @@ BlobURLRequestJob::BlobURLRequestJob(
|
||||
BlobData* blob_data,
|
||||
base::MessageLoopProxy* file_thread_proxy)
|
||||
: net::URLRequestJob(request),
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
|
||||
blob_data_(blob_data),
|
||||
file_thread_proxy_(file_thread_proxy),
|
||||
@ -111,16 +110,14 @@ void BlobURLRequestJob::Kill() {
|
||||
CloseStream();
|
||||
|
||||
net::URLRequestJob::Kill();
|
||||
callback_factory_.RevokeAll();
|
||||
weak_factory_.InvalidateWeakPtrs();
|
||||
method_factory_.RevokeAll();
|
||||
}
|
||||
|
||||
void BlobURLRequestJob::ResolveFile(const FilePath& file_path) {
|
||||
base::FileUtilProxy::GetFileInfo(
|
||||
file_thread_proxy_,
|
||||
file_path,
|
||||
callback_factory_.NewCallback(&BlobURLRequestJob::DidResolve));
|
||||
file_thread_proxy_, file_path,
|
||||
base::Bind(&BlobURLRequestJob::DidResolve, weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void BlobURLRequestJob::DidResolve(base::PlatformFileError rv,
|
||||
|
@ -6,7 +6,6 @@
|
||||
#define WEBKIT_BLOB_BLOB_URL_REQUEST_JOB_H_
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_callback_factory.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/platform_file.h"
|
||||
@ -69,7 +68,6 @@ class BlobURLRequestJob : public net::URLRequestJob {
|
||||
bool created);
|
||||
void DidRead(int result);
|
||||
|
||||
base::ScopedCallbackFactory<BlobURLRequestJob> callback_factory_;
|
||||
base::WeakPtrFactory<BlobURLRequestJob> weak_factory_;
|
||||
scoped_refptr<BlobData> blob_data_;
|
||||
scoped_refptr<base::MessageLoopProxy> file_thread_proxy_;
|
||||
|
@ -224,11 +224,11 @@ class RelayGetFileInfo : public MessageLoopRelay {
|
||||
RelayGetFileInfo(
|
||||
const fileapi::FileSystemOperationContext& context,
|
||||
const FilePath& file_path,
|
||||
fileapi::FileSystemFileUtilProxy::GetFileInfoCallback* callback)
|
||||
const fileapi::FileSystemFileUtilProxy::GetFileInfoCallback& callback)
|
||||
: MessageLoopRelay(context),
|
||||
callback_(callback),
|
||||
file_path_(file_path) {
|
||||
DCHECK(callback);
|
||||
DCHECK_EQ(false, callback.is_null());
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -238,12 +238,11 @@ class RelayGetFileInfo : public MessageLoopRelay {
|
||||
}
|
||||
|
||||
virtual void RunCallback() {
|
||||
callback_->Run(error_code(), file_info_, platform_path_);
|
||||
delete callback_;
|
||||
callback_.Run(error_code(), file_info_, platform_path_);
|
||||
}
|
||||
|
||||
private:
|
||||
fileapi::FileSystemFileUtilProxy::GetFileInfoCallback* callback_;
|
||||
fileapi::FileSystemFileUtilProxy::GetFileInfoCallback callback_;
|
||||
FilePath file_path_;
|
||||
base::PlatformFileInfo file_info_;
|
||||
FilePath platform_path_;
|
||||
@ -470,7 +469,7 @@ bool FileSystemFileUtilProxy::GetFileInfo(
|
||||
const FileSystemOperationContext& context,
|
||||
scoped_refptr<MessageLoopProxy> message_loop_proxy,
|
||||
const FilePath& file_path,
|
||||
GetFileInfoCallback* callback) {
|
||||
const GetFileInfoCallback& callback) {
|
||||
return Start(FROM_HERE, message_loop_proxy, new RelayGetFileInfo(context,
|
||||
file_path, callback));
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/callback_old.h"
|
||||
#include "base/file_path.h"
|
||||
#include "base/file_util_proxy.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
@ -36,10 +37,11 @@ class FileSystemFileUtilProxy {
|
||||
typedef base::FileUtilProxy::CreateOrOpenCallback CreateOrOpenCallback;
|
||||
typedef base::FileUtilProxy::EnsureFileExistsCallback
|
||||
EnsureFileExistsCallback;
|
||||
typedef Callback3<PlatformFileError /* error code */,
|
||||
const PlatformFileInfo& /* file_info */,
|
||||
const FilePath& /* platform_path, where possible */
|
||||
>::Type GetFileInfoCallback;
|
||||
typedef base::Callback<
|
||||
void(PlatformFileError /* error code */,
|
||||
const PlatformFileInfo& /* file_info */,
|
||||
const FilePath& /* platform_path, where possible */)>
|
||||
GetFileInfoCallback;
|
||||
typedef Callback2<PlatformFileError /* error code */,
|
||||
const FilePath& /* local_path, where possible */
|
||||
>::Type GetLocalPathCallback;
|
||||
@ -90,7 +92,7 @@ class FileSystemFileUtilProxy {
|
||||
const FileSystemOperationContext& context,
|
||||
scoped_refptr<MessageLoopProxy> message_loop_proxy,
|
||||
const FilePath& file_path,
|
||||
GetFileInfoCallback* callback);
|
||||
const GetFileInfoCallback& callback);
|
||||
|
||||
static bool ReadDirectory(const FileSystemOperationContext& context,
|
||||
scoped_refptr<MessageLoopProxy> message_loop_proxy,
|
||||
|
@ -310,9 +310,9 @@ void FileSystemOperation::DirectoryExists(const GURL& path) {
|
||||
if (!file_system_operation_context_.src_file_util())
|
||||
file_system_operation_context_.set_src_file_util(file_util);
|
||||
FileSystemFileUtilProxy::GetFileInfo(
|
||||
file_system_operation_context_,
|
||||
proxy_, virtual_path, callback_factory_.NewCallback(
|
||||
&FileSystemOperation::DidDirectoryExists));
|
||||
file_system_operation_context_, proxy_, virtual_path,
|
||||
base::Bind(&FileSystemOperation::DidDirectoryExists,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void FileSystemOperation::FileExists(const GURL& path) {
|
||||
@ -335,9 +335,9 @@ void FileSystemOperation::FileExists(const GURL& path) {
|
||||
if (!file_system_operation_context_.src_file_util())
|
||||
file_system_operation_context_.set_src_file_util(file_util);
|
||||
FileSystemFileUtilProxy::GetFileInfo(
|
||||
file_system_operation_context_,
|
||||
proxy_, virtual_path, callback_factory_.NewCallback(
|
||||
&FileSystemOperation::DidFileExists));
|
||||
file_system_operation_context_, proxy_, virtual_path,
|
||||
base::Bind(&FileSystemOperation::DidFileExists,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void FileSystemOperation::GetMetadata(const GURL& path) {
|
||||
@ -360,9 +360,9 @@ void FileSystemOperation::GetMetadata(const GURL& path) {
|
||||
if (!file_system_operation_context_.src_file_util())
|
||||
file_system_operation_context_.set_src_file_util(file_util);
|
||||
FileSystemFileUtilProxy::GetFileInfo(
|
||||
file_system_operation_context_,
|
||||
proxy_, virtual_path, callback_factory_.NewCallback(
|
||||
&FileSystemOperation::DidGetMetadata));
|
||||
file_system_operation_context_, proxy_, virtual_path,
|
||||
base::Bind(&FileSystemOperation::DidGetMetadata,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void FileSystemOperation::ReadDirectory(const GURL& path) {
|
||||
|
@ -52,6 +52,7 @@ PPB_FileIO_Impl::CallbackEntry::~CallbackEntry() {
|
||||
PPB_FileIO_Impl::PPB_FileIO_Impl(PP_Instance instance)
|
||||
: Resource(instance),
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
|
||||
file_(base::kInvalidPlatformFileValue),
|
||||
file_system_type_(PP_FILESYSTEMTYPE_INVALID),
|
||||
pending_op_(OPERATION_NONE),
|
||||
@ -132,7 +133,8 @@ int32_t PPB_FileIO_Impl::Query(PP_FileInfo* info,
|
||||
|
||||
if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
|
||||
plugin_delegate->GetFileThreadMessageLoopProxy(), file_,
|
||||
callback_factory_.NewCallback(&PPB_FileIO_Impl::QueryInfoCallback)))
|
||||
base::Bind(&PPB_FileIO_Impl::QueryInfoCallback,
|
||||
weak_factory_.GetWeakPtr())))
|
||||
return PP_ERROR_FAILED;
|
||||
|
||||
RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL);
|
||||
|
@ -126,6 +126,7 @@ class PPB_FileIO_Impl : public ::ppapi::Resource,
|
||||
void WillWriteCallback(base::PlatformFileError error_code, int bytes_written);
|
||||
|
||||
base::ScopedCallbackFactory<PPB_FileIO_Impl> callback_factory_;
|
||||
base::WeakPtrFactory<PPB_FileIO_Impl> weak_factory_;
|
||||
|
||||
base::PlatformFile file_;
|
||||
PP_FileSystemType file_system_type_;
|
||||
|
@ -7,8 +7,9 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/memory/scoped_callback_factory.h"
|
||||
#include "base/message_loop_proxy.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/task.h"
|
||||
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
|
||||
#include "webkit/plugins/ppapi/resource_helper.h"
|
||||
@ -224,8 +225,7 @@ QuotaFileIO::QuotaFileIO(
|
||||
outstanding_errors_(0),
|
||||
max_written_offset_(0),
|
||||
inflight_operations_(0),
|
||||
callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
||||
weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
|
||||
DCHECK_NE(base::kInvalidPlatformFileValue, file_);
|
||||
DCHECK_NE(quota::kStorageTypeUnknown, storage_type_);
|
||||
}
|
||||
@ -294,8 +294,8 @@ bool QuotaFileIO::RegisterOperationForQuotaChecks(
|
||||
++outstanding_quota_queries_;
|
||||
if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
|
||||
plugin_delegate->GetFileThreadMessageLoopProxy(), file_,
|
||||
callback_factory_.NewCallback(
|
||||
&QuotaFileIO::DidQueryInfoForQuota))) {
|
||||
base::Bind(&QuotaFileIO::DidQueryInfoForQuota,
|
||||
weak_factory_.GetWeakPtr()))) {
|
||||
// This makes the call fail synchronously; we do not fire the callback
|
||||
// here but just delete the operation and return false.
|
||||
return false;
|
||||
@ -306,7 +306,7 @@ bool QuotaFileIO::RegisterOperationForQuotaChecks(
|
||||
plugin_delegate->QueryAvailableSpace(
|
||||
GURL(file_url_.path()).GetOrigin(), storage_type_,
|
||||
base::Bind(&QuotaFileIO::DidQueryAvailableSpace,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
pending_operations_.push_back(op.release());
|
||||
return true;
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <deque>
|
||||
|
||||
#include "base/file_util_proxy.h"
|
||||
#include "base/memory/scoped_callback_factory.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/platform_file.h"
|
||||
#include "googleurl/src/gurl.h"
|
||||
@ -42,7 +41,7 @@ class QuotaFileIO {
|
||||
// Otherwise it returns false and |callback| will not be dispatched.
|
||||
// |callback| will not be dispatched either when this instance is
|
||||
// destroyed before the operation completes.
|
||||
// SetLength/WillSetLength cannot be called while there're any inflight
|
||||
// SetLength/WillSetLength cannot be called while there're any in-flight
|
||||
// operations. For Write/WillWrite it is guaranteed that |callback| are
|
||||
// always dispatched in the same order as Write being called.
|
||||
bool Write(int64_t offset,
|
||||
@ -96,7 +95,7 @@ class QuotaFileIO {
|
||||
int64_t cached_file_size_;
|
||||
int64_t cached_available_space_;
|
||||
|
||||
// Quota-related queries and errors occured during inflight quota checks.
|
||||
// Quota-related queries and errors occurred during in-flight quota checks.
|
||||
int outstanding_quota_queries_;
|
||||
int outstanding_errors_;
|
||||
|
||||
@ -104,8 +103,8 @@ class QuotaFileIO {
|
||||
int64_t max_written_offset_;
|
||||
int inflight_operations_;
|
||||
|
||||
base::ScopedCallbackFactory<QuotaFileIO> callback_factory_;
|
||||
base::WeakPtrFactory<QuotaFileIO> weak_ptr_factory_;
|
||||
base::WeakPtrFactory<QuotaFileIO> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(QuotaFileIO);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user