| 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" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/threading/thread_local.h" | 13 #include "base/threading/thread_local.h" |
| 13 #include "content/child/child_thread.h" | 14 #include "content/child/child_thread.h" |
| 14 #include "content/child/fileapi/file_system_dispatcher.h" | 15 #include "content/child/fileapi/file_system_dispatcher.h" |
| 15 #include "content/child/fileapi/webfilesystem_callback_adapters.h" | 16 #include "content/child/fileapi/webfilesystem_callback_adapters.h" |
| 16 #include "content/child/fileapi/webfilewriter_impl.h" | 17 #include "content/child/fileapi/webfilewriter_impl.h" |
| 17 #include "content/common/fileapi/file_system_messages.h" | 18 #include "content/common/fileapi/file_system_messages.h" |
| 18 #include "third_party/WebKit/public/platform/WebFileInfo.h" | 19 #include "third_party/WebKit/public/platform/WebFileInfo.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 "third_party/WebKit/public/web/WebFileSystemCallbacks.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 private: | 88 private: |
| 88 CallbacksMap() { | 89 CallbacksMap() { |
| 89 g_callbacks_map_tls.Pointer()->Set(this); | 90 g_callbacks_map_tls.Pointer()->Set(this); |
| 90 } | 91 } |
| 91 | 92 |
| 92 IDMap<WebFileSystemCallbacks> callbacks_; | 93 IDMap<WebFileSystemCallbacks> callbacks_; |
| 93 | 94 |
| 94 DISALLOW_COPY_AND_ASSIGN(CallbacksMap); | 95 DISALLOW_COPY_AND_ASSIGN(CallbacksMap); |
| 95 }; | 96 }; |
| 96 | 97 |
| 98 class WaitableCallbackResults { |
| 99 public: |
| 100 static WaitableCallbackResults* MaybeCreate( |
| 101 WebKit::WebFileSystemCallbacks* callbacks) { |
| 102 if (callbacks->shouldBlockUntilCompletion()) |
| 103 return new WaitableCallbackResults; |
| 104 return NULL; |
| 105 } |
| 106 ~WaitableCallbackResults() {} |
| 107 |
| 108 void SetResultsAndSignal(const base::Closure& results_closure) { |
| 109 results_closure_ = results_closure; |
| 110 event_->Signal(); |
| 111 } |
| 112 |
| 113 void WaitAndRun() { |
| 114 event_->Wait(); |
| 115 DCHECK(!results_closure_.is_null()); |
| 116 results_closure_.Run(); |
| 117 } |
| 118 |
| 119 private: |
| 120 WaitableCallbackResults() : event_(new base::WaitableEvent(true, false)) {} |
| 121 |
| 122 base::WaitableEvent* event_; |
| 123 base::Closure results_closure_; |
| 124 DISALLOW_COPY_AND_ASSIGN(WaitableCallbackResults); |
| 125 }; |
| 126 |
| 97 void DidReceiveSnapshotFile(int request_id) { | 127 void DidReceiveSnapshotFile(int request_id) { |
| 98 if (ChildThread::current()) | 128 if (ChildThread::current()) |
| 99 ChildThread::current()->Send( | 129 ChildThread::current()->Send( |
| 100 new FileSystemHostMsg_DidReceiveSnapshotFile(request_id)); | 130 new FileSystemHostMsg_DidReceiveSnapshotFile(request_id)); |
| 101 } | 131 } |
| 102 | 132 |
| 103 int CurrentWorkerId() { | 133 int CurrentWorkerId() { |
| 104 return WorkerTaskRunner::Instance()->CurrentWorkerId(); | 134 return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
| 105 } | 135 } |
| 106 | 136 |
| 107 template <typename Method, typename Params> | 137 template <typename Method, typename Params> |
| 108 void CallDispatcherOnMainThread( | 138 void CallDispatcherOnMainThread( |
| 109 base::MessageLoopProxy* loop, | 139 base::MessageLoopProxy* loop, |
| 110 Method method, const Params& params) { | 140 Method method, const Params& params, |
| 141 scoped_ptr<WaitableCallbackResults> waitable_results) { |
| 142 scoped_ptr<WaitableCallbackResults> null_waitable; |
| 111 if (!loop->RunsTasksOnCurrentThread()) { | 143 if (!loop->RunsTasksOnCurrentThread()) { |
| 112 loop->PostTask(FROM_HERE, | 144 loop->PostTask(FROM_HERE, |
| 113 base::Bind(&CallDispatcherOnMainThread<Method, Params>, | 145 base::Bind(&CallDispatcherOnMainThread<Method, Params>, |
| 114 make_scoped_refptr(loop), method, params)); | 146 make_scoped_refptr(loop), method, params, |
| 115 return; | 147 base::Passed(&null_waitable))); |
| 148 if (!waitable_results) |
| 149 return; |
| 150 waitable_results->WaitAndRun(); |
| 116 } | 151 } |
| 117 if (!ChildThread::current() || | 152 if (!ChildThread::current() || |
| 118 !ChildThread::current()->file_system_dispatcher()) | 153 !ChildThread::current()->file_system_dispatcher()) |
| 119 return; | 154 return; |
| 120 | 155 |
| 156 DCHECK(!waitable_results); |
| 121 DispatchToMethod(ChildThread::current()->file_system_dispatcher(), | 157 DispatchToMethod(ChildThread::current()->file_system_dispatcher(), |
| 122 method, params); | 158 method, params); |
| 123 } | 159 } |
| 124 | 160 |
| 161 // Run WebFileSystemCallbacks's |method| with |params|. |
| 125 template <typename Method, typename Params> | 162 template <typename Method, typename Params> |
| 126 void CallbackFileSystemCallbacks( | 163 void RunCallbacks(int callbacks_id, Method method, const Params& params) { |
| 127 int thread_id, int callbacks_id, | |
| 128 Method method, const Params& params) { | |
| 129 if (thread_id != CurrentWorkerId()) { | |
| 130 WorkerTaskRunner::Instance()->PostTask( | |
| 131 thread_id, | |
| 132 base::Bind(&CallbackFileSystemCallbacks<Method, Params>, | |
| 133 thread_id, callbacks_id, method, params)); | |
| 134 return; | |
| 135 } | |
| 136 if (!CallbacksMap::Get()) | 164 if (!CallbacksMap::Get()) |
| 137 return; | 165 return; |
| 138 | |
| 139 WebFileSystemCallbacks* callbacks = | 166 WebFileSystemCallbacks* callbacks = |
| 140 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); | 167 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); |
| 141 DCHECK(callbacks); | 168 DCHECK(callbacks); |
| 142 DispatchToMethod(callbacks, method, params); | 169 DispatchToMethod(callbacks, method, params); |
| 143 } | 170 } |
| 144 | 171 |
| 172 void DispatchResultsClosure(int thread_id, int callbacks_id, |
| 173 WaitableCallbackResults* waitable_results, |
| 174 const base::Closure& results_closure) { |
| 175 if (thread_id != CurrentWorkerId()) { |
| 176 if (waitable_results) { |
| 177 waitable_results->SetResultsAndSignal(results_closure); |
| 178 return; |
| 179 } |
| 180 WorkerTaskRunner::Instance()->PostTask(thread_id, results_closure); |
| 181 return; |
| 182 } |
| 183 results_closure.Run(); |
| 184 } |
| 185 |
| 186 template <typename Method, typename Params> |
| 187 void CallbackFileSystemCallbacks( |
| 188 int thread_id, int callbacks_id, |
| 189 WaitableCallbackResults* waitable_results, |
| 190 Method method, const Params& params) { |
| 191 DispatchResultsClosure( |
| 192 thread_id, callbacks_id, waitable_results, |
| 193 base::Bind(&RunCallbacks<Method, Params>, callbacks_id, method, params)); |
| 194 } |
| 195 |
| 145 void StatusCallbackAdapter(int thread_id, int callbacks_id, | 196 void StatusCallbackAdapter(int thread_id, int callbacks_id, |
| 197 WaitableCallbackResults* waitable_results, |
| 146 base::PlatformFileError error) { | 198 base::PlatformFileError error) { |
| 147 if (error == base::PLATFORM_FILE_OK) { | 199 if (error == base::PLATFORM_FILE_OK) { |
| 148 CallbackFileSystemCallbacks( | 200 CallbackFileSystemCallbacks( |
| 149 thread_id, callbacks_id, | 201 thread_id, callbacks_id, waitable_results, |
| 150 &WebFileSystemCallbacks::didSucceed, MakeTuple()); | 202 &WebFileSystemCallbacks::didSucceed, MakeTuple()); |
| 151 } else { | 203 } else { |
| 152 CallbackFileSystemCallbacks( | 204 CallbackFileSystemCallbacks( |
| 153 thread_id, callbacks_id, | 205 thread_id, callbacks_id, waitable_results, |
| 154 &WebFileSystemCallbacks::didFail, | 206 &WebFileSystemCallbacks::didFail, |
| 155 MakeTuple(fileapi::PlatformFileErrorToWebFileError(error))); | 207 MakeTuple(fileapi::PlatformFileErrorToWebFileError(error))); |
| 156 } | 208 } |
| 157 } | 209 } |
| 158 | 210 |
| 159 void ReadMetadataCallbackAdapter(int thread_id, int callbacks_id, | 211 void ReadMetadataCallbackAdapter(int thread_id, int callbacks_id, |
| 212 WaitableCallbackResults* waitable_results, |
| 160 const base::PlatformFileInfo& file_info) { | 213 const base::PlatformFileInfo& file_info) { |
| 161 WebFileInfo web_file_info; | 214 WebFileInfo web_file_info; |
| 162 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); | 215 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); |
| 163 CallbackFileSystemCallbacks( | 216 CallbackFileSystemCallbacks( |
| 164 thread_id, callbacks_id, | 217 thread_id, callbacks_id, waitable_results, |
| 165 &WebFileSystemCallbacks::didReadMetadata, | 218 &WebFileSystemCallbacks::didReadMetadata, |
| 166 MakeTuple(web_file_info)); | 219 MakeTuple(web_file_info)); |
| 167 } | 220 } |
| 168 | 221 |
| 169 void ReadDirectoryCallbackAdapater( | 222 void ReadDirectoryCallbackAdapater( |
| 170 int thread_id, int callbacks_id, | 223 int thread_id, int callbacks_id, WaitableCallbackResults* waitable_results, |
| 171 const std::vector<fileapi::DirectoryEntry>& entries, | 224 const std::vector<fileapi::DirectoryEntry>& entries, |
| 172 bool has_more) { | 225 bool has_more) { |
| 173 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); | 226 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); |
| 174 for (size_t i = 0; i < entries.size(); i++) { | 227 for (size_t i = 0; i < entries.size(); i++) { |
| 175 file_system_entries[i].name = | 228 file_system_entries[i].name = |
| 176 base::FilePath(entries[i].name).AsUTF16Unsafe(); | 229 base::FilePath(entries[i].name).AsUTF16Unsafe(); |
| 177 file_system_entries[i].isDirectory = entries[i].is_directory; | 230 file_system_entries[i].isDirectory = entries[i].is_directory; |
| 178 } | 231 } |
| 179 CallbackFileSystemCallbacks( | 232 CallbackFileSystemCallbacks( |
| 180 thread_id, callbacks_id, | 233 thread_id, callbacks_id, waitable_results, |
| 181 &WebFileSystemCallbacks::didReadDirectory, | 234 &WebFileSystemCallbacks::didReadDirectory, |
| 182 MakeTuple(file_system_entries, has_more)); | 235 MakeTuple(file_system_entries, has_more)); |
| 183 } | 236 } |
| 184 | 237 |
| 185 void CreateFileWriterCallbackAdapter( | 238 void DidCreateFileWriter( |
| 186 int thread_id, int callbacks_id, | 239 int callbacks_id, |
| 187 base::MessageLoopProxy* main_thread_loop, | |
| 188 const GURL& path, | 240 const GURL& path, |
| 189 WebKit::WebFileWriterClient* client, | 241 WebKit::WebFileWriterClient* client, |
| 242 base::MessageLoopProxy* main_thread_loop, |
| 190 const base::PlatformFileInfo& file_info) { | 243 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()) | 244 if (!CallbacksMap::Get()) |
| 202 return; | 245 return; |
| 203 | 246 |
| 204 WebFileSystemCallbacks* callbacks = | 247 WebFileSystemCallbacks* callbacks = |
| 205 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); | 248 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); |
| 206 DCHECK(callbacks); | 249 DCHECK(callbacks); |
| 207 | 250 |
| 208 if (file_info.is_directory || file_info.size < 0) { | 251 if (file_info.is_directory || file_info.size < 0) { |
| 209 callbacks->didFail(WebKit::WebFileErrorInvalidState); | 252 callbacks->didFail(WebKit::WebFileErrorInvalidState); |
| 210 return; | 253 return; |
| 211 } | 254 } |
| 212 callbacks->didCreateFileWriter( | 255 callbacks->didCreateFileWriter( |
| 213 new WebFileWriterImpl(path, client, main_thread_loop), file_info.size); | 256 new WebFileWriterImpl(path, client, main_thread_loop), file_info.size); |
| 214 } | 257 } |
| 215 | 258 |
| 216 void CreateSnapshotFileCallbackAdapter( | 259 void CreateFileWriterCallbackAdapter( |
| 217 int thread_id, int callbacks_id, | 260 int thread_id, int callbacks_id, |
| 261 WaitableCallbackResults* waitable_results, |
| 262 base::MessageLoopProxy* main_thread_loop, |
| 263 const GURL& path, |
| 264 WebKit::WebFileWriterClient* client, |
| 265 const base::PlatformFileInfo& file_info) { |
| 266 DispatchResultsClosure( |
| 267 thread_id, callbacks_id, waitable_results, |
| 268 base::Bind(&DidCreateFileWriter, callbacks_id, path, client, |
| 269 make_scoped_refptr(main_thread_loop), file_info)); |
| 270 } |
| 271 |
| 272 void DidCreateSnapshotFile( |
| 273 int callbacks_id, |
| 218 base::MessageLoopProxy* main_thread_loop, | 274 base::MessageLoopProxy* main_thread_loop, |
| 219 const base::PlatformFileInfo& file_info, | 275 const base::PlatformFileInfo& file_info, |
| 220 const base::FilePath& platform_path, | 276 const base::FilePath& platform_path, |
| 221 int request_id) { | 277 int request_id) { |
| 222 if (thread_id != CurrentWorkerId()) { | |
| 223 WorkerTaskRunner::Instance()->PostTask( | |
| 224 thread_id, | |
| 225 base::Bind(&CreateSnapshotFileCallbackAdapter, | |
| 226 thread_id, callbacks_id, | |
| 227 make_scoped_refptr(main_thread_loop), | |
| 228 file_info, platform_path, request_id)); | |
| 229 return; | |
| 230 } | |
| 231 | |
| 232 if (!CallbacksMap::Get()) | 278 if (!CallbacksMap::Get()) |
| 233 return; | 279 return; |
| 234 | 280 |
| 235 WebFileSystemCallbacks* callbacks = | 281 WebFileSystemCallbacks* callbacks = |
| 236 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); | 282 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); |
| 237 DCHECK(callbacks); | 283 DCHECK(callbacks); |
| 238 | 284 |
| 239 WebFileInfo web_file_info; | 285 WebFileInfo web_file_info; |
| 240 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); | 286 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); |
| 241 web_file_info.platformPath = platform_path.AsUTF16Unsafe(); | 287 web_file_info.platformPath = platform_path.AsUTF16Unsafe(); |
| 242 callbacks->didCreateSnapshotFile(web_file_info); | 288 callbacks->didCreateSnapshotFile(web_file_info); |
| 243 | 289 |
| 244 // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes | 290 // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes |
| 245 // non-bridge model. | 291 // non-bridge model. |
| 246 main_thread_loop->PostTask( | 292 main_thread_loop->PostTask( |
| 247 FROM_HERE, base::Bind(&DidReceiveSnapshotFile, request_id)); | 293 FROM_HERE, base::Bind(&DidReceiveSnapshotFile, request_id)); |
| 248 } | 294 } |
| 249 | 295 |
| 296 void CreateSnapshotFileCallbackAdapter( |
| 297 int thread_id, int callbacks_id, |
| 298 WaitableCallbackResults* waitable_results, |
| 299 base::MessageLoopProxy* main_thread_loop, |
| 300 const base::PlatformFileInfo& file_info, |
| 301 const base::FilePath& platform_path, |
| 302 int request_id) { |
| 303 DispatchResultsClosure( |
| 304 thread_id, callbacks_id, waitable_results, |
| 305 base::Bind(&DidCreateSnapshotFile, callbacks_id, |
| 306 make_scoped_refptr(main_thread_loop), |
| 307 file_info, platform_path, request_id)); |
| 308 } |
| 309 |
| 250 } // namespace | 310 } // namespace |
| 251 | 311 |
| 252 WebFileSystemImpl::~WebFileSystemImpl() { | 312 WebFileSystemImpl::~WebFileSystemImpl() { |
| 253 } | 313 } |
| 254 | 314 |
| 255 WebFileSystemImpl::WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop) | 315 WebFileSystemImpl::WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop) |
| 256 : main_thread_loop_(main_thread_loop) { | 316 : main_thread_loop_(main_thread_loop) { |
| 257 } | 317 } |
| 258 | 318 |
| 259 void WebFileSystemImpl::move( | 319 void WebFileSystemImpl::move( |
| 260 const WebKit::WebURL& src_path, | 320 const WebKit::WebURL& src_path, |
| 261 const WebKit::WebURL& dest_path, | 321 const WebKit::WebURL& dest_path, |
| 262 WebKit::WebFileSystemCallbacks* callbacks) { | 322 WebKit::WebFileSystemCallbacks* callbacks) { |
| 263 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 323 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 324 WaitableCallbackResults* waitable_results = |
| 325 WaitableCallbackResults::MaybeCreate(callbacks); |
| 264 CallDispatcherOnMainThread( | 326 CallDispatcherOnMainThread( |
| 265 main_thread_loop_.get(), | 327 main_thread_loop_.get(), |
| 266 &FileSystemDispatcher::Move, | 328 &FileSystemDispatcher::Move, |
| 267 MakeTuple(GURL(src_path), GURL(dest_path), | 329 MakeTuple(GURL(src_path), GURL(dest_path), |
| 268 base::Bind(&StatusCallbackAdapter, | 330 base::Bind(&StatusCallbackAdapter, |
| 269 CurrentWorkerId(), callbacks_id))); | 331 CurrentWorkerId(), callbacks_id, |
| 332 base::Unretained(waitable_results))), |
| 333 make_scoped_ptr(waitable_results)); |
| 270 } | 334 } |
| 271 | 335 |
| 272 void WebFileSystemImpl::copy( | 336 void WebFileSystemImpl::copy( |
| 273 const WebKit::WebURL& src_path, | 337 const WebKit::WebURL& src_path, |
| 274 const WebKit::WebURL& dest_path, | 338 const WebKit::WebURL& dest_path, |
| 275 WebKit::WebFileSystemCallbacks* callbacks) { | 339 WebKit::WebFileSystemCallbacks* callbacks) { |
| 276 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 340 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 341 WaitableCallbackResults* waitable_results = |
| 342 WaitableCallbackResults::MaybeCreate(callbacks); |
| 277 CallDispatcherOnMainThread( | 343 CallDispatcherOnMainThread( |
| 278 main_thread_loop_.get(), | 344 main_thread_loop_.get(), |
| 279 &FileSystemDispatcher::Copy, | 345 &FileSystemDispatcher::Copy, |
| 280 MakeTuple(GURL(src_path), GURL(dest_path), | 346 MakeTuple(GURL(src_path), GURL(dest_path), |
| 281 base::Bind(&StatusCallbackAdapter, | 347 base::Bind(&StatusCallbackAdapter, |
| 282 CurrentWorkerId(), callbacks_id))); | 348 CurrentWorkerId(), callbacks_id, |
| 349 base::Unretained(waitable_results))), |
| 350 make_scoped_ptr(waitable_results)); |
| 283 } | 351 } |
| 284 | 352 |
| 285 void WebFileSystemImpl::remove( | 353 void WebFileSystemImpl::remove( |
| 286 const WebKit::WebURL& path, | 354 const WebKit::WebURL& path, |
| 287 WebKit::WebFileSystemCallbacks* callbacks) { | 355 WebKit::WebFileSystemCallbacks* callbacks) { |
| 288 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 356 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 357 WaitableCallbackResults* waitable_results = |
| 358 WaitableCallbackResults::MaybeCreate(callbacks); |
| 289 CallDispatcherOnMainThread( | 359 CallDispatcherOnMainThread( |
| 290 main_thread_loop_.get(), | 360 main_thread_loop_.get(), |
| 291 &FileSystemDispatcher::Remove, | 361 &FileSystemDispatcher::Remove, |
| 292 MakeTuple(GURL(path), false /* recursive */, | 362 MakeTuple(GURL(path), false /* recursive */, |
| 293 base::Bind(&StatusCallbackAdapter, | 363 base::Bind(&StatusCallbackAdapter, |
| 294 CurrentWorkerId(), callbacks_id))); | 364 CurrentWorkerId(), callbacks_id, |
| 365 base::Unretained(waitable_results))), |
| 366 make_scoped_ptr(waitable_results)); |
| 295 } | 367 } |
| 296 | 368 |
| 297 void WebFileSystemImpl::removeRecursively( | 369 void WebFileSystemImpl::removeRecursively( |
| 298 const WebKit::WebURL& path, | 370 const WebKit::WebURL& path, |
| 299 WebKit::WebFileSystemCallbacks* callbacks) { | 371 WebKit::WebFileSystemCallbacks* callbacks) { |
| 300 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 372 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 373 WaitableCallbackResults* waitable_results = |
| 374 WaitableCallbackResults::MaybeCreate(callbacks); |
| 301 CallDispatcherOnMainThread( | 375 CallDispatcherOnMainThread( |
| 302 main_thread_loop_.get(), | 376 main_thread_loop_.get(), |
| 303 &FileSystemDispatcher::Remove, | 377 &FileSystemDispatcher::Remove, |
| 304 MakeTuple(GURL(path), true /* recursive */, | 378 MakeTuple(GURL(path), true /* recursive */, |
| 305 base::Bind(&StatusCallbackAdapter, | 379 base::Bind(&StatusCallbackAdapter, |
| 306 CurrentWorkerId(), callbacks_id))); | 380 CurrentWorkerId(), callbacks_id, |
| 381 base::Unretained(waitable_results))), |
| 382 make_scoped_ptr(waitable_results)); |
| 307 } | 383 } |
| 308 | 384 |
| 309 void WebFileSystemImpl::readMetadata( | 385 void WebFileSystemImpl::readMetadata( |
| 310 const WebKit::WebURL& path, | 386 const WebKit::WebURL& path, |
| 311 WebKit::WebFileSystemCallbacks* callbacks) { | 387 WebKit::WebFileSystemCallbacks* callbacks) { |
| 312 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 388 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 389 WaitableCallbackResults* waitable_results = |
| 390 WaitableCallbackResults::MaybeCreate(callbacks); |
| 313 CallDispatcherOnMainThread( | 391 CallDispatcherOnMainThread( |
| 314 main_thread_loop_.get(), | 392 main_thread_loop_.get(), |
| 315 &FileSystemDispatcher::ReadMetadata, | 393 &FileSystemDispatcher::ReadMetadata, |
| 316 MakeTuple(GURL(path), | 394 MakeTuple(GURL(path), |
| 317 base::Bind(&ReadMetadataCallbackAdapter, | 395 base::Bind(&ReadMetadataCallbackAdapter, |
| 318 CurrentWorkerId(), callbacks_id), | 396 CurrentWorkerId(), callbacks_id, |
| 397 base::Unretained(waitable_results)), |
| 319 base::Bind(&StatusCallbackAdapter, | 398 base::Bind(&StatusCallbackAdapter, |
| 320 CurrentWorkerId(), callbacks_id))); | 399 CurrentWorkerId(), callbacks_id, |
| 400 base::Unretained(waitable_results))), |
| 401 make_scoped_ptr(waitable_results)); |
| 321 } | 402 } |
| 322 | 403 |
| 323 void WebFileSystemImpl::createFile( | 404 void WebFileSystemImpl::createFile( |
| 324 const WebKit::WebURL& path, | 405 const WebKit::WebURL& path, |
| 325 bool exclusive, | 406 bool exclusive, |
| 326 WebKit::WebFileSystemCallbacks* callbacks) { | 407 WebKit::WebFileSystemCallbacks* callbacks) { |
| 327 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 408 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 409 WaitableCallbackResults* waitable_results = |
| 410 WaitableCallbackResults::MaybeCreate(callbacks); |
| 328 CallDispatcherOnMainThread( | 411 CallDispatcherOnMainThread( |
| 329 main_thread_loop_.get(), | 412 main_thread_loop_.get(), |
| 330 &FileSystemDispatcher::CreateFile, | 413 &FileSystemDispatcher::CreateFile, |
| 331 MakeTuple(GURL(path), exclusive, | 414 MakeTuple(GURL(path), exclusive, |
| 332 base::Bind(&StatusCallbackAdapter, | 415 base::Bind(&StatusCallbackAdapter, |
| 333 CurrentWorkerId(), callbacks_id))); | 416 CurrentWorkerId(), callbacks_id, |
| 417 base::Unretained(waitable_results))), |
| 418 make_scoped_ptr(waitable_results)); |
| 334 } | 419 } |
| 335 | 420 |
| 336 void WebFileSystemImpl::createDirectory( | 421 void WebFileSystemImpl::createDirectory( |
| 337 const WebKit::WebURL& path, | 422 const WebKit::WebURL& path, |
| 338 bool exclusive, | 423 bool exclusive, |
| 339 WebKit::WebFileSystemCallbacks* callbacks) { | 424 WebKit::WebFileSystemCallbacks* callbacks) { |
| 340 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 425 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 426 WaitableCallbackResults* waitable_results = |
| 427 WaitableCallbackResults::MaybeCreate(callbacks); |
| 341 CallDispatcherOnMainThread( | 428 CallDispatcherOnMainThread( |
| 342 main_thread_loop_.get(), | 429 main_thread_loop_.get(), |
| 343 &FileSystemDispatcher::CreateDirectory, | 430 &FileSystemDispatcher::CreateDirectory, |
| 344 MakeTuple(GURL(path), exclusive, false /* recursive */, | 431 MakeTuple(GURL(path), exclusive, false /* recursive */, |
| 345 base::Bind(&StatusCallbackAdapter, | 432 base::Bind(&StatusCallbackAdapter, |
| 346 CurrentWorkerId(), callbacks_id))); | 433 CurrentWorkerId(), callbacks_id, |
| 434 base::Unretained(waitable_results))), |
| 435 make_scoped_ptr(waitable_results)); |
| 347 } | 436 } |
| 348 | 437 |
| 349 void WebFileSystemImpl::fileExists( | 438 void WebFileSystemImpl::fileExists( |
| 350 const WebKit::WebURL& path, | 439 const WebKit::WebURL& path, |
| 351 WebKit::WebFileSystemCallbacks* callbacks) { | 440 WebKit::WebFileSystemCallbacks* callbacks) { |
| 352 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 441 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 442 WaitableCallbackResults* waitable_results = |
| 443 WaitableCallbackResults::MaybeCreate(callbacks); |
| 353 CallDispatcherOnMainThread( | 444 CallDispatcherOnMainThread( |
| 354 main_thread_loop_.get(), | 445 main_thread_loop_.get(), |
| 355 &FileSystemDispatcher::Exists, | 446 &FileSystemDispatcher::Exists, |
| 356 MakeTuple(GURL(path), false /* directory */, | 447 MakeTuple(GURL(path), false /* directory */, |
| 357 base::Bind(&StatusCallbackAdapter, | 448 base::Bind(&StatusCallbackAdapter, |
| 358 CurrentWorkerId(), callbacks_id))); | 449 CurrentWorkerId(), callbacks_id, |
| 450 base::Unretained(waitable_results))), |
| 451 make_scoped_ptr(waitable_results)); |
| 359 } | 452 } |
| 360 | 453 |
| 361 void WebFileSystemImpl::directoryExists( | 454 void WebFileSystemImpl::directoryExists( |
| 362 const WebKit::WebURL& path, | 455 const WebKit::WebURL& path, |
| 363 WebKit::WebFileSystemCallbacks* callbacks) { | 456 WebKit::WebFileSystemCallbacks* callbacks) { |
| 364 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 457 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 458 WaitableCallbackResults* waitable_results = |
| 459 WaitableCallbackResults::MaybeCreate(callbacks); |
| 365 CallDispatcherOnMainThread( | 460 CallDispatcherOnMainThread( |
| 366 main_thread_loop_.get(), | 461 main_thread_loop_.get(), |
| 367 &FileSystemDispatcher::Exists, | 462 &FileSystemDispatcher::Exists, |
| 368 MakeTuple(GURL(path), true /* directory */, | 463 MakeTuple(GURL(path), true /* directory */, |
| 369 base::Bind(&StatusCallbackAdapter, | 464 base::Bind(&StatusCallbackAdapter, |
| 370 CurrentWorkerId(), callbacks_id))); | 465 CurrentWorkerId(), callbacks_id, |
| 466 base::Unretained(waitable_results))), |
| 467 make_scoped_ptr(waitable_results)); |
| 371 } | 468 } |
| 372 | 469 |
| 373 void WebFileSystemImpl::readDirectory( | 470 void WebFileSystemImpl::readDirectory( |
| 374 const WebKit::WebURL& path, | 471 const WebKit::WebURL& path, |
| 375 WebKit::WebFileSystemCallbacks* callbacks) { | 472 WebKit::WebFileSystemCallbacks* callbacks) { |
| 376 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 473 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 474 WaitableCallbackResults* waitable_results = |
| 475 WaitableCallbackResults::MaybeCreate(callbacks); |
| 377 CallDispatcherOnMainThread( | 476 CallDispatcherOnMainThread( |
| 378 main_thread_loop_.get(), | 477 main_thread_loop_.get(), |
| 379 &FileSystemDispatcher::ReadDirectory, | 478 &FileSystemDispatcher::ReadDirectory, |
| 380 MakeTuple(GURL(path), | 479 MakeTuple(GURL(path), |
| 381 base::Bind(&ReadDirectoryCallbackAdapater, | 480 base::Bind(&ReadDirectoryCallbackAdapater, |
| 382 CurrentWorkerId(), callbacks_id), | 481 CurrentWorkerId(), callbacks_id, |
| 482 base::Unretained(waitable_results)), |
| 383 base::Bind(&StatusCallbackAdapter, | 483 base::Bind(&StatusCallbackAdapter, |
| 384 CurrentWorkerId(), callbacks_id))); | 484 CurrentWorkerId(), callbacks_id, |
| 485 base::Unretained(waitable_results))), |
| 486 make_scoped_ptr(waitable_results)); |
| 385 } | 487 } |
| 386 | 488 |
| 387 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( | 489 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( |
| 388 const WebURL& path, WebKit::WebFileWriterClient* client) { | 490 const WebURL& path, WebKit::WebFileWriterClient* client) { |
| 389 return new WebFileWriterImpl(GURL(path), client, main_thread_loop_.get()); | 491 return new WebFileWriterImpl(GURL(path), client, main_thread_loop_.get()); |
| 390 } | 492 } |
| 391 | 493 |
| 392 void WebFileSystemImpl::createFileWriter( | 494 void WebFileSystemImpl::createFileWriter( |
| 393 const WebURL& path, | 495 const WebURL& path, |
| 394 WebKit::WebFileWriterClient* client, | 496 WebKit::WebFileWriterClient* client, |
| 395 WebKit::WebFileSystemCallbacks* callbacks) { | 497 WebKit::WebFileSystemCallbacks* callbacks) { |
| 396 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 498 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 499 WaitableCallbackResults* waitable_results = |
| 500 WaitableCallbackResults::MaybeCreate(callbacks); |
| 397 CallDispatcherOnMainThread( | 501 CallDispatcherOnMainThread( |
| 398 main_thread_loop_.get(), | 502 main_thread_loop_.get(), |
| 399 &FileSystemDispatcher::ReadMetadata, | 503 &FileSystemDispatcher::ReadMetadata, |
| 400 MakeTuple(GURL(path), | 504 MakeTuple(GURL(path), |
| 401 base::Bind(&CreateFileWriterCallbackAdapter, | 505 base::Bind(&CreateFileWriterCallbackAdapter, |
| 402 CurrentWorkerId(), callbacks_id, main_thread_loop_, | 506 CurrentWorkerId(), callbacks_id, |
| 403 GURL(path), client), | 507 base::Unretained(waitable_results), |
| 508 main_thread_loop_, GURL(path), client), |
| 404 base::Bind(&StatusCallbackAdapter, | 509 base::Bind(&StatusCallbackAdapter, |
| 405 CurrentWorkerId(), callbacks_id))); | 510 CurrentWorkerId(), callbacks_id, |
| 511 base::Unretained(waitable_results))), |
| 512 make_scoped_ptr(waitable_results)); |
| 406 } | 513 } |
| 407 | 514 |
| 408 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( | 515 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( |
| 409 const WebKit::WebURL& path, | 516 const WebKit::WebURL& path, |
| 410 WebKit::WebFileSystemCallbacks* callbacks) { | 517 WebKit::WebFileSystemCallbacks* callbacks) { |
| 411 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 518 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
| 519 WaitableCallbackResults* waitable_results = |
| 520 WaitableCallbackResults::MaybeCreate(callbacks); |
| 412 CallDispatcherOnMainThread( | 521 CallDispatcherOnMainThread( |
| 413 main_thread_loop_.get(), | 522 main_thread_loop_.get(), |
| 414 &FileSystemDispatcher::CreateSnapshotFile, | 523 &FileSystemDispatcher::CreateSnapshotFile, |
| 415 MakeTuple(GURL(path), | 524 MakeTuple(GURL(path), |
| 416 base::Bind(&CreateSnapshotFileCallbackAdapter, | 525 base::Bind(&CreateSnapshotFileCallbackAdapter, |
| 417 CurrentWorkerId(), callbacks_id, | 526 CurrentWorkerId(), callbacks_id, |
| 527 base::Unretained(waitable_results), |
| 418 main_thread_loop_), | 528 main_thread_loop_), |
| 419 base::Bind(&StatusCallbackAdapter, | 529 base::Bind(&StatusCallbackAdapter, |
| 420 CurrentWorkerId(), callbacks_id))); | 530 CurrentWorkerId(), callbacks_id, |
| 531 base::Unretained(waitable_results))), |
| 532 make_scoped_ptr(waitable_results)); |
| 421 } | 533 } |
| 422 | 534 |
| 423 } // namespace content | 535 } // namespace content |
| OLD | NEW |