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 "chrome/common/file_system/webfilesystem_callback_dispatcher.h" | 5 #include "chrome/common/file_system/webfilesystem_callback_dispatcher.h" |
6 | 6 |
7 #include "base/file_util_proxy.h" | 7 #include "base/file_util_proxy.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" |
11 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
13 #include "webkit/glue/webkit_glue.h" | 13 #include "webkit/glue/webkit_glue.h" |
14 | 14 |
15 using WebKit::WebFileInfo; | 15 using WebKit::WebFileInfo; |
16 using WebKit::WebFileSystemCallbacks; | 16 using WebKit::WebFileSystemCallbacks; |
17 using WebKit::WebFileSystemEntry; | 17 using WebKit::WebFileSystemEntry; |
18 using WebKit::WebString; | 18 using WebKit::WebString; |
19 using WebKit::WebVector; | 19 using WebKit::WebVector; |
20 | 20 |
21 namespace { | |
22 | |
23 WebKit::WebFileError PlatformFileErrorToWebFileError( | |
24 base::PlatformFileError error_code) { | |
25 switch (error_code) { | |
26 case base::PLATFORM_FILE_ERROR_NOT_FOUND: | |
27 return WebKit::WebFileErrorNotFound; | |
28 case base::PLATFORM_FILE_ERROR_INVALID_OPERATION: | |
29 case base::PLATFORM_FILE_ERROR_EXISTS: | |
30 case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY: | |
31 return WebKit::WebFileErrorInvalidModification; | |
32 case base::PLATFORM_FILE_ERROR_ACCESS_DENIED: | |
33 return WebKit::WebFileErrorNoModificationAllowed; | |
34 case base::PLATFORM_FILE_ERROR_FAILED: | |
35 return WebKit::WebFileErrorInvalidState; | |
36 case base::PLATFORM_FILE_ERROR_ABORT: | |
37 return WebKit::WebFileErrorAbort; | |
38 default: | |
39 return WebKit::WebFileErrorInvalidModification; | |
40 } | |
41 } | |
42 | |
43 } | |
44 | |
45 WebFileSystemCallbackDispatcher::WebFileSystemCallbackDispatcher( | 21 WebFileSystemCallbackDispatcher::WebFileSystemCallbackDispatcher( |
46 WebFileSystemCallbacks* callbacks) | 22 WebFileSystemCallbacks* callbacks) |
47 : callbacks_(callbacks) { | 23 : callbacks_(callbacks) { |
48 DCHECK(callbacks_); | 24 DCHECK(callbacks_); |
49 } | 25 } |
50 | 26 |
51 void WebFileSystemCallbackDispatcher::DidSucceed() { | 27 void WebFileSystemCallbackDispatcher::DidSucceed() { |
52 callbacks_->didSucceed(); | 28 callbacks_->didSucceed(); |
53 } | 29 } |
54 | 30 |
55 void WebFileSystemCallbackDispatcher::DidReadMetadata( | 31 void WebFileSystemCallbackDispatcher::DidReadMetadata( |
56 const base::PlatformFileInfo& file_info) { | 32 const base::PlatformFileInfo& file_info) { |
57 WebFileInfo web_file_info; | 33 WebFileInfo web_file_info; |
58 web_file_info.modificationTime = file_info.last_modified.ToDoubleT(); | 34 web_file_info.modificationTime = file_info.last_modified.ToDoubleT(); |
| 35 web_file_info.length = file_info.size; |
| 36 if (file_info.is_directory) |
| 37 web_file_info.type = WebFileInfo::TypeDirectory; |
| 38 else |
| 39 web_file_info.type = WebFileInfo::TypeFile; |
59 callbacks_->didReadMetadata(web_file_info); | 40 callbacks_->didReadMetadata(web_file_info); |
60 } | 41 } |
61 | 42 |
62 void WebFileSystemCallbackDispatcher::DidReadDirectory( | 43 void WebFileSystemCallbackDispatcher::DidReadDirectory( |
63 const std::vector<base::file_util_proxy::Entry>& entries, bool has_more) { | 44 const std::vector<base::file_util_proxy::Entry>& entries, bool has_more) { |
64 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); | 45 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); |
65 for (size_t i = 0; i < entries.size(); i++) { | 46 for (size_t i = 0; i < entries.size(); i++) { |
66 file_system_entries[i].name = | 47 file_system_entries[i].name = |
67 webkit_glue::FilePathStringToWebString(entries[i].name); | 48 webkit_glue::FilePathStringToWebString(entries[i].name); |
68 file_system_entries[i].isDirectory = entries[i].is_directory; | 49 file_system_entries[i].isDirectory = entries[i].is_directory; |
69 } | 50 } |
70 callbacks_->didReadDirectory(file_system_entries, has_more); | 51 callbacks_->didReadDirectory(file_system_entries, has_more); |
71 } | 52 } |
72 | 53 |
73 void WebFileSystemCallbackDispatcher::DidOpenFileSystem( | 54 void WebFileSystemCallbackDispatcher::DidOpenFileSystem( |
74 const std::string& name, const FilePath& root_path) { | 55 const std::string& name, const FilePath& root_path) { |
75 callbacks_->didOpenFileSystem(UTF8ToUTF16(name), | 56 callbacks_->didOpenFileSystem(UTF8ToUTF16(name), |
76 webkit_glue::FilePathToWebString(root_path)); | 57 webkit_glue::FilePathToWebString(root_path)); |
77 } | 58 } |
78 | 59 |
79 void WebFileSystemCallbackDispatcher::DidFail( | 60 void WebFileSystemCallbackDispatcher::DidFail( |
80 base::PlatformFileError error_code) { | 61 base::PlatformFileError error_code) { |
81 callbacks_->didFail(PlatformFileErrorToWebFileError(error_code)); | 62 callbacks_->didFail( |
| 63 webkit_glue::PlatformFileErrorToWebFileError(error_code)); |
82 } | 64 } |
| 65 |
| 66 void WebFileSystemCallbackDispatcher::DidWrite(int64 bytes, bool complete) { |
| 67 NOTREACHED(); |
| 68 } |
| 69 |
OLD | NEW |