| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.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/platform/WebURL.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 21 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 21 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 22 #include "webkit/fileapi/file_system_context.h" | 22 #include "webkit/fileapi/file_system_context.h" |
| 23 #include "webkit/fileapi/file_system_operation.h" | 23 #include "webkit/fileapi/file_system_operation_interface.h" |
| 24 #include "webkit/fileapi/file_system_types.h" | 24 #include "webkit/fileapi/file_system_types.h" |
| 25 #include "webkit/fileapi/mock_file_system_options.h" | 25 #include "webkit/fileapi/mock_file_system_options.h" |
| 26 #include "webkit/glue/webkit_glue.h" | 26 #include "webkit/glue/webkit_glue.h" |
| 27 #include "webkit/tools/test_shell/simple_file_writer.h" | 27 #include "webkit/tools/test_shell/simple_file_writer.h" |
| 28 | 28 |
| 29 using base::WeakPtr; | 29 using base::WeakPtr; |
| 30 | 30 |
| 31 using WebKit::WebFileInfo; | 31 using WebKit::WebFileInfo; |
| 32 using WebKit::WebFileSystem; | 32 using WebKit::WebFileSystem; |
| 33 using WebKit::WebFileSystemCallbacks; | 33 using WebKit::WebFileSystemCallbacks; |
| 34 using WebKit::WebFileSystemEntry; | 34 using WebKit::WebFileSystemEntry; |
| 35 using WebKit::WebFileWriter; | 35 using WebKit::WebFileWriter; |
| 36 using WebKit::WebFileWriterClient; | 36 using WebKit::WebFileWriterClient; |
| 37 using WebKit::WebFrame; | 37 using WebKit::WebFrame; |
| 38 using WebKit::WebSecurityOrigin; | 38 using WebKit::WebSecurityOrigin; |
| 39 using WebKit::WebString; | 39 using WebKit::WebString; |
| 40 using WebKit::WebURL; | 40 using WebKit::WebURL; |
| 41 using WebKit::WebVector; | 41 using WebKit::WebVector; |
| 42 | 42 |
| 43 using fileapi::FileSystemCallbackDispatcher; | 43 using fileapi::FileSystemCallbackDispatcher; |
| 44 using fileapi::FileSystemContext; | 44 using fileapi::FileSystemContext; |
| 45 using fileapi::FileSystemOperation; | 45 using fileapi::FileSystemOperationInterface; |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 class SimpleFileSystemCallbackDispatcher | 49 class SimpleFileSystemCallbackDispatcher |
| 50 : public FileSystemCallbackDispatcher { | 50 : public FileSystemCallbackDispatcher { |
| 51 public: | 51 public: |
| 52 // An instance of this class must be created by Create() | 52 // An instance of this class must be created by Create() |
| 53 // (so that we do not leak ownerships). | 53 // (so that we do not leak ownerships). |
| 54 static scoped_ptr<FileSystemCallbackDispatcher> Create( | 54 static scoped_ptr<FileSystemCallbackDispatcher> Create( |
| 55 const WeakPtr<SimpleFileSystem>& file_system, | 55 const WeakPtr<SimpleFileSystem>& file_system, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 172 |
| 173 GURL origin_url(frame->document().securityOrigin().toString()); | 173 GURL origin_url(frame->document().securityOrigin().toString()); |
| 174 file_system_context_->OpenFileSystem( | 174 file_system_context_->OpenFileSystem( |
| 175 origin_url, type, create, | 175 origin_url, type, create, |
| 176 SimpleFileSystemCallbackDispatcher::Create(AsWeakPtr(), callbacks)); | 176 SimpleFileSystemCallbackDispatcher::Create(AsWeakPtr(), callbacks)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void SimpleFileSystem::move( | 179 void SimpleFileSystem::move( |
| 180 const WebURL& src_path, | 180 const WebURL& src_path, |
| 181 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { | 181 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { |
| 182 GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path)); | 182 GetNewOperation(src_path, callbacks)->Move(GURL(src_path), GURL(dest_path)); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void SimpleFileSystem::copy( | 185 void SimpleFileSystem::copy( |
| 186 const WebURL& src_path, const WebURL& dest_path, | 186 const WebURL& src_path, const WebURL& dest_path, |
| 187 WebFileSystemCallbacks* callbacks) { | 187 WebFileSystemCallbacks* callbacks) { |
| 188 GetNewOperation(callbacks)->Copy(GURL(src_path), GURL(dest_path)); | 188 GetNewOperation(src_path, callbacks)->Copy(GURL(src_path), GURL(dest_path)); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void SimpleFileSystem::remove( | 191 void SimpleFileSystem::remove( |
| 192 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 192 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 193 GetNewOperation(callbacks)->Remove(path, false /* recursive */); | 193 GetNewOperation(path, callbacks)->Remove(path, false /* recursive */); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void SimpleFileSystem::removeRecursively( | 196 void SimpleFileSystem::removeRecursively( |
| 197 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 197 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 198 GetNewOperation(callbacks)->Remove(path, true /* recursive */); | 198 GetNewOperation(path, callbacks)->Remove(path, true /* recursive */); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void SimpleFileSystem::readMetadata( | 201 void SimpleFileSystem::readMetadata( |
| 202 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 202 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 203 GetNewOperation(callbacks)->GetMetadata(path); | 203 GetNewOperation(path, callbacks)->GetMetadata(path); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void SimpleFileSystem::createFile( | 206 void SimpleFileSystem::createFile( |
| 207 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 207 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
| 208 GetNewOperation(callbacks)->CreateFile(path, exclusive); | 208 GetNewOperation(path, callbacks)->CreateFile(path, exclusive); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void SimpleFileSystem::createDirectory( | 211 void SimpleFileSystem::createDirectory( |
| 212 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 212 const WebURL& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
| 213 GetNewOperation(callbacks)->CreateDirectory(path, exclusive, false); | 213 GetNewOperation(path, callbacks)->CreateDirectory(path, exclusive, false); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void SimpleFileSystem::fileExists( | 216 void SimpleFileSystem::fileExists( |
| 217 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 217 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 218 GetNewOperation(callbacks)->FileExists(path); | 218 GetNewOperation(path, callbacks)->FileExists(path); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void SimpleFileSystem::directoryExists( | 221 void SimpleFileSystem::directoryExists( |
| 222 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 222 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 223 GetNewOperation(callbacks)->DirectoryExists(path); | 223 GetNewOperation(path, callbacks)->DirectoryExists(path); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void SimpleFileSystem::readDirectory( | 226 void SimpleFileSystem::readDirectory( |
| 227 const WebURL& path, WebFileSystemCallbacks* callbacks) { | 227 const WebURL& path, WebFileSystemCallbacks* callbacks) { |
| 228 GetNewOperation(callbacks)->ReadDirectory(path); | 228 GetNewOperation(path, callbacks)->ReadDirectory(path); |
| 229 } | 229 } |
| 230 | 230 |
| 231 WebFileWriter* SimpleFileSystem::createFileWriter( | 231 WebFileWriter* SimpleFileSystem::createFileWriter( |
| 232 const WebURL& path, WebFileWriterClient* client) { | 232 const WebURL& path, WebFileWriterClient* client) { |
| 233 return new SimpleFileWriter(path, client, file_system_context_.get()); | 233 return new SimpleFileWriter(path, client, file_system_context_.get()); |
| 234 } | 234 } |
| 235 | 235 |
| 236 FileSystemOperation* SimpleFileSystem::GetNewOperation( | 236 FileSystemOperationInterface* SimpleFileSystem::GetNewOperation( |
| 237 WebFileSystemCallbacks* callbacks) { | 237 const WebURL& url, WebFileSystemCallbacks* callbacks) { |
| 238 FileSystemOperation* operation = new FileSystemOperation( | 238 return file_system_context_->CreateFileSystemOperation( |
| 239 GURL(url), |
| 239 SimpleFileSystemCallbackDispatcher::Create(AsWeakPtr(), callbacks), | 240 SimpleFileSystemCallbackDispatcher::Create(AsWeakPtr(), callbacks), |
| 240 base::MessageLoopProxy::current(), | 241 base::MessageLoopProxy::current()); |
| 241 file_system_context_.get()); | |
| 242 return operation; | |
| 243 } | 242 } |
| OLD | NEW |