OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/browser/fileapi/async_file_util_adapter.h" | 5 #include "webkit/browser/fileapi/async_file_util_adapter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 true /* has_more */)); | 126 true /* has_more */)); |
127 entries.clear(); | 127 entries.clear(); |
128 } | 128 } |
129 } | 129 } |
130 origin_loop->PostTask( | 130 origin_loop->PostTask( |
131 FROM_HERE, base::Bind(callback, base::File::FILE_OK, entries, | 131 FROM_HERE, base::Bind(callback, base::File::FILE_OK, entries, |
132 false /* has_more */)); | 132 false /* has_more */)); |
133 } | 133 } |
134 | 134 |
135 void RunCreateOrOpenCallback( | 135 void RunCreateOrOpenCallback( |
| 136 FileSystemOperationContext* context, |
136 const AsyncFileUtil::CreateOrOpenCallback& callback, | 137 const AsyncFileUtil::CreateOrOpenCallback& callback, |
137 base::File::Error result, | 138 base::File file) { |
138 base::PassPlatformFile file, | 139 // TODO(rvargas): Remove PlatformFile from AsyncFileUtil. |
139 bool created) { | 140 base::File::Error error; |
140 callback.Run(result, file, base::Closure()); | 141 base::PlatformFile platform_file; |
| 142 if (file.IsValid()) { |
| 143 error = base::File::FILE_OK; |
| 144 platform_file = file.TakePlatformFile(); |
| 145 } else { |
| 146 error = file.error_details(); |
| 147 platform_file = base::kInvalidPlatformFileValue; |
| 148 } |
| 149 |
| 150 callback.Run(error, base::PassPlatformFile(&platform_file), base::Closure()); |
| 151 base::File closer(platform_file); |
141 } | 152 } |
142 | 153 |
143 } // namespace | 154 } // namespace |
144 | 155 |
145 AsyncFileUtilAdapter::AsyncFileUtilAdapter( | 156 AsyncFileUtilAdapter::AsyncFileUtilAdapter( |
146 FileSystemFileUtil* sync_file_util) | 157 FileSystemFileUtil* sync_file_util) |
147 : sync_file_util_(sync_file_util) { | 158 : sync_file_util_(sync_file_util) { |
148 DCHECK(sync_file_util_.get()); | 159 DCHECK(sync_file_util_.get()); |
149 } | 160 } |
150 | 161 |
151 AsyncFileUtilAdapter::~AsyncFileUtilAdapter() { | 162 AsyncFileUtilAdapter::~AsyncFileUtilAdapter() { |
152 } | 163 } |
153 | 164 |
154 void AsyncFileUtilAdapter::CreateOrOpen( | 165 void AsyncFileUtilAdapter::CreateOrOpen( |
155 scoped_ptr<FileSystemOperationContext> context, | 166 scoped_ptr<FileSystemOperationContext> context, |
156 const FileSystemURL& url, | 167 const FileSystemURL& url, |
157 int file_flags, | 168 int file_flags, |
158 const CreateOrOpenCallback& callback) { | 169 const CreateOrOpenCallback& callback) { |
159 FileSystemOperationContext* context_ptr = context.release(); | 170 FileSystemOperationContext* context_ptr = context.release(); |
160 const bool success = base::FileUtilProxy::RelayCreateOrOpen( | 171 base::PostTaskAndReplyWithResult( |
161 context_ptr->task_runner(), | 172 context_ptr->task_runner(), |
| 173 FROM_HERE, |
162 Bind(&FileSystemFileUtil::CreateOrOpen, Unretained(sync_file_util_.get()), | 174 Bind(&FileSystemFileUtil::CreateOrOpen, Unretained(sync_file_util_.get()), |
163 context_ptr, url, file_flags), | 175 context_ptr, url, file_flags), |
164 Bind(&FileSystemFileUtil::Close, Unretained(sync_file_util_.get()), | 176 Bind(&RunCreateOrOpenCallback, base::Owned(context_ptr), callback)); |
165 base::Owned(context_ptr)), | |
166 Bind(&RunCreateOrOpenCallback, callback)); | |
167 DCHECK(success); | |
168 } | 177 } |
169 | 178 |
170 void AsyncFileUtilAdapter::EnsureFileExists( | 179 void AsyncFileUtilAdapter::EnsureFileExists( |
171 scoped_ptr<FileSystemOperationContext> context, | 180 scoped_ptr<FileSystemOperationContext> context, |
172 const FileSystemURL& url, | 181 const FileSystemURL& url, |
173 const EnsureFileExistsCallback& callback) { | 182 const EnsureFileExistsCallback& callback) { |
174 EnsureFileExistsHelper* helper = new EnsureFileExistsHelper; | 183 EnsureFileExistsHelper* helper = new EnsureFileExistsHelper; |
175 FileSystemOperationContext* context_ptr = context.release(); | 184 FileSystemOperationContext* context_ptr = context.release(); |
176 const bool success = context_ptr->task_runner()->PostTaskAndReply( | 185 const bool success = context_ptr->task_runner()->PostTaskAndReply( |
177 FROM_HERE, | 186 FROM_HERE, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 GetFileInfoHelper* helper = new GetFileInfoHelper; | 355 GetFileInfoHelper* helper = new GetFileInfoHelper; |
347 const bool success = context_ptr->task_runner()->PostTaskAndReply( | 356 const bool success = context_ptr->task_runner()->PostTaskAndReply( |
348 FROM_HERE, | 357 FROM_HERE, |
349 Bind(&GetFileInfoHelper::CreateSnapshotFile, Unretained(helper), | 358 Bind(&GetFileInfoHelper::CreateSnapshotFile, Unretained(helper), |
350 sync_file_util_.get(), base::Owned(context_ptr), url), | 359 sync_file_util_.get(), base::Owned(context_ptr), url), |
351 Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback)); | 360 Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback)); |
352 DCHECK(success); | 361 DCHECK(success); |
353 } | 362 } |
354 | 363 |
355 } // namespace fileapi | 364 } // namespace fileapi |
OLD | NEW |