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/file_info_util.h" | 15 #include "content/child/file_info_util.h" |
16 #include "content/child/fileapi/file_system_dispatcher.h" | 16 #include "content/child/fileapi/file_system_dispatcher.h" |
17 #include "content/child/fileapi/webfilewriter_impl.h" | 17 #include "content/child/fileapi/webfilewriter_impl.h" |
18 #include "content/child/worker_task_runner.h" | 18 #include "content/child/worker_task_runner.h" |
19 #include "content/common/fileapi/file_system_messages.h" | 19 #include "content/common/fileapi/file_system_messages.h" |
20 #include "third_party/WebKit/public/platform/WebFileInfo.h" | 20 #include "third_party/WebKit/public/platform/WebFileInfo.h" |
21 #include "third_party/WebKit/public/platform/WebFileSystemCallbacks.h" | 21 #include "third_party/WebKit/public/platform/WebFileSystemCallbacks.h" |
22 #include "third_party/WebKit/public/platform/WebString.h" | 22 #include "third_party/WebKit/public/platform/WebString.h" |
23 #include "third_party/WebKit/public/platform/WebURL.h" | 23 #include "third_party/WebKit/public/platform/WebURL.h" |
24 #include "third_party/WebKit/public/web/WebHeap.h" | 24 #include "third_party/WebKit/public/web/WebHeap.h" |
25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
26 #include "webkit/common/fileapi/directory_entry.h" | 26 #include "storage/common/fileapi/directory_entry.h" |
27 #include "webkit/common/fileapi/file_system_util.h" | 27 #include "storage/common/fileapi/file_system_util.h" |
28 | 28 |
29 using blink::WebFileInfo; | 29 using blink::WebFileInfo; |
30 using blink::WebFileSystemCallbacks; | 30 using blink::WebFileSystemCallbacks; |
31 using blink::WebFileSystemEntry; | 31 using blink::WebFileSystemEntry; |
32 using blink::WebString; | 32 using blink::WebString; |
33 using blink::WebURL; | 33 using blink::WebURL; |
34 using blink::WebVector; | 34 using blink::WebVector; |
35 | 35 |
36 namespace content { | 36 namespace content { |
37 | 37 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 callbacks->didSucceed(); | 133 callbacks->didSucceed(); |
134 } | 134 } |
135 | 135 |
136 void DidReadMetadata(const base::File::Info& file_info, | 136 void DidReadMetadata(const base::File::Info& file_info, |
137 WebFileSystemCallbacks* callbacks) { | 137 WebFileSystemCallbacks* callbacks) { |
138 WebFileInfo web_file_info; | 138 WebFileInfo web_file_info; |
139 FileInfoToWebFileInfo(file_info, &web_file_info); | 139 FileInfoToWebFileInfo(file_info, &web_file_info); |
140 callbacks->didReadMetadata(web_file_info); | 140 callbacks->didReadMetadata(web_file_info); |
141 } | 141 } |
142 | 142 |
143 void DidReadDirectory(const std::vector<fileapi::DirectoryEntry>& entries, | 143 void DidReadDirectory(const std::vector<storage::DirectoryEntry>& entries, |
144 bool has_more, WebFileSystemCallbacks* callbacks) { | 144 bool has_more, |
| 145 WebFileSystemCallbacks* callbacks) { |
145 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); | 146 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); |
146 for (size_t i = 0; i < entries.size(); ++i) { | 147 for (size_t i = 0; i < entries.size(); ++i) { |
147 file_system_entries[i].name = | 148 file_system_entries[i].name = |
148 base::FilePath(entries[i].name).AsUTF16Unsafe(); | 149 base::FilePath(entries[i].name).AsUTF16Unsafe(); |
149 file_system_entries[i].isDirectory = entries[i].is_directory; | 150 file_system_entries[i].isDirectory = entries[i].is_directory; |
150 } | 151 } |
151 callbacks->didReadDirectory(file_system_entries, has_more); | 152 callbacks->didReadDirectory(file_system_entries, has_more); |
152 } | 153 } |
153 | 154 |
154 void DidOpenFileSystem(const base::string16& name, const GURL& root, | 155 void DidOpenFileSystem(const base::string16& name, const GURL& root, |
155 WebFileSystemCallbacks* callbacks) { | 156 WebFileSystemCallbacks* callbacks) { |
156 callbacks->didOpenFileSystem(name, root); | 157 callbacks->didOpenFileSystem(name, root); |
157 } | 158 } |
158 | 159 |
159 void DidResolveURL( | 160 void DidResolveURL(const base::string16& name, |
160 const base::string16& name, | 161 const GURL& root_url, |
161 const GURL& root_url, | 162 storage::FileSystemType mount_type, |
162 fileapi::FileSystemType mount_type, | 163 const base::string16& file_path, |
163 const base::string16& file_path, | 164 bool is_directory, |
164 bool is_directory, | 165 WebFileSystemCallbacks* callbacks) { |
165 WebFileSystemCallbacks* callbacks) { | |
166 callbacks->didResolveURL( | 166 callbacks->didResolveURL( |
167 name, | 167 name, |
168 root_url, | 168 root_url, |
169 static_cast<blink::WebFileSystemType>(mount_type), | 169 static_cast<blink::WebFileSystemType>(mount_type), |
170 file_path, | 170 file_path, |
171 is_directory); | 171 is_directory); |
172 } | 172 } |
173 | 173 |
174 void DidFail(base::File::Error error, WebFileSystemCallbacks* callbacks) { | 174 void DidFail(base::File::Error error, WebFileSystemCallbacks* callbacks) { |
175 callbacks->didFail(fileapi::FileErrorToWebFileError(error)); | 175 callbacks->didFail(storage::FileErrorToWebFileError(error)); |
176 } | 176 } |
177 | 177 |
178 // Run WebFileSystemCallbacks's |method| with |params|. | 178 // Run WebFileSystemCallbacks's |method| with |params|. |
179 void RunCallbacks( | 179 void RunCallbacks( |
180 int callbacks_id, | 180 int callbacks_id, |
181 const base::Callback<void(WebFileSystemCallbacks*)>& callback, | 181 const base::Callback<void(WebFileSystemCallbacks*)>& callback, |
182 CallbacksUnregisterMode callbacks_unregister_mode) { | 182 CallbacksUnregisterMode callbacks_unregister_mode) { |
183 WebFileSystemImpl* filesystem = | 183 WebFileSystemImpl* filesystem = |
184 WebFileSystemImpl::ThreadSpecificInstance(NULL); | 184 WebFileSystemImpl::ThreadSpecificInstance(NULL); |
185 if (!filesystem) | 185 if (!filesystem) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 void OpenFileSystemCallbackAdapter( | 229 void OpenFileSystemCallbackAdapter( |
230 int thread_id, int callbacks_id, | 230 int thread_id, int callbacks_id, |
231 WaitableCallbackResults* waitable_results, | 231 WaitableCallbackResults* waitable_results, |
232 const std::string& name, const GURL& root) { | 232 const std::string& name, const GURL& root) { |
233 CallbackFileSystemCallbacks( | 233 CallbackFileSystemCallbacks( |
234 thread_id, callbacks_id, waitable_results, | 234 thread_id, callbacks_id, waitable_results, |
235 base::Bind(&DidOpenFileSystem, base::UTF8ToUTF16(name), root), | 235 base::Bind(&DidOpenFileSystem, base::UTF8ToUTF16(name), root), |
236 UNREGISTER_CALLBACKS); | 236 UNREGISTER_CALLBACKS); |
237 } | 237 } |
238 | 238 |
239 void ResolveURLCallbackAdapter( | 239 void ResolveURLCallbackAdapter(int thread_id, |
240 int thread_id, int callbacks_id, | 240 int callbacks_id, |
241 WaitableCallbackResults* waitable_results, | 241 WaitableCallbackResults* waitable_results, |
242 const fileapi::FileSystemInfo& info, | 242 const storage::FileSystemInfo& info, |
243 const base::FilePath& file_path, bool is_directory) { | 243 const base::FilePath& file_path, |
| 244 bool is_directory) { |
244 base::FilePath normalized_path( | 245 base::FilePath normalized_path( |
245 fileapi::VirtualPath::GetNormalizedFilePath(file_path)); | 246 storage::VirtualPath::GetNormalizedFilePath(file_path)); |
246 CallbackFileSystemCallbacks( | 247 CallbackFileSystemCallbacks( |
247 thread_id, callbacks_id, waitable_results, | 248 thread_id, callbacks_id, waitable_results, |
248 base::Bind(&DidResolveURL, base::UTF8ToUTF16(info.name), info.root_url, | 249 base::Bind(&DidResolveURL, base::UTF8ToUTF16(info.name), info.root_url, |
249 info.mount_type, | 250 info.mount_type, |
250 normalized_path.AsUTF16Unsafe(), is_directory), | 251 normalized_path.AsUTF16Unsafe(), is_directory), |
251 UNREGISTER_CALLBACKS); | 252 UNREGISTER_CALLBACKS); |
252 } | 253 } |
253 | 254 |
254 void StatusCallbackAdapter(int thread_id, int callbacks_id, | 255 void StatusCallbackAdapter(int thread_id, int callbacks_id, |
255 WaitableCallbackResults* waitable_results, | 256 WaitableCallbackResults* waitable_results, |
(...skipping 14 matching lines...) Expand all Loading... |
270 void ReadMetadataCallbackAdapter(int thread_id, int callbacks_id, | 271 void ReadMetadataCallbackAdapter(int thread_id, int callbacks_id, |
271 WaitableCallbackResults* waitable_results, | 272 WaitableCallbackResults* waitable_results, |
272 const base::File::Info& file_info) { | 273 const base::File::Info& file_info) { |
273 CallbackFileSystemCallbacks( | 274 CallbackFileSystemCallbacks( |
274 thread_id, callbacks_id, waitable_results, | 275 thread_id, callbacks_id, waitable_results, |
275 base::Bind(&DidReadMetadata, file_info), | 276 base::Bind(&DidReadMetadata, file_info), |
276 UNREGISTER_CALLBACKS); | 277 UNREGISTER_CALLBACKS); |
277 } | 278 } |
278 | 279 |
279 void ReadDirectoryCallbackAdapter( | 280 void ReadDirectoryCallbackAdapter( |
280 int thread_id, int callbacks_id, WaitableCallbackResults* waitable_results, | 281 int thread_id, |
281 const std::vector<fileapi::DirectoryEntry>& entries, | 282 int callbacks_id, |
| 283 WaitableCallbackResults* waitable_results, |
| 284 const std::vector<storage::DirectoryEntry>& entries, |
282 bool has_more) { | 285 bool has_more) { |
283 CallbackFileSystemCallbacks( | 286 CallbackFileSystemCallbacks( |
284 thread_id, callbacks_id, waitable_results, | 287 thread_id, callbacks_id, waitable_results, |
285 base::Bind(&DidReadDirectory, entries, has_more), | 288 base::Bind(&DidReadDirectory, entries, has_more), |
286 has_more ? DO_NOT_UNREGISTER_CALLBACKS : UNREGISTER_CALLBACKS); | 289 has_more ? DO_NOT_UNREGISTER_CALLBACKS : UNREGISTER_CALLBACKS); |
287 } | 290 } |
288 | 291 |
289 void DidCreateFileWriter( | 292 void DidCreateFileWriter( |
290 int callbacks_id, | 293 int callbacks_id, |
291 const GURL& path, | 294 const GURL& path, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 const blink::WebURL& storage_partition, | 406 const blink::WebURL& storage_partition, |
404 blink::WebFileSystemType type, | 407 blink::WebFileSystemType type, |
405 WebFileSystemCallbacks callbacks) { | 408 WebFileSystemCallbacks callbacks) { |
406 int callbacks_id = RegisterCallbacks(callbacks); | 409 int callbacks_id = RegisterCallbacks(callbacks); |
407 scoped_refptr<WaitableCallbackResults> waitable_results = | 410 scoped_refptr<WaitableCallbackResults> waitable_results = |
408 MaybeCreateWaitableResults(callbacks, callbacks_id); | 411 MaybeCreateWaitableResults(callbacks, callbacks_id); |
409 CallDispatcherOnMainThread( | 412 CallDispatcherOnMainThread( |
410 main_thread_loop_.get(), | 413 main_thread_loop_.get(), |
411 &FileSystemDispatcher::OpenFileSystem, | 414 &FileSystemDispatcher::OpenFileSystem, |
412 MakeTuple(GURL(storage_partition), | 415 MakeTuple(GURL(storage_partition), |
413 static_cast<fileapi::FileSystemType>(type), | 416 static_cast<storage::FileSystemType>(type), |
414 base::Bind(&OpenFileSystemCallbackAdapter, | 417 base::Bind(&OpenFileSystemCallbackAdapter, |
415 CurrentWorkerId(), callbacks_id, waitable_results), | 418 CurrentWorkerId(), |
| 419 callbacks_id, |
| 420 waitable_results), |
416 base::Bind(&StatusCallbackAdapter, | 421 base::Bind(&StatusCallbackAdapter, |
417 CurrentWorkerId(), callbacks_id, waitable_results)), | 422 CurrentWorkerId(), |
| 423 callbacks_id, |
| 424 waitable_results)), |
418 waitable_results.get()); | 425 waitable_results.get()); |
419 } | 426 } |
420 | 427 |
421 void WebFileSystemImpl::resolveURL( | 428 void WebFileSystemImpl::resolveURL( |
422 const blink::WebURL& filesystem_url, | 429 const blink::WebURL& filesystem_url, |
423 WebFileSystemCallbacks callbacks) { | 430 WebFileSystemCallbacks callbacks) { |
424 int callbacks_id = RegisterCallbacks(callbacks); | 431 int callbacks_id = RegisterCallbacks(callbacks); |
425 scoped_refptr<WaitableCallbackResults> waitable_results = | 432 scoped_refptr<WaitableCallbackResults> waitable_results = |
426 MaybeCreateWaitableResults(callbacks, callbacks_id); | 433 MaybeCreateWaitableResults(callbacks, callbacks_id); |
427 CallDispatcherOnMainThread( | 434 CallDispatcherOnMainThread( |
(...skipping 11 matching lines...) Expand all Loading... |
439 const blink::WebURL& storage_partition, | 446 const blink::WebURL& storage_partition, |
440 blink::WebFileSystemType type, | 447 blink::WebFileSystemType type, |
441 WebFileSystemCallbacks callbacks) { | 448 WebFileSystemCallbacks callbacks) { |
442 int callbacks_id = RegisterCallbacks(callbacks); | 449 int callbacks_id = RegisterCallbacks(callbacks); |
443 scoped_refptr<WaitableCallbackResults> waitable_results = | 450 scoped_refptr<WaitableCallbackResults> waitable_results = |
444 MaybeCreateWaitableResults(callbacks, callbacks_id); | 451 MaybeCreateWaitableResults(callbacks, callbacks_id); |
445 CallDispatcherOnMainThread( | 452 CallDispatcherOnMainThread( |
446 main_thread_loop_.get(), | 453 main_thread_loop_.get(), |
447 &FileSystemDispatcher::DeleteFileSystem, | 454 &FileSystemDispatcher::DeleteFileSystem, |
448 MakeTuple(GURL(storage_partition), | 455 MakeTuple(GURL(storage_partition), |
449 static_cast<fileapi::FileSystemType>(type), | 456 static_cast<storage::FileSystemType>(type), |
450 base::Bind(&StatusCallbackAdapter, | 457 base::Bind(&StatusCallbackAdapter, |
451 CurrentWorkerId(), callbacks_id, waitable_results)), | 458 CurrentWorkerId(), |
| 459 callbacks_id, |
| 460 waitable_results)), |
452 waitable_results.get()); | 461 waitable_results.get()); |
453 } | 462 } |
454 | 463 |
455 void WebFileSystemImpl::move( | 464 void WebFileSystemImpl::move( |
456 const blink::WebURL& src_path, | 465 const blink::WebURL& src_path, |
457 const blink::WebURL& dest_path, | 466 const blink::WebURL& dest_path, |
458 WebFileSystemCallbacks callbacks) { | 467 WebFileSystemCallbacks callbacks) { |
459 int callbacks_id = RegisterCallbacks(callbacks); | 468 int callbacks_id = RegisterCallbacks(callbacks); |
460 scoped_refptr<WaitableCallbackResults> waitable_results = | 469 scoped_refptr<WaitableCallbackResults> waitable_results = |
461 MaybeCreateWaitableResults(callbacks, callbacks_id); | 470 MaybeCreateWaitableResults(callbacks, callbacks_id); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 WaitableCallbackResults* WebFileSystemImpl::MaybeCreateWaitableResults( | 694 WaitableCallbackResults* WebFileSystemImpl::MaybeCreateWaitableResults( |
686 const WebFileSystemCallbacks& callbacks, int callbacks_id) { | 695 const WebFileSystemCallbacks& callbacks, int callbacks_id) { |
687 if (!callbacks.shouldBlockUntilCompletion()) | 696 if (!callbacks.shouldBlockUntilCompletion()) |
688 return NULL; | 697 return NULL; |
689 WaitableCallbackResults* results = new WaitableCallbackResults(); | 698 WaitableCallbackResults* results = new WaitableCallbackResults(); |
690 waitable_results_[callbacks_id] = results; | 699 waitable_results_[callbacks_id] = results; |
691 return results; | 700 return results; |
692 } | 701 } |
693 | 702 |
694 } // namespace content | 703 } // namespace content |
OLD | NEW |