| 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 "webkit/glue/plugins/pepper_file_callbacks.h" | |
| 6 | |
| 7 #include "base/file_path.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "ppapi/c/dev/ppb_file_system_dev.h" | |
| 10 #include "ppapi/c/dev/pp_file_info_dev.h" | |
| 11 #include "ppapi/c/pp_errors.h" | |
| 12 #include "webkit/glue/plugins/pepper_directory_reader.h" | |
| 13 #include "webkit/glue/plugins/pepper_error_util.h" | |
| 14 #include "webkit/glue/plugins/pepper_file_system.h" | |
| 15 #include "webkit/fileapi/file_system_types.h" | |
| 16 | |
| 17 namespace pepper { | |
| 18 | |
| 19 FileCallbacks::FileCallbacks(const base::WeakPtr<PluginModule>& module, | |
| 20 PP_CompletionCallback callback, | |
| 21 PP_FileInfo_Dev* info, | |
| 22 scoped_refptr<FileSystem> file_system, | |
| 23 scoped_refptr<DirectoryReader> directory_reader) | |
| 24 : module_(module), | |
| 25 callback_(callback), | |
| 26 info_(info), | |
| 27 file_system_(file_system), | |
| 28 directory_reader_(directory_reader) { | |
| 29 } | |
| 30 | |
| 31 FileCallbacks::~FileCallbacks() {} | |
| 32 | |
| 33 void FileCallbacks::DidSucceed() { | |
| 34 if (!module_.get() || !callback_.func) | |
| 35 return; | |
| 36 | |
| 37 PP_RunCompletionCallback(&callback_, PP_OK); | |
| 38 } | |
| 39 | |
| 40 void FileCallbacks::DidReadMetadata( | |
| 41 const base::PlatformFileInfo& file_info) { | |
| 42 if (!module_.get() || !callback_.func) | |
| 43 return; | |
| 44 | |
| 45 DCHECK(info_); | |
| 46 DCHECK(file_system_); | |
| 47 info_->size = file_info.size; | |
| 48 info_->creation_time = file_info.creation_time.ToDoubleT(); | |
| 49 info_->last_access_time = file_info.last_accessed.ToDoubleT(); | |
| 50 info_->last_modified_time = file_info.last_modified.ToDoubleT(); | |
| 51 info_->system_type = file_system_->type(); | |
| 52 if (file_info.is_directory) | |
| 53 info_->type = PP_FILETYPE_DIRECTORY; | |
| 54 else | |
| 55 info_->type = PP_FILETYPE_REGULAR; | |
| 56 | |
| 57 PP_RunCompletionCallback(&callback_, PP_OK); | |
| 58 } | |
| 59 | |
| 60 void FileCallbacks::DidReadDirectory( | |
| 61 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { | |
| 62 if (!module_.get() || !callback_.func) | |
| 63 return; | |
| 64 | |
| 65 DCHECK(directory_reader_); | |
| 66 directory_reader_->AddNewEntries(entries, has_more); | |
| 67 | |
| 68 PP_RunCompletionCallback(&callback_, PP_OK); | |
| 69 } | |
| 70 | |
| 71 void FileCallbacks::DidOpenFileSystem(const std::string&, | |
| 72 const FilePath& root_path) { | |
| 73 if (!module_.get() || !callback_.func) | |
| 74 return; | |
| 75 | |
| 76 DCHECK(file_system_); | |
| 77 file_system_->set_root_path(root_path); | |
| 78 file_system_->set_opened(true); | |
| 79 | |
| 80 PP_RunCompletionCallback(&callback_, PP_OK); | |
| 81 } | |
| 82 | |
| 83 void FileCallbacks::DidFail(base::PlatformFileError error_code) { | |
| 84 RunCallback(error_code); | |
| 85 } | |
| 86 | |
| 87 void FileCallbacks::DidWrite(int64 bytes, bool complete) { | |
| 88 NOTREACHED(); | |
| 89 } | |
| 90 | |
| 91 void FileCallbacks::RunCallback(base::PlatformFileError error_code) { | |
| 92 if (!module_.get() || !callback_.func) | |
| 93 return; | |
| 94 | |
| 95 PP_RunCompletionCallback( | |
| 96 &callback_, pepper::PlatformFileErrorToPepperError(error_code)); | |
| 97 } | |
| 98 | |
| 99 } // namespace pepper | |
| OLD | NEW |