| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "content/child/fileapi/webfilesystem_impl.h" | 5 #include "content/child/fileapi/webfilesystem_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 CallbackFileSystemCallbacks( | 164 CallbackFileSystemCallbacks( |
| 165 thread_id, callbacks_id, waitable_results, | 165 thread_id, callbacks_id, waitable_results, |
| 166 &WebFileSystemCallbacks::didResolveURL, | 166 &WebFileSystemCallbacks::didResolveURL, |
| 167 MakeTuple(base::UTF8ToUTF16(info.name), info.root_url, | 167 MakeTuple(base::UTF8ToUTF16(info.name), info.root_url, |
| 168 static_cast<blink::WebFileSystemType>(info.mount_type), | 168 static_cast<blink::WebFileSystemType>(info.mount_type), |
| 169 normalized_path.AsUTF16Unsafe(), is_directory)); | 169 normalized_path.AsUTF16Unsafe(), is_directory)); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void StatusCallbackAdapter(int thread_id, int callbacks_id, | 172 void StatusCallbackAdapter(int thread_id, int callbacks_id, |
| 173 WaitableCallbackResults* waitable_results, | 173 WaitableCallbackResults* waitable_results, |
| 174 base::PlatformFileError error) { | 174 base::File::Error error) { |
| 175 if (error == base::PLATFORM_FILE_OK) { | 175 if (error == base::File::FILE_OK) { |
| 176 CallbackFileSystemCallbacks( | 176 CallbackFileSystemCallbacks( |
| 177 thread_id, callbacks_id, waitable_results, | 177 thread_id, callbacks_id, waitable_results, |
| 178 &WebFileSystemCallbacks::didSucceed, MakeTuple()); | 178 &WebFileSystemCallbacks::didSucceed, MakeTuple()); |
| 179 } else { | 179 } else { |
| 180 CallbackFileSystemCallbacks( | 180 CallbackFileSystemCallbacks( |
| 181 thread_id, callbacks_id, waitable_results, | 181 thread_id, callbacks_id, waitable_results, |
| 182 &WebFileSystemCallbacks::didFail, | 182 &WebFileSystemCallbacks::didFail, |
| 183 MakeTuple(fileapi::PlatformFileErrorToWebFileError(error))); | 183 MakeTuple(fileapi::FileErrorToWebFileError(error))); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 void ReadMetadataCallbackAdapter(int thread_id, int callbacks_id, | 187 void ReadMetadataCallbackAdapter(int thread_id, int callbacks_id, |
| 188 WaitableCallbackResults* waitable_results, | 188 WaitableCallbackResults* waitable_results, |
| 189 const base::PlatformFileInfo& file_info) { | 189 const base::File::Info& file_info) { |
| 190 WebFileInfo web_file_info; | 190 WebFileInfo web_file_info; |
| 191 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); | 191 webkit_glue::FileInfoToWebFileInfo(file_info, &web_file_info); |
| 192 CallbackFileSystemCallbacks( | 192 CallbackFileSystemCallbacks( |
| 193 thread_id, callbacks_id, waitable_results, | 193 thread_id, callbacks_id, waitable_results, |
| 194 &WebFileSystemCallbacks::didReadMetadata, | 194 &WebFileSystemCallbacks::didReadMetadata, |
| 195 MakeTuple(web_file_info)); | 195 MakeTuple(web_file_info)); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void ReadDirectoryCallbackAdapater( | 198 void ReadDirectoryCallbackAdapater( |
| 199 int thread_id, int callbacks_id, WaitableCallbackResults* waitable_results, | 199 int thread_id, int callbacks_id, WaitableCallbackResults* waitable_results, |
| 200 const std::vector<fileapi::DirectoryEntry>& entries, | 200 const std::vector<fileapi::DirectoryEntry>& entries, |
| 201 bool has_more) { | 201 bool has_more) { |
| 202 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); | 202 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); |
| 203 for (size_t i = 0; i < entries.size(); i++) { | 203 for (size_t i = 0; i < entries.size(); i++) { |
| 204 file_system_entries[i].name = | 204 file_system_entries[i].name = |
| 205 base::FilePath(entries[i].name).AsUTF16Unsafe(); | 205 base::FilePath(entries[i].name).AsUTF16Unsafe(); |
| 206 file_system_entries[i].isDirectory = entries[i].is_directory; | 206 file_system_entries[i].isDirectory = entries[i].is_directory; |
| 207 } | 207 } |
| 208 CallbackFileSystemCallbacks( | 208 CallbackFileSystemCallbacks( |
| 209 thread_id, callbacks_id, waitable_results, | 209 thread_id, callbacks_id, waitable_results, |
| 210 &WebFileSystemCallbacks::didReadDirectory, | 210 &WebFileSystemCallbacks::didReadDirectory, |
| 211 MakeTuple(file_system_entries, has_more)); | 211 MakeTuple(file_system_entries, has_more)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void DidCreateFileWriter( | 214 void DidCreateFileWriter( |
| 215 int callbacks_id, | 215 int callbacks_id, |
| 216 const GURL& path, | 216 const GURL& path, |
| 217 blink::WebFileWriterClient* client, | 217 blink::WebFileWriterClient* client, |
| 218 base::MessageLoopProxy* main_thread_loop, | 218 base::MessageLoopProxy* main_thread_loop, |
| 219 const base::PlatformFileInfo& file_info) { | 219 const base::File::Info& file_info) { |
| 220 WebFileSystemImpl* filesystem = | 220 WebFileSystemImpl* filesystem = |
| 221 WebFileSystemImpl::ThreadSpecificInstance(NULL); | 221 WebFileSystemImpl::ThreadSpecificInstance(NULL); |
| 222 if (!filesystem) | 222 if (!filesystem) |
| 223 return; | 223 return; |
| 224 | 224 |
| 225 WebFileSystemCallbacks callbacks = | 225 WebFileSystemCallbacks callbacks = |
| 226 filesystem->GetAndUnregisterCallbacks(callbacks_id); | 226 filesystem->GetAndUnregisterCallbacks(callbacks_id); |
| 227 | 227 |
| 228 if (file_info.is_directory || file_info.size < 0) { | 228 if (file_info.is_directory || file_info.size < 0) { |
| 229 callbacks.didFail(blink::WebFileErrorInvalidState); | 229 callbacks.didFail(blink::WebFileErrorInvalidState); |
| 230 return; | 230 return; |
| 231 } | 231 } |
| 232 WebFileWriterImpl::Type type = | 232 WebFileWriterImpl::Type type = |
| 233 callbacks.shouldBlockUntilCompletion() ? | 233 callbacks.shouldBlockUntilCompletion() ? |
| 234 WebFileWriterImpl::TYPE_SYNC : WebFileWriterImpl::TYPE_ASYNC; | 234 WebFileWriterImpl::TYPE_SYNC : WebFileWriterImpl::TYPE_ASYNC; |
| 235 callbacks.didCreateFileWriter( | 235 callbacks.didCreateFileWriter( |
| 236 new WebFileWriterImpl(path, client, type, main_thread_loop), | 236 new WebFileWriterImpl(path, client, type, main_thread_loop), |
| 237 file_info.size); | 237 file_info.size); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void CreateFileWriterCallbackAdapter( | 240 void CreateFileWriterCallbackAdapter( |
| 241 int thread_id, int callbacks_id, | 241 int thread_id, int callbacks_id, |
| 242 WaitableCallbackResults* waitable_results, | 242 WaitableCallbackResults* waitable_results, |
| 243 base::MessageLoopProxy* main_thread_loop, | 243 base::MessageLoopProxy* main_thread_loop, |
| 244 const GURL& path, | 244 const GURL& path, |
| 245 blink::WebFileWriterClient* client, | 245 blink::WebFileWriterClient* client, |
| 246 const base::PlatformFileInfo& file_info) { | 246 const base::File::Info& file_info) { |
| 247 DispatchResultsClosure( | 247 DispatchResultsClosure( |
| 248 thread_id, callbacks_id, waitable_results, | 248 thread_id, callbacks_id, waitable_results, |
| 249 base::Bind(&DidCreateFileWriter, callbacks_id, path, client, | 249 base::Bind(&DidCreateFileWriter, callbacks_id, path, client, |
| 250 make_scoped_refptr(main_thread_loop), file_info)); | 250 make_scoped_refptr(main_thread_loop), file_info)); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void DidCreateSnapshotFile( | 253 void DidCreateSnapshotFile( |
| 254 int callbacks_id, | 254 int callbacks_id, |
| 255 base::MessageLoopProxy* main_thread_loop, | 255 base::MessageLoopProxy* main_thread_loop, |
| 256 const base::PlatformFileInfo& file_info, | 256 const base::File::Info& file_info, |
| 257 const base::FilePath& platform_path, | 257 const base::FilePath& platform_path, |
| 258 int request_id) { | 258 int request_id) { |
| 259 WebFileSystemImpl* filesystem = | 259 WebFileSystemImpl* filesystem = |
| 260 WebFileSystemImpl::ThreadSpecificInstance(NULL); | 260 WebFileSystemImpl::ThreadSpecificInstance(NULL); |
| 261 if (!filesystem) | 261 if (!filesystem) |
| 262 return; | 262 return; |
| 263 | 263 |
| 264 WebFileSystemCallbacks callbacks = | 264 WebFileSystemCallbacks callbacks = |
| 265 filesystem->GetAndUnregisterCallbacks(callbacks_id); | 265 filesystem->GetAndUnregisterCallbacks(callbacks_id); |
| 266 | 266 |
| 267 WebFileInfo web_file_info; | 267 WebFileInfo web_file_info; |
| 268 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); | 268 webkit_glue::FileInfoToWebFileInfo(file_info, &web_file_info); |
| 269 web_file_info.platformPath = platform_path.AsUTF16Unsafe(); | 269 web_file_info.platformPath = platform_path.AsUTF16Unsafe(); |
| 270 callbacks.didCreateSnapshotFile(web_file_info); | 270 callbacks.didCreateSnapshotFile(web_file_info); |
| 271 | 271 |
| 272 // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes | 272 // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes |
| 273 // non-bridge model. | 273 // non-bridge model. |
| 274 main_thread_loop->PostTask( | 274 main_thread_loop->PostTask( |
| 275 FROM_HERE, base::Bind(&DidReceiveSnapshotFile, request_id)); | 275 FROM_HERE, base::Bind(&DidReceiveSnapshotFile, request_id)); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void CreateSnapshotFileCallbackAdapter( | 278 void CreateSnapshotFileCallbackAdapter( |
| 279 int thread_id, int callbacks_id, | 279 int thread_id, int callbacks_id, |
| 280 WaitableCallbackResults* waitable_results, | 280 WaitableCallbackResults* waitable_results, |
| 281 base::MessageLoopProxy* main_thread_loop, | 281 base::MessageLoopProxy* main_thread_loop, |
| 282 const base::PlatformFileInfo& file_info, | 282 const base::File::Info& file_info, |
| 283 const base::FilePath& platform_path, | 283 const base::FilePath& platform_path, |
| 284 int request_id) { | 284 int request_id) { |
| 285 DispatchResultsClosure( | 285 DispatchResultsClosure( |
| 286 thread_id, callbacks_id, waitable_results, | 286 thread_id, callbacks_id, waitable_results, |
| 287 base::Bind(&DidCreateSnapshotFile, callbacks_id, | 287 base::Bind(&DidCreateSnapshotFile, callbacks_id, |
| 288 make_scoped_refptr(main_thread_loop), | 288 make_scoped_refptr(main_thread_loop), |
| 289 file_info, platform_path, request_id)); | 289 file_info, platform_path, request_id)); |
| 290 } | 290 } |
| 291 | 291 |
| 292 } // namespace | 292 } // namespace |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 int callbacks_id) { | 605 int callbacks_id) { |
| 606 DCHECK(CalledOnValidThread()); | 606 DCHECK(CalledOnValidThread()); |
| 607 CallbacksMap::iterator found = callbacks_.find(callbacks_id); | 607 CallbacksMap::iterator found = callbacks_.find(callbacks_id); |
| 608 DCHECK(found != callbacks_.end()); | 608 DCHECK(found != callbacks_.end()); |
| 609 WebFileSystemCallbacks callbacks = found->second; | 609 WebFileSystemCallbacks callbacks = found->second; |
| 610 callbacks_.erase(found); | 610 callbacks_.erase(found); |
| 611 return callbacks; | 611 return callbacks; |
| 612 } | 612 } |
| 613 | 613 |
| 614 } // namespace content | 614 } // namespace content |
| OLD | NEW |