| 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/id_map.h" | 8 #include "base/id_map.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 private: | 87 private: |
| 88 CallbacksMap() { | 88 CallbacksMap() { |
| 89 g_callbacks_map_tls.Pointer()->Set(this); | 89 g_callbacks_map_tls.Pointer()->Set(this); |
| 90 } | 90 } |
| 91 | 91 |
| 92 IDMap<WebFileSystemCallbacks> callbacks_; | 92 IDMap<WebFileSystemCallbacks> callbacks_; |
| 93 | 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(CallbacksMap); | 94 DISALLOW_COPY_AND_ASSIGN(CallbacksMap); |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 void DidReadMetadataForCreateFileWriter( | |
| 98 const GURL& path, | |
| 99 WebKit::WebFileWriterClient* client, | |
| 100 WebKit::WebFileSystemCallbacks* callbacks, | |
| 101 const base::PlatformFileInfo& file_info) { | |
| 102 if (file_info.is_directory || file_info.size < 0) { | |
| 103 callbacks->didFail(WebKit::WebFileErrorInvalidState); | |
| 104 return; | |
| 105 } | |
| 106 callbacks->didCreateFileWriter(new WebFileWriterImpl(path, client), | |
| 107 file_info.size); | |
| 108 } | |
| 109 | |
| 110 void DidReceiveSnapshotFile(int request_id) { | 97 void DidReceiveSnapshotFile(int request_id) { |
| 111 if (ChildThread::current()) | 98 if (ChildThread::current()) |
| 112 ChildThread::current()->Send( | 99 ChildThread::current()->Send( |
| 113 new FileSystemHostMsg_DidReceiveSnapshotFile(request_id)); | 100 new FileSystemHostMsg_DidReceiveSnapshotFile(request_id)); |
| 114 } | 101 } |
| 115 | 102 |
| 116 int CurrentWorkerId() { | 103 int CurrentWorkerId() { |
| 117 return WorkerTaskRunner::Instance()->CurrentWorkerId(); | 104 return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
| 118 } | 105 } |
| 119 | 106 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 file_system_entries[i].name = | 175 file_system_entries[i].name = |
| 189 base::FilePath(entries[i].name).AsUTF16Unsafe(); | 176 base::FilePath(entries[i].name).AsUTF16Unsafe(); |
| 190 file_system_entries[i].isDirectory = entries[i].is_directory; | 177 file_system_entries[i].isDirectory = entries[i].is_directory; |
| 191 } | 178 } |
| 192 CallbackFileSystemCallbacks( | 179 CallbackFileSystemCallbacks( |
| 193 thread_id, callbacks_id, | 180 thread_id, callbacks_id, |
| 194 &WebFileSystemCallbacks::didReadDirectory, | 181 &WebFileSystemCallbacks::didReadDirectory, |
| 195 MakeTuple(file_system_entries, has_more)); | 182 MakeTuple(file_system_entries, has_more)); |
| 196 } | 183 } |
| 197 | 184 |
| 185 void CreateFileWriterCallbackAdapter( |
| 186 int thread_id, int callbacks_id, |
| 187 base::MessageLoopProxy* main_thread_loop, |
| 188 const GURL& path, |
| 189 WebKit::WebFileWriterClient* client, |
| 190 const base::PlatformFileInfo& file_info) { |
| 191 if (thread_id != CurrentWorkerId()) { |
| 192 WorkerTaskRunner::Instance()->PostTask( |
| 193 thread_id, |
| 194 base::Bind(&CreateFileWriterCallbackAdapter, |
| 195 thread_id, callbacks_id, |
| 196 make_scoped_refptr(main_thread_loop), |
| 197 path, client, file_info)); |
| 198 return; |
| 199 } |
| 200 |
| 201 if (!CallbacksMap::Get()) |
| 202 return; |
| 203 |
| 204 WebFileSystemCallbacks* callbacks = |
| 205 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); |
| 206 DCHECK(callbacks); |
| 207 |
| 208 if (file_info.is_directory || file_info.size < 0) { |
| 209 callbacks->didFail(WebKit::WebFileErrorInvalidState); |
| 210 return; |
| 211 } |
| 212 callbacks->didCreateFileWriter( |
| 213 new WebFileWriterImpl(path, client, main_thread_loop), file_info.size); |
| 214 } |
| 215 |
| 198 void CreateSnapshotFileCallbackAdapter( | 216 void CreateSnapshotFileCallbackAdapter( |
| 199 int thread_id, int callbacks_id, | 217 int thread_id, int callbacks_id, |
| 200 base::MessageLoopProxy* main_thread_loop, | 218 base::MessageLoopProxy* main_thread_loop, |
| 201 const base::PlatformFileInfo& file_info, | 219 const base::PlatformFileInfo& file_info, |
| 202 const base::FilePath& platform_path, | 220 const base::FilePath& platform_path, |
| 203 int request_id) { | 221 int request_id) { |
| 204 if (thread_id != CurrentWorkerId()) { | 222 if (thread_id != CurrentWorkerId()) { |
| 205 WorkerTaskRunner::Instance()->PostTask( | 223 WorkerTaskRunner::Instance()->PostTask( |
| 206 thread_id, | 224 thread_id, |
| 207 base::Bind(&CreateSnapshotFileCallbackAdapter, | 225 base::Bind(&CreateSnapshotFileCallbackAdapter, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 &FileSystemDispatcher::ReadDirectory, | 379 &FileSystemDispatcher::ReadDirectory, |
| 362 MakeTuple(GURL(path), | 380 MakeTuple(GURL(path), |
| 363 base::Bind(&ReadDirectoryCallbackAdapater, | 381 base::Bind(&ReadDirectoryCallbackAdapater, |
| 364 CurrentWorkerId(), callbacks_id), | 382 CurrentWorkerId(), callbacks_id), |
| 365 base::Bind(&StatusCallbackAdapter, | 383 base::Bind(&StatusCallbackAdapter, |
| 366 CurrentWorkerId(), callbacks_id))); | 384 CurrentWorkerId(), callbacks_id))); |
| 367 } | 385 } |
| 368 | 386 |
| 369 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( | 387 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( |
| 370 const WebURL& path, WebKit::WebFileWriterClient* client) { | 388 const WebURL& path, WebKit::WebFileWriterClient* client) { |
| 371 return new WebFileWriterImpl(GURL(path), client); | 389 return new WebFileWriterImpl(GURL(path), client, main_thread_loop_.get()); |
| 372 } | 390 } |
| 373 | 391 |
| 374 void WebFileSystemImpl::createFileWriter( | 392 void WebFileSystemImpl::createFileWriter( |
| 375 const WebURL& path, | 393 const WebURL& path, |
| 376 WebKit::WebFileWriterClient* client, | 394 WebKit::WebFileWriterClient* client, |
| 377 WebKit::WebFileSystemCallbacks* callbacks) { | 395 WebKit::WebFileSystemCallbacks* callbacks) { |
| 378 // TODO(kinuko): Convert this method to use bridge model. (crbug.com/257349) | 396 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 379 DCHECK(main_thread_loop_->RunsTasksOnCurrentThread()); | 397 CallDispatcherOnMainThread( |
| 380 FileSystemDispatcher* dispatcher = | 398 main_thread_loop_.get(), |
| 381 ChildThread::current()->file_system_dispatcher(); | 399 &FileSystemDispatcher::ReadMetadata, |
| 382 dispatcher->ReadMetadata( | 400 MakeTuple(GURL(path), |
| 383 GURL(path), | 401 base::Bind(&CreateFileWriterCallbackAdapter, |
| 384 base::Bind(&DidReadMetadataForCreateFileWriter, | 402 CurrentWorkerId(), callbacks_id, main_thread_loop_, |
| 385 GURL(path), client, callbacks), | 403 GURL(path), client), |
| 386 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 404 base::Bind(&StatusCallbackAdapter, |
| 405 CurrentWorkerId(), callbacks_id))); |
| 387 } | 406 } |
| 388 | 407 |
| 389 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( | 408 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( |
| 390 const WebKit::WebURL& path, | 409 const WebKit::WebURL& path, |
| 391 WebKit::WebFileSystemCallbacks* callbacks) { | 410 WebKit::WebFileSystemCallbacks* callbacks) { |
| 392 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 411 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 393 CallDispatcherOnMainThread( | 412 CallDispatcherOnMainThread( |
| 394 main_thread_loop_.get(), | 413 main_thread_loop_.get(), |
| 395 &FileSystemDispatcher::CreateSnapshotFile, | 414 &FileSystemDispatcher::CreateSnapshotFile, |
| 396 MakeTuple(GURL(path), | 415 MakeTuple(GURL(path), |
| 397 base::Bind(&CreateSnapshotFileCallbackAdapter, | 416 base::Bind(&CreateSnapshotFileCallbackAdapter, |
| 398 CurrentWorkerId(), callbacks_id, | 417 CurrentWorkerId(), callbacks_id, |
| 399 main_thread_loop_), | 418 main_thread_loop_), |
| 400 base::Bind(&StatusCallbackAdapter, | 419 base::Bind(&StatusCallbackAdapter, |
| 401 CurrentWorkerId(), callbacks_id))); | 420 CurrentWorkerId(), callbacks_id))); |
| 402 } | 421 } |
| 403 | 422 |
| 404 } // namespace content | 423 } // namespace content |
| OLD | NEW |