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_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h" |
11 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemEntry.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemEntry.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
13 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 13 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
14 #include "webkit/glue/webkit_glue.h" | 14 #include "webkit/glue/webkit_glue.h" |
15 #include "webkit/tools/test_shell/simple_file_writer.h" | 15 #include "webkit/tools/test_shell/simple_file_writer.h" |
16 | 16 |
17 using WebKit::WebFileInfo; | 17 using WebKit::WebFileInfo; |
18 using WebKit::WebFileSystemCallbacks; | 18 using WebKit::WebFileSystemCallbacks; |
19 using WebKit::WebFileSystemEntry; | 19 using WebKit::WebFileSystemEntry; |
20 using WebKit::WebFileWriter; | 20 using WebKit::WebFileWriter; |
21 using WebKit::WebFileWriterClient; | 21 using WebKit::WebFileWriterClient; |
22 using WebKit::WebString; | 22 using WebKit::WebString; |
23 using WebKit::WebVector; | 23 using WebKit::WebVector; |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 class TestShellFileSystemCallbackDispatcher | 27 class SimpleFileSystemCallbackDispatcher |
28 : public fileapi::FileSystemCallbackDispatcher { | 28 : public fileapi::FileSystemCallbackDispatcher { |
29 public: | 29 public: |
30 TestShellFileSystemCallbackDispatcher( | 30 SimpleFileSystemCallbackDispatcher( |
31 SimpleFileSystem* file_system, | 31 SimpleFileSystem* file_system, |
32 WebFileSystemCallbacks* callbacks) | 32 WebFileSystemCallbacks* callbacks) |
33 : file_system_(file_system), | 33 : file_system_(file_system), |
34 callbacks_(callbacks), | 34 callbacks_(callbacks) { |
35 request_id_(-1) { | |
36 } | 35 } |
37 | 36 |
38 void set_request_id(int request_id) { request_id_ = request_id; } | |
39 | |
40 virtual void DidSucceed() { | 37 virtual void DidSucceed() { |
41 callbacks_->didSucceed(); | 38 callbacks_->didSucceed(); |
42 file_system_->RemoveCompletedOperation(request_id_); | |
43 } | 39 } |
44 | 40 |
45 virtual void DidReadMetadata(const base::PlatformFileInfo& info) { | 41 virtual void DidReadMetadata(const base::PlatformFileInfo& info) { |
46 WebFileInfo web_file_info; | 42 WebFileInfo web_file_info; |
47 web_file_info.length = info.size; | 43 web_file_info.length = info.size; |
48 web_file_info.modificationTime = info.last_modified.ToDoubleT(); | 44 web_file_info.modificationTime = info.last_modified.ToDoubleT(); |
49 web_file_info.type = info.is_directory ? | 45 web_file_info.type = info.is_directory ? |
50 WebFileInfo::TypeDirectory : WebFileInfo::TypeFile; | 46 WebFileInfo::TypeDirectory : WebFileInfo::TypeFile; |
51 callbacks_->didReadMetadata(web_file_info); | 47 callbacks_->didReadMetadata(web_file_info); |
52 file_system_->RemoveCompletedOperation(request_id_); | |
53 } | 48 } |
54 | 49 |
55 virtual void DidReadDirectory( | 50 virtual void DidReadDirectory( |
56 const std::vector<base::FileUtilProxy::Entry>& entries, | 51 const std::vector<base::FileUtilProxy::Entry>& entries, |
57 bool has_more) { | 52 bool has_more) { |
58 std::vector<WebFileSystemEntry> web_entries_vector; | 53 std::vector<WebFileSystemEntry> web_entries_vector; |
59 for (std::vector<base::FileUtilProxy::Entry>::const_iterator it = | 54 for (std::vector<base::FileUtilProxy::Entry>::const_iterator it = |
60 entries.begin(); it != entries.end(); ++it) { | 55 entries.begin(); it != entries.end(); ++it) { |
61 WebFileSystemEntry entry; | 56 WebFileSystemEntry entry; |
62 entry.name = webkit_glue::FilePathStringToWebString(it->name); | 57 entry.name = webkit_glue::FilePathStringToWebString(it->name); |
63 entry.isDirectory = it->is_directory; | 58 entry.isDirectory = it->is_directory; |
64 web_entries_vector.push_back(entry); | 59 web_entries_vector.push_back(entry); |
65 } | 60 } |
66 WebVector<WebKit::WebFileSystemEntry> web_entries = | 61 WebVector<WebKit::WebFileSystemEntry> web_entries = |
67 web_entries_vector; | 62 web_entries_vector; |
68 callbacks_->didReadDirectory(web_entries, has_more); | 63 callbacks_->didReadDirectory(web_entries, has_more); |
69 file_system_->RemoveCompletedOperation(request_id_); | |
70 } | 64 } |
71 | 65 |
72 virtual void DidOpenFileSystem(const std::string&, const FilePath&) { | 66 virtual void DidOpenFileSystem(const std::string&, const FilePath&) { |
73 NOTREACHED(); | 67 NOTREACHED(); |
74 } | 68 } |
75 | 69 |
76 virtual void DidFail(base::PlatformFileError error_code) { | 70 virtual void DidFail(base::PlatformFileError error_code) { |
77 callbacks_->didFail( | 71 callbacks_->didFail( |
78 webkit_glue::PlatformFileErrorToWebFileError(error_code)); | 72 webkit_glue::PlatformFileErrorToWebFileError(error_code)); |
79 file_system_->RemoveCompletedOperation(request_id_); | |
80 } | 73 } |
81 | 74 |
82 virtual void DidWrite(int64, bool) { | 75 virtual void DidWrite(int64, bool) { |
83 NOTREACHED(); | 76 NOTREACHED(); |
84 } | 77 } |
85 | 78 |
86 private: | 79 private: |
87 SimpleFileSystem* file_system_; | 80 SimpleFileSystem* file_system_; |
michaeln
2010/11/18 01:49:06
Would a WeakPtr make sense here now or maybe you d
| |
88 WebFileSystemCallbacks* callbacks_; | 81 WebFileSystemCallbacks* callbacks_; |
89 int request_id_; | |
90 }; | 82 }; |
91 | 83 |
92 } // namespace | 84 } // namespace |
93 | 85 |
94 SimpleFileSystem::~SimpleFileSystem() { | 86 SimpleFileSystem::~SimpleFileSystem() { |
95 // Drop all the operations. | |
96 for (OperationsMap::const_iterator iter(&operations_); | |
97 !iter.IsAtEnd(); iter.Advance()) | |
98 operations_.Remove(iter.GetCurrentKey()); | |
michaeln
2010/11/18 01:49:06
In the chrome case, FileSystemDispatcherHost is re
| |
99 } | 87 } |
100 | 88 |
101 void SimpleFileSystem::move( | 89 void SimpleFileSystem::move( |
102 const WebString& src_path, | 90 const WebString& src_path, |
103 const WebString& dest_path, WebFileSystemCallbacks* callbacks) { | 91 const WebString& dest_path, WebFileSystemCallbacks* callbacks) { |
104 FilePath dest_filepath(webkit_glue::WebStringToFilePath(dest_path)); | 92 FilePath dest_filepath(webkit_glue::WebStringToFilePath(dest_path)); |
105 FilePath src_filepath(webkit_glue::WebStringToFilePath(src_path)); | 93 FilePath src_filepath(webkit_glue::WebStringToFilePath(src_path)); |
106 | 94 |
107 GetNewOperation(callbacks)->Move(src_filepath, dest_filepath); | 95 GetNewOperation(callbacks)->Move(src_filepath, dest_filepath); |
108 } | 96 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 GetNewOperation(callbacks)->ReadDirectory(filepath); | 160 GetNewOperation(callbacks)->ReadDirectory(filepath); |
173 } | 161 } |
174 | 162 |
175 WebFileWriter* SimpleFileSystem::createFileWriter( | 163 WebFileWriter* SimpleFileSystem::createFileWriter( |
176 const WebString& path, WebFileWriterClient* client) { | 164 const WebString& path, WebFileWriterClient* client) { |
177 return new SimpleFileWriter(path, client); | 165 return new SimpleFileWriter(path, client); |
178 } | 166 } |
179 | 167 |
180 fileapi::FileSystemOperation* SimpleFileSystem::GetNewOperation( | 168 fileapi::FileSystemOperation* SimpleFileSystem::GetNewOperation( |
181 WebFileSystemCallbacks* callbacks) { | 169 WebFileSystemCallbacks* callbacks) { |
182 // This pointer will be owned by |operation|. | 170 SimpleFileSystemCallbackDispatcher* dispatcher = |
183 TestShellFileSystemCallbackDispatcher* dispatcher = | 171 new SimpleFileSystemCallbackDispatcher(this, callbacks); |
184 new TestShellFileSystemCallbackDispatcher(this, callbacks); | |
185 fileapi::FileSystemOperation* operation = new fileapi::FileSystemOperation( | 172 fileapi::FileSystemOperation* operation = new fileapi::FileSystemOperation( |
186 dispatcher, base::MessageLoopProxy::CreateForCurrentThread()); | 173 dispatcher, base::MessageLoopProxy::CreateForCurrentThread()); |
187 int32 request_id = operations_.Add(operation); | |
188 dispatcher->set_request_id(request_id); | |
189 return operation; | 174 return operation; |
190 } | 175 } |
191 | |
192 void SimpleFileSystem::RemoveCompletedOperation(int request_id) { | |
193 operations_.Remove(request_id); | |
194 } | |
OLD | NEW |