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 |
| 108 callbacks_->didOpenFileSystem( | 110 //TODO(ericu): This should keep making the old string call for now, |
| 109 WebString::fromUTF8(name), WebString::fromUTF8(root.spec())); | 111 //then we'll add the new call to webkit, then we'll convert this call, |
| 112 //then we'll remove the old call from webkit. | |
| 113 callbacks_->didOpenFileSystem(WebString::fromUTF8(name), WebURL(root)); | |
| 110 } | 114 } |
| 111 | 115 |
| 112 virtual void DidFail(base::PlatformFileError error_code) { | 116 virtual void DidFail(base::PlatformFileError error_code) { |
| 113 DCHECK(file_system_); | 117 DCHECK(file_system_); |
| 114 callbacks_->didFail( | 118 callbacks_->didFail( |
| 115 webkit_glue::PlatformFileErrorToWebFileError(error_code)); | 119 webkit_glue::PlatformFileErrorToWebFileError(error_code)); |
| 116 } | 120 } |
| 117 | 121 |
| 118 virtual void DidWrite(int64, bool) { | 122 virtual void DidWrite(int64, bool) { |
| 119 NOTREACHED(); | 123 NOTREACHED(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 else { | 170 else { |
| 167 // Unknown type filesystem is requested. | 171 // Unknown type filesystem is requested. |
| 168 callbacks->didFail(WebKit::WebFileErrorSecurity); | 172 callbacks->didFail(WebKit::WebFileErrorSecurity); |
| 169 return; | 173 return; |
| 170 } | 174 } |
| 171 | 175 |
| 172 GURL origin_url(frame->securityOrigin().toString()); | 176 GURL origin_url(frame->securityOrigin().toString()); |
| 173 GetNewOperation(callbacks)->OpenFileSystem(origin_url, type, create); | 177 GetNewOperation(callbacks)->OpenFileSystem(origin_url, type, create); |
| 174 } | 178 } |
| 175 | 179 |
| 180 void SimpleFileSystem::move(const WebString& src_path, | |
| 181 const WebString& dest_path, | |
|
kinuko
2011/04/28 12:43:31
nit: indent
| |
| 182 WebFileSystemCallbacks* callbacks) { | |
| 183 move(WebURL(GURL(src_path)), WebURL(GURL(dest_path)), callbacks); | |
| 184 } | |
| 185 | |
| 186 void SimpleFileSystem::copy(const WebString& src_path, | |
| 187 const WebString& dest_path, | |
| 188 WebFileSystemCallbacks* callbacks) { | |
| 189 copy(WebURL(GURL(src_path)), WebURL(GURL(dest_path)), callbacks); | |
| 190 } | |
| 191 | |
| 192 void SimpleFileSystem::remove(const WebString& path, | |
| 193 WebFileSystemCallbacks* callbacks) { | |
| 194 remove(WebURL(GURL(path)), callbacks); | |
| 195 } | |
| 196 | |
| 197 void SimpleFileSystem::removeRecursively(const WebString& path, | |
| 198 WebFileSystemCallbacks* callbacks) { | |
| 199 removeRecursively(WebURL(GURL(path)), callbacks); | |
| 200 } | |
| 201 | |
| 202 void SimpleFileSystem::readMetadata(const WebString& path, | |
| 203 WebFileSystemCallbacks* callbacks) { | |
| 204 readMetadata(WebURL(GURL(path)), callbacks); | |
| 205 } | |
| 206 | |
| 207 void SimpleFileSystem::createFile(const WebString& path, | |
| 208 bool exclusive, | |
| 209 WebFileSystemCallbacks* callbacks) { | |
| 210 createFile(WebURL(GURL(path)), exclusive, callbacks); | |
| 211 } | |
| 212 | |
| 213 void SimpleFileSystem::createDirectory(const WebString& path, | |
| 214 bool exclusive, | |
| 215 WebFileSystemCallbacks* callbacks) { | |
| 216 createDirectory(WebURL(GURL(path)), exclusive, callbacks); | |
| 217 } | |
| 218 | |
| 219 void SimpleFileSystem::fileExists(const WebString& path, | |
| 220 WebFileSystemCallbacks* callbacks) { | |
| 221 fileExists(WebURL(GURL(path)), callbacks); | |
| 222 } | |
| 223 | |
| 224 void SimpleFileSystem::directoryExists(const WebString& path, | |
| 225 WebFileSystemCallbacks* callbacks) { | |
| 226 directoryExists(WebURL(GURL(path)), callbacks); | |
| 227 } | |
| 228 | |
| 229 void SimpleFileSystem::readDirectory(const WebString& path, | |
| 230 WebFileSystemCallbacks* callbacks) { | |
| 231 readDirectory(WebURL(GURL(path)), callbacks); | |
| 232 } | |
| 233 | |
| 234 WebKit::WebFileWriter* SimpleFileSystem::createFileWriter( | |
| 235 const WebString& path, WebKit::WebFileWriterClient* client) { | |
| 236 return createFileWriter(WebURL(GURL(path)), client); | |
| 237 } | |
| 238 | |
| 176 void SimpleFileSystem::move( | 239 void SimpleFileSystem::move( |
| 177 const WebString& src_path, | 240 const WebURL& src_path, |
| 178 const WebString& dest_path, WebFileSystemCallbacks* callbacks) { | 241 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { |
| 179 GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path)); | 242 GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path)); |
| 180 } | 243 } |
| 181 | 244 |
| 182 void SimpleFileSystem::copy( | 245 void SimpleFileSystem::copy( |
| 183 const WebString& src_path, const WebString& dest_path, | 246 const WebURL& src_path, const WebURL& dest_path, |
| 184 WebFileSystemCallbacks* callbacks) { | 247 WebFileSystemCallbacks* callbacks) { |
| 185 GetNewOperation(callbacks)->Copy(GURL(src_path), GURL(dest_path)); | 248 GetNewOperation(callbacks)->Copy(GURL(src_path), GURL(dest_path)); |
| 186 } | 249 } |
| 187 | 250 |
| 188 void SimpleFileSystem::remove( | 251 void SimpleFileSystem::remove( |
| 189 const WebString& path, WebFileSystemCallbacks* callbacks) { | 252 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 190 GetNewOperation(callbacks)->Remove(GURL(path), false /* recursive */); | 253 GetNewOperation(callbacks)->Remove(path, false /* recursive */); |
| 191 } | 254 } |
| 192 | 255 |
| 193 void SimpleFileSystem::removeRecursively( | 256 void SimpleFileSystem::removeRecursively( |
| 194 const WebString& path, WebFileSystemCallbacks* callbacks) { | 257 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 195 GetNewOperation(callbacks)->Remove(GURL(path), true /* recursive */); | 258 GetNewOperation(callbacks)->Remove(path, true /* recursive */); |
| 196 } | 259 } |
| 197 | 260 |
| 198 void SimpleFileSystem::readMetadata( | 261 void SimpleFileSystem::readMetadata( |
| 199 const WebString& path, WebFileSystemCallbacks* callbacks) { | 262 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 200 GetNewOperation(callbacks)->GetMetadata(GURL(path)); | 263 GetNewOperation(callbacks)->GetMetadata(path); |
| 201 } | 264 } |
| 202 | 265 |
| 203 void SimpleFileSystem::createFile( | 266 void SimpleFileSystem::createFile( |
| 204 const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 267 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
| 205 GetNewOperation(callbacks)->CreateFile(GURL(path), exclusive); | 268 GetNewOperation(callbacks)->CreateFile(path, exclusive); |
| 206 } | 269 } |
| 207 | 270 |
| 208 void SimpleFileSystem::createDirectory( | 271 void SimpleFileSystem::createDirectory( |
| 209 const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 272 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
| 210 GetNewOperation(callbacks)->CreateDirectory(GURL(path), exclusive, false); | 273 GetNewOperation(callbacks)->CreateDirectory(path, exclusive, false); |
| 211 } | 274 } |
| 212 | 275 |
| 213 void SimpleFileSystem::fileExists( | 276 void SimpleFileSystem::fileExists( |
| 214 const WebString& path, WebFileSystemCallbacks* callbacks) { | 277 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 215 GetNewOperation(callbacks)->FileExists(GURL(path)); | 278 GetNewOperation(callbacks)->FileExists(path); |
| 216 } | 279 } |
| 217 | 280 |
| 218 void SimpleFileSystem::directoryExists( | 281 void SimpleFileSystem::directoryExists( |
| 219 const WebString& path, WebFileSystemCallbacks* callbacks) { | 282 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 220 GetNewOperation(callbacks)->DirectoryExists(GURL(path)); | 283 GetNewOperation(callbacks)->DirectoryExists(path); |
| 221 } | 284 } |
| 222 | 285 |
| 223 void SimpleFileSystem::readDirectory( | 286 void SimpleFileSystem::readDirectory( |
| 224 const WebString& path, WebFileSystemCallbacks* callbacks) { | 287 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 225 GetNewOperation(callbacks)->ReadDirectory(GURL(path)); | 288 GetNewOperation(callbacks)->ReadDirectory(path); |
| 226 } | 289 } |
| 227 | 290 |
| 228 WebFileWriter* SimpleFileSystem::createFileWriter( | 291 WebFileWriter* SimpleFileSystem::createFileWriter( |
| 229 const WebString& path, WebFileWriterClient* client) { | 292 const WebURL& path, WebFileWriterClient* client) { |
| 230 return new SimpleFileWriter(GURL(path), client, file_system_context_.get()); | 293 return new SimpleFileWriter(path, client, file_system_context_.get()); |
| 231 } | 294 } |
| 232 | 295 |
| 233 FileSystemOperation* SimpleFileSystem::GetNewOperation( | 296 FileSystemOperation* SimpleFileSystem::GetNewOperation( |
| 234 WebFileSystemCallbacks* callbacks) { | 297 WebFileSystemCallbacks* callbacks) { |
| 235 SimpleFileSystemCallbackDispatcher* dispatcher = | 298 SimpleFileSystemCallbackDispatcher* dispatcher = |
| 236 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); | 299 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); |
| 237 FileSystemOperation* operation = new FileSystemOperation( | 300 FileSystemOperation* operation = new FileSystemOperation( |
| 238 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(), | 301 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(), |
| 239 file_system_context_.get(), NULL); | 302 file_system_context_.get(), NULL); |
| 240 return operation; | 303 return operation; |
| 241 } | 304 } |
| OLD | NEW |