1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "webkit/fileapi/file_system_file_util_proxy.h"
8 #include "base/message_loop_proxy.h"
15 using base::PlatformFileError
;
16 using base::Unretained
;
18 typedef fileapi::FileSystemFileUtilProxy Proxy
;
20 class EnsureFileExistsHelper
{
22 EnsureFileExistsHelper() : error_(base::PLATFORM_FILE_OK
), created_(false) {}
24 void RunWork(const Proxy::EnsureFileExistsTask
& task
) {
25 error_
= task
.Run(&created_
);
28 void Reply(const Proxy::EnsureFileExistsCallback
& callback
) {
29 if (!callback
.is_null()) {
30 callback
.Run(error_
, created_
);
35 base::PlatformFileError error_
;
37 DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper
);
40 class GetFileInfoHelper
{
42 GetFileInfoHelper() : error_(base::PLATFORM_FILE_OK
) {}
44 void RunWork(const Proxy::GetFileInfoTask
& task
) {
45 error_
= task
.Run(&file_info_
, &platform_path_
);
48 void Reply(const Proxy::GetFileInfoCallback
& callback
) {
49 if (!callback
.is_null()) {
50 callback
.Run(error_
, file_info_
, platform_path_
);
55 base::PlatformFileError error_
;
56 base::PlatformFileInfo file_info_
;
57 FilePath platform_path_
;
58 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper
);
61 class ReadDirectoryHelper
{
63 ReadDirectoryHelper() : error_(base::PLATFORM_FILE_OK
) {}
65 void RunWork(const Proxy::ReadDirectoryTask
& task
) {
66 error_
= task
.Run(&entries_
);
69 void Reply(const Proxy::ReadDirectoryCallback
& callback
) {
70 if (!callback
.is_null()) {
71 callback
.Run(error_
, entries_
);
76 base::PlatformFileError error_
;
77 std::vector
<Proxy::Entry
> entries_
;
78 DISALLOW_COPY_AND_ASSIGN(ReadDirectoryHelper
);
86 bool FileSystemFileUtilProxy::RelayEnsureFileExists(
87 scoped_refptr
<MessageLoopProxy
> message_loop_proxy
,
88 const EnsureFileExistsTask
& task
,
89 const EnsureFileExistsCallback
& callback
) {
90 EnsureFileExistsHelper
* helper
= new EnsureFileExistsHelper
;
91 return message_loop_proxy
->PostTaskAndReply(
93 Bind(&EnsureFileExistsHelper::RunWork
, Unretained(helper
), task
),
94 Bind(&EnsureFileExistsHelper::Reply
, Owned(helper
), callback
));
98 bool FileSystemFileUtilProxy::RelayGetFileInfo(
99 scoped_refptr
<MessageLoopProxy
> message_loop_proxy
,
100 const GetFileInfoTask
& task
,
101 const GetFileInfoCallback
& callback
) {
102 GetFileInfoHelper
* helper
= new GetFileInfoHelper
;
103 return message_loop_proxy
->PostTaskAndReply(
105 Bind(&GetFileInfoHelper::RunWork
, Unretained(helper
), task
),
106 Bind(&GetFileInfoHelper::Reply
, Owned(helper
), callback
));
110 bool FileSystemFileUtilProxy::RelayReadDirectory(
111 scoped_refptr
<MessageLoopProxy
> message_loop_proxy
,
112 const ReadDirectoryTask
& task
,
113 const ReadDirectoryCallback
& callback
) {
114 ReadDirectoryHelper
* helper
= new ReadDirectoryHelper
;
115 return message_loop_proxy
->PostTaskAndReply(
117 Bind(&ReadDirectoryHelper::RunWork
, Unretained(helper
), task
),
118 Bind(&ReadDirectoryHelper::Reply
, Owned(helper
), callback
));
121 } // namespace fileapi