Chromium Code Reviews| Index: webkit/plugins/ppapi/file_callbacks.cc |
| diff --git a/webkit/plugins/ppapi/file_callbacks.cc b/webkit/plugins/ppapi/file_callbacks.cc |
| index fedf583dc9b572e94f7afd95fba8fba6c3df0fe3..f003fbb8d17073c8470ed61e53a386c3d7d58fa2 100644 |
| --- a/webkit/plugins/ppapi/file_callbacks.cc |
| +++ b/webkit/plugins/ppapi/file_callbacks.cc |
| @@ -5,14 +5,18 @@ |
| #include "webkit/plugins/ppapi/file_callbacks.h" |
| #include "base/logging.h" |
| +#include "base/utf_string_conversions.h" |
| #include "ppapi/c/pp_file_info.h" |
| #include "ppapi/c/pp_errors.h" |
| #include "ppapi/c/ppb_file_system.h" |
| #include "ppapi/shared_impl/file_type_conversion.h" |
| +#include "ppapi/shared_impl/ppb_file_ref_shared.h" |
| #include "ppapi/shared_impl/time_conversion.h" |
| #include "ppapi/shared_impl/tracked_callback.h" |
| #include "webkit/fileapi/file_system_types.h" |
| +#include "webkit/fileapi/file_system_util.h" |
| #include "webkit/plugins/ppapi/plugin_module.h" |
| +#include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
| using ppapi::Resource; |
| using ppapi::TimeToPPTime; |
| @@ -27,7 +31,10 @@ FileCallbacks::FileCallbacks( |
| PP_FileInfo* info) |
| : callback_(callback), |
| info_(info), |
| - file_system_type_(PP_FILESYSTEMTYPE_INVALID) { |
| + file_system_type_(PP_FILESYSTEMTYPE_INVALID), |
| + read_entries_dir_ref_(NULL), |
| + read_entries_files_(NULL), |
| + read_entries_file_types_(NULL) { |
| } |
| FileCallbacks::FileCallbacks( |
| @@ -37,7 +44,22 @@ FileCallbacks::FileCallbacks( |
| PP_FileSystemType file_system_type) |
| : callback_(callback), |
| info_(info), |
| - file_system_type_(file_system_type) { |
| + file_system_type_(file_system_type), |
| + read_entries_dir_ref_(NULL), |
| + read_entries_files_(NULL), |
| + read_entries_file_types_(NULL) { |
| +} |
| + |
| +FileCallbacks::FileCallbacks( |
| + ::ppapi::Resource* resource, |
| + scoped_refptr< ::ppapi::TrackedCallback> callback, |
| + const ReadEntriesParams& params) |
| + : callback_(callback), |
| + info_(NULL), |
| + file_system_type_(PP_FILESYSTEMTYPE_INVALID), |
| + read_entries_dir_ref_(params.dir_ref), |
| + read_entries_files_(params.files), |
| + read_entries_file_types_(params.file_types) { |
| } |
| FileCallbacks::~FileCallbacks() {} |
| @@ -77,7 +99,35 @@ void FileCallbacks::DidCreateSnapshotFile( |
| void FileCallbacks::DidReadDirectory( |
| const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { |
| - NOTREACHED(); |
| + if (callback_->completed()) |
| + return; |
| + |
| + // The current filesystem backend always returns false. |
| + DCHECK(!has_more); |
| + |
| + DCHECK(read_entries_dir_ref_); |
| + DCHECK(read_entries_files_); |
| + DCHECK(read_entries_file_types_); |
| + |
| + std::string dir_path = read_entries_dir_ref_->GetCreateInfo().path; |
| + if (dir_path[dir_path.size() - 1] != '/') |
|
palmer
2013/05/03 00:07:24
Could dir_path.size() ever return 0? I would do th
hamaji
2013/05/03 01:10:34
Done. I believe it won't be an empty string, but I
|
| + dir_path += '/'; |
| + |
| + for (size_t i = 0; i < entries.size(); ++i) { |
| + const base::FileUtilProxy::Entry& entry = entries[i]; |
| + scoped_refptr<PPB_FileRef_Impl> file_ref(PPB_FileRef_Impl::CreateInternal( |
| + read_entries_dir_ref_->pp_instance(), |
| + read_entries_dir_ref_->file_system_resource(), |
| + dir_path + fileapi::FilePathToString(base::FilePath(entry.name)))); |
| + read_entries_files_->push_back(file_ref->GetCreateInfo()); |
| + read_entries_file_types_->push_back( |
| + entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR); |
| + // Add a ref count on behalf of the plugin side. |
| + file_ref->GetReference(); |
| + } |
| + CHECK_EQ(read_entries_files_->size(), read_entries_file_types_->size()); |
| + |
| + callback_->Run(PP_OK); |
| } |
| void FileCallbacks::DidOpenFileSystem(const std::string&, |