| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/threading/thread_local.h" | 16 #include "base/threading/thread_local.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "content/child/child_thread_impl.h" | 18 #include "content/child/child_thread_impl.h" |
| 19 #include "content/child/file_info_util.h" | 19 #include "content/child/file_info_util.h" |
| 20 #include "content/child/fileapi/file_system_dispatcher.h" | 20 #include "content/child/fileapi/file_system_dispatcher.h" |
| 21 #include "content/child/fileapi/webfilewriter_impl.h" | 21 #include "content/child/fileapi/webfilewriter_impl.h" |
| 22 #include "content/common/fileapi/file_system_messages.h" | 22 #include "content/common/fileapi/file_system_messages.h" |
| 23 #include "storage/common/fileapi/directory_entry.h" | 23 #include "storage/common/fileapi/directory_entry.h" |
| 24 #include "storage/common/fileapi/file_system_util.h" | 24 #include "storage/common/fileapi/file_system_util.h" |
| 25 #include "third_party/WebKit/public/platform/FilePathConversion.h" |
| 25 #include "third_party/WebKit/public/platform/WebFileInfo.h" | 26 #include "third_party/WebKit/public/platform/WebFileInfo.h" |
| 26 #include "third_party/WebKit/public/platform/WebFileSystemCallbacks.h" | 27 #include "third_party/WebKit/public/platform/WebFileSystemCallbacks.h" |
| 27 #include "third_party/WebKit/public/platform/WebString.h" | 28 #include "third_party/WebKit/public/platform/WebString.h" |
| 28 #include "third_party/WebKit/public/platform/WebURL.h" | 29 #include "third_party/WebKit/public/platform/WebURL.h" |
| 29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 30 | 31 |
| 31 using blink::WebFileInfo; | 32 using blink::WebFileInfo; |
| 32 using blink::WebFileSystemCallbacks; | 33 using blink::WebFileSystemCallbacks; |
| 33 using blink::WebFileSystemEntry; | 34 using blink::WebFileSystemEntry; |
| 34 using blink::WebString; | 35 using blink::WebString; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 FileInfoToWebFileInfo(file_info, &web_file_info); | 136 FileInfoToWebFileInfo(file_info, &web_file_info); |
| 136 callbacks->didReadMetadata(web_file_info); | 137 callbacks->didReadMetadata(web_file_info); |
| 137 } | 138 } |
| 138 | 139 |
| 139 void DidReadDirectory(const std::vector<storage::DirectoryEntry>& entries, | 140 void DidReadDirectory(const std::vector<storage::DirectoryEntry>& entries, |
| 140 bool has_more, | 141 bool has_more, |
| 141 WebFileSystemCallbacks* callbacks) { | 142 WebFileSystemCallbacks* callbacks) { |
| 142 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); | 143 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); |
| 143 for (size_t i = 0; i < entries.size(); ++i) { | 144 for (size_t i = 0; i < entries.size(); ++i) { |
| 144 file_system_entries[i].name = | 145 file_system_entries[i].name = |
| 145 base::FilePath(entries[i].name).AsUTF16Unsafe(); | 146 blink::FilePathToWebString(base::FilePath(entries[i].name)); |
| 146 file_system_entries[i].isDirectory = entries[i].is_directory; | 147 file_system_entries[i].isDirectory = entries[i].is_directory; |
| 147 } | 148 } |
| 148 callbacks->didReadDirectory(file_system_entries, has_more); | 149 callbacks->didReadDirectory(file_system_entries, has_more); |
| 149 } | 150 } |
| 150 | 151 |
| 151 void DidOpenFileSystem(const base::string16& name, const GURL& root, | 152 void DidOpenFileSystem(const std::string& name, |
| 153 const GURL& root, |
| 152 WebFileSystemCallbacks* callbacks) { | 154 WebFileSystemCallbacks* callbacks) { |
| 153 callbacks->didOpenFileSystem(name, root); | 155 callbacks->didOpenFileSystem(blink::WebString::fromUTF8(name), root); |
| 154 } | 156 } |
| 155 | 157 |
| 156 void DidResolveURL(const base::string16& name, | 158 void DidResolveURL(const std::string& name, |
| 157 const GURL& root_url, | 159 const GURL& root_url, |
| 158 storage::FileSystemType mount_type, | 160 storage::FileSystemType mount_type, |
| 159 const base::string16& file_path, | 161 const base::FilePath& file_path, |
| 160 bool is_directory, | 162 bool is_directory, |
| 161 WebFileSystemCallbacks* callbacks) { | 163 WebFileSystemCallbacks* callbacks) { |
| 162 callbacks->didResolveURL( | 164 callbacks->didResolveURL(blink::WebString::fromUTF8(name), root_url, |
| 163 name, | 165 static_cast<blink::WebFileSystemType>(mount_type), |
| 164 root_url, | 166 blink::FilePathToWebString(file_path), is_directory); |
| 165 static_cast<blink::WebFileSystemType>(mount_type), | |
| 166 file_path, | |
| 167 is_directory); | |
| 168 } | 167 } |
| 169 | 168 |
| 170 void DidFail(base::File::Error error, WebFileSystemCallbacks* callbacks) { | 169 void DidFail(base::File::Error error, WebFileSystemCallbacks* callbacks) { |
| 171 callbacks->didFail(storage::FileErrorToWebFileError(error)); | 170 callbacks->didFail(storage::FileErrorToWebFileError(error)); |
| 172 } | 171 } |
| 173 | 172 |
| 174 // Run WebFileSystemCallbacks's |method| with |params|. | 173 // Run WebFileSystemCallbacks's |method| with |params|. |
| 175 void RunCallbacks( | 174 void RunCallbacks( |
| 176 int callbacks_id, | 175 int callbacks_id, |
| 177 const base::Callback<void(WebFileSystemCallbacks*)>& callback, | 176 const base::Callback<void(WebFileSystemCallbacks*)>& callback, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // Callback adapters. Callbacks must be called on the original calling thread, | 222 // Callback adapters. Callbacks must be called on the original calling thread, |
| 224 // so these callback adapters relay back the results to the calling thread | 223 // so these callback adapters relay back the results to the calling thread |
| 225 // if necessary. | 224 // if necessary. |
| 226 | 225 |
| 227 void OpenFileSystemCallbackAdapter( | 226 void OpenFileSystemCallbackAdapter( |
| 228 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 227 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 229 int callbacks_id, | 228 int callbacks_id, |
| 230 WaitableCallbackResults* waitable_results, | 229 WaitableCallbackResults* waitable_results, |
| 231 const std::string& name, | 230 const std::string& name, |
| 232 const GURL& root) { | 231 const GURL& root) { |
| 233 CallbackFileSystemCallbacks( | 232 CallbackFileSystemCallbacks(task_runner, callbacks_id, waitable_results, |
| 234 task_runner, callbacks_id, waitable_results, | 233 base::Bind(&DidOpenFileSystem, name, root), |
| 235 base::Bind(&DidOpenFileSystem, base::UTF8ToUTF16(name), root), | 234 UNREGISTER_CALLBACKS); |
| 236 UNREGISTER_CALLBACKS); | |
| 237 } | 235 } |
| 238 | 236 |
| 239 void ResolveURLCallbackAdapter( | 237 void ResolveURLCallbackAdapter( |
| 240 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 238 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 241 int callbacks_id, | 239 int callbacks_id, |
| 242 WaitableCallbackResults* waitable_results, | 240 WaitableCallbackResults* waitable_results, |
| 243 const storage::FileSystemInfo& info, | 241 const storage::FileSystemInfo& info, |
| 244 const base::FilePath& file_path, | 242 const base::FilePath& file_path, |
| 245 bool is_directory) { | 243 bool is_directory) { |
| 246 base::FilePath normalized_path( | 244 base::FilePath normalized_path( |
| 247 storage::VirtualPath::GetNormalizedFilePath(file_path)); | 245 storage::VirtualPath::GetNormalizedFilePath(file_path)); |
| 248 CallbackFileSystemCallbacks( | 246 CallbackFileSystemCallbacks( |
| 249 task_runner, callbacks_id, waitable_results, | 247 task_runner, callbacks_id, waitable_results, |
| 250 base::Bind(&DidResolveURL, base::UTF8ToUTF16(info.name), info.root_url, | 248 base::Bind(&DidResolveURL, info.name, info.root_url, info.mount_type, |
| 251 info.mount_type, normalized_path.AsUTF16Unsafe(), | 249 normalized_path, is_directory), |
| 252 is_directory), | |
| 253 UNREGISTER_CALLBACKS); | 250 UNREGISTER_CALLBACKS); |
| 254 } | 251 } |
| 255 | 252 |
| 256 void StatusCallbackAdapter( | 253 void StatusCallbackAdapter( |
| 257 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 254 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 258 int callbacks_id, | 255 int callbacks_id, |
| 259 WaitableCallbackResults* waitable_results, | 256 WaitableCallbackResults* waitable_results, |
| 260 base::File::Error error) { | 257 base::File::Error error) { |
| 261 if (error == base::File::FILE_OK) { | 258 if (error == base::File::FILE_OK) { |
| 262 CallbackFileSystemCallbacks(task_runner, callbacks_id, waitable_results, | 259 CallbackFileSystemCallbacks(task_runner, callbacks_id, waitable_results, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 WebFileSystemImpl* filesystem = | 336 WebFileSystemImpl* filesystem = |
| 340 WebFileSystemImpl::ThreadSpecificInstance(NULL); | 337 WebFileSystemImpl::ThreadSpecificInstance(NULL); |
| 341 if (!filesystem) | 338 if (!filesystem) |
| 342 return; | 339 return; |
| 343 | 340 |
| 344 WebFileSystemCallbacks callbacks = filesystem->GetCallbacks(callbacks_id); | 341 WebFileSystemCallbacks callbacks = filesystem->GetCallbacks(callbacks_id); |
| 345 filesystem->UnregisterCallbacks(callbacks_id); | 342 filesystem->UnregisterCallbacks(callbacks_id); |
| 346 | 343 |
| 347 WebFileInfo web_file_info; | 344 WebFileInfo web_file_info; |
| 348 FileInfoToWebFileInfo(file_info, &web_file_info); | 345 FileInfoToWebFileInfo(file_info, &web_file_info); |
| 349 web_file_info.platformPath = platform_path.AsUTF16Unsafe(); | 346 web_file_info.platformPath = blink::FilePathToWebString(platform_path); |
| 350 callbacks.didCreateSnapshotFile(web_file_info); | 347 callbacks.didCreateSnapshotFile(web_file_info); |
| 351 | 348 |
| 352 // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes | 349 // TODO(michaeln,kinuko): Use ThreadSafeSender when Blob becomes |
| 353 // non-bridge model. | 350 // non-bridge model. |
| 354 main_thread_task_runner->PostTask( | 351 main_thread_task_runner->PostTask( |
| 355 FROM_HERE, base::Bind(&DidReceiveSnapshotFile, request_id)); | 352 FROM_HERE, base::Bind(&DidReceiveSnapshotFile, request_id)); |
| 356 } | 353 } |
| 357 | 354 |
| 358 void CreateSnapshotFileCallbackAdapter( | 355 void CreateSnapshotFileCallbackAdapter( |
| 359 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 356 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 WaitableCallbackResults* WebFileSystemImpl::MaybeCreateWaitableResults( | 709 WaitableCallbackResults* WebFileSystemImpl::MaybeCreateWaitableResults( |
| 713 const WebFileSystemCallbacks& callbacks, int callbacks_id) { | 710 const WebFileSystemCallbacks& callbacks, int callbacks_id) { |
| 714 if (!callbacks.shouldBlockUntilCompletion()) | 711 if (!callbacks.shouldBlockUntilCompletion()) |
| 715 return NULL; | 712 return NULL; |
| 716 WaitableCallbackResults* results = new WaitableCallbackResults(); | 713 WaitableCallbackResults* results = new WaitableCallbackResults(); |
| 717 waitable_results_[callbacks_id] = results; | 714 waitable_results_[callbacks_id] = results; |
| 718 return results; | 715 return results; |
| 719 } | 716 } |
| 720 | 717 |
| 721 } // namespace content | 718 } // namespace content |
| OLD | NEW |