| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::FileSystemOperation; |
| 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 SimpleFileSystemCallbackDispatcher( | 52 // An instance of this class must be created by Create() |
| 53 // (so that we do not leak ownerships). |
| 54 static scoped_ptr<FileSystemCallbackDispatcher> Create( |
| 53 const WeakPtr<SimpleFileSystem>& file_system, | 55 const WeakPtr<SimpleFileSystem>& file_system, |
| 54 WebFileSystemCallbacks* callbacks) | 56 WebFileSystemCallbacks* callbacks) { |
| 55 : file_system_(file_system), | 57 return scoped_ptr<FileSystemCallbackDispatcher>( |
| 56 callbacks_(callbacks) { | 58 new SimpleFileSystemCallbackDispatcher(file_system, callbacks)); |
| 57 } | 59 } |
| 58 | 60 |
| 59 ~SimpleFileSystemCallbackDispatcher() { | 61 ~SimpleFileSystemCallbackDispatcher() { |
| 60 } | 62 } |
| 61 | 63 |
| 62 virtual void DidSucceed() { | 64 virtual void DidSucceed() { |
| 63 DCHECK(file_system_); | 65 DCHECK(file_system_); |
| 64 callbacks_->didSucceed(); | 66 callbacks_->didSucceed(); |
| 65 } | 67 } |
| 66 | 68 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 DCHECK(file_system_); | 109 DCHECK(file_system_); |
| 108 callbacks_->didFail( | 110 callbacks_->didFail( |
| 109 webkit_glue::PlatformFileErrorToWebFileError(error_code)); | 111 webkit_glue::PlatformFileErrorToWebFileError(error_code)); |
| 110 } | 112 } |
| 111 | 113 |
| 112 virtual void DidWrite(int64, bool) { | 114 virtual void DidWrite(int64, bool) { |
| 113 NOTREACHED(); | 115 NOTREACHED(); |
| 114 } | 116 } |
| 115 | 117 |
| 116 private: | 118 private: |
| 119 SimpleFileSystemCallbackDispatcher( |
| 120 const WeakPtr<SimpleFileSystem>& file_system, |
| 121 WebFileSystemCallbacks* callbacks) |
| 122 : file_system_(file_system), |
| 123 callbacks_(callbacks) { |
| 124 } |
| 125 |
| 117 WeakPtr<SimpleFileSystem> file_system_; | 126 WeakPtr<SimpleFileSystem> file_system_; |
| 118 WebFileSystemCallbacks* callbacks_; | 127 WebFileSystemCallbacks* callbacks_; |
| 119 }; | 128 }; |
| 120 | 129 |
| 121 } // namespace | 130 } // namespace |
| 122 | 131 |
| 123 SimpleFileSystem::SimpleFileSystem() { | 132 SimpleFileSystem::SimpleFileSystem() { |
| 124 if (file_system_dir_.CreateUniqueTempDir()) { | 133 if (file_system_dir_.CreateUniqueTempDir()) { |
| 125 file_system_context_ = new FileSystemContext( | 134 file_system_context_ = new FileSystemContext( |
| 126 base::MessageLoopProxy::current(), | 135 base::MessageLoopProxy::current(), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 155 type = fileapi::kFileSystemTypePersistent; | 164 type = fileapi::kFileSystemTypePersistent; |
| 156 else if (web_filesystem_type == WebFileSystem::TypeExternal) | 165 else if (web_filesystem_type == WebFileSystem::TypeExternal) |
| 157 type = fileapi::kFileSystemTypeExternal; | 166 type = fileapi::kFileSystemTypeExternal; |
| 158 else { | 167 else { |
| 159 // Unknown type filesystem is requested. | 168 // Unknown type filesystem is requested. |
| 160 callbacks->didFail(WebKit::WebFileErrorSecurity); | 169 callbacks->didFail(WebKit::WebFileErrorSecurity); |
| 161 return; | 170 return; |
| 162 } | 171 } |
| 163 | 172 |
| 164 GURL origin_url(frame->document().securityOrigin().toString()); | 173 GURL origin_url(frame->document().securityOrigin().toString()); |
| 165 GetNewOperation(callbacks)->OpenFileSystem(origin_url, type, create); | 174 file_system_context_->OpenFileSystem( |
| 175 origin_url, type, create, |
| 176 SimpleFileSystemCallbackDispatcher::Create(AsWeakPtr(), callbacks)); |
| 166 } | 177 } |
| 167 | 178 |
| 168 void SimpleFileSystem::move( | 179 void SimpleFileSystem::move( |
| 169 const WebURL& src_path, | 180 const WebURL& src_path, |
| 170 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { | 181 const WebURL& dest_path, WebFileSystemCallbacks* callbacks) { |
| 171 GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path)); | 182 GetNewOperation(callbacks)->Move(GURL(src_path), GURL(dest_path)); |
| 172 } | 183 } |
| 173 | 184 |
| 174 void SimpleFileSystem::copy( | 185 void SimpleFileSystem::copy( |
| 175 const WebURL& src_path, const WebURL& dest_path, | 186 const WebURL& src_path, const WebURL& dest_path, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 GetNewOperation(callbacks)->ReadDirectory(path); | 228 GetNewOperation(callbacks)->ReadDirectory(path); |
| 218 } | 229 } |
| 219 | 230 |
| 220 WebFileWriter* SimpleFileSystem::createFileWriter( | 231 WebFileWriter* SimpleFileSystem::createFileWriter( |
| 221 const WebURL& path, WebFileWriterClient* client) { | 232 const WebURL& path, WebFileWriterClient* client) { |
| 222 return new SimpleFileWriter(path, client, file_system_context_.get()); | 233 return new SimpleFileWriter(path, client, file_system_context_.get()); |
| 223 } | 234 } |
| 224 | 235 |
| 225 FileSystemOperation* SimpleFileSystem::GetNewOperation( | 236 FileSystemOperation* SimpleFileSystem::GetNewOperation( |
| 226 WebFileSystemCallbacks* callbacks) { | 237 WebFileSystemCallbacks* callbacks) { |
| 227 SimpleFileSystemCallbackDispatcher* dispatcher = | |
| 228 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); | |
| 229 FileSystemOperation* operation = new FileSystemOperation( | 238 FileSystemOperation* operation = new FileSystemOperation( |
| 230 dispatcher, base::MessageLoopProxy::current(), | 239 SimpleFileSystemCallbackDispatcher::Create(AsWeakPtr(), callbacks), |
| 240 base::MessageLoopProxy::current(), |
| 231 file_system_context_.get()); | 241 file_system_context_.get()); |
| 232 return operation; | 242 return operation; |
| 233 } | 243 } |
| OLD | NEW |