| 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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/threading/thread_local.h" | 13 #include "base/threading/thread_local.h" |
| 14 #include "content/child/child_thread.h" | 14 #include "content/child/child_thread.h" |
| 15 #include "content/child/fileapi/file_system_dispatcher.h" | 15 #include "content/child/fileapi/file_system_dispatcher.h" |
| 16 #include "content/child/fileapi/webfilewriter_impl.h" | 16 #include "content/child/fileapi/webfilewriter_impl.h" |
| 17 #include "content/common/fileapi/file_system_messages.h" | 17 #include "content/common/fileapi/file_system_messages.h" |
| 18 #include "third_party/WebKit/public/platform/WebFileInfo.h" | 18 #include "third_party/WebKit/public/platform/WebFileInfo.h" |
| 19 #include "third_party/WebKit/public/platform/WebFileSystemCallbacks.h" |
| 19 #include "third_party/WebKit/public/platform/WebString.h" | 20 #include "third_party/WebKit/public/platform/WebString.h" |
| 20 #include "third_party/WebKit/public/platform/WebURL.h" | 21 #include "third_party/WebKit/public/platform/WebURL.h" |
| 21 #include "third_party/WebKit/public/web/WebFileSystemCallbacks.h" | |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 #include "webkit/child/worker_task_runner.h" | 23 #include "webkit/child/worker_task_runner.h" |
| 24 #include "webkit/common/fileapi/directory_entry.h" | 24 #include "webkit/common/fileapi/directory_entry.h" |
| 25 #include "webkit/common/fileapi/file_system_util.h" | 25 #include "webkit/common/fileapi/file_system_util.h" |
| 26 #include "webkit/glue/webkit_glue.h" | 26 #include "webkit/glue/webkit_glue.h" |
| 27 | 27 |
| 28 using WebKit::WebFileInfo; | 28 using WebKit::WebFileInfo; |
| 29 using WebKit::WebFileSystemCallbacks; | 29 using WebKit::WebFileSystemCallbacks; |
| 30 using WebKit::WebFileSystemEntry; | 30 using WebKit::WebFileSystemEntry; |
| 31 using WebKit::WebString; | 31 using WebKit::WebString; |
| 32 using WebKit::WebURL; | 32 using WebKit::WebURL; |
| 33 using WebKit::WebVector; | 33 using WebKit::WebVector; |
| 34 using webkit_glue::WorkerTaskRunner; | 34 using webkit_glue::WorkerTaskRunner; |
| 35 | 35 |
| 36 namespace content { | 36 namespace content { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // TODO(kinuko): Remove this hack after the two-sided patch lands. |
| 41 WebFileSystemCallbacks* Wrapper(WebFileSystemCallbacksType& cb) { |
| 42 #ifdef NON_SELFDESTRUCT_WEBFILESYSTEMCALLBACKS |
| 43 return &cb; |
| 44 #else |
| 45 return cb; |
| 46 #endif |
| 47 } |
| 48 |
| 40 base::LazyInstance<base::ThreadLocalPointer<WebFileSystemImpl> >::Leaky | 49 base::LazyInstance<base::ThreadLocalPointer<WebFileSystemImpl> >::Leaky |
| 41 g_webfilesystem_tls = LAZY_INSTANCE_INITIALIZER; | 50 g_webfilesystem_tls = LAZY_INSTANCE_INITIALIZER; |
| 42 | 51 |
| 43 class WaitableCallbackResults { | 52 class WaitableCallbackResults { |
| 44 public: | 53 public: |
| 45 static WaitableCallbackResults* MaybeCreate( | 54 static WaitableCallbackResults* MaybeCreate( |
| 46 WebKit::WebFileSystemCallbacks* callbacks) { | 55 WebFileSystemCallbacksType callbacks) { |
| 47 if (callbacks->shouldBlockUntilCompletion()) | 56 if (Wrapper(callbacks)->shouldBlockUntilCompletion()) |
| 48 return new WaitableCallbackResults; | 57 return new WaitableCallbackResults; |
| 49 return NULL; | 58 return NULL; |
| 50 } | 59 } |
| 51 ~WaitableCallbackResults() {} | 60 ~WaitableCallbackResults() {} |
| 52 | 61 |
| 53 void SetResultsAndSignal(const base::Closure& results_closure) { | 62 void SetResultsAndSignal(const base::Closure& results_closure) { |
| 54 results_closure_ = results_closure; | 63 results_closure_ = results_closure; |
| 55 event_->Signal(); | 64 event_->Signal(); |
| 56 } | 65 } |
| 57 | 66 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 method, params); | 112 method, params); |
| 104 } | 113 } |
| 105 | 114 |
| 106 // Run WebFileSystemCallbacks's |method| with |params|. | 115 // Run WebFileSystemCallbacks's |method| with |params|. |
| 107 template <typename Method, typename Params> | 116 template <typename Method, typename Params> |
| 108 void RunCallbacks(int callbacks_id, Method method, const Params& params) { | 117 void RunCallbacks(int callbacks_id, Method method, const Params& params) { |
| 109 WebFileSystemImpl* filesystem = | 118 WebFileSystemImpl* filesystem = |
| 110 WebFileSystemImpl::ThreadSpecificInstance(NULL); | 119 WebFileSystemImpl::ThreadSpecificInstance(NULL); |
| 111 if (!filesystem) | 120 if (!filesystem) |
| 112 return; | 121 return; |
| 113 WebFileSystemCallbacks* callbacks = | 122 WebFileSystemCallbacksType callbacks = |
| 114 filesystem->GetAndUnregisterCallbacks(callbacks_id); | 123 filesystem->GetAndUnregisterCallbacks(callbacks_id); |
| 115 DCHECK(callbacks); | 124 DispatchToMethod(Wrapper(callbacks), method, params); |
| 116 DispatchToMethod(callbacks, method, params); | |
| 117 } | 125 } |
| 118 | 126 |
| 119 void DispatchResultsClosure(int thread_id, int callbacks_id, | 127 void DispatchResultsClosure(int thread_id, int callbacks_id, |
| 120 WaitableCallbackResults* waitable_results, | 128 WaitableCallbackResults* waitable_results, |
| 121 const base::Closure& results_closure) { | 129 const base::Closure& results_closure) { |
| 122 if (thread_id != CurrentWorkerId()) { | 130 if (thread_id != CurrentWorkerId()) { |
| 123 if (waitable_results) { | 131 if (waitable_results) { |
| 124 waitable_results->SetResultsAndSignal(results_closure); | 132 waitable_results->SetResultsAndSignal(results_closure); |
| 125 return; | 133 return; |
| 126 } | 134 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 int callbacks_id, | 209 int callbacks_id, |
| 202 const GURL& path, | 210 const GURL& path, |
| 203 WebKit::WebFileWriterClient* client, | 211 WebKit::WebFileWriterClient* client, |
| 204 base::MessageLoopProxy* main_thread_loop, | 212 base::MessageLoopProxy* main_thread_loop, |
| 205 const base::PlatformFileInfo& file_info) { | 213 const base::PlatformFileInfo& file_info) { |
| 206 WebFileSystemImpl* filesystem = | 214 WebFileSystemImpl* filesystem = |
| 207 WebFileSystemImpl::ThreadSpecificInstance(NULL); | 215 WebFileSystemImpl::ThreadSpecificInstance(NULL); |
| 208 if (!filesystem) | 216 if (!filesystem) |
| 209 return; | 217 return; |
| 210 | 218 |
| 211 WebFileSystemCallbacks* callbacks = | 219 WebFileSystemCallbacksType callbacks = |
| 212 filesystem->GetAndUnregisterCallbacks(callbacks_id); | 220 filesystem->GetAndUnregisterCallbacks(callbacks_id); |
| 213 DCHECK(callbacks); | |
| 214 | 221 |
| 215 if (file_info.is_directory || file_info.size < 0) { | 222 if (file_info.is_directory || file_info.size < 0) { |
| 216 callbacks->didFail(WebKit::WebFileErrorInvalidState); | 223 Wrapper(callbacks)->didFail(WebKit::WebFileErrorInvalidState); |
| 217 return; | 224 return; |
| 218 } | 225 } |
| 219 WebFileWriterImpl::Type type = callbacks->shouldBlockUntilCompletion() ? | 226 WebFileWriterImpl::Type type = |
| 220 WebFileWriterImpl::TYPE_SYNC : WebFileWriterImpl::TYPE_ASYNC; | 227 Wrapper(callbacks)->shouldBlockUntilCompletion() ? |
| 221 callbacks->didCreateFileWriter( | 228 WebFileWriterImpl::TYPE_SYNC : WebFileWriterImpl::TYPE_ASYNC; |
| 229 Wrapper(callbacks)->didCreateFileWriter( |
| 222 new WebFileWriterImpl(path, client, type, main_thread_loop), | 230 new WebFileWriterImpl(path, client, type, main_thread_loop), |
| 223 file_info.size); | 231 file_info.size); |
| 224 } | 232 } |
| 225 | 233 |
| 226 void CreateFileWriterCallbackAdapter( | 234 void CreateFileWriterCallbackAdapter( |
| 227 int thread_id, int callbacks_id, | 235 int thread_id, int callbacks_id, |
| 228 WaitableCallbackResults* waitable_results, | 236 WaitableCallbackResults* waitable_results, |
| 229 base::MessageLoopProxy* main_thread_loop, | 237 base::MessageLoopProxy* main_thread_loop, |
| 230 const GURL& path, | 238 const GURL& path, |
| 231 WebKit::WebFileWriterClient* client, | 239 WebKit::WebFileWriterClient* client, |
| 232 const base::PlatformFileInfo& file_info) { | 240 const base::PlatformFileInfo& file_info) { |
| 233 DispatchResultsClosure( | 241 DispatchResultsClosure( |
| 234 thread_id, callbacks_id, waitable_results, | 242 thread_id, callbacks_id, waitable_results, |
| 235 base::Bind(&DidCreateFileWriter, callbacks_id, path, client, | 243 base::Bind(&DidCreateFileWriter, callbacks_id, path, client, |
| 236 make_scoped_refptr(main_thread_loop), file_info)); | 244 make_scoped_refptr(main_thread_loop), file_info)); |
| 237 } | 245 } |
| 238 | 246 |
| 239 void DidCreateSnapshotFile( | 247 void DidCreateSnapshotFile( |
| 240 int callbacks_id, | 248 int callbacks_id, |
| 241 base::MessageLoopProxy* main_thread_loop, | 249 base::MessageLoopProxy* main_thread_loop, |
| 242 const base::PlatformFileInfo& file_info, | 250 const base::PlatformFileInfo& file_info, |
| 243 const base::FilePath& platform_path, | 251 const base::FilePath& platform_path, |
| 244 int request_id) { | 252 int request_id) { |
| 245 WebFileSystemImpl* filesystem = | 253 WebFileSystemImpl* filesystem = |
| 246 WebFileSystemImpl::ThreadSpecificInstance(NULL); | 254 WebFileSystemImpl::ThreadSpecificInstance(NULL); |
| 247 if (!filesystem) | 255 if (!filesystem) |
| 248 return; | 256 return; |
| 249 | 257 |
| 250 WebFileSystemCallbacks* callbacks = | 258 WebFileSystemCallbacksType callbacks = |
| 251 filesystem->GetAndUnregisterCallbacks(callbacks_id); | 259 filesystem->GetAndUnregisterCallbacks(callbacks_id); |
| 252 DCHECK(callbacks); | |
| 253 | 260 |
| 254 WebFileInfo web_file_info; | 261 WebFileInfo web_file_info; |
| 255 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); | 262 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); |
| 256 web_file_info.platformPath = platform_path.AsUTF16Unsafe(); | 263 web_file_info.platformPath = platform_path.AsUTF16Unsafe(); |
| 257 callbacks->didCreateSnapshotFile(web_file_info); | 264 Wrapper(callbacks)->didCreateSnapshotFile(web_file_info); |
| 258 | 265 |
| 259 // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes | 266 // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes |
| 260 // non-bridge model. | 267 // non-bridge model. |
| 261 main_thread_loop->PostTask( | 268 main_thread_loop->PostTask( |
| 262 FROM_HERE, base::Bind(&DidReceiveSnapshotFile, request_id)); | 269 FROM_HERE, base::Bind(&DidReceiveSnapshotFile, request_id)); |
| 263 } | 270 } |
| 264 | 271 |
| 265 void CreateSnapshotFileCallbackAdapter( | 272 void CreateSnapshotFileCallbackAdapter( |
| 266 int thread_id, int callbacks_id, | 273 int thread_id, int callbacks_id, |
| 267 WaitableCallbackResults* waitable_results, | 274 WaitableCallbackResults* waitable_results, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 291 return filesystem; | 298 return filesystem; |
| 292 } | 299 } |
| 293 | 300 |
| 294 void WebFileSystemImpl::DeleteThreadSpecificInstance() { | 301 void WebFileSystemImpl::DeleteThreadSpecificInstance() { |
| 295 DCHECK(!WorkerTaskRunner::Instance()->CurrentWorkerId()); | 302 DCHECK(!WorkerTaskRunner::Instance()->CurrentWorkerId()); |
| 296 if (g_webfilesystem_tls.Pointer()->Get()) | 303 if (g_webfilesystem_tls.Pointer()->Get()) |
| 297 delete g_webfilesystem_tls.Pointer()->Get(); | 304 delete g_webfilesystem_tls.Pointer()->Get(); |
| 298 } | 305 } |
| 299 | 306 |
| 300 WebFileSystemImpl::WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop) | 307 WebFileSystemImpl::WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop) |
| 301 : main_thread_loop_(main_thread_loop) { | 308 : main_thread_loop_(main_thread_loop), |
| 309 next_callbacks_id_(0) { |
| 302 g_webfilesystem_tls.Pointer()->Set(this); | 310 g_webfilesystem_tls.Pointer()->Set(this); |
| 303 } | 311 } |
| 304 | 312 |
| 305 WebFileSystemImpl::~WebFileSystemImpl() { | 313 WebFileSystemImpl::~WebFileSystemImpl() { |
| 306 IDMap<WebFileSystemCallbacks>::iterator iter(&callbacks_); | 314 #if !defined(NON_SELFDESTRUCT_WEBFILESYSTEMCALLBACKS) |
| 307 while (!iter.IsAtEnd()) { | 315 for (CallbacksMap::iterator iter = callbacks_.begin(); |
| 308 iter.GetCurrentValue()->didFail(WebKit::WebFileErrorAbort); | 316 iter != callbacks_.end(); ++iter) { |
| 309 iter.Advance(); | 317 iter->second->didFail(WebKit::WebFileErrorAbort); |
| 310 } | 318 } |
| 319 #endif |
| 311 g_webfilesystem_tls.Pointer()->Set(NULL); | 320 g_webfilesystem_tls.Pointer()->Set(NULL); |
| 312 } | 321 } |
| 313 | 322 |
| 314 void WebFileSystemImpl::OnWorkerRunLoopStopped() { | 323 void WebFileSystemImpl::OnWorkerRunLoopStopped() { |
| 315 delete this; | 324 delete this; |
| 316 } | 325 } |
| 317 | 326 |
| 318 void WebFileSystemImpl::openFileSystem( | 327 void WebFileSystemImpl::openFileSystem( |
| 319 const WebKit::WebURL& storage_partition, | 328 const WebKit::WebURL& storage_partition, |
| 320 WebKit::WebFileSystemType type, | 329 WebKit::WebFileSystemType type, |
| 321 bool create, | 330 bool create, |
| 322 WebKit::WebFileSystemCallbacks* callbacks) { | 331 WebFileSystemCallbacksType callbacks) { |
| 323 int callbacks_id = RegisterCallbacks(callbacks); | 332 int callbacks_id = RegisterCallbacks(callbacks); |
| 324 WaitableCallbackResults* waitable_results = | 333 WaitableCallbackResults* waitable_results = |
| 325 WaitableCallbackResults::MaybeCreate(callbacks); | 334 WaitableCallbackResults::MaybeCreate(callbacks); |
| 326 CallDispatcherOnMainThread( | 335 CallDispatcherOnMainThread( |
| 327 main_thread_loop_.get(), | 336 main_thread_loop_.get(), |
| 328 &FileSystemDispatcher::OpenFileSystem, | 337 &FileSystemDispatcher::OpenFileSystem, |
| 329 MakeTuple(GURL(storage_partition), | 338 MakeTuple(GURL(storage_partition), |
| 330 static_cast<fileapi::FileSystemType>(type), | 339 static_cast<fileapi::FileSystemType>(type), |
| 331 0 /* size (not used) */, create, | 340 0 /* size (not used) */, create, |
| 332 base::Bind(&OpenFileSystemCallbackAdapter, | 341 base::Bind(&OpenFileSystemCallbackAdapter, |
| 333 CurrentWorkerId(), callbacks_id, | 342 CurrentWorkerId(), callbacks_id, |
| 334 base::Unretained(waitable_results)), | 343 base::Unretained(waitable_results)), |
| 335 base::Bind(&StatusCallbackAdapter, | 344 base::Bind(&StatusCallbackAdapter, |
| 336 CurrentWorkerId(), callbacks_id, | 345 CurrentWorkerId(), callbacks_id, |
| 337 base::Unretained(waitable_results))), | 346 base::Unretained(waitable_results))), |
| 338 make_scoped_ptr(waitable_results)); | 347 make_scoped_ptr(waitable_results)); |
| 339 } | 348 } |
| 340 | 349 |
| 341 void WebFileSystemImpl::deleteFileSystem( | 350 void WebFileSystemImpl::deleteFileSystem( |
| 342 const WebKit::WebURL& storage_partition, | 351 const WebKit::WebURL& storage_partition, |
| 343 WebKit::WebFileSystemType type, | 352 WebKit::WebFileSystemType type, |
| 344 WebKit::WebFileSystemCallbacks* callbacks) { | 353 WebFileSystemCallbacksType callbacks) { |
| 345 int callbacks_id = RegisterCallbacks(callbacks); | 354 int callbacks_id = RegisterCallbacks(callbacks); |
| 346 WaitableCallbackResults* waitable_results = | 355 WaitableCallbackResults* waitable_results = |
| 347 WaitableCallbackResults::MaybeCreate(callbacks); | 356 WaitableCallbackResults::MaybeCreate(callbacks); |
| 348 CallDispatcherOnMainThread( | 357 CallDispatcherOnMainThread( |
| 349 main_thread_loop_.get(), | 358 main_thread_loop_.get(), |
| 350 &FileSystemDispatcher::DeleteFileSystem, | 359 &FileSystemDispatcher::DeleteFileSystem, |
| 351 MakeTuple(GURL(storage_partition), | 360 MakeTuple(GURL(storage_partition), |
| 352 static_cast<fileapi::FileSystemType>(type), | 361 static_cast<fileapi::FileSystemType>(type), |
| 353 base::Bind(&StatusCallbackAdapter, | 362 base::Bind(&StatusCallbackAdapter, |
| 354 CurrentWorkerId(), callbacks_id, | 363 CurrentWorkerId(), callbacks_id, |
| 355 base::Unretained(waitable_results))), | 364 base::Unretained(waitable_results))), |
| 356 make_scoped_ptr(waitable_results)); | 365 make_scoped_ptr(waitable_results)); |
| 357 } | 366 } |
| 358 | 367 |
| 359 void WebFileSystemImpl::move( | 368 void WebFileSystemImpl::move( |
| 360 const WebKit::WebURL& src_path, | 369 const WebKit::WebURL& src_path, |
| 361 const WebKit::WebURL& dest_path, | 370 const WebKit::WebURL& dest_path, |
| 362 WebKit::WebFileSystemCallbacks* callbacks) { | 371 WebFileSystemCallbacksType callbacks) { |
| 363 int callbacks_id = RegisterCallbacks(callbacks); | 372 int callbacks_id = RegisterCallbacks(callbacks); |
| 364 WaitableCallbackResults* waitable_results = | 373 WaitableCallbackResults* waitable_results = |
| 365 WaitableCallbackResults::MaybeCreate(callbacks); | 374 WaitableCallbackResults::MaybeCreate(callbacks); |
| 366 CallDispatcherOnMainThread( | 375 CallDispatcherOnMainThread( |
| 367 main_thread_loop_.get(), | 376 main_thread_loop_.get(), |
| 368 &FileSystemDispatcher::Move, | 377 &FileSystemDispatcher::Move, |
| 369 MakeTuple(GURL(src_path), GURL(dest_path), | 378 MakeTuple(GURL(src_path), GURL(dest_path), |
| 370 base::Bind(&StatusCallbackAdapter, | 379 base::Bind(&StatusCallbackAdapter, |
| 371 CurrentWorkerId(), callbacks_id, | 380 CurrentWorkerId(), callbacks_id, |
| 372 base::Unretained(waitable_results))), | 381 base::Unretained(waitable_results))), |
| 373 make_scoped_ptr(waitable_results)); | 382 make_scoped_ptr(waitable_results)); |
| 374 } | 383 } |
| 375 | 384 |
| 376 void WebFileSystemImpl::copy( | 385 void WebFileSystemImpl::copy( |
| 377 const WebKit::WebURL& src_path, | 386 const WebKit::WebURL& src_path, |
| 378 const WebKit::WebURL& dest_path, | 387 const WebKit::WebURL& dest_path, |
| 379 WebKit::WebFileSystemCallbacks* callbacks) { | 388 WebFileSystemCallbacksType callbacks) { |
| 380 int callbacks_id = RegisterCallbacks(callbacks); | 389 int callbacks_id = RegisterCallbacks(callbacks); |
| 381 WaitableCallbackResults* waitable_results = | 390 WaitableCallbackResults* waitable_results = |
| 382 WaitableCallbackResults::MaybeCreate(callbacks); | 391 WaitableCallbackResults::MaybeCreate(callbacks); |
| 383 CallDispatcherOnMainThread( | 392 CallDispatcherOnMainThread( |
| 384 main_thread_loop_.get(), | 393 main_thread_loop_.get(), |
| 385 &FileSystemDispatcher::Copy, | 394 &FileSystemDispatcher::Copy, |
| 386 MakeTuple(GURL(src_path), GURL(dest_path), | 395 MakeTuple(GURL(src_path), GURL(dest_path), |
| 387 base::Bind(&StatusCallbackAdapter, | 396 base::Bind(&StatusCallbackAdapter, |
| 388 CurrentWorkerId(), callbacks_id, | 397 CurrentWorkerId(), callbacks_id, |
| 389 base::Unretained(waitable_results))), | 398 base::Unretained(waitable_results))), |
| 390 make_scoped_ptr(waitable_results)); | 399 make_scoped_ptr(waitable_results)); |
| 391 } | 400 } |
| 392 | 401 |
| 393 void WebFileSystemImpl::remove( | 402 void WebFileSystemImpl::remove( |
| 394 const WebKit::WebURL& path, | 403 const WebKit::WebURL& path, |
| 395 WebKit::WebFileSystemCallbacks* callbacks) { | 404 WebFileSystemCallbacksType callbacks) { |
| 396 int callbacks_id = RegisterCallbacks(callbacks); | 405 int callbacks_id = RegisterCallbacks(callbacks); |
| 397 WaitableCallbackResults* waitable_results = | 406 WaitableCallbackResults* waitable_results = |
| 398 WaitableCallbackResults::MaybeCreate(callbacks); | 407 WaitableCallbackResults::MaybeCreate(callbacks); |
| 399 CallDispatcherOnMainThread( | 408 CallDispatcherOnMainThread( |
| 400 main_thread_loop_.get(), | 409 main_thread_loop_.get(), |
| 401 &FileSystemDispatcher::Remove, | 410 &FileSystemDispatcher::Remove, |
| 402 MakeTuple(GURL(path), false /* recursive */, | 411 MakeTuple(GURL(path), false /* recursive */, |
| 403 base::Bind(&StatusCallbackAdapter, | 412 base::Bind(&StatusCallbackAdapter, |
| 404 CurrentWorkerId(), callbacks_id, | 413 CurrentWorkerId(), callbacks_id, |
| 405 base::Unretained(waitable_results))), | 414 base::Unretained(waitable_results))), |
| 406 make_scoped_ptr(waitable_results)); | 415 make_scoped_ptr(waitable_results)); |
| 407 } | 416 } |
| 408 | 417 |
| 409 void WebFileSystemImpl::removeRecursively( | 418 void WebFileSystemImpl::removeRecursively( |
| 410 const WebKit::WebURL& path, | 419 const WebKit::WebURL& path, |
| 411 WebKit::WebFileSystemCallbacks* callbacks) { | 420 WebFileSystemCallbacksType callbacks) { |
| 412 int callbacks_id = RegisterCallbacks(callbacks); | 421 int callbacks_id = RegisterCallbacks(callbacks); |
| 413 WaitableCallbackResults* waitable_results = | 422 WaitableCallbackResults* waitable_results = |
| 414 WaitableCallbackResults::MaybeCreate(callbacks); | 423 WaitableCallbackResults::MaybeCreate(callbacks); |
| 415 CallDispatcherOnMainThread( | 424 CallDispatcherOnMainThread( |
| 416 main_thread_loop_.get(), | 425 main_thread_loop_.get(), |
| 417 &FileSystemDispatcher::Remove, | 426 &FileSystemDispatcher::Remove, |
| 418 MakeTuple(GURL(path), true /* recursive */, | 427 MakeTuple(GURL(path), true /* recursive */, |
| 419 base::Bind(&StatusCallbackAdapter, | 428 base::Bind(&StatusCallbackAdapter, |
| 420 CurrentWorkerId(), callbacks_id, | 429 CurrentWorkerId(), callbacks_id, |
| 421 base::Unretained(waitable_results))), | 430 base::Unretained(waitable_results))), |
| 422 make_scoped_ptr(waitable_results)); | 431 make_scoped_ptr(waitable_results)); |
| 423 } | 432 } |
| 424 | 433 |
| 425 void WebFileSystemImpl::readMetadata( | 434 void WebFileSystemImpl::readMetadata( |
| 426 const WebKit::WebURL& path, | 435 const WebKit::WebURL& path, |
| 427 WebKit::WebFileSystemCallbacks* callbacks) { | 436 WebFileSystemCallbacksType callbacks) { |
| 428 int callbacks_id = RegisterCallbacks(callbacks); | 437 int callbacks_id = RegisterCallbacks(callbacks); |
| 429 WaitableCallbackResults* waitable_results = | 438 WaitableCallbackResults* waitable_results = |
| 430 WaitableCallbackResults::MaybeCreate(callbacks); | 439 WaitableCallbackResults::MaybeCreate(callbacks); |
| 431 CallDispatcherOnMainThread( | 440 CallDispatcherOnMainThread( |
| 432 main_thread_loop_.get(), | 441 main_thread_loop_.get(), |
| 433 &FileSystemDispatcher::ReadMetadata, | 442 &FileSystemDispatcher::ReadMetadata, |
| 434 MakeTuple(GURL(path), | 443 MakeTuple(GURL(path), |
| 435 base::Bind(&ReadMetadataCallbackAdapter, | 444 base::Bind(&ReadMetadataCallbackAdapter, |
| 436 CurrentWorkerId(), callbacks_id, | 445 CurrentWorkerId(), callbacks_id, |
| 437 base::Unretained(waitable_results)), | 446 base::Unretained(waitable_results)), |
| 438 base::Bind(&StatusCallbackAdapter, | 447 base::Bind(&StatusCallbackAdapter, |
| 439 CurrentWorkerId(), callbacks_id, | 448 CurrentWorkerId(), callbacks_id, |
| 440 base::Unretained(waitable_results))), | 449 base::Unretained(waitable_results))), |
| 441 make_scoped_ptr(waitable_results)); | 450 make_scoped_ptr(waitable_results)); |
| 442 } | 451 } |
| 443 | 452 |
| 444 void WebFileSystemImpl::createFile( | 453 void WebFileSystemImpl::createFile( |
| 445 const WebKit::WebURL& path, | 454 const WebKit::WebURL& path, |
| 446 bool exclusive, | 455 bool exclusive, |
| 447 WebKit::WebFileSystemCallbacks* callbacks) { | 456 WebFileSystemCallbacksType callbacks) { |
| 448 int callbacks_id = RegisterCallbacks(callbacks); | 457 int callbacks_id = RegisterCallbacks(callbacks); |
| 449 WaitableCallbackResults* waitable_results = | 458 WaitableCallbackResults* waitable_results = |
| 450 WaitableCallbackResults::MaybeCreate(callbacks); | 459 WaitableCallbackResults::MaybeCreate(callbacks); |
| 451 CallDispatcherOnMainThread( | 460 CallDispatcherOnMainThread( |
| 452 main_thread_loop_.get(), | 461 main_thread_loop_.get(), |
| 453 &FileSystemDispatcher::CreateFile, | 462 &FileSystemDispatcher::CreateFile, |
| 454 MakeTuple(GURL(path), exclusive, | 463 MakeTuple(GURL(path), exclusive, |
| 455 base::Bind(&StatusCallbackAdapter, | 464 base::Bind(&StatusCallbackAdapter, |
| 456 CurrentWorkerId(), callbacks_id, | 465 CurrentWorkerId(), callbacks_id, |
| 457 base::Unretained(waitable_results))), | 466 base::Unretained(waitable_results))), |
| 458 make_scoped_ptr(waitable_results)); | 467 make_scoped_ptr(waitable_results)); |
| 459 } | 468 } |
| 460 | 469 |
| 461 void WebFileSystemImpl::createDirectory( | 470 void WebFileSystemImpl::createDirectory( |
| 462 const WebKit::WebURL& path, | 471 const WebKit::WebURL& path, |
| 463 bool exclusive, | 472 bool exclusive, |
| 464 WebKit::WebFileSystemCallbacks* callbacks) { | 473 WebFileSystemCallbacksType callbacks) { |
| 465 int callbacks_id = RegisterCallbacks(callbacks); | 474 int callbacks_id = RegisterCallbacks(callbacks); |
| 466 WaitableCallbackResults* waitable_results = | 475 WaitableCallbackResults* waitable_results = |
| 467 WaitableCallbackResults::MaybeCreate(callbacks); | 476 WaitableCallbackResults::MaybeCreate(callbacks); |
| 468 CallDispatcherOnMainThread( | 477 CallDispatcherOnMainThread( |
| 469 main_thread_loop_.get(), | 478 main_thread_loop_.get(), |
| 470 &FileSystemDispatcher::CreateDirectory, | 479 &FileSystemDispatcher::CreateDirectory, |
| 471 MakeTuple(GURL(path), exclusive, false /* recursive */, | 480 MakeTuple(GURL(path), exclusive, false /* recursive */, |
| 472 base::Bind(&StatusCallbackAdapter, | 481 base::Bind(&StatusCallbackAdapter, |
| 473 CurrentWorkerId(), callbacks_id, | 482 CurrentWorkerId(), callbacks_id, |
| 474 base::Unretained(waitable_results))), | 483 base::Unretained(waitable_results))), |
| 475 make_scoped_ptr(waitable_results)); | 484 make_scoped_ptr(waitable_results)); |
| 476 } | 485 } |
| 477 | 486 |
| 478 void WebFileSystemImpl::fileExists( | 487 void WebFileSystemImpl::fileExists( |
| 479 const WebKit::WebURL& path, | 488 const WebKit::WebURL& path, |
| 480 WebKit::WebFileSystemCallbacks* callbacks) { | 489 WebFileSystemCallbacksType callbacks) { |
| 481 int callbacks_id = RegisterCallbacks(callbacks); | 490 int callbacks_id = RegisterCallbacks(callbacks); |
| 482 WaitableCallbackResults* waitable_results = | 491 WaitableCallbackResults* waitable_results = |
| 483 WaitableCallbackResults::MaybeCreate(callbacks); | 492 WaitableCallbackResults::MaybeCreate(callbacks); |
| 484 CallDispatcherOnMainThread( | 493 CallDispatcherOnMainThread( |
| 485 main_thread_loop_.get(), | 494 main_thread_loop_.get(), |
| 486 &FileSystemDispatcher::Exists, | 495 &FileSystemDispatcher::Exists, |
| 487 MakeTuple(GURL(path), false /* directory */, | 496 MakeTuple(GURL(path), false /* directory */, |
| 488 base::Bind(&StatusCallbackAdapter, | 497 base::Bind(&StatusCallbackAdapter, |
| 489 CurrentWorkerId(), callbacks_id, | 498 CurrentWorkerId(), callbacks_id, |
| 490 base::Unretained(waitable_results))), | 499 base::Unretained(waitable_results))), |
| 491 make_scoped_ptr(waitable_results)); | 500 make_scoped_ptr(waitable_results)); |
| 492 } | 501 } |
| 493 | 502 |
| 494 void WebFileSystemImpl::directoryExists( | 503 void WebFileSystemImpl::directoryExists( |
| 495 const WebKit::WebURL& path, | 504 const WebKit::WebURL& path, |
| 496 WebKit::WebFileSystemCallbacks* callbacks) { | 505 WebFileSystemCallbacksType callbacks) { |
| 497 int callbacks_id = RegisterCallbacks(callbacks); | 506 int callbacks_id = RegisterCallbacks(callbacks); |
| 498 WaitableCallbackResults* waitable_results = | 507 WaitableCallbackResults* waitable_results = |
| 499 WaitableCallbackResults::MaybeCreate(callbacks); | 508 WaitableCallbackResults::MaybeCreate(callbacks); |
| 500 CallDispatcherOnMainThread( | 509 CallDispatcherOnMainThread( |
| 501 main_thread_loop_.get(), | 510 main_thread_loop_.get(), |
| 502 &FileSystemDispatcher::Exists, | 511 &FileSystemDispatcher::Exists, |
| 503 MakeTuple(GURL(path), true /* directory */, | 512 MakeTuple(GURL(path), true /* directory */, |
| 504 base::Bind(&StatusCallbackAdapter, | 513 base::Bind(&StatusCallbackAdapter, |
| 505 CurrentWorkerId(), callbacks_id, | 514 CurrentWorkerId(), callbacks_id, |
| 506 base::Unretained(waitable_results))), | 515 base::Unretained(waitable_results))), |
| 507 make_scoped_ptr(waitable_results)); | 516 make_scoped_ptr(waitable_results)); |
| 508 } | 517 } |
| 509 | 518 |
| 510 void WebFileSystemImpl::readDirectory( | 519 void WebFileSystemImpl::readDirectory( |
| 511 const WebKit::WebURL& path, | 520 const WebKit::WebURL& path, |
| 512 WebKit::WebFileSystemCallbacks* callbacks) { | 521 WebFileSystemCallbacksType callbacks) { |
| 513 int callbacks_id = RegisterCallbacks(callbacks); | 522 int callbacks_id = RegisterCallbacks(callbacks); |
| 514 WaitableCallbackResults* waitable_results = | 523 WaitableCallbackResults* waitable_results = |
| 515 WaitableCallbackResults::MaybeCreate(callbacks); | 524 WaitableCallbackResults::MaybeCreate(callbacks); |
| 516 CallDispatcherOnMainThread( | 525 CallDispatcherOnMainThread( |
| 517 main_thread_loop_.get(), | 526 main_thread_loop_.get(), |
| 518 &FileSystemDispatcher::ReadDirectory, | 527 &FileSystemDispatcher::ReadDirectory, |
| 519 MakeTuple(GURL(path), | 528 MakeTuple(GURL(path), |
| 520 base::Bind(&ReadDirectoryCallbackAdapater, | 529 base::Bind(&ReadDirectoryCallbackAdapater, |
| 521 CurrentWorkerId(), callbacks_id, | 530 CurrentWorkerId(), callbacks_id, |
| 522 base::Unretained(waitable_results)), | 531 base::Unretained(waitable_results)), |
| 523 base::Bind(&StatusCallbackAdapter, | 532 base::Bind(&StatusCallbackAdapter, |
| 524 CurrentWorkerId(), callbacks_id, | 533 CurrentWorkerId(), callbacks_id, |
| 525 base::Unretained(waitable_results))), | 534 base::Unretained(waitable_results))), |
| 526 make_scoped_ptr(waitable_results)); | 535 make_scoped_ptr(waitable_results)); |
| 527 } | 536 } |
| 528 | 537 |
| 529 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( | 538 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( |
| 530 const WebURL& path, WebKit::WebFileWriterClient* client) { | 539 const WebURL& path, WebKit::WebFileWriterClient* client) { |
| 531 return new WebFileWriterImpl(GURL(path), client, | 540 return new WebFileWriterImpl(GURL(path), client, |
| 532 WebFileWriterImpl::TYPE_ASYNC, | 541 WebFileWriterImpl::TYPE_ASYNC, |
| 533 main_thread_loop_.get()); | 542 main_thread_loop_.get()); |
| 534 } | 543 } |
| 535 | 544 |
| 536 void WebFileSystemImpl::createFileWriter( | 545 void WebFileSystemImpl::createFileWriter( |
| 537 const WebURL& path, | 546 const WebURL& path, |
| 538 WebKit::WebFileWriterClient* client, | 547 WebKit::WebFileWriterClient* client, |
| 539 WebKit::WebFileSystemCallbacks* callbacks) { | 548 WebFileSystemCallbacksType callbacks) { |
| 540 int callbacks_id = RegisterCallbacks(callbacks); | 549 int callbacks_id = RegisterCallbacks(callbacks); |
| 541 WaitableCallbackResults* waitable_results = | 550 WaitableCallbackResults* waitable_results = |
| 542 WaitableCallbackResults::MaybeCreate(callbacks); | 551 WaitableCallbackResults::MaybeCreate(callbacks); |
| 543 CallDispatcherOnMainThread( | 552 CallDispatcherOnMainThread( |
| 544 main_thread_loop_.get(), | 553 main_thread_loop_.get(), |
| 545 &FileSystemDispatcher::ReadMetadata, | 554 &FileSystemDispatcher::ReadMetadata, |
| 546 MakeTuple(GURL(path), | 555 MakeTuple(GURL(path), |
| 547 base::Bind(&CreateFileWriterCallbackAdapter, | 556 base::Bind(&CreateFileWriterCallbackAdapter, |
| 548 CurrentWorkerId(), callbacks_id, | 557 CurrentWorkerId(), callbacks_id, |
| 549 base::Unretained(waitable_results), | 558 base::Unretained(waitable_results), |
| 550 main_thread_loop_, GURL(path), client), | 559 main_thread_loop_, GURL(path), client), |
| 551 base::Bind(&StatusCallbackAdapter, | 560 base::Bind(&StatusCallbackAdapter, |
| 552 CurrentWorkerId(), callbacks_id, | 561 CurrentWorkerId(), callbacks_id, |
| 553 base::Unretained(waitable_results))), | 562 base::Unretained(waitable_results))), |
| 554 make_scoped_ptr(waitable_results)); | 563 make_scoped_ptr(waitable_results)); |
| 555 } | 564 } |
| 556 | 565 |
| 557 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( | 566 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( |
| 558 const WebKit::WebURL& path, | 567 const WebKit::WebURL& path, |
| 559 WebKit::WebFileSystemCallbacks* callbacks) { | 568 WebFileSystemCallbacksType callbacks) { |
| 560 int callbacks_id = RegisterCallbacks(callbacks); | 569 int callbacks_id = RegisterCallbacks(callbacks); |
| 561 WaitableCallbackResults* waitable_results = | 570 WaitableCallbackResults* waitable_results = |
| 562 WaitableCallbackResults::MaybeCreate(callbacks); | 571 WaitableCallbackResults::MaybeCreate(callbacks); |
| 563 CallDispatcherOnMainThread( | 572 CallDispatcherOnMainThread( |
| 564 main_thread_loop_.get(), | 573 main_thread_loop_.get(), |
| 565 &FileSystemDispatcher::CreateSnapshotFile, | 574 &FileSystemDispatcher::CreateSnapshotFile, |
| 566 MakeTuple(GURL(path), | 575 MakeTuple(GURL(path), |
| 567 base::Bind(&CreateSnapshotFileCallbackAdapter, | 576 base::Bind(&CreateSnapshotFileCallbackAdapter, |
| 568 CurrentWorkerId(), callbacks_id, | 577 CurrentWorkerId(), callbacks_id, |
| 569 base::Unretained(waitable_results), | 578 base::Unretained(waitable_results), |
| 570 main_thread_loop_), | 579 main_thread_loop_), |
| 571 base::Bind(&StatusCallbackAdapter, | 580 base::Bind(&StatusCallbackAdapter, |
| 572 CurrentWorkerId(), callbacks_id, | 581 CurrentWorkerId(), callbacks_id, |
| 573 base::Unretained(waitable_results))), | 582 base::Unretained(waitable_results))), |
| 574 make_scoped_ptr(waitable_results)); | 583 make_scoped_ptr(waitable_results)); |
| 575 } | 584 } |
| 576 | 585 |
| 577 int WebFileSystemImpl::RegisterCallbacks(WebFileSystemCallbacks* callbacks) { | 586 int WebFileSystemImpl::RegisterCallbacks(WebFileSystemCallbacksType callbacks) { |
| 578 return callbacks_.Add(callbacks); | 587 DCHECK(CalledOnValidThread()); |
| 588 int id = next_callbacks_id_++; |
| 589 callbacks_[id] = callbacks; |
| 590 return id; |
| 579 } | 591 } |
| 580 | 592 |
| 581 WebFileSystemCallbacks* WebFileSystemImpl::GetAndUnregisterCallbacks( | 593 WebFileSystemCallbacksType WebFileSystemImpl::GetAndUnregisterCallbacks( |
| 582 int callbacks_id) { | 594 int callbacks_id) { |
| 583 WebFileSystemCallbacks* callbacks = callbacks_.Lookup(callbacks_id); | 595 DCHECK(CalledOnValidThread()); |
| 584 callbacks_.Remove(callbacks_id); | 596 CallbacksMap::iterator found = callbacks_.find(callbacks_id); |
| 597 DCHECK(found != callbacks_.end()); |
| 598 WebFileSystemCallbacksType callbacks = found->second; |
| 599 callbacks_.erase(found); |
| 585 return callbacks; | 600 return callbacks; |
| 586 } | 601 } |
| 587 | 602 |
| 588 } // namespace content | 603 } // namespace content |
| OLD | NEW |