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

Unified Diff: base/file_util_proxy.cc

Issue 8423041: Revert 108258 - broke Mac LayoutTests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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 | « base/file_util_proxy.h ('k') | webkit/fileapi/file_system_file_util_proxy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_proxy.cc
===================================================================
--- base/file_util_proxy.cc (revision 108273)
+++ base/file_util_proxy.cc (working copy)
@@ -26,7 +26,7 @@
// message_loop_proxy->PostTaskAndReply(
// from_here,
// ReturnAsParam<R>(Bind(&DoWorkAndReturn), result),
-// RelayHelper(Bind(&Callback), Owned(result)));
+// CallbackWithReturn(Bind(&Callback), Owned(result)));
//
// Or just use PostTaskAndReplyWithStatus helper template (see the code below).
template <typename R1, typename R2>
@@ -60,18 +60,6 @@
return Bind(&ReturnAsParamAdapter<R1, R2>, func, result);
}
-template <typename R, typename A1>
-void ReturnAsParamAdapter1(const Callback<R(A1)>& func, A1 a1, R* result) {
- if (!func.is_null())
- *result = func.Run(a1);
-}
-
-template <typename R, typename A1>
-Closure ReturnAsParam(const Callback<R(A1)>& func, A1 a1, R* result) {
- DCHECK(result);
- return Bind(&ReturnAsParamAdapter1<R, A1>, func, a1, result);
-}
-
template <typename R>
void ReplyAdapter(const Callback<void(R)>& callback, R* result) {
DCHECK(result);
@@ -101,23 +89,28 @@
// Helper classes or routines for individual methods.
class CreateOrOpenHelper {
public:
- CreateOrOpenHelper(MessageLoopProxy* message_loop_proxy,
- const FileUtilProxy::CloseTask& close_task)
+ CreateOrOpenHelper(MessageLoopProxy* message_loop_proxy)
: message_loop_proxy_(message_loop_proxy),
- close_task_(close_task),
file_handle_(kInvalidPlatformFileValue),
created_(false),
error_(PLATFORM_FILE_OK) {}
~CreateOrOpenHelper() {
if (file_handle_ != kInvalidPlatformFileValue) {
- message_loop_proxy_->PostTask(
- FROM_HERE, base::Bind(close_task_, file_handle_));
+ FileUtilProxy::Close(message_loop_proxy_, file_handle_,
+ FileUtilProxy::StatusCallback());
}
}
- void RunWork(const FileUtilProxy::CreateOrOpenTask& task) {
- error_ = task.Run(&file_handle_, &created_);
+ void RunWork(const FilePath& file_path, int file_flags) {
+ if (!file_util::DirectoryExists(file_path.DirName())) {
+ // If its parent does not exist, should return NOT_FOUND error.
+ error_ = PLATFORM_FILE_ERROR_NOT_FOUND;
+ return;
+ }
+ error_ = PLATFORM_FILE_OK;
+ file_handle_ = CreatePlatformFile(file_path, file_flags,
+ &created_, &error_);
}
void Reply(const FileUtilProxy::CreateOrOpenCallback& callback) {
@@ -127,7 +120,6 @@
private:
scoped_refptr<MessageLoopProxy> message_loop_proxy_;
- FileUtilProxy::CloseTask close_task_;
PlatformFile file_handle_;
bool created_;
PlatformFileError error_;
@@ -275,28 +267,6 @@
DISALLOW_COPY_AND_ASSIGN(WriteHelper);
};
-
-PlatformFileError CreateOrOpenAdapter(
- const FilePath& file_path, int file_flags,
- PlatformFile* file_handle, bool* created) {
- DCHECK(file_handle);
- DCHECK(created);
- if (!file_util::DirectoryExists(file_path.DirName())) {
- // If its parent does not exist, should return NOT_FOUND error.
- return PLATFORM_FILE_ERROR_NOT_FOUND;
- }
- PlatformFileError error = PLATFORM_FILE_OK;
- *file_handle = CreatePlatformFile(file_path, file_flags, created, &error);
- return error;
-}
-
-PlatformFileError CloseAdapter(PlatformFile file_handle) {
- if (!ClosePlatformFile(file_handle)) {
- return PLATFORM_FILE_ERROR_FAILED;
- }
- return PLATFORM_FILE_OK;
-}
-
} // namespace
// static
@@ -304,11 +274,12 @@
scoped_refptr<MessageLoopProxy> message_loop_proxy,
const FilePath& file_path, int file_flags,
const CreateOrOpenCallback& callback) {
- return RelayCreateOrOpen(
- message_loop_proxy,
- base::Bind(&CreateOrOpenAdapter, file_path, file_flags),
- base::Bind(&CloseAdapter),
- callback);
+ CreateOrOpenHelper* helper = new CreateOrOpenHelper(message_loop_proxy);
+ return message_loop_proxy->PostTaskAndReply(
+ FROM_HERE,
+ Bind(&CreateOrOpenHelper::RunWork, Unretained(helper),
+ file_path, file_flags),
+ Bind(&CreateOrOpenHelper::Reply, Owned(helper), callback));
}
// static
@@ -325,14 +296,13 @@
}
// static
-bool FileUtilProxy::Close(
- scoped_refptr<MessageLoopProxy> message_loop_proxy,
- base::PlatformFile file_handle,
- const StatusCallback& callback) {
- return RelayClose(
- message_loop_proxy,
- base::Bind(&CloseAdapter),
- file_handle, callback);
+bool FileUtilProxy::Close(scoped_refptr<MessageLoopProxy> message_loop_proxy,
+ PlatformFile file_handle,
+ const StatusCallback& callback) {
+ return PostTaskAndReplyWithStatus<bool>(
+ message_loop_proxy, FROM_HERE,
+ Bind(&ClosePlatformFile, file_handle), callback,
+ new PlatformFileError);
}
// Retrieves the information about a file. It is invalid to pass NULL for the
@@ -471,31 +441,4 @@
new PlatformFileError);
}
-// static
-bool FileUtilProxy::RelayCreateOrOpen(
- scoped_refptr<MessageLoopProxy> message_loop_proxy,
- const CreateOrOpenTask& open_task,
- const CloseTask& close_task,
- const CreateOrOpenCallback& callback) {
- CreateOrOpenHelper* helper = new CreateOrOpenHelper(
- message_loop_proxy, close_task);
- return message_loop_proxy->PostTaskAndReply(
- FROM_HERE,
- Bind(&CreateOrOpenHelper::RunWork, Unretained(helper), open_task),
- Bind(&CreateOrOpenHelper::Reply, Owned(helper), callback));
-}
-
-// static
-bool FileUtilProxy::RelayClose(
- scoped_refptr<MessageLoopProxy> message_loop_proxy,
- const CloseTask& close_task,
- PlatformFile file_handle,
- const StatusCallback& callback) {
- PlatformFileError* result = new PlatformFileError;
- return message_loop_proxy->PostTaskAndReply(
- FROM_HERE,
- ReturnAsParam(close_task, file_handle, result),
- ReplyHelper(callback, Owned(result)));
-}
-
} // namespace base
« no previous file with comments | « base/file_util_proxy.h ('k') | webkit/fileapi/file_system_file_util_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698