OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/common/file_system/webfilesystem_callback_dispatcher.h" |
| 6 |
| 7 #include "base/file_util_proxy.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 13 #include "webkit/glue/webkit_glue.h" |
| 14 |
| 15 using WebKit::WebFileInfo; |
| 16 using WebKit::WebFileSystemCallbacks; |
| 17 using WebKit::WebFileSystemEntry; |
| 18 using WebKit::WebString; |
| 19 using WebKit::WebVector; |
| 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( |
| 46 WebFileSystemCallbacks* callbacks) |
| 47 : callbacks_(callbacks) { |
| 48 DCHECK(callbacks_); |
| 49 } |
| 50 |
| 51 void WebFileSystemCallbackDispatcher::DidSucceed() { |
| 52 callbacks_->didSucceed(); |
| 53 } |
| 54 |
| 55 void WebFileSystemCallbackDispatcher::DidReadMetadata( |
| 56 const base::PlatformFileInfo& file_info) { |
| 57 WebFileInfo web_file_info; |
| 58 web_file_info.modificationTime = file_info.last_modified.ToDoubleT(); |
| 59 callbacks_->didReadMetadata(web_file_info); |
| 60 } |
| 61 |
| 62 void WebFileSystemCallbackDispatcher::DidReadDirectory( |
| 63 const std::vector<base::file_util_proxy::Entry>& entries, bool has_more) { |
| 64 WebVector<WebFileSystemEntry> file_system_entries(entries.size()); |
| 65 for (size_t i = 0; i < entries.size(); i++) { |
| 66 file_system_entries[i].name = |
| 67 webkit_glue::FilePathStringToWebString(entries[i].name); |
| 68 file_system_entries[i].isDirectory = entries[i].is_directory; |
| 69 } |
| 70 callbacks_->didReadDirectory(file_system_entries, has_more); |
| 71 } |
| 72 |
| 73 void WebFileSystemCallbackDispatcher::DidOpenFileSystem( |
| 74 const std::string& name, const FilePath& root_path) { |
| 75 callbacks_->didOpenFileSystem(UTF8ToUTF16(name), |
| 76 webkit_glue::FilePathToWebString(root_path)); |
| 77 } |
| 78 |
| 79 void WebFileSystemCallbackDispatcher::DidFail( |
| 80 base::PlatformFileError error_code) { |
| 81 callbacks_->didFail(PlatformFileErrorToWebFileError(error_code)); |
| 82 } |
OLD | NEW |