chrome: bluetooth: hook up the AdapterAdded signal
[chromium-blink-merge.git] / webkit / fileapi / file_system_file_util_proxy.cc
blobd77191a655c6a00690467d4bf80966aafeb13b8b
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"
7 #include "base/bind.h"
8 #include "base/message_loop_proxy.h"
10 namespace {
12 using base::Bind;
13 using base::Callback;
14 using base::Owned;
15 using base::PlatformFileError;
16 using base::Unretained;
18 typedef fileapi::FileSystemFileUtilProxy Proxy;
20 class EnsureFileExistsHelper {
21 public:
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_);
34 private:
35 base::PlatformFileError error_;
36 bool created_;
37 DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper);
40 class GetFileInfoHelper {
41 public:
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_);
54 private:
55 base::PlatformFileError error_;
56 base::PlatformFileInfo file_info_;
57 FilePath platform_path_;
58 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper);
61 class ReadDirectoryHelper {
62 public:
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_);
75 private:
76 base::PlatformFileError error_;
77 std::vector<Proxy::Entry> entries_;
78 DISALLOW_COPY_AND_ASSIGN(ReadDirectoryHelper);
81 } // namespace
83 namespace fileapi {
85 // static
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(
92 FROM_HERE,
93 Bind(&EnsureFileExistsHelper::RunWork, Unretained(helper), task),
94 Bind(&EnsureFileExistsHelper::Reply, Owned(helper), callback));
97 // static
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(
104 FROM_HERE,
105 Bind(&GetFileInfoHelper::RunWork, Unretained(helper), task),
106 Bind(&GetFileInfoHelper::Reply, Owned(helper), callback));
109 // static
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(
116 FROM_HERE,
117 Bind(&ReadDirectoryHelper::RunWork, Unretained(helper), task),
118 Bind(&ReadDirectoryHelper::Reply, Owned(helper), callback));
121 } // namespace fileapi