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()) | |
michaeln
2013/07/31 23:34:03
Looks like this all assumes that a call that origi
kinuko
2013/08/01 06:12:26
Done.
| |
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(false, false)) {} | |
michaeln
2013/07/31 23:34:03
would manual reset make more sense since this is a
kinuko
2013/08/01 06:12:26
Done.
| |
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 WaitableCallbackResults* waitable_results) { | |
111 if (!loop->RunsTasksOnCurrentThread()) { | 142 if (!loop->RunsTasksOnCurrentThread()) { |
112 loop->PostTask(FROM_HERE, | 143 loop->PostTask(FROM_HERE, |
113 base::Bind(&CallDispatcherOnMainThread<Method, Params>, | 144 base::Bind(&CallDispatcherOnMainThread<Method, Params>, |
114 make_scoped_refptr(loop), method, params)); | 145 make_scoped_refptr(loop), method, params, |
115 return; | 146 waitable_results)); |
michaeln
2013/07/31 23:34:03
maybe bind NULL here for waitable_results since it
kinuko
2013/08/01 06:12:26
Done. Also added DCHECK(!waitable_results) in the
| |
147 if (!waitable_results) | |
148 return; | |
149 waitable_results->WaitAndRun(); | |
150 delete waitable_results; | |
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 |
121 DispatchToMethod(ChildThread::current()->file_system_dispatcher(), | 156 DispatchToMethod(ChildThread::current()->file_system_dispatcher(), |
122 method, params); | 157 method, params); |
123 } | 158 } |
124 | 159 |
125 template <typename Method, typename Params> | 160 template <typename Method, typename Params> |
126 void CallbackFileSystemCallbacks( | 161 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()) | 162 if (!CallbacksMap::Get()) |
137 return; | 163 return; |
138 | |
139 WebFileSystemCallbacks* callbacks = | 164 WebFileSystemCallbacks* callbacks = |
140 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); | 165 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); |
141 DCHECK(callbacks); | 166 DCHECK(callbacks); |
142 DispatchToMethod(callbacks, method, params); | 167 DispatchToMethod(callbacks, method, params); |
143 } | 168 } |
144 | 169 |
170 void DispatchResultsClosure(int thread_id, int callbacks_id, | |
171 WaitableCallbackResults* waitable_results, | |
172 const base::Closure& results_closure) { | |
173 if (thread_id != CurrentWorkerId()) { | |
174 if (waitable_results) { | |
175 waitable_results->SetResultsAndSignal(results_closure); | |
176 return; | |
177 } | |
178 WorkerTaskRunner::Instance()->PostTask(thread_id, results_closure); | |
179 return; | |
180 } | |
181 results_closure.Run(); | |
182 } | |
183 | |
184 template <typename Method, typename Params> | |
185 void CallbackFileSystemCallbacks( | |
186 int thread_id, int callbacks_id, | |
187 WaitableCallbackResults* waitable_results, | |
188 Method method, const Params& params) { | |
189 DispatchResultsClosure( | |
190 thread_id, callbacks_id, waitable_results, | |
191 base::Bind(&RunCallbacks<Method, Params>, callbacks_id, method, params)); | |
192 } | |
193 | |
145 void StatusCallbackAdapter(int thread_id, int callbacks_id, | 194 void StatusCallbackAdapter(int thread_id, int callbacks_id, |
195 WaitableCallbackResults* waitable_results, | |
146 base::PlatformFileError error) { | 196 base::PlatformFileError error) { |
147 if (error == base::PLATFORM_FILE_OK) { | 197 if (error == base::PLATFORM_FILE_OK) { |
148 CallbackFileSystemCallbacks( | 198 CallbackFileSystemCallbacks( |
149 thread_id, callbacks_id, | 199 thread_id, callbacks_id, waitable_results, |
150 &WebFileSystemCallbacks::didSucceed, MakeTuple()); | 200 &WebFileSystemCallbacks::didSucceed, MakeTuple()); |
151 } else { | 201 } else { |
152 CallbackFileSystemCallbacks( | 202 CallbackFileSystemCallbacks( |
153 thread_id, callbacks_id, | 203 thread_id, callbacks_id, waitable_results, |
154 &WebFileSystemCallbacks::didFail, | 204 &WebFileSystemCallbacks::didFail, |
155 MakeTuple(fileapi::PlatformFileErrorToWebFileError(error))); | 205 MakeTuple(fileapi::PlatformFileErrorToWebFileError(error))); |
156 } | 206 } |
157 } | 207 } |
158 | 208 |
159 void ReadMetadataCallbackAdapter(int thread_id, int callbacks_id, | 209 void ReadMetadataCallbackAdapter(int thread_id, int callbacks_id, |
210 WaitableCallbackResults* waitable_results, | |
160 const base::PlatformFileInfo& file_info) { | 211 const base::PlatformFileInfo& file_info) { |
161 WebFileInfo web_file_info; | 212 WebFileInfo web_file_info; |
162 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); | 213 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); |
163 CallbackFileSystemCallbacks( | 214 CallbackFileSystemCallbacks( |
164 thread_id, callbacks_id, | 215 thread_id, callbacks_id, waitable_results, |
165 &WebFileSystemCallbacks::didReadMetadata, | 216 &WebFileSystemCallbacks::didReadMetadata, |
166 MakeTuple(web_file_info)); | 217 MakeTuple(web_file_info)); |
167 } | 218 } |
168 | 219 |
169 void ReadDirectoryCallbackAdapater( | 220 void ReadDirectoryCallbackAdapater( |
170 int thread_id, int callbacks_id, | 221 int thread_id, int callbacks_id, WaitableCallbackResults* waitable_results, |
171 const std::vector<fileapi::DirectoryEntry>& entries, | 222 const std::vector<fileapi::DirectoryEntry>& entries, |
172 bool has_more) { | 223 bool has_more) { |
173 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); | 224 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); |
174 for (size_t i = 0; i < entries.size(); i++) { | 225 for (size_t i = 0; i < entries.size(); i++) { |
175 file_system_entries[i].name = | 226 file_system_entries[i].name = |
176 base::FilePath(entries[i].name).AsUTF16Unsafe(); | 227 base::FilePath(entries[i].name).AsUTF16Unsafe(); |
177 file_system_entries[i].isDirectory = entries[i].is_directory; | 228 file_system_entries[i].isDirectory = entries[i].is_directory; |
178 } | 229 } |
179 CallbackFileSystemCallbacks( | 230 CallbackFileSystemCallbacks( |
180 thread_id, callbacks_id, | 231 thread_id, callbacks_id, waitable_results, |
181 &WebFileSystemCallbacks::didReadDirectory, | 232 &WebFileSystemCallbacks::didReadDirectory, |
182 MakeTuple(file_system_entries, has_more)); | 233 MakeTuple(file_system_entries, has_more)); |
183 } | 234 } |
184 | 235 |
185 void CreateFileWriterCallbackAdapter( | 236 void DidCreateFileWriter( |
186 int thread_id, int callbacks_id, | 237 int callbacks_id, |
187 base::MessageLoopProxy* main_thread_loop, | |
188 const GURL& path, | 238 const GURL& path, |
189 WebKit::WebFileWriterClient* client, | 239 WebKit::WebFileWriterClient* client, |
240 base::MessageLoopProxy* main_thread_loop, | |
190 const base::PlatformFileInfo& file_info) { | 241 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()) | 242 if (!CallbacksMap::Get()) |
202 return; | 243 return; |
203 | 244 |
204 WebFileSystemCallbacks* callbacks = | 245 WebFileSystemCallbacks* callbacks = |
205 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); | 246 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); |
206 DCHECK(callbacks); | 247 DCHECK(callbacks); |
207 | 248 |
208 if (file_info.is_directory || file_info.size < 0) { | 249 if (file_info.is_directory || file_info.size < 0) { |
209 callbacks->didFail(WebKit::WebFileErrorInvalidState); | 250 callbacks->didFail(WebKit::WebFileErrorInvalidState); |
210 return; | 251 return; |
211 } | 252 } |
212 callbacks->didCreateFileWriter( | 253 callbacks->didCreateFileWriter( |
213 new WebFileWriterImpl(path, client, main_thread_loop), file_info.size); | 254 new WebFileWriterImpl(path, client, main_thread_loop), file_info.size); |
214 } | 255 } |
215 | 256 |
216 void CreateSnapshotFileCallbackAdapter( | 257 void CreateFileWriterCallbackAdapter( |
217 int thread_id, int callbacks_id, | 258 int thread_id, int callbacks_id, |
259 WaitableCallbackResults* waitable_results, | |
260 base::MessageLoopProxy* main_thread_loop, | |
261 const GURL& path, | |
262 WebKit::WebFileWriterClient* client, | |
263 const base::PlatformFileInfo& file_info) { | |
264 DispatchResultsClosure( | |
265 thread_id, callbacks_id, waitable_results, | |
266 base::Bind(&DidCreateFileWriter, callbacks_id, path, client, | |
267 make_scoped_refptr(main_thread_loop), file_info)); | |
268 } | |
269 | |
270 void DidCreateSnapshotFile( | |
271 int callbacks_id, | |
218 base::MessageLoopProxy* main_thread_loop, | 272 base::MessageLoopProxy* main_thread_loop, |
219 const base::PlatformFileInfo& file_info, | 273 const base::PlatformFileInfo& file_info, |
220 const base::FilePath& platform_path, | 274 const base::FilePath& platform_path, |
221 int request_id) { | 275 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()) | 276 if (!CallbacksMap::Get()) |
233 return; | 277 return; |
234 | 278 |
235 WebFileSystemCallbacks* callbacks = | 279 WebFileSystemCallbacks* callbacks = |
236 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); | 280 CallbacksMap::Get()->GetAndUnregisterCallbacks(callbacks_id); |
237 DCHECK(callbacks); | 281 DCHECK(callbacks); |
238 | 282 |
239 WebFileInfo web_file_info; | 283 WebFileInfo web_file_info; |
240 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); | 284 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); |
241 web_file_info.platformPath = platform_path.AsUTF16Unsafe(); | 285 web_file_info.platformPath = platform_path.AsUTF16Unsafe(); |
242 callbacks->didCreateSnapshotFile(web_file_info); | 286 callbacks->didCreateSnapshotFile(web_file_info); |
243 | 287 |
244 // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes | 288 // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes |
245 // non-bridge model. | 289 // non-bridge model. |
246 main_thread_loop->PostTask( | 290 main_thread_loop->PostTask( |
247 FROM_HERE, base::Bind(&DidReceiveSnapshotFile, request_id)); | 291 FROM_HERE, base::Bind(&DidReceiveSnapshotFile, request_id)); |
248 } | 292 } |
249 | 293 |
294 void CreateSnapshotFileCallbackAdapter( | |
295 int thread_id, int callbacks_id, | |
296 WaitableCallbackResults* waitable_results, | |
297 base::MessageLoopProxy* main_thread_loop, | |
298 const base::PlatformFileInfo& file_info, | |
299 const base::FilePath& platform_path, | |
300 int request_id) { | |
301 DispatchResultsClosure( | |
302 thread_id, callbacks_id, waitable_results, | |
303 base::Bind(&DidCreateSnapshotFile, callbacks_id, | |
304 make_scoped_refptr(main_thread_loop), | |
305 file_info, platform_path, request_id)); | |
306 } | |
307 | |
250 } // namespace | 308 } // namespace |
251 | 309 |
252 WebFileSystemImpl::~WebFileSystemImpl() { | 310 WebFileSystemImpl::~WebFileSystemImpl() { |
253 } | 311 } |
254 | 312 |
255 WebFileSystemImpl::WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop) | 313 WebFileSystemImpl::WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop) |
256 : main_thread_loop_(main_thread_loop) { | 314 : main_thread_loop_(main_thread_loop) { |
257 } | 315 } |
258 | 316 |
259 void WebFileSystemImpl::move( | 317 void WebFileSystemImpl::move( |
260 const WebKit::WebURL& src_path, | 318 const WebKit::WebURL& src_path, |
261 const WebKit::WebURL& dest_path, | 319 const WebKit::WebURL& dest_path, |
262 WebKit::WebFileSystemCallbacks* callbacks) { | 320 WebKit::WebFileSystemCallbacks* callbacks) { |
263 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 321 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
322 WaitableCallbackResults* waitable_results = | |
323 WaitableCallbackResults::MaybeCreate(callbacks); | |
264 CallDispatcherOnMainThread( | 324 CallDispatcherOnMainThread( |
265 main_thread_loop_.get(), | 325 main_thread_loop_.get(), |
266 &FileSystemDispatcher::Move, | 326 &FileSystemDispatcher::Move, |
267 MakeTuple(GURL(src_path), GURL(dest_path), | 327 MakeTuple(GURL(src_path), GURL(dest_path), |
268 base::Bind(&StatusCallbackAdapter, | 328 base::Bind(&StatusCallbackAdapter, |
269 CurrentWorkerId(), callbacks_id))); | 329 CurrentWorkerId(), callbacks_id, waitable_results)), |
michaeln
2013/07/31 23:51:27
Using base::Unretained(waitable_results) for the c
kinuko
2013/08/01 06:12:26
Partially done.
Pass() clears up before we pass t
| |
330 waitable_results); | |
270 } | 331 } |
271 | 332 |
272 void WebFileSystemImpl::copy( | 333 void WebFileSystemImpl::copy( |
273 const WebKit::WebURL& src_path, | 334 const WebKit::WebURL& src_path, |
274 const WebKit::WebURL& dest_path, | 335 const WebKit::WebURL& dest_path, |
275 WebKit::WebFileSystemCallbacks* callbacks) { | 336 WebKit::WebFileSystemCallbacks* callbacks) { |
276 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 337 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
338 WaitableCallbackResults* waitable_results = | |
339 WaitableCallbackResults::MaybeCreate(callbacks); | |
277 CallDispatcherOnMainThread( | 340 CallDispatcherOnMainThread( |
278 main_thread_loop_.get(), | 341 main_thread_loop_.get(), |
279 &FileSystemDispatcher::Copy, | 342 &FileSystemDispatcher::Copy, |
280 MakeTuple(GURL(src_path), GURL(dest_path), | 343 MakeTuple(GURL(src_path), GURL(dest_path), |
281 base::Bind(&StatusCallbackAdapter, | 344 base::Bind(&StatusCallbackAdapter, |
282 CurrentWorkerId(), callbacks_id))); | 345 CurrentWorkerId(), callbacks_id, waitable_results)), |
346 waitable_results); | |
283 } | 347 } |
284 | 348 |
285 void WebFileSystemImpl::remove( | 349 void WebFileSystemImpl::remove( |
286 const WebKit::WebURL& path, | 350 const WebKit::WebURL& path, |
287 WebKit::WebFileSystemCallbacks* callbacks) { | 351 WebKit::WebFileSystemCallbacks* callbacks) { |
288 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 352 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
353 WaitableCallbackResults* waitable_results = | |
354 WaitableCallbackResults::MaybeCreate(callbacks); | |
289 CallDispatcherOnMainThread( | 355 CallDispatcherOnMainThread( |
290 main_thread_loop_.get(), | 356 main_thread_loop_.get(), |
291 &FileSystemDispatcher::Remove, | 357 &FileSystemDispatcher::Remove, |
292 MakeTuple(GURL(path), false /* recursive */, | 358 MakeTuple(GURL(path), false /* recursive */, |
293 base::Bind(&StatusCallbackAdapter, | 359 base::Bind(&StatusCallbackAdapter, |
294 CurrentWorkerId(), callbacks_id))); | 360 CurrentWorkerId(), callbacks_id, waitable_results)), |
361 waitable_results); | |
295 } | 362 } |
296 | 363 |
297 void WebFileSystemImpl::removeRecursively( | 364 void WebFileSystemImpl::removeRecursively( |
298 const WebKit::WebURL& path, | 365 const WebKit::WebURL& path, |
299 WebKit::WebFileSystemCallbacks* callbacks) { | 366 WebKit::WebFileSystemCallbacks* callbacks) { |
300 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 367 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
368 WaitableCallbackResults* waitable_results = | |
369 WaitableCallbackResults::MaybeCreate(callbacks); | |
301 CallDispatcherOnMainThread( | 370 CallDispatcherOnMainThread( |
302 main_thread_loop_.get(), | 371 main_thread_loop_.get(), |
303 &FileSystemDispatcher::Remove, | 372 &FileSystemDispatcher::Remove, |
304 MakeTuple(GURL(path), true /* recursive */, | 373 MakeTuple(GURL(path), true /* recursive */, |
305 base::Bind(&StatusCallbackAdapter, | 374 base::Bind(&StatusCallbackAdapter, |
306 CurrentWorkerId(), callbacks_id))); | 375 CurrentWorkerId(), callbacks_id, waitable_results)), |
376 waitable_results); | |
307 } | 377 } |
308 | 378 |
309 void WebFileSystemImpl::readMetadata( | 379 void WebFileSystemImpl::readMetadata( |
310 const WebKit::WebURL& path, | 380 const WebKit::WebURL& path, |
311 WebKit::WebFileSystemCallbacks* callbacks) { | 381 WebKit::WebFileSystemCallbacks* callbacks) { |
312 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 382 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
383 WaitableCallbackResults* waitable_results = | |
384 WaitableCallbackResults::MaybeCreate(callbacks); | |
313 CallDispatcherOnMainThread( | 385 CallDispatcherOnMainThread( |
314 main_thread_loop_.get(), | 386 main_thread_loop_.get(), |
315 &FileSystemDispatcher::ReadMetadata, | 387 &FileSystemDispatcher::ReadMetadata, |
316 MakeTuple(GURL(path), | 388 MakeTuple(GURL(path), |
317 base::Bind(&ReadMetadataCallbackAdapter, | 389 base::Bind(&ReadMetadataCallbackAdapter, |
318 CurrentWorkerId(), callbacks_id), | 390 CurrentWorkerId(), callbacks_id, waitable_results), |
319 base::Bind(&StatusCallbackAdapter, | 391 base::Bind(&StatusCallbackAdapter, |
320 CurrentWorkerId(), callbacks_id))); | 392 CurrentWorkerId(), callbacks_id, waitable_results)), |
393 waitable_results); | |
321 } | 394 } |
322 | 395 |
323 void WebFileSystemImpl::createFile( | 396 void WebFileSystemImpl::createFile( |
324 const WebKit::WebURL& path, | 397 const WebKit::WebURL& path, |
325 bool exclusive, | 398 bool exclusive, |
326 WebKit::WebFileSystemCallbacks* callbacks) { | 399 WebKit::WebFileSystemCallbacks* callbacks) { |
327 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 400 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
401 WaitableCallbackResults* waitable_results = | |
402 WaitableCallbackResults::MaybeCreate(callbacks); | |
328 CallDispatcherOnMainThread( | 403 CallDispatcherOnMainThread( |
329 main_thread_loop_.get(), | 404 main_thread_loop_.get(), |
330 &FileSystemDispatcher::CreateFile, | 405 &FileSystemDispatcher::CreateFile, |
331 MakeTuple(GURL(path), exclusive, | 406 MakeTuple(GURL(path), exclusive, |
332 base::Bind(&StatusCallbackAdapter, | 407 base::Bind(&StatusCallbackAdapter, |
333 CurrentWorkerId(), callbacks_id))); | 408 CurrentWorkerId(), callbacks_id, waitable_results)), |
409 waitable_results); | |
334 } | 410 } |
335 | 411 |
336 void WebFileSystemImpl::createDirectory( | 412 void WebFileSystemImpl::createDirectory( |
337 const WebKit::WebURL& path, | 413 const WebKit::WebURL& path, |
338 bool exclusive, | 414 bool exclusive, |
339 WebKit::WebFileSystemCallbacks* callbacks) { | 415 WebKit::WebFileSystemCallbacks* callbacks) { |
340 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 416 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
417 WaitableCallbackResults* waitable_results = | |
418 WaitableCallbackResults::MaybeCreate(callbacks); | |
341 CallDispatcherOnMainThread( | 419 CallDispatcherOnMainThread( |
342 main_thread_loop_.get(), | 420 main_thread_loop_.get(), |
343 &FileSystemDispatcher::CreateDirectory, | 421 &FileSystemDispatcher::CreateDirectory, |
344 MakeTuple(GURL(path), exclusive, false /* recursive */, | 422 MakeTuple(GURL(path), exclusive, false /* recursive */, |
345 base::Bind(&StatusCallbackAdapter, | 423 base::Bind(&StatusCallbackAdapter, |
346 CurrentWorkerId(), callbacks_id))); | 424 CurrentWorkerId(), callbacks_id, waitable_results)), |
425 waitable_results); | |
347 } | 426 } |
348 | 427 |
349 void WebFileSystemImpl::fileExists( | 428 void WebFileSystemImpl::fileExists( |
350 const WebKit::WebURL& path, | 429 const WebKit::WebURL& path, |
351 WebKit::WebFileSystemCallbacks* callbacks) { | 430 WebKit::WebFileSystemCallbacks* callbacks) { |
352 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 431 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
432 WaitableCallbackResults* waitable_results = | |
433 WaitableCallbackResults::MaybeCreate(callbacks); | |
353 CallDispatcherOnMainThread( | 434 CallDispatcherOnMainThread( |
354 main_thread_loop_.get(), | 435 main_thread_loop_.get(), |
355 &FileSystemDispatcher::Exists, | 436 &FileSystemDispatcher::Exists, |
356 MakeTuple(GURL(path), false /* directory */, | 437 MakeTuple(GURL(path), false /* directory */, |
357 base::Bind(&StatusCallbackAdapter, | 438 base::Bind(&StatusCallbackAdapter, |
358 CurrentWorkerId(), callbacks_id))); | 439 CurrentWorkerId(), callbacks_id, waitable_results)), |
440 waitable_results); | |
359 } | 441 } |
360 | 442 |
361 void WebFileSystemImpl::directoryExists( | 443 void WebFileSystemImpl::directoryExists( |
362 const WebKit::WebURL& path, | 444 const WebKit::WebURL& path, |
363 WebKit::WebFileSystemCallbacks* callbacks) { | 445 WebKit::WebFileSystemCallbacks* callbacks) { |
364 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 446 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
447 WaitableCallbackResults* waitable_results = | |
448 WaitableCallbackResults::MaybeCreate(callbacks); | |
365 CallDispatcherOnMainThread( | 449 CallDispatcherOnMainThread( |
366 main_thread_loop_.get(), | 450 main_thread_loop_.get(), |
367 &FileSystemDispatcher::Exists, | 451 &FileSystemDispatcher::Exists, |
368 MakeTuple(GURL(path), true /* directory */, | 452 MakeTuple(GURL(path), true /* directory */, |
369 base::Bind(&StatusCallbackAdapter, | 453 base::Bind(&StatusCallbackAdapter, |
370 CurrentWorkerId(), callbacks_id))); | 454 CurrentWorkerId(), callbacks_id, waitable_results)), |
455 waitable_results); | |
371 } | 456 } |
372 | 457 |
373 void WebFileSystemImpl::readDirectory( | 458 void WebFileSystemImpl::readDirectory( |
374 const WebKit::WebURL& path, | 459 const WebKit::WebURL& path, |
375 WebKit::WebFileSystemCallbacks* callbacks) { | 460 WebKit::WebFileSystemCallbacks* callbacks) { |
376 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 461 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
462 WaitableCallbackResults* waitable_results = | |
463 WaitableCallbackResults::MaybeCreate(callbacks); | |
377 CallDispatcherOnMainThread( | 464 CallDispatcherOnMainThread( |
378 main_thread_loop_.get(), | 465 main_thread_loop_.get(), |
379 &FileSystemDispatcher::ReadDirectory, | 466 &FileSystemDispatcher::ReadDirectory, |
380 MakeTuple(GURL(path), | 467 MakeTuple(GURL(path), |
381 base::Bind(&ReadDirectoryCallbackAdapater, | 468 base::Bind(&ReadDirectoryCallbackAdapater, |
382 CurrentWorkerId(), callbacks_id), | 469 CurrentWorkerId(), callbacks_id, waitable_results), |
383 base::Bind(&StatusCallbackAdapter, | 470 base::Bind(&StatusCallbackAdapter, |
384 CurrentWorkerId(), callbacks_id))); | 471 CurrentWorkerId(), callbacks_id, waitable_results)), |
472 waitable_results); | |
385 } | 473 } |
386 | 474 |
387 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( | 475 WebKit::WebFileWriter* WebFileSystemImpl::createFileWriter( |
388 const WebURL& path, WebKit::WebFileWriterClient* client) { | 476 const WebURL& path, WebKit::WebFileWriterClient* client) { |
389 return new WebFileWriterImpl(GURL(path), client, main_thread_loop_.get()); | 477 return new WebFileWriterImpl(GURL(path), client, main_thread_loop_.get()); |
390 } | 478 } |
391 | 479 |
392 void WebFileSystemImpl::createFileWriter( | 480 void WebFileSystemImpl::createFileWriter( |
393 const WebURL& path, | 481 const WebURL& path, |
394 WebKit::WebFileWriterClient* client, | 482 WebKit::WebFileWriterClient* client, |
395 WebKit::WebFileSystemCallbacks* callbacks) { | 483 WebKit::WebFileSystemCallbacks* callbacks) { |
396 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 484 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
485 WaitableCallbackResults* waitable_results = | |
486 WaitableCallbackResults::MaybeCreate(callbacks); | |
397 CallDispatcherOnMainThread( | 487 CallDispatcherOnMainThread( |
398 main_thread_loop_.get(), | 488 main_thread_loop_.get(), |
399 &FileSystemDispatcher::ReadMetadata, | 489 &FileSystemDispatcher::ReadMetadata, |
400 MakeTuple(GURL(path), | 490 MakeTuple(GURL(path), |
401 base::Bind(&CreateFileWriterCallbackAdapter, | 491 base::Bind(&CreateFileWriterCallbackAdapter, |
402 CurrentWorkerId(), callbacks_id, main_thread_loop_, | 492 CurrentWorkerId(), callbacks_id, waitable_results, |
493 main_thread_loop_, | |
403 GURL(path), client), | 494 GURL(path), client), |
404 base::Bind(&StatusCallbackAdapter, | 495 base::Bind(&StatusCallbackAdapter, |
405 CurrentWorkerId(), callbacks_id))); | 496 CurrentWorkerId(), callbacks_id, waitable_results)), |
497 waitable_results); | |
406 } | 498 } |
407 | 499 |
408 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( | 500 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( |
409 const WebKit::WebURL& path, | 501 const WebKit::WebURL& path, |
410 WebKit::WebFileSystemCallbacks* callbacks) { | 502 WebKit::WebFileSystemCallbacks* callbacks) { |
411 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); | 503 int callbacks_id = CallbacksMap::GetOrCreate()->RegisterCallbacks(callbacks); |
504 WaitableCallbackResults* waitable_results = | |
505 WaitableCallbackResults::MaybeCreate(callbacks); | |
412 CallDispatcherOnMainThread( | 506 CallDispatcherOnMainThread( |
413 main_thread_loop_.get(), | 507 main_thread_loop_.get(), |
414 &FileSystemDispatcher::CreateSnapshotFile, | 508 &FileSystemDispatcher::CreateSnapshotFile, |
415 MakeTuple(GURL(path), | 509 MakeTuple(GURL(path), |
416 base::Bind(&CreateSnapshotFileCallbackAdapter, | 510 base::Bind(&CreateSnapshotFileCallbackAdapter, |
417 CurrentWorkerId(), callbacks_id, | 511 CurrentWorkerId(), callbacks_id, waitable_results, |
418 main_thread_loop_), | 512 main_thread_loop_), |
419 base::Bind(&StatusCallbackAdapter, | 513 base::Bind(&StatusCallbackAdapter, |
420 CurrentWorkerId(), callbacks_id))); | 514 CurrentWorkerId(), callbacks_id, waitable_results)), |
515 waitable_results); | |
421 } | 516 } |
422 | 517 |
423 } // namespace content | 518 } // namespace content |
OLD | NEW |