| 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" |
| 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/threading/thread_local.h" |
| 8 #include "content/child/child_thread.h" | 13 #include "content/child/child_thread.h" |
| 9 #include "content/child/fileapi/file_system_dispatcher.h" | 14 #include "content/child/fileapi/file_system_dispatcher.h" |
| 10 #include "content/child/fileapi/webfilesystem_callback_adapters.h" | 15 #include "content/child/fileapi/webfilesystem_callback_adapters.h" |
| 11 #include "content/child/fileapi/webfilewriter_impl.h" | 16 #include "content/child/fileapi/webfilewriter_impl.h" |
| 12 #include "third_party/WebKit/public/web/WebFileSystemCallbacks.h" | 17 #include "content/common/fileapi/file_system_messages.h" |
| 13 #include "third_party/WebKit/public/platform/WebFileInfo.h" | 18 #include "third_party/WebKit/public/platform/WebFileInfo.h" |
| 14 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
| 15 #include "third_party/WebKit/public/platform/WebURL.h" | 20 #include "third_party/WebKit/public/platform/WebURL.h" |
| 21 #include "third_party/WebKit/public/web/WebFileSystemCallbacks.h" |
| 22 #include "url/gurl.h" |
| 23 #include "webkit/child/worker_task_runner.h" |
| 24 #include "webkit/common/fileapi/directory_entry.h" |
| 25 #include "webkit/common/fileapi/file_system_util.h" |
| 16 #include "webkit/glue/webkit_glue.h" | 26 #include "webkit/glue/webkit_glue.h" |
| 17 | 27 |
| 18 using WebKit::WebFileInfo; | 28 using WebKit::WebFileInfo; |
| 19 using WebKit::WebFileSystemCallbacks; | 29 using WebKit::WebFileSystemCallbacks; |
| 20 using WebKit::WebFileSystemEntry; | 30 using WebKit::WebFileSystemEntry; |
| 21 using WebKit::WebString; | 31 using WebKit::WebString; |
| 22 using WebKit::WebURL; | 32 using WebKit::WebURL; |
| 23 using WebKit::WebVector; | 33 using WebKit::WebVector; |
| 34 using webkit_glue::WorkerTaskRunner; |
| 24 | 35 |
| 25 namespace content { | 36 namespace content { |
| 26 | 37 |
| 27 namespace { | 38 namespace { |
| 28 | 39 |
| 40 class CallbacksMap; |
| 41 |
| 42 base::LazyInstance<base::ThreadLocalPointer<CallbacksMap> >::Leaky |
| 43 g_callbacks_map_tls = LAZY_INSTANCE_INITIALIZER; |
| 44 |
| 45 // TODO(kinuko): Integrate this into WebFileSystemImpl when blink side |
| 46 // becomes ready to make WebFileSystemImpl thread-local. |
| 47 class CallbacksMap : public WorkerTaskRunner::Observer { |
| 48 public: |
| 49 static CallbacksMap* Get() { |
| 50 return g_callbacks_map_tls.Pointer()->Get(); |
| 51 } |
| 52 |
| 53 static CallbacksMap* GetOrCreate() { |
| 54 if (g_callbacks_map_tls.Pointer()->Get()) |
| 55 return g_callbacks_map_tls.Pointer()->Get(); |
| 56 CallbacksMap* map = new CallbacksMap; |
| 57 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) |
| 58 WorkerTaskRunner::Instance()->AddStopObserver(map); |
| 59 return map; |
| 60 } |
| 61 |
| 62 virtual ~CallbacksMap() { |
| 63 IDMap<WebFileSystemCallbacks>::iterator iter(&callbacks_); |
| 64 while (!iter.IsAtEnd()) { |
| 65 iter.GetCurrentValue()->didFail(WebKit::WebFileErrorAbort); |
| 66 iter.Advance(); |
| 67 } |
| 68 g_callbacks_map_tls.Pointer()->Set(NULL); |
| 69 } |
| 70 |
| 71 // webkit_glue::WorkerTaskRunner::Observer implementation. |
| 72 virtual void OnWorkerRunLoopStopped() OVERRIDE { |
| 73 delete this; |
| 74 } |
| 75 |
| 76 int RegisterCallbacks(WebFileSystemCallbacks* callbacks) { |
| 77 return callbacks_.Add(callbacks); |
| 78 } |
| 79 |
| 80 WebFileSystemCallbacks* GetAndUnregisterCallbacks( |
| 81 int callbacks_id) { |
| 82 WebFileSystemCallbacks* callbacks = callbacks_.Lookup(callbacks_id); |
| 83 callbacks_.Remove(callbacks_id); |
| 84 return callbacks; |
| 85 } |
| 86 |
| 87 private: |
| 88 CallbacksMap() { |
| 89 g_callbacks_map_tls.Pointer()->Set(this); |
| 90 } |
| 91 |
| 92 IDMap<WebFileSystemCallbacks> callbacks_; |
| 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(CallbacksMap); |
| 95 }; |
| 96 |
| 29 void DidReadMetadataForCreateFileWriter( | 97 void DidReadMetadataForCreateFileWriter( |
| 30 const GURL& path, | 98 const GURL& path, |
| 31 WebKit::WebFileWriterClient* client, | 99 WebKit::WebFileWriterClient* client, |
| 32 WebKit::WebFileSystemCallbacks* callbacks, | 100 WebKit::WebFileSystemCallbacks* callbacks, |
| 33 const base::PlatformFileInfo& file_info) { | 101 const base::PlatformFileInfo& file_info) { |
| 34 if (file_info.is_directory || file_info.size < 0) { | 102 if (file_info.is_directory || file_info.size < 0) { |
| 35 callbacks->didFail(WebKit::WebFileErrorInvalidState); | 103 callbacks->didFail(WebKit::WebFileErrorInvalidState); |
| 36 return; | 104 return; |
| 37 } | 105 } |
| 38 callbacks->didCreateFileWriter(new WebFileWriterImpl(path, client), | 106 callbacks->didCreateFileWriter(new WebFileWriterImpl(path, client), |
| 39 file_info.size); | 107 file_info.size); |
| 40 } | 108 } |
| 41 | 109 |
| 110 void DidReceiveSnapshotFile(int request_id) { |
| 111 if (ChildThread::current()) |
| 112 ChildThread::current()->Send( |
| 113 new FileSystemHostMsg_DidReceiveSnapshotFile(request_id)); |
| 114 } |
| 115 |
| 116 int CurrentWorkerId() { |
| 117 return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
| 118 } |
| 119 |
| 120 template <typename Method, typename Params> |
| 121 void CallDispatcherOnMainThread( |
| 122 base::MessageLoopProxy* loop, |
| 123 Method method, const Params& params) { |
| 124 if (!loop->RunsTasksOnCurrentThread()) { |
| 125 loop->PostTask(FROM_HERE, |
| 126 base::Bind(&CallDispatcherOnMainThread<Method, Params>, |
| 127 make_scoped_refptr(loop), method, params)); |
| 128 return; |
| 129 } |
| 130 if (!ChildThread::current() || |
| 131 !ChildThread::current()->file_system_dispatcher()) |
| 132 return; |
| 133 |
| 134 DispatchToMethod(ChildThread::current()->file_system_dispatcher(), |
| 135 method, params); |
| 136 } |
| 137 |
| 138 template <typename Method, typename Params> |
| 139 void CallbackFileSystemCallbacks( |
| 140 int thread_id, int callbacks_id, |
| 141 Method method, const Params& params) { |
| 142 if (thread_id != CurrentWorkerId()) { |
| 143 WorkerTaskRunner::Instance()->PostTask( |
| 144 thread_id, |
| 145 base::Bind(&CallbackFileSystemCallbacks<Method, Params>, |
| 146 thread_id, callbacks_id, method, params)); |
| 147 return; |
| 148 } |
| 149 if (!CallbacksMap::Get()) |
| 150 return; |
| 151 |
| 152 WebFileSystemCallbacks* callbacks = |
| 153 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); |
| 154 DCHECK(callbacks); |
| 155 DispatchToMethod(callbacks, method, params); |
| 156 } |
| 157 |
| 158 void StatusCallbackAdapter(int thread_id, int callbacks_id, |
| 159 base::PlatformFileError error) { |
| 160 if (error == base::PLATFORM_FILE_OK) { |
| 161 CallbackFileSystemCallbacks( |
| 162 thread_id, callbacks_id, |
| 163 &WebFileSystemCallbacks::didSucceed, MakeTuple()); |
| 164 } else { |
| 165 CallbackFileSystemCallbacks( |
| 166 thread_id, callbacks_id, |
| 167 &WebFileSystemCallbacks::didFail, |
| 168 MakeTuple(fileapi::PlatformFileErrorToWebFileError(error))); |
| 169 } |
| 170 } |
| 171 |
| 172 void ReadMetadataCallbackAdapter(int thread_id, int callbacks_id, |
| 173 const base::PlatformFileInfo& file_info) { |
| 174 WebFileInfo web_file_info; |
| 175 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); |
| 176 CallbackFileSystemCallbacks( |
| 177 thread_id, callbacks_id, |
| 178 &WebFileSystemCallbacks::didReadMetadata, |
| 179 MakeTuple(web_file_info)); |
| 180 } |
| 181 |
| 182 void ReadDirectoryCallbackAdapater( |
| 183 int thread_id, int callbacks_id, |
| 184 const std::vector<fileapi::DirectoryEntry>& entries, |
| 185 bool has_more) { |
| 186 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); |
| 187 for (size_t i = 0; i < entries.size(); i++) { |
| 188 file_system_entries[i].name = |
| 189 base::FilePath(entries[i].name).AsUTF16Unsafe(); |
| 190 file_system_entries[i].isDirectory = entries[i].is_directory; |
| 191 } |
| 192 CallbackFileSystemCallbacks( |
| 193 thread_id, callbacks_id, |
| 194 &WebFileSystemCallbacks::didReadDirectory, |
| 195 MakeTuple(file_system_entries, has_more)); |
| 196 } |
| 197 |
| 198 void CreateSnapshotFileCallbackAdapter( |
| 199 int thread_id, int callbacks_id, |
| 200 base::MessageLoopProxy* main_thread_loop, |
| 201 const base::PlatformFileInfo& file_info, |
| 202 const base::FilePath& platform_path, |
| 203 int request_id) { |
| 204 if (thread_id != CurrentWorkerId()) { |
| 205 WorkerTaskRunner::Instance()->PostTask( |
| 206 thread_id, |
| 207 base::Bind(&CreateSnapshotFileCallbackAdapter, |
| 208 thread_id, callbacks_id, |
| 209 make_scoped_refptr(main_thread_loop), |
| 210 file_info, platform_path, request_id)); |
| 211 return; |
| 212 } |
| 213 |
| 214 if (!CallbacksMap::Get()) |
| 215 return; |
| 216 |
| 217 WebFileSystemCallbacks* callbacks = |
| 218 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); |
| 219 DCHECK(callbacks); |
| 220 |
| 221 WebFileInfo web_file_info; |
| 222 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); |
| 223 web_file_info.platformPath = platform_path.AsUTF16Unsafe(); |
| 224 callbacks->didCreateSnapshotFile(web_file_info); |
| 225 |
| 226 // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes |
| 227 // non-bridge model. |
| 228 main_thread_loop->PostTask( |
| 229 FROM_HERE, base::Bind(&DidReceiveSnapshotFile, request_id)); |
| 230 } |
| 231 |
| 42 } // namespace | 232 } // namespace |
| 43 | 233 |
| 44 WebFileSystemImpl::WebFileSystemImpl() { | 234 WebFileSystemImpl::~WebFileSystemImpl() { |
| 45 } | 235 } |
| 46 | 236 |
| 47 void WebFileSystemImpl::move(const WebURL& src_path, | 237 WebFileSystemImpl::WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop) |
| 48 const WebURL& dest_path, | 238 : main_thread_loop_(main_thread_loop) { |
| 49 WebFileSystemCallbacks* callbacks) { | 239 } |
| 50 FileSystemDispatcher* dispatcher = | 240 |
| 51 ChildThread::current()->file_system_dispatcher(); | 241 void WebFileSystemImpl::move( |
| 52 dispatcher->Move(GURL(src_path), | 242 const WebKit::WebURL& src_path, |
| 53 GURL(dest_path), | 243 const WebKit::WebURL& dest_path, |
| 54 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 244 WebKit::WebFileSystemCallbacks* callbacks) { |
| 55 } | 245 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 56 | 246 CallDispatcherOnMainThread( |
| 57 void WebFileSystemImpl::copy(const WebURL& src_path, | 247 main_thread_loop_.get(), |
| 58 const WebURL& dest_path, | 248 &FileSystemDispatcher::Move, |
| 59 WebFileSystemCallbacks* callbacks) { | 249 MakeTuple(GURL(src_path), GURL(dest_path), |
| 60 FileSystemDispatcher* dispatcher = | 250 base::Bind(&StatusCallbackAdapter, |
| 61 ChildThread::current()->file_system_dispatcher(); | 251 CurrentWorkerId(), callbacks_id))); |
| 62 dispatcher->Copy(GURL(src_path), | 252 } |
| 63 GURL(dest_path), | 253 |
| 64 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 254 void WebFileSystemImpl::copy( |
| 65 } | 255 const WebKit::WebURL& src_path, |
| 66 | 256 const WebKit::WebURL& dest_path, |
| 67 void WebFileSystemImpl::remove(const WebURL& path, | 257 WebKit::WebFileSystemCallbacks* callbacks) { |
| 68 WebFileSystemCallbacks* callbacks) { | 258 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 69 FileSystemDispatcher* dispatcher = | 259 CallDispatcherOnMainThread( |
| 70 ChildThread::current()->file_system_dispatcher(); | 260 main_thread_loop_.get(), |
| 71 dispatcher->Remove( | 261 &FileSystemDispatcher::Copy, |
| 72 GURL(path), | 262 MakeTuple(GURL(src_path), GURL(dest_path), |
| 73 false /* recursive */, | 263 base::Bind(&StatusCallbackAdapter, |
| 74 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 264 CurrentWorkerId(), callbacks_id))); |
| 75 } | 265 } |
| 76 | 266 |
| 77 void WebFileSystemImpl::removeRecursively(const WebURL& path, | 267 void WebFileSystemImpl::remove( |
| 78 WebFileSystemCallbacks* callbacks) { | 268 const WebKit::WebURL& path, |
| 79 FileSystemDispatcher* dispatcher = | 269 WebKit::WebFileSystemCallbacks* callbacks) { |
| 80 ChildThread::current()->file_system_dispatcher(); | 270 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 81 dispatcher->Remove( | 271 CallDispatcherOnMainThread( |
| 82 GURL(path), | 272 main_thread_loop_.get(), |
| 83 true /* recursive */, | 273 &FileSystemDispatcher::Remove, |
| 84 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 274 MakeTuple(GURL(path), false /* recursive */, |
| 85 } | 275 base::Bind(&StatusCallbackAdapter, |
| 86 | 276 CurrentWorkerId(), callbacks_id))); |
| 87 void WebFileSystemImpl::readMetadata(const WebURL& path, | 277 } |
| 88 WebFileSystemCallbacks* callbacks) { | 278 |
| 89 FileSystemDispatcher* dispatcher = | 279 void WebFileSystemImpl::removeRecursively( |
| 90 ChildThread::current()->file_system_dispatcher(); | 280 const WebKit::WebURL& path, |
| 91 dispatcher->ReadMetadata( | 281 WebKit::WebFileSystemCallbacks* callbacks) { |
| 92 GURL(path), | 282 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 93 base::Bind(&ReadMetadataCallbackAdapter, callbacks), | 283 CallDispatcherOnMainThread( |
| 94 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 284 main_thread_loop_.get(), |
| 95 } | 285 &FileSystemDispatcher::Remove, |
| 96 | 286 MakeTuple(GURL(path), true /* recursive */, |
| 97 void WebFileSystemImpl::createFile(const WebURL& path, | 287 base::Bind(&StatusCallbackAdapter, |
| 98 bool exclusive, | 288 CurrentWorkerId(), callbacks_id))); |
| 99 WebFileSystemCallbacks* callbacks) { | 289 } |
| 100 FileSystemDispatcher* dispatcher = | 290 |
| 101 ChildThread::current()->file_system_dispatcher(); | 291 void WebFileSystemImpl::readMetadata( |
| 102 dispatcher->CreateFile( | 292 const WebKit::WebURL& path, |
| 103 GURL(path), exclusive, | 293 WebKit::WebFileSystemCallbacks* callbacks) { |
| 104 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 294 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 105 } | 295 CallDispatcherOnMainThread( |
| 106 | 296 main_thread_loop_.get(), |
| 107 void WebFileSystemImpl::createDirectory(const WebURL& path, | 297 &FileSystemDispatcher::ReadMetadata, |
| 108 bool exclusive, | 298 MakeTuple(GURL(path), |
| 109 WebFileSystemCallbacks* callbacks) { | 299 base::Bind(&ReadMetadataCallbackAdapter, |
| 110 FileSystemDispatcher* dispatcher = | 300 CurrentWorkerId(), callbacks_id), |
| 111 ChildThread::current()->file_system_dispatcher(); | 301 base::Bind(&StatusCallbackAdapter, |
| 112 dispatcher->CreateDirectory( | 302 CurrentWorkerId(), callbacks_id))); |
| 113 GURL(path), exclusive, false /* recursive */, | 303 } |
| 114 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 304 |
| 115 } | 305 void WebFileSystemImpl::createFile( |
| 116 | 306 const WebKit::WebURL& path, |
| 117 void WebFileSystemImpl::fileExists(const WebURL& path, | 307 bool exclusive, |
| 118 WebFileSystemCallbacks* callbacks) { | 308 WebKit::WebFileSystemCallbacks* callbacks) { |
| 119 FileSystemDispatcher* dispatcher = | 309 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 120 ChildThread::current()->file_system_dispatcher(); | 310 CallDispatcherOnMainThread( |
| 121 dispatcher->Exists( | 311 main_thread_loop_.get(), |
| 122 GURL(path), false /* directory */, | 312 &FileSystemDispatcher::CreateFile, |
| 123 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 313 MakeTuple(GURL(path), exclusive, |
| 124 } | 314 base::Bind(&StatusCallbackAdapter, |
| 125 | 315 CurrentWorkerId(), callbacks_id))); |
| 126 void WebFileSystemImpl::directoryExists(const WebURL& path, | 316 } |
| 127 WebFileSystemCallbacks* callbacks) { | 317 |
| 128 FileSystemDispatcher* dispatcher = | 318 void WebFileSystemImpl::createDirectory( |
| 129 ChildThread::current()->file_system_dispatcher(); | 319 const WebKit::WebURL& path, |
| 130 dispatcher->Exists( | 320 bool exclusive, |
| 131 GURL(path), true /* directory */, | 321 WebKit::WebFileSystemCallbacks* callbacks) { |
| 132 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 322 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 133 } | 323 CallDispatcherOnMainThread( |
| 134 | 324 main_thread_loop_.get(), |
| 135 void WebFileSystemImpl::readDirectory(const WebURL& path, | 325 &FileSystemDispatcher::CreateDirectory, |
| 136 WebFileSystemCallbacks* callbacks) { | 326 MakeTuple(GURL(path), exclusive, false /* recursive */, |
| 137 FileSystemDispatcher* dispatcher = | 327 base::Bind(&StatusCallbackAdapter, |
| 138 ChildThread::current()->file_system_dispatcher(); | 328 CurrentWorkerId(), callbacks_id))); |
| 139 dispatcher->ReadDirectory( | 329 } |
| 140 GURL(path), | 330 |
| 141 base::Bind(&ReadDirectoryCallbackAdapater, callbacks), | 331 void WebFileSystemImpl::fileExists( |
| 142 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 332 const WebKit::WebURL& path, |
| 333 WebKit::WebFileSystemCallbacks* callbacks) { |
| 334 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 335 CallDispatcherOnMainThread( |
| 336 main_thread_loop_.get(), |
| 337 &FileSystemDispatcher::Exists, |
| 338 MakeTuple(GURL(path), false /* directory */, |
| 339 base::Bind(&StatusCallbackAdapter, |
| 340 CurrentWorkerId(), callbacks_id))); |
| 341 } |
| 342 |
| 343 void WebFileSystemImpl::directoryExists( |
| 344 const WebKit::WebURL& path, |
| 345 WebKit::WebFileSystemCallbacks* callbacks) { |
| 346 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 347 CallDispatcherOnMainThread( |
| 348 main_thread_loop_.get(), |
| 349 &FileSystemDispatcher::Exists, |
| 350 MakeTuple(GURL(path), true /* directory */, |
| 351 base::Bind(&StatusCallbackAdapter, |
| 352 CurrentWorkerId(), callbacks_id))); |
| 353 } |
| 354 |
| 355 void WebFileSystemImpl::readDirectory( |
| 356 const WebKit::WebURL& path, |
| 357 WebKit::WebFileSystemCallbacks* callbacks) { |
| 358 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 359 CallDispatcherOnMainThread( |
| 360 main_thread_loop_.get(), |
| 361 &FileSystemDispatcher::ReadDirectory, |
| 362 MakeTuple(GURL(path), |
| 363 base::Bind(&ReadDirectoryCallbackAdapater, |
| 364 CurrentWorkerId(), callbacks_id), |
| 365 base::Bind(&StatusCallbackAdapter, |
| 366 CurrentWorkerId(), callbacks_id))); |
| 143 } | 367 } |
| 144 | 368 |
| 145 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( | 369 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( |
| 146 const WebURL& path, WebKit::WebFileWriterClient* client) { | 370 const WebURL& path, WebKit::WebFileWriterClient* client) { |
| 147 return new WebFileWriterImpl(GURL(path), client); | 371 return new WebFileWriterImpl(GURL(path), client); |
| 148 } | 372 } |
| 149 | 373 |
| 150 void WebFileSystemImpl::createFileWriter( | 374 void WebFileSystemImpl::createFileWriter( |
| 151 const WebURL& path, | 375 const WebURL& path, |
| 152 WebKit::WebFileWriterClient* client, | 376 WebKit::WebFileWriterClient* client, |
| 153 WebKit::WebFileSystemCallbacks* callbacks) { | 377 WebKit::WebFileSystemCallbacks* callbacks) { |
| 378 // TODO(kinuko): Convert this method to use bridge model. (crbug.com/257349) |
| 379 DCHECK(main_thread_loop_->RunsTasksOnCurrentThread()); |
| 154 FileSystemDispatcher* dispatcher = | 380 FileSystemDispatcher* dispatcher = |
| 155 ChildThread::current()->file_system_dispatcher(); | 381 ChildThread::current()->file_system_dispatcher(); |
| 156 dispatcher->ReadMetadata( | 382 dispatcher->ReadMetadata( |
| 157 GURL(path), | 383 GURL(path), |
| 158 base::Bind(&DidReadMetadataForCreateFileWriter, | 384 base::Bind(&DidReadMetadataForCreateFileWriter, |
| 159 GURL(path), client, callbacks), | 385 GURL(path), client, callbacks), |
| 160 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 386 base::Bind(&FileStatusCallbackAdapter, callbacks)); |
| 161 } | 387 } |
| 162 | 388 |
| 163 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( | 389 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( |
| 164 const WebKit::WebURL& path, | 390 const WebKit::WebURL& path, |
| 165 WebKit::WebFileSystemCallbacks* callbacks) { | 391 WebKit::WebFileSystemCallbacks* callbacks) { |
| 166 FileSystemDispatcher* dispatcher = | 392 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 167 ChildThread::current()->file_system_dispatcher(); | 393 CallDispatcherOnMainThread( |
| 168 dispatcher->CreateSnapshotFile( | 394 main_thread_loop_.get(), |
| 169 GURL(path), | 395 &FileSystemDispatcher::CreateSnapshotFile, |
| 170 base::Bind(&CreateSnapshotFileCallbackAdapter, callbacks), | 396 MakeTuple(GURL(path), |
| 171 base::Bind(&FileStatusCallbackAdapter, callbacks)); | 397 base::Bind(&CreateSnapshotFileCallbackAdapter, |
| 398 CurrentWorkerId(), callbacks_id, |
| 399 main_thread_loop_), |
| 400 base::Bind(&StatusCallbackAdapter, |
| 401 CurrentWorkerId(), callbacks_id))); |
| 172 } | 402 } |
| 173 | 403 |
| 174 } // namespace content | 404 } // namespace content |
| OLD | NEW |