Index: content/renderer/pepper/pepper_directory_reader_host.cc |
diff --git a/content/renderer/pepper/pepper_directory_reader_host.cc b/content/renderer/pepper/pepper_directory_reader_host.cc |
deleted file mode 100644 |
index 8bf0ce99da163c717db479d4674bac903b83a307..0000000000000000000000000000000000000000 |
--- a/content/renderer/pepper/pepper_directory_reader_host.cc |
+++ /dev/null |
@@ -1,189 +0,0 @@ |
-// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-#include "content/renderer/pepper/pepper_directory_reader_host.h" |
- |
-#include "base/callback.h" |
-#include "base/compiler_specific.h" |
-#include "base/files/file_path.h" |
-#include "base/utf_string_conversions.h" |
-#include "content/public/renderer/renderer_ppapi_host.h" |
-#include "content/renderer/pepper/null_file_system_callback_dispatcher.h" |
-#include "ppapi/c/pp_errors.h" |
-#include "ppapi/host/dispatch_host_message.h" |
-#include "ppapi/host/ppapi_host.h" |
-#include "ppapi/proxy/ppapi_messages.h" |
-#include "ppapi/shared_impl/file_type_conversion.h" |
-#include "ppapi/shared_impl/ppb_file_ref_shared.h" |
-#include "ppapi/thunk/enter.h" |
-#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
-#include "webkit/plugins/ppapi/resource_helper.h" |
- |
-using ppapi::thunk::EnterResource; |
-using ppapi::thunk::PPB_FileRef_API; |
-using webkit::ppapi::PPB_FileRef_Impl; |
- |
-namespace content { |
- |
-namespace { |
- |
-std::string FilePathStringToUTF8String(const base::FilePath::StringType& str) { |
-#if defined(OS_WIN) |
- return WideToUTF8(str); |
-#elif defined(OS_POSIX) |
- return str; |
-#else |
-#error "Unsupported platform." |
-#endif |
-} |
- |
-base::FilePath::StringType UTF8StringToFilePathString(const std::string& str) { |
-#if defined(OS_WIN) |
- return UTF8ToWide(str); |
-#elif defined(OS_POSIX) |
- return str; |
-#else |
-#error "Unsupported platform." |
-#endif |
-} |
- |
-class ReadDirectoryCallback : public NullFileSystemCallbackDispatcher { |
- public: |
- typedef base::Callback<void (const PepperDirectoryReaderHost::Entries&, |
- bool, int32_t)> |
- OnReadDirectoryCallback; |
- |
- explicit ReadDirectoryCallback(const OnReadDirectoryCallback& callback) |
- : callback_(callback) {} |
- virtual ~ReadDirectoryCallback() {} |
- |
- virtual void DidReadDirectory( |
- const std::vector<base::FileUtilProxy::Entry>& entries, |
- bool has_more) OVERRIDE { |
- callback_.Run(entries, has_more, PP_OK); |
- } |
- |
- virtual void DidFail(base::PlatformFileError platform_error) OVERRIDE { |
- callback_.Run(PepperDirectoryReaderHost::Entries(), false, |
- ppapi::PlatformFileErrorToPepperError(platform_error)); |
- } |
- |
- private: |
- OnReadDirectoryCallback callback_; |
-}; |
- |
-} // namespace |
- |
-PepperDirectoryReaderHost::PepperDirectoryReaderHost( |
- RendererPpapiHost* host, |
- PP_Instance instance, |
- PP_Resource resource) |
- : ResourceHost(host->GetPpapiHost(), instance, resource), |
- renderer_ppapi_host_(host), |
- weak_factory_(this) { |
-} |
- |
-PepperDirectoryReaderHost::~PepperDirectoryReaderHost() { |
-} |
- |
-int32_t PepperDirectoryReaderHost::OnResourceMessageReceived( |
- const IPC::Message& msg, |
- ppapi::host::HostMessageContext* context) { |
- IPC_BEGIN_MESSAGE_MAP(PepperDirectoryReaderHost, msg) |
- PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
- PpapiHostMsg_DirectoryReader_GetEntries, OnGetEntries) |
- IPC_END_MESSAGE_MAP() |
- return PP_ERROR_FAILED; |
-} |
- |
-int32_t PepperDirectoryReaderHost::OnGetEntries( |
- ppapi::host::HostMessageContext* host_context, |
- const ppapi::HostResource& resource) { |
- reply_context_ = host_context->MakeReplyMessageContext(); |
- |
- EnterResource<PPB_FileRef_API> enter(resource.host_resource(), true); |
- if (enter.failed()) |
- return PP_ERROR_FAILED; |
- directory_ref_ = static_cast<PPB_FileRef_Impl*>(enter.object()); |
- |
- if (directory_ref_->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) |
- return PP_ERROR_FAILED; |
- |
- webkit::ppapi::PluginInstance* plugin_instance = |
- renderer_ppapi_host_->GetPluginInstance(pp_instance()); |
- if (!plugin_instance) |
- return PP_ERROR_FAILED; |
- |
- if (!plugin_instance->delegate()->ReadDirectory( |
- directory_ref_->GetFileSystemURL(), |
- new ReadDirectoryCallback( |
- base::Bind(&PepperDirectoryReaderHost::OnReadDirectory, |
- weak_factory_.GetWeakPtr())))) |
- return PP_ERROR_FAILED; |
- return PP_OK_COMPLETIONPENDING; |
-} |
- |
-void PepperDirectoryReaderHost::OnReadDirectory(const Entries& entries, |
- bool has_more, |
- int32_t result) { |
- // The current filesystem backend always returns false. |
- DCHECK(!has_more); |
- if (result == PP_OK && !AddNewEntries(entries)) |
- result = PP_ERROR_FAILED; |
- SendGetEntriesReply(result); |
-} |
- |
-bool PepperDirectoryReaderHost::AddNewEntries(const Entries& entries) { |
- std::string dir_path = directory_ref_->GetCreateInfo().path; |
- if (dir_path[dir_path.size() - 1] != '/') |
- dir_path += '/'; |
- base::FilePath::StringType dir_file_path = |
- UTF8StringToFilePathString(dir_path); |
- |
- for (Entries::const_iterator it = entries.begin(); |
- it != entries.end(); ++it) { |
- EntryData data; |
- data.file_ref = PPB_FileRef_Impl::CreateInternal( |
- pp_instance(), |
- directory_ref_->file_system_resource(), |
- FilePathStringToUTF8String(dir_file_path + it->name)); |
- if (!data.file_ref) { |
- entry_data_.clear(); |
- return false; |
- } |
- data.file_type = it->is_directory ? |
- PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR; |
- entry_data_.push_back(data); |
- } |
- |
- return true; |
-} |
- |
-void PepperDirectoryReaderHost::SendGetEntriesReply(int32_t result) { |
- std::vector<ppapi::PPB_FileRef_CreateInfo> host_resources; |
- std::vector<PP_FileType> file_types; |
- |
- for (std::vector<EntryData>::iterator it = entry_data_.begin(); |
- it != entry_data_.end(); ++it) { |
- // Add a ref count on behalf of the plugin side. |
- it->file_ref->GetReference(); |
- host_resources.push_back(it->file_ref->GetCreateInfo()); |
- file_types.push_back(it->file_type); |
- } |
- entry_data_.clear(); |
- |
- reply_context_.params.set_result(result); |
- host()->SendReply( |
- reply_context_, |
- PpapiPluginMsg_DirectoryReader_GetEntriesReply(host_resources, |
- file_types)); |
-} |
- |
-PepperDirectoryReaderHost::EntryData::EntryData() { |
-} |
- |
-PepperDirectoryReaderHost::EntryData::~EntryData() { |
-} |
- |
-} // namespace content |