Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/tools/test_shell/simple_file_system.h" | 5 #include "webkit/tools/test_shell/simple_file_system.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/memory/scoped_callback_factory.h" | 8 #include "base/memory/scoped_callback_factory.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback s.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback s.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemEntry.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemEntry.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
| 20 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 21 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 21 #include "webkit/fileapi/file_system_context.h" | 22 #include "webkit/fileapi/file_system_context.h" |
| 22 #include "webkit/fileapi/file_system_file_util.h" | 23 #include "webkit/fileapi/file_system_file_util.h" |
| 23 #include "webkit/fileapi/file_system_operation.h" | 24 #include "webkit/fileapi/file_system_operation.h" |
| 24 #include "webkit/fileapi/file_system_path_manager.h" | 25 #include "webkit/fileapi/file_system_path_manager.h" |
| 25 #include "webkit/fileapi/file_system_types.h" | 26 #include "webkit/fileapi/file_system_types.h" |
| 26 #include "webkit/glue/webkit_glue.h" | 27 #include "webkit/glue/webkit_glue.h" |
| 27 #include "webkit/tools/test_shell/simple_file_writer.h" | 28 #include "webkit/tools/test_shell/simple_file_writer.h" |
| 28 | 29 |
| 29 using base::WeakPtr; | 30 using base::WeakPtr; |
| 30 | 31 |
| 31 using WebKit::WebFileInfo; | 32 using WebKit::WebFileInfo; |
| 32 using WebKit::WebFileSystem; | 33 using WebKit::WebFileSystem; |
| 33 using WebKit::WebFileSystemCallbacks; | 34 using WebKit::WebFileSystemCallbacks; |
| 34 using WebKit::WebFileSystemEntry; | 35 using WebKit::WebFileSystemEntry; |
| 35 using WebKit::WebFileWriter; | 36 using WebKit::WebFileWriter; |
| 36 using WebKit::WebFileWriterClient; | 37 using WebKit::WebFileWriterClient; |
| 37 using WebKit::WebFrame; | 38 using WebKit::WebFrame; |
| 38 using WebKit::WebSecurityOrigin; | 39 using WebKit::WebSecurityOrigin; |
| 39 using WebKit::WebString; | 40 using WebKit::WebString; |
| 41 using WebKit::WebURL; | |
| 40 using WebKit::WebVector; | 42 using WebKit::WebVector; |
| 41 | 43 |
| 42 using fileapi::FileSystemCallbackDispatcher; | 44 using fileapi::FileSystemCallbackDispatcher; |
| 43 using fileapi::FileSystemContext; | 45 using fileapi::FileSystemContext; |
| 44 using fileapi::FileSystemFileUtil; | 46 using fileapi::FileSystemFileUtil; |
| 45 using fileapi::FileSystemOperation; | 47 using fileapi::FileSystemOperation; |
| 46 | 48 |
| 47 namespace { | 49 namespace { |
| 48 | 50 |
| 49 class SimpleFileSystemCallbackDispatcher | 51 class SimpleFileSystemCallbackDispatcher |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 web_entries_vector; | 100 web_entries_vector; |
| 99 callbacks_->didReadDirectory(web_entries, has_more); | 101 callbacks_->didReadDirectory(web_entries, has_more); |
| 100 } | 102 } |
| 101 | 103 |
| 102 virtual void DidOpenFileSystem( | 104 virtual void DidOpenFileSystem( |
| 103 const std::string& name, const GURL& root) { | 105 const std::string& name, const GURL& root) { |
| 104 DCHECK(file_system_); | 106 DCHECK(file_system_); |
| 105 if (!root.is_valid()) | 107 if (!root.is_valid()) |
| 106 callbacks_->didFail(WebKit::WebFileErrorSecurity); | 108 callbacks_->didFail(WebKit::WebFileErrorSecurity); |
| 107 else | 109 else |
| 110 // Temporary hack to ease a 4-phase Chromium/WebKit commit. | |
| 111 #ifdef WEBFILESYSTEMCALLBACKS_USE_URL_NOT_STRING | |
| 112 callbacks_->didOpenFileSystem(WebString::fromUTF8(name), WebURL(root)); | |
| 113 #else | |
| 108 callbacks_->didOpenFileSystem( | 114 callbacks_->didOpenFileSystem( |
| 109 WebString::fromUTF8(name), WebString::fromUTF8(root.spec())); | 115 WebString::fromUTF8(name), WebString::fromUTF8(root.spec())); |
| 116 #endif | |
| 110 } | 117 } |
| 111 | 118 |
| 112 virtual void DidFail(base::PlatformFileError error_code) { | 119 virtual void DidFail(base::PlatformFileError error_code) { |
| 113 DCHECK(file_system_); | 120 DCHECK(file_system_); |
| 114 callbacks_->didFail( | 121 callbacks_->didFail( |
| 115 webkit_glue::PlatformFileErrorToWebFileError(error_code)); | 122 webkit_glue::PlatformFileErrorToWebFileError(error_code)); |
| 116 } | 123 } |
| 117 | 124 |
| 118 virtual void DidWrite(int64, bool) { | 125 virtual void DidWrite(int64, bool) { |
| 119 NOTREACHED(); | 126 NOTREACHED(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 else { | 173 else { |
| 167 // Unknown type filesystem is requested. | 174 // Unknown type filesystem is requested. |
| 168 callbacks->didFail(WebKit::WebFileErrorSecurity); | 175 callbacks->didFail(WebKit::WebFileErrorSecurity); |
| 169 return; | 176 return; |
| 170 } | 177 } |
| 171 | 178 |
| 172 GURL origin_url(frame->securityOrigin().toString()); | 179 GURL origin_url(frame->securityOrigin().toString()); |
| 173 GetNewOperation(callbacks)->OpenFileSystem(origin_url, type, create); | 180 GetNewOperation(callbacks)->OpenFileSystem(origin_url, type, create); |
| 174 } | 181 } |
| 175 | 182 |
| 183 void SimpleFileSystem::move(const WebString& src_path, | |
| 184 const WebString& dest_path, | |
|
kinuko
2011/05/06 07:46:57
nit: indent (here and below)
ericu
2011/05/11 22:02:18
Done, thanks; I'm not sure how I did that.
| |
| 185 WebFileSystemCallbacks* callbacks) { | |
| 186 move(WebURL(GURL(src_path)), WebURL(GURL(dest_path)), callbacks); | |
| 187 } | |
| 188 | |
| 189 void SimpleFileSystem::copy(const WebString& src_path, | |
| 190 const WebString& dest_path, | |
| 191 WebFileSystemCallbacks* callbacks) { | |
| 192 copy(WebURL(GURL(src_path)), WebURL(GURL(dest_path)), callbacks); | |
| 193 } | |
| 194 | |
| 195 void SimpleFileSystem::remove(const WebString& path, | |
| 196 WebFileSystemCallbacks* callbacks) { | |
| 197 remove(WebURL(GURL(path)), callbacks); | |
| 198 } | |
| 199 | |
| 200 void SimpleFileSystem::removeRecursively(const WebString& path, | |
| 201 WebFileSystemCallbacks* callbacks) { | |
| 202 removeRecursively(WebURL(GURL(path)), callbacks); | |
| 203 } | |
| 204 | |
| 205 void SimpleFileSystem::readMetadata(const WebString& path, | |
| 206 WebFileSystemCallbacks* callbacks) { | |
| 207 readMetadata(WebURL(GURL(path)), callbacks); | |
| 208 } | |
| 209 | |
| 210 void SimpleFileSystem::createFile(const WebString& path, | |
| 211 bool exclusive, | |
| 212 WebFileSystemCallbacks* callbacks) { | |
| 213 createFile(WebURL(GURL(path)), exclusive, callbacks); | |
| 214 } | |
| 215 | |
| 216 void SimpleFileSystem::createDirectory(const WebString& path, | |
| 217 bool exclusive, | |
| 218 WebFileSystemCallbacks* callbacks) { | |
| 219 createDirectory(WebURL(GURL(path)), exclusive, callbacks); | |
| 220 } | |
| 221 | |
| 222 void SimpleFileSystem::fileExists(const WebString& path, | |
| 223 WebFileSystemCallbacks* callbacks) { | |
| 224 fileExists(WebURL(GURL(path)), callbacks); | |
| 225 } | |
| 226 | |
| 227 void SimpleFileSystem::directoryExists(const WebString& path, | |
| 228 WebFileSystemCallbacks* callbacks) { | |
| 229 directoryExists(WebURL(GURL(path)), callbacks); | |
| 230 } | |
| 231 | |
| 232 void SimpleFileSystem::readDirectory(const WebString& path, | |
| 233 WebFileSystemCallbacks* callbacks) { | |
| 234 readDirectory(WebURL(GURL(path)), callbacks); | |
| 235 } | |
| 236 | |
| 237 WebKit::WebFileWriter* SimpleFileSystem::createFileWriter( | |
| 238 const WebString& path, WebKit::WebFileWriterClient* client) { | |
| 239 return createFileWriter(WebURL(GURL(path)), client); | |
| 240 } | |
| 241 | |
| 176 void SimpleFileSystem::move( | 242 void SimpleFileSystem::move( |
| 177 const WebString& src_path, | 243 const WebURL& src_path, |
| 178 const WebString& dest_path, WebFileSystemCallbacks* callbacks) { | 244 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { |
| 179 GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path)); | 245 GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path)); |
| 180 } | 246 } |
| 181 | 247 |
| 182 void SimpleFileSystem::copy( | 248 void SimpleFileSystem::copy( |
| 183 const WebString& src_path, const WebString& dest_path, | 249 const WebURL& src_path, const WebURL& dest_path, |
| 184 WebFileSystemCallbacks* callbacks) { | 250 WebFileSystemCallbacks* callbacks) { |
| 185 GetNewOperation(callbacks)->Copy(GURL(src_path), GURL(dest_path)); | 251 GetNewOperation(callbacks)->Copy(GURL(src_path), GURL(dest_path)); |
| 186 } | 252 } |
| 187 | 253 |
| 188 void SimpleFileSystem::remove( | 254 void SimpleFileSystem::remove( |
| 189 const WebString& path, WebFileSystemCallbacks* callbacks) { | 255 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 190 GetNewOperation(callbacks)->Remove(GURL(path), false /* recursive */); | 256 GetNewOperation(callbacks)->Remove(path, false /* recursive */); |
| 191 } | 257 } |
| 192 | 258 |
| 193 void SimpleFileSystem::removeRecursively( | 259 void SimpleFileSystem::removeRecursively( |
| 194 const WebString& path, WebFileSystemCallbacks* callbacks) { | 260 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 195 GetNewOperation(callbacks)->Remove(GURL(path), true /* recursive */); | 261 GetNewOperation(callbacks)->Remove(path, true /* recursive */); |
| 196 } | 262 } |
| 197 | 263 |
| 198 void SimpleFileSystem::readMetadata( | 264 void SimpleFileSystem::readMetadata( |
| 199 const WebString& path, WebFileSystemCallbacks* callbacks) { | 265 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 200 GetNewOperation(callbacks)->GetMetadata(GURL(path)); | 266 GetNewOperation(callbacks)->GetMetadata(path); |
| 201 } | 267 } |
| 202 | 268 |
| 203 void SimpleFileSystem::createFile( | 269 void SimpleFileSystem::createFile( |
| 204 const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 270 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
| 205 GetNewOperation(callbacks)->CreateFile(GURL(path), exclusive); | 271 GetNewOperation(callbacks)->CreateFile(path, exclusive); |
| 206 } | 272 } |
| 207 | 273 |
| 208 void SimpleFileSystem::createDirectory( | 274 void SimpleFileSystem::createDirectory( |
| 209 const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 275 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
| 210 GetNewOperation(callbacks)->CreateDirectory(GURL(path), exclusive, false); | 276 GetNewOperation(callbacks)->CreateDirectory(path, exclusive, false); |
| 211 } | 277 } |
| 212 | 278 |
| 213 void SimpleFileSystem::fileExists( | 279 void SimpleFileSystem::fileExists( |
| 214 const WebString& path, WebFileSystemCallbacks* callbacks) { | 280 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 215 GetNewOperation(callbacks)->FileExists(GURL(path)); | 281 GetNewOperation(callbacks)->FileExists(path); |
| 216 } | 282 } |
| 217 | 283 |
| 218 void SimpleFileSystem::directoryExists( | 284 void SimpleFileSystem::directoryExists( |
| 219 const WebString& path, WebFileSystemCallbacks* callbacks) { | 285 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 220 GetNewOperation(callbacks)->DirectoryExists(GURL(path)); | 286 GetNewOperation(callbacks)->DirectoryExists(path); |
| 221 } | 287 } |
| 222 | 288 |
| 223 void SimpleFileSystem::readDirectory( | 289 void SimpleFileSystem::readDirectory( |
| 224 const WebString& path, WebFileSystemCallbacks* callbacks) { | 290 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 225 GetNewOperation(callbacks)->ReadDirectory(GURL(path)); | 291 GetNewOperation(callbacks)->ReadDirectory(path); |
| 226 } | 292 } |
| 227 | 293 |
| 228 WebFileWriter* SimpleFileSystem::createFileWriter( | 294 WebFileWriter* SimpleFileSystem::createFileWriter( |
| 229 const WebString& path, WebFileWriterClient* client) { | 295 const WebURL& path, WebFileWriterClient* client) { |
| 230 return new SimpleFileWriter(GURL(path), client, file_system_context_.get()); | 296 return new SimpleFileWriter(path, client, file_system_context_.get()); |
| 231 } | 297 } |
| 232 | 298 |
| 233 FileSystemOperation* SimpleFileSystem::GetNewOperation( | 299 FileSystemOperation* SimpleFileSystem::GetNewOperation( |
| 234 WebFileSystemCallbacks* callbacks) { | 300 WebFileSystemCallbacks* callbacks) { |
| 235 SimpleFileSystemCallbackDispatcher* dispatcher = | 301 SimpleFileSystemCallbackDispatcher* dispatcher = |
| 236 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); | 302 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); |
| 237 FileSystemOperation* operation = new FileSystemOperation( | 303 FileSystemOperation* operation = new FileSystemOperation( |
| 238 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(), | 304 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(), |
| 239 file_system_context_.get(), NULL); | 305 file_system_context_.get(), NULL); |
| 240 return operation; | 306 return operation; |
| 241 } | 307 } |
| OLD | NEW |