| 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" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 entry.name = webkit_glue::FilePathStringToWebString(it->name); | 88 entry.name = webkit_glue::FilePathStringToWebString(it->name); |
| 89 entry.isDirectory = it->is_directory; | 89 entry.isDirectory = it->is_directory; |
| 90 web_entries_vector.push_back(entry); | 90 web_entries_vector.push_back(entry); |
| 91 } | 91 } |
| 92 WebVector<WebKit::WebFileSystemEntry> web_entries = | 92 WebVector<WebKit::WebFileSystemEntry> web_entries = |
| 93 web_entries_vector; | 93 web_entries_vector; |
| 94 callbacks_->didReadDirectory(web_entries, has_more); | 94 callbacks_->didReadDirectory(web_entries, has_more); |
| 95 } | 95 } |
| 96 | 96 |
| 97 virtual void DidOpenFileSystem( | 97 virtual void DidOpenFileSystem( |
| 98 const std::string& name, const FilePath& path) { | 98 const std::string& name, const GURL& root) { |
| 99 DCHECK(file_system_); | 99 DCHECK(file_system_); |
| 100 if (path.empty()) | 100 if (!root.is_valid()) |
| 101 callbacks_->didFail(WebKit::WebFileErrorSecurity); | 101 callbacks_->didFail(WebKit::WebFileErrorSecurity); |
| 102 else | 102 else |
| 103 callbacks_->didOpenFileSystem( | 103 callbacks_->didOpenFileSystem( |
| 104 UTF8ToUTF16(name), webkit_glue::FilePathToWebString(path)); | 104 WebString::fromUTF8(name), WebString::fromUTF8(root.spec())); |
| 105 } | 105 } |
| 106 | 106 |
| 107 virtual void DidFail(base::PlatformFileError error_code) { | 107 virtual void DidFail(base::PlatformFileError error_code) { |
| 108 DCHECK(file_system_); | 108 DCHECK(file_system_); |
| 109 callbacks_->didFail( | 109 callbacks_->didFail( |
| 110 webkit_glue::PlatformFileErrorToWebFileError(error_code)); | 110 webkit_glue::PlatformFileErrorToWebFileError(error_code)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 virtual void DidWrite(int64, bool) { | 113 virtual void DidWrite(int64, bool) { |
| 114 NOTREACHED(); | 114 NOTREACHED(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 | 163 |
| 164 GURL origin_url(frame->securityOrigin().toString()); | 164 GURL origin_url(frame->securityOrigin().toString()); |
| 165 GetNewOperation(callbacks)->OpenFileSystem(origin_url, type, create); | 165 GetNewOperation(callbacks)->OpenFileSystem(origin_url, type, create); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void SimpleFileSystem::move( | 168 void SimpleFileSystem::move( |
| 169 const WebString& src_path, | 169 const WebString& src_path, |
| 170 const WebString& dest_path, WebFileSystemCallbacks* callbacks) { | 170 const WebString& dest_path, WebFileSystemCallbacks* callbacks) { |
| 171 FilePath dest_filepath(webkit_glue::WebStringToFilePath(dest_path)); | 171 GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path)); |
| 172 FilePath src_filepath(webkit_glue::WebStringToFilePath(src_path)); | |
| 173 | |
| 174 GetNewOperation(callbacks)->Move(src_filepath, dest_filepath); | |
| 175 } | 172 } |
| 176 | 173 |
| 177 void SimpleFileSystem::copy( | 174 void SimpleFileSystem::copy( |
| 178 const WebString& src_path, const WebString& dest_path, | 175 const WebString& src_path, const WebString& dest_path, |
| 179 WebFileSystemCallbacks* callbacks) { | 176 WebFileSystemCallbacks* callbacks) { |
| 180 FilePath dest_filepath(webkit_glue::WebStringToFilePath(dest_path)); | 177 GetNewOperation(callbacks)->Copy(GURL(src_path), GURL(dest_path)); |
| 181 FilePath src_filepath(webkit_glue::WebStringToFilePath(src_path)); | |
| 182 | |
| 183 GetNewOperation(callbacks)->Copy(src_filepath, dest_filepath); | |
| 184 } | 178 } |
| 185 | 179 |
| 186 void SimpleFileSystem::remove( | 180 void SimpleFileSystem::remove( |
| 187 const WebString& path, WebFileSystemCallbacks* callbacks) { | 181 const WebString& path, WebFileSystemCallbacks* callbacks) { |
| 188 FilePath filepath(webkit_glue::WebStringToFilePath(path)); | 182 GetNewOperation(callbacks)->Remove(GURL(path), false /* recursive */); |
| 189 | |
| 190 GetNewOperation(callbacks)->Remove(filepath, false /* recursive */); | |
| 191 } | 183 } |
| 192 | 184 |
| 193 void SimpleFileSystem::removeRecursively( | 185 void SimpleFileSystem::removeRecursively( |
| 194 const WebString& path, WebFileSystemCallbacks* callbacks) { | 186 const WebString& path, WebFileSystemCallbacks* callbacks) { |
| 195 FilePath filepath(webkit_glue::WebStringToFilePath(path)); | 187 GetNewOperation(callbacks)->Remove(GURL(path), true /* recursive */); |
| 196 | |
| 197 GetNewOperation(callbacks)->Remove(filepath, true /* recursive */); | |
| 198 } | 188 } |
| 199 | 189 |
| 200 void SimpleFileSystem::readMetadata( | 190 void SimpleFileSystem::readMetadata( |
| 201 const WebString& path, WebFileSystemCallbacks* callbacks) { | 191 const WebString& path, WebFileSystemCallbacks* callbacks) { |
| 202 FilePath filepath(webkit_glue::WebStringToFilePath(path)); | 192 GetNewOperation(callbacks)->GetMetadata(GURL(path)); |
| 203 | |
| 204 GetNewOperation(callbacks)->GetMetadata(filepath); | |
| 205 } | 193 } |
| 206 | 194 |
| 207 void SimpleFileSystem::createFile( | 195 void SimpleFileSystem::createFile( |
| 208 const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 196 const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
| 209 FilePath filepath(webkit_glue::WebStringToFilePath(path)); | 197 GetNewOperation(callbacks)->CreateFile(GURL(path), exclusive); |
| 210 | |
| 211 GetNewOperation(callbacks)->CreateFile(filepath, exclusive); | |
| 212 } | 198 } |
| 213 | 199 |
| 214 void SimpleFileSystem::createDirectory( | 200 void SimpleFileSystem::createDirectory( |
| 215 const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { | 201 const WebString& path, bool exclusive, WebFileSystemCallbacks* callbacks) { |
| 216 FilePath filepath(webkit_glue::WebStringToFilePath(path)); | 202 GetNewOperation(callbacks)->CreateDirectory(GURL(path), exclusive, false); |
| 217 | |
| 218 GetNewOperation(callbacks)->CreateDirectory(filepath, exclusive, false); | |
| 219 } | 203 } |
| 220 | 204 |
| 221 void SimpleFileSystem::fileExists( | 205 void SimpleFileSystem::fileExists( |
| 222 const WebString& path, WebFileSystemCallbacks* callbacks) { | 206 const WebString& path, WebFileSystemCallbacks* callbacks) { |
| 223 FilePath filepath(webkit_glue::WebStringToFilePath(path)); | 207 GetNewOperation(callbacks)->FileExists(GURL(path)); |
| 224 | |
| 225 GetNewOperation(callbacks)->FileExists(filepath); | |
| 226 } | 208 } |
| 227 | 209 |
| 228 void SimpleFileSystem::directoryExists( | 210 void SimpleFileSystem::directoryExists( |
| 229 const WebString& path, WebFileSystemCallbacks* callbacks) { | 211 const WebString& path, WebFileSystemCallbacks* callbacks) { |
| 230 FilePath filepath(webkit_glue::WebStringToFilePath(path)); | 212 GetNewOperation(callbacks)->DirectoryExists(GURL(path)); |
| 231 | |
| 232 GetNewOperation(callbacks)->DirectoryExists(filepath); | |
| 233 } | 213 } |
| 234 | 214 |
| 235 void SimpleFileSystem::readDirectory( | 215 void SimpleFileSystem::readDirectory( |
| 236 const WebString& path, WebFileSystemCallbacks* callbacks) { | 216 const WebString& path, WebFileSystemCallbacks* callbacks) { |
| 237 FilePath filepath(webkit_glue::WebStringToFilePath(path)); | 217 GetNewOperation(callbacks)->ReadDirectory(GURL(path)); |
| 238 | |
| 239 GetNewOperation(callbacks)->ReadDirectory(filepath); | |
| 240 } | 218 } |
| 241 | 219 |
| 242 WebFileWriter* SimpleFileSystem::createFileWriter( | 220 WebFileWriter* SimpleFileSystem::createFileWriter( |
| 243 const WebString& path, WebFileWriterClient* client) { | 221 const WebString& path, WebFileWriterClient* client) { |
| 244 return new SimpleFileWriter(path, client, file_system_context_.get()); | 222 return new SimpleFileWriter(GURL(path), client, file_system_context_.get()); |
| 245 } | 223 } |
| 246 | 224 |
| 247 FileSystemOperation* SimpleFileSystem::GetNewOperation( | 225 FileSystemOperation* SimpleFileSystem::GetNewOperation( |
| 248 WebFileSystemCallbacks* callbacks) { | 226 WebFileSystemCallbacks* callbacks) { |
| 249 SimpleFileSystemCallbackDispatcher* dispatcher = | 227 SimpleFileSystemCallbackDispatcher* dispatcher = |
| 250 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); | 228 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); |
| 251 FileSystemOperation* operation = new FileSystemOperation( | 229 FileSystemOperation* operation = new FileSystemOperation( |
| 252 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(), | 230 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(), |
| 253 file_system_context_.get(), NULL); | 231 file_system_context_.get(), NULL); |
| 254 return operation; | 232 return operation; |
| 255 } | 233 } |
| OLD | NEW |