OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_callback_factory.h" | 10 #include "base/scoped_callback_factory.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/WebVector.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
20 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 20 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
21 #include "webkit/fileapi/file_system_context.h" | 21 #include "webkit/fileapi/file_system_context.h" |
| 22 #include "webkit/fileapi/file_system_file_util.h" |
22 #include "webkit/fileapi/file_system_operation.h" | 23 #include "webkit/fileapi/file_system_operation.h" |
23 #include "webkit/fileapi/file_system_path_manager.h" | 24 #include "webkit/fileapi/file_system_path_manager.h" |
24 #include "webkit/fileapi/file_system_types.h" | 25 #include "webkit/fileapi/file_system_types.h" |
25 #include "webkit/glue/webkit_glue.h" | 26 #include "webkit/glue/webkit_glue.h" |
26 #include "webkit/tools/test_shell/simple_file_writer.h" | 27 #include "webkit/tools/test_shell/simple_file_writer.h" |
27 | 28 |
28 using base::WeakPtr; | 29 using base::WeakPtr; |
29 | 30 |
30 using WebKit::WebFileInfo; | 31 using WebKit::WebFileInfo; |
31 using WebKit::WebFileSystem; | 32 using WebKit::WebFileSystem; |
32 using WebKit::WebFileSystemCallbacks; | 33 using WebKit::WebFileSystemCallbacks; |
33 using WebKit::WebFileSystemEntry; | 34 using WebKit::WebFileSystemEntry; |
34 using WebKit::WebFileWriter; | 35 using WebKit::WebFileWriter; |
35 using WebKit::WebFileWriterClient; | 36 using WebKit::WebFileWriterClient; |
36 using WebKit::WebFrame; | 37 using WebKit::WebFrame; |
37 using WebKit::WebSecurityOrigin; | 38 using WebKit::WebSecurityOrigin; |
38 using WebKit::WebString; | 39 using WebKit::WebString; |
39 using WebKit::WebVector; | 40 using WebKit::WebVector; |
40 | 41 |
41 using fileapi::FileSystemCallbackDispatcher; | 42 using fileapi::FileSystemCallbackDispatcher; |
42 using fileapi::FileSystemContext; | 43 using fileapi::FileSystemContext; |
| 44 using fileapi::FileSystemFileUtil; |
43 using fileapi::FileSystemOperation; | 45 using fileapi::FileSystemOperation; |
44 | 46 |
45 namespace { | 47 namespace { |
46 | 48 |
47 class SimpleFileSystemCallbackDispatcher | 49 class SimpleFileSystemCallbackDispatcher |
48 : public FileSystemCallbackDispatcher { | 50 : public FileSystemCallbackDispatcher { |
49 public: | 51 public: |
50 SimpleFileSystemCallbackDispatcher( | 52 SimpleFileSystemCallbackDispatcher( |
51 const WeakPtr<SimpleFileSystem>& file_system, | 53 const WeakPtr<SimpleFileSystem>& file_system, |
52 WebFileSystemCallbacks* callbacks) | 54 WebFileSystemCallbacks* callbacks) |
53 : file_system_(file_system), | 55 : file_system_(file_system), |
54 callbacks_(callbacks) { | 56 callbacks_(callbacks) { |
55 } | 57 } |
56 | 58 |
57 ~SimpleFileSystemCallbackDispatcher() { | 59 ~SimpleFileSystemCallbackDispatcher() { |
58 } | 60 } |
59 | 61 |
60 virtual void DidSucceed() { | 62 virtual void DidSucceed() { |
61 DCHECK(file_system_); | 63 DCHECK(file_system_); |
62 callbacks_->didSucceed(); | 64 callbacks_->didSucceed(); |
63 } | 65 } |
64 | 66 |
65 virtual void DidReadMetadata(const base::PlatformFileInfo& info) { | 67 virtual void DidReadMetadata(const base::PlatformFileInfo& info) { |
66 DCHECK(file_system_); | 68 DCHECK(file_system_); |
67 WebFileInfo web_file_info; | 69 WebFileInfo web_file_info; |
68 web_file_info.length = info.size; | 70 web_file_info.length = info.size; |
69 web_file_info.modificationTime = info.last_modified.ToDoubleT(); | 71 web_file_info.modificationTime = info.last_modified.ToDoubleT(); |
70 web_file_info.type = info.is_directory ? | 72 web_file_info.type = info.is_directory ? |
71 WebFileInfo::TypeDirectory : WebFileInfo::TypeFile; | 73 WebFileInfo::TypeDirectory : WebFileInfo::TypeFile; |
| 74 web_file_info.platformPath = |
| 75 webkit_glue::FilePathToWebString(info.path); |
72 callbacks_->didReadMetadata(web_file_info); | 76 callbacks_->didReadMetadata(web_file_info); |
73 } | 77 } |
74 | 78 |
75 virtual void DidReadDirectory( | 79 virtual void DidReadDirectory( |
76 const std::vector<base::FileUtilProxy::Entry>& entries, | 80 const std::vector<base::FileUtilProxy::Entry>& entries, |
77 bool has_more) { | 81 bool has_more) { |
78 DCHECK(file_system_); | 82 DCHECK(file_system_); |
79 std::vector<WebFileSystemEntry> web_entries_vector; | 83 std::vector<WebFileSystemEntry> web_entries_vector; |
80 for (std::vector<base::FileUtilProxy::Entry>::const_iterator it = | 84 for (std::vector<base::FileUtilProxy::Entry>::const_iterator it = |
81 entries.begin(); it != entries.end(); ++it) { | 85 entries.begin(); it != entries.end(); ++it) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 233 |
230 void SimpleFileSystem::readDirectory( | 234 void SimpleFileSystem::readDirectory( |
231 const WebString& path, WebFileSystemCallbacks* callbacks) { | 235 const WebString& path, WebFileSystemCallbacks* callbacks) { |
232 FilePath filepath(webkit_glue::WebStringToFilePath(path)); | 236 FilePath filepath(webkit_glue::WebStringToFilePath(path)); |
233 | 237 |
234 GetNewOperation(callbacks)->ReadDirectory(filepath); | 238 GetNewOperation(callbacks)->ReadDirectory(filepath); |
235 } | 239 } |
236 | 240 |
237 WebFileWriter* SimpleFileSystem::createFileWriter( | 241 WebFileWriter* SimpleFileSystem::createFileWriter( |
238 const WebString& path, WebFileWriterClient* client) { | 242 const WebString& path, WebFileWriterClient* client) { |
239 return new SimpleFileWriter(path, client); | 243 return new SimpleFileWriter(path, client, file_system_context_.get()); |
240 } | 244 } |
241 | 245 |
242 FileSystemOperation* SimpleFileSystem::GetNewOperation( | 246 FileSystemOperation* SimpleFileSystem::GetNewOperation( |
243 WebFileSystemCallbacks* callbacks) { | 247 WebFileSystemCallbacks* callbacks) { |
244 SimpleFileSystemCallbackDispatcher* dispatcher = | 248 SimpleFileSystemCallbackDispatcher* dispatcher = |
245 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); | 249 new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks); |
246 FileSystemOperation* operation = new FileSystemOperation( | 250 FileSystemOperation* operation = new FileSystemOperation( |
247 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(), | 251 dispatcher, base::MessageLoopProxy::CreateForCurrentThread(), |
248 file_system_context_.get()); | 252 file_system_context_.get(), NULL); |
249 return operation; | 253 return operation; |
250 } | 254 } |
OLD | NEW |