1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/fileapi/file_system_file_util_proxy.h"
#include "base/bind.h"
#include "base/message_loop_proxy.h"
namespace {
using base::Bind;
using base::Callback;
using base::Owned;
using base::PlatformFileError;
using base::Unretained;
typedef fileapi::FileSystemFileUtilProxy Proxy;
class EnsureFileExistsHelper {
public:
EnsureFileExistsHelper() : error_(base::PLATFORM_FILE_OK), created_(false) {}
void RunWork(const Proxy::EnsureFileExistsTask& task) {
error_ = task.Run(&created_);
}
void Reply(const Proxy::EnsureFileExistsCallback& callback) {
if (!callback.is_null()) {
callback.Run(error_, created_);
}
}
private:
base::PlatformFileError error_;
bool created_;
DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper);
};
class GetFileInfoHelper {
public:
GetFileInfoHelper() : error_(base::PLATFORM_FILE_OK) {}
void RunWork(const Proxy::GetFileInfoTask& task) {
error_ = task.Run(&file_info_, &platform_path_);
}
void Reply(const Proxy::GetFileInfoCallback& callback) {
if (!callback.is_null()) {
callback.Run(error_, file_info_, platform_path_);
}
}
private:
base::PlatformFileError error_;
base::PlatformFileInfo file_info_;
FilePath platform_path_;
DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper);
};
class ReadDirectoryHelper {
public:
ReadDirectoryHelper() : error_(base::PLATFORM_FILE_OK) {}
void RunWork(const Proxy::ReadDirectoryTask& task) {
error_ = task.Run(&entries_);
}
void Reply(const Proxy::ReadDirectoryCallback& callback) {
if (!callback.is_null()) {
callback.Run(error_, entries_);
}
}
private:
base::PlatformFileError error_;
std::vector<Proxy::Entry> entries_;
DISALLOW_COPY_AND_ASSIGN(ReadDirectoryHelper);
};
} // namespace
namespace fileapi {
// static
bool FileSystemFileUtilProxy::RelayEnsureFileExists(
scoped_refptr<MessageLoopProxy> message_loop_proxy,
const EnsureFileExistsTask& task,
const EnsureFileExistsCallback& callback) {
EnsureFileExistsHelper* helper = new EnsureFileExistsHelper;
return message_loop_proxy->PostTaskAndReply(
FROM_HERE,
Bind(&EnsureFileExistsHelper::RunWork, Unretained(helper), task),
Bind(&EnsureFileExistsHelper::Reply, Owned(helper), callback));
}
// static
bool FileSystemFileUtilProxy::RelayGetFileInfo(
scoped_refptr<MessageLoopProxy> message_loop_proxy,
const GetFileInfoTask& task,
const GetFileInfoCallback& callback) {
GetFileInfoHelper* helper = new GetFileInfoHelper;
return message_loop_proxy->PostTaskAndReply(
FROM_HERE,
Bind(&GetFileInfoHelper::RunWork, Unretained(helper), task),
Bind(&GetFileInfoHelper::Reply, Owned(helper), callback));
}
// static
bool FileSystemFileUtilProxy::RelayReadDirectory(
scoped_refptr<MessageLoopProxy> message_loop_proxy,
const ReadDirectoryTask& task,
const ReadDirectoryCallback& callback) {
ReadDirectoryHelper* helper = new ReadDirectoryHelper;
return message_loop_proxy->PostTaskAndReply(
FROM_HERE,
Bind(&ReadDirectoryHelper::RunWork, Unretained(helper), task),
Bind(&ReadDirectoryHelper::Reply, Owned(helper), callback));
}
} // namespace fileapi
|