| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/common/file_system/webfilesystem_impl.h" | 5 #include "chrome/common/file_system/webfilesystem_impl.h" |
| 6 | 6 |
| 7 #include "chrome/common/file_system/file_system_dispatcher.h" | 7 #include "chrome/common/file_system/file_system_dispatcher.h" |
| 8 #include "chrome/common/file_system/webfilesystem_callback_dispatcher.h" |
| 8 #include "chrome/common/child_thread.h" | 9 #include "chrome/common/child_thread.h" |
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 12 #include "webkit/glue/webkit_glue.h" | 13 #include "webkit/glue/webkit_glue.h" |
| 13 | 14 |
| 14 using WebKit::WebFileInfo; | 15 using WebKit::WebFileInfo; |
| 15 using WebKit::WebFileSystemCallbacks; | 16 using WebKit::WebFileSystemCallbacks; |
| 16 using WebKit::WebFileSystemEntry; | 17 using WebKit::WebFileSystemEntry; |
| 17 using WebKit::WebString; | 18 using WebKit::WebString; |
| 18 using WebKit::WebVector; | 19 using WebKit::WebVector; |
| 19 | 20 |
| 20 namespace { | |
| 21 | |
| 22 WebKit::WebFileError PlatformFileErrorToWebFileError( | |
| 23 base::PlatformFileError error_code) { | |
| 24 switch (error_code) { | |
| 25 case base::PLATFORM_FILE_ERROR_NOT_FOUND: | |
| 26 return WebKit::WebFileErrorNotFound; | |
| 27 case base::PLATFORM_FILE_ERROR_INVALID_OPERATION: | |
| 28 case base::PLATFORM_FILE_ERROR_EXISTS: | |
| 29 case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY: | |
| 30 return WebKit::WebFileErrorInvalidModification; | |
| 31 case base::PLATFORM_FILE_ERROR_ACCESS_DENIED: | |
| 32 return WebKit::WebFileErrorNoModificationAllowed; | |
| 33 case base::PLATFORM_FILE_ERROR_FAILED: | |
| 34 return WebKit::WebFileErrorInvalidState; | |
| 35 case base::PLATFORM_FILE_ERROR_ABORT: | |
| 36 return WebKit::WebFileErrorAbort; | |
| 37 default: | |
| 38 return WebKit::WebFileErrorInvalidModification; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 class WebFileSystemCallbackDispatcherImpl | |
| 43 : public fileapi::FileSystemCallbackDispatcher { | |
| 44 public: | |
| 45 explicit WebFileSystemCallbackDispatcherImpl( | |
| 46 WebFileSystemCallbacks* callbacks) | |
| 47 : callbacks_(callbacks) { | |
| 48 DCHECK(callbacks_); | |
| 49 } | |
| 50 | |
| 51 virtual ~WebFileSystemCallbackDispatcherImpl() { | |
| 52 } | |
| 53 | |
| 54 // FileSystemCallbackDispatcher implementation | |
| 55 virtual void DidSucceed() { | |
| 56 callbacks_->didSucceed(); | |
| 57 } | |
| 58 | |
| 59 virtual void DidReadMetadata(const base::PlatformFileInfo& file_info) { | |
| 60 WebFileInfo web_file_info; | |
| 61 web_file_info.modificationTime = file_info.last_modified.ToDoubleT(); | |
| 62 callbacks_->didReadMetadata(web_file_info); | |
| 63 } | |
| 64 | |
| 65 virtual void DidReadDirectory( | |
| 66 const std::vector<base::file_util_proxy::Entry>& entries, bool has_more) { | |
| 67 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); | |
| 68 for (size_t i = 0; i < entries.size(); i++) { | |
| 69 file_system_entries[i].name = | |
| 70 webkit_glue::FilePathStringToWebString(entries[i].name); | |
| 71 file_system_entries[i].isDirectory = entries[i].is_directory; | |
| 72 } | |
| 73 callbacks_->didReadDirectory(file_system_entries, has_more); | |
| 74 } | |
| 75 | |
| 76 virtual void DidOpenFileSystem(const string16&, const FilePath&) { | |
| 77 NOTREACHED(); | |
| 78 } | |
| 79 | |
| 80 virtual void DidFail(base::PlatformFileError error_code) { | |
| 81 callbacks_->didFail(PlatformFileErrorToWebFileError(error_code)); | |
| 82 } | |
| 83 | |
| 84 private: | |
| 85 WebFileSystemCallbacks* callbacks_; | |
| 86 }; | |
| 87 | |
| 88 } // namespace | |
| 89 | |
| 90 WebFileSystemImpl::WebFileSystemImpl() { | 21 WebFileSystemImpl::WebFileSystemImpl() { |
| 91 } | 22 } |
| 92 | 23 |
| 93 void WebFileSystemImpl::move(const WebString& src_path, | 24 void WebFileSystemImpl::move(const WebString& src_path, |
| 94 const WebString& dest_path, | 25 const WebString& dest_path, |
| 95 WebFileSystemCallbacks* callbacks) { | 26 WebFileSystemCallbacks* callbacks) { |
| 96 FileSystemDispatcher* dispatcher = | 27 FileSystemDispatcher* dispatcher = |
| 97 ChildThread::current()->file_system_dispatcher(); | 28 ChildThread::current()->file_system_dispatcher(); |
| 98 dispatcher->Move(webkit_glue::WebStringToFilePath(src_path), | 29 dispatcher->Move(webkit_glue::WebStringToFilePath(src_path), |
| 99 webkit_glue::WebStringToFilePath(dest_path), | 30 webkit_glue::WebStringToFilePath(dest_path), |
| 100 new WebFileSystemCallbackDispatcherImpl(callbacks)); | 31 new WebFileSystemCallbackDispatcher(callbacks)); |
| 101 } | 32 } |
| 102 | 33 |
| 103 void WebFileSystemImpl::copy(const WebString& src_path, | 34 void WebFileSystemImpl::copy(const WebString& src_path, |
| 104 const WebString& dest_path, | 35 const WebString& dest_path, |
| 105 WebFileSystemCallbacks* callbacks) { | 36 WebFileSystemCallbacks* callbacks) { |
| 106 FileSystemDispatcher* dispatcher = | 37 FileSystemDispatcher* dispatcher = |
| 107 ChildThread::current()->file_system_dispatcher(); | 38 ChildThread::current()->file_system_dispatcher(); |
| 108 dispatcher->Copy(webkit_glue::WebStringToFilePath(src_path), | 39 dispatcher->Copy(webkit_glue::WebStringToFilePath(src_path), |
| 109 webkit_glue::WebStringToFilePath(dest_path), | 40 webkit_glue::WebStringToFilePath(dest_path), |
| 110 new WebFileSystemCallbackDispatcherImpl(callbacks)); | 41 new WebFileSystemCallbackDispatcher(callbacks)); |
| 111 } | 42 } |
| 112 | 43 |
| 113 void WebFileSystemImpl::remove(const WebString& path, | 44 void WebFileSystemImpl::remove(const WebString& path, |
| 114 WebFileSystemCallbacks* callbacks) { | 45 WebFileSystemCallbacks* callbacks) { |
| 115 FileSystemDispatcher* dispatcher = | 46 FileSystemDispatcher* dispatcher = |
| 116 ChildThread::current()->file_system_dispatcher(); | 47 ChildThread::current()->file_system_dispatcher(); |
| 117 dispatcher->Remove(webkit_glue::WebStringToFilePath(path), | 48 dispatcher->Remove(webkit_glue::WebStringToFilePath(path), |
| 118 new WebFileSystemCallbackDispatcherImpl(callbacks)); | 49 new WebFileSystemCallbackDispatcher(callbacks)); |
| 119 } | 50 } |
| 120 | 51 |
| 121 void WebFileSystemImpl::readMetadata(const WebString& path, | 52 void WebFileSystemImpl::readMetadata(const WebString& path, |
| 122 WebFileSystemCallbacks* callbacks) { | 53 WebFileSystemCallbacks* callbacks) { |
| 123 FileSystemDispatcher* dispatcher = | 54 FileSystemDispatcher* dispatcher = |
| 124 ChildThread::current()->file_system_dispatcher(); | 55 ChildThread::current()->file_system_dispatcher(); |
| 125 dispatcher->ReadMetadata(webkit_glue::WebStringToFilePath(path), | 56 dispatcher->ReadMetadata(webkit_glue::WebStringToFilePath(path), |
| 126 new WebFileSystemCallbackDispatcherImpl(callbacks)); | 57 new WebFileSystemCallbackDispatcher(callbacks)); |
| 127 } | 58 } |
| 128 | 59 |
| 129 void WebFileSystemImpl::createFile(const WebString& path, | 60 void WebFileSystemImpl::createFile(const WebString& path, |
| 130 bool exclusive, | 61 bool exclusive, |
| 131 WebFileSystemCallbacks* callbacks) { | 62 WebFileSystemCallbacks* callbacks) { |
| 132 FileSystemDispatcher* dispatcher = | 63 FileSystemDispatcher* dispatcher = |
| 133 ChildThread::current()->file_system_dispatcher(); | 64 ChildThread::current()->file_system_dispatcher(); |
| 134 dispatcher->Create(webkit_glue::WebStringToFilePath(path), exclusive, false, | 65 dispatcher->Create(webkit_glue::WebStringToFilePath(path), exclusive, false, |
| 135 false, new WebFileSystemCallbackDispatcherImpl(callbacks)); | 66 false, new WebFileSystemCallbackDispatcher(callbacks)); |
| 136 } | 67 } |
| 137 | 68 |
| 138 void WebFileSystemImpl::createDirectory(const WebString& path, | 69 void WebFileSystemImpl::createDirectory(const WebString& path, |
| 139 bool exclusive, | 70 bool exclusive, |
| 140 WebFileSystemCallbacks* callbacks) { | 71 WebFileSystemCallbacks* callbacks) { |
| 141 FileSystemDispatcher* dispatcher = | 72 FileSystemDispatcher* dispatcher = |
| 142 ChildThread::current()->file_system_dispatcher(); | 73 ChildThread::current()->file_system_dispatcher(); |
| 143 dispatcher->Create(webkit_glue::WebStringToFilePath(path), exclusive, true, | 74 dispatcher->Create(webkit_glue::WebStringToFilePath(path), exclusive, true, |
| 144 false, new WebFileSystemCallbackDispatcherImpl(callbacks)); | 75 false, new WebFileSystemCallbackDispatcher(callbacks)); |
| 145 } | 76 } |
| 146 | 77 |
| 147 void WebFileSystemImpl::fileExists(const WebString& path, | 78 void WebFileSystemImpl::fileExists(const WebString& path, |
| 148 WebFileSystemCallbacks* callbacks) { | 79 WebFileSystemCallbacks* callbacks) { |
| 149 FileSystemDispatcher* dispatcher = | 80 FileSystemDispatcher* dispatcher = |
| 150 ChildThread::current()->file_system_dispatcher(); | 81 ChildThread::current()->file_system_dispatcher(); |
| 151 dispatcher->Exists(webkit_glue::WebStringToFilePath(path), false, | 82 dispatcher->Exists(webkit_glue::WebStringToFilePath(path), false, |
| 152 new WebFileSystemCallbackDispatcherImpl(callbacks)); | 83 new WebFileSystemCallbackDispatcher(callbacks)); |
| 153 } | 84 } |
| 154 | 85 |
| 155 void WebFileSystemImpl::directoryExists(const WebString& path, | 86 void WebFileSystemImpl::directoryExists(const WebString& path, |
| 156 WebFileSystemCallbacks* callbacks) { | 87 WebFileSystemCallbacks* callbacks) { |
| 157 FileSystemDispatcher* dispatcher = | 88 FileSystemDispatcher* dispatcher = |
| 158 ChildThread::current()->file_system_dispatcher(); | 89 ChildThread::current()->file_system_dispatcher(); |
| 159 dispatcher->Exists(webkit_glue::WebStringToFilePath(path), true, | 90 dispatcher->Exists(webkit_glue::WebStringToFilePath(path), true, |
| 160 new WebFileSystemCallbackDispatcherImpl(callbacks)); | 91 new WebFileSystemCallbackDispatcher(callbacks)); |
| 161 } | 92 } |
| 162 | 93 |
| 163 void WebFileSystemImpl::readDirectory(const WebString& path, | 94 void WebFileSystemImpl::readDirectory(const WebString& path, |
| 164 WebFileSystemCallbacks* callbacks) { | 95 WebFileSystemCallbacks* callbacks) { |
| 165 FileSystemDispatcher* dispatcher = | 96 FileSystemDispatcher* dispatcher = |
| 166 ChildThread::current()->file_system_dispatcher(); | 97 ChildThread::current()->file_system_dispatcher(); |
| 167 dispatcher->ReadDirectory(webkit_glue::WebStringToFilePath(path), | 98 dispatcher->ReadDirectory(webkit_glue::WebStringToFilePath(path), |
| 168 new WebFileSystemCallbackDispatcherImpl(callbacks)); | 99 new WebFileSystemCallbackDispatcher(callbacks)); |
| 169 } | 100 } |
| OLD | NEW |