diff options
author | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-19 04:16:36 +0000 |
---|---|---|
committer | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-19 04:16:36 +0000 |
commit | c77144727785be9a25c10a7954e38a3a579b417a (patch) | |
tree | 5fe5083e10e8af5ec822848a07cb04b416682496 /ppapi/proxy/file_io_resource.h | |
parent | 7a6acd091023b662745562592406b5efbc1a5b42 (diff) | |
download | chromium_src-c77144727785be9a25c10a7954e38a3a579b417a.zip chromium_src-c77144727785be9a25c10a7954e38a3a579b417a.tar.gz chromium_src-c77144727785be9a25c10a7954e38a3a579b417a.tar.bz2 |
Refactor FileIO to the new resource host system.
Taking over from Victor's CL: https://codereview.chromium.org/11419131/
Re-landing, with a fix. The original waited to reset the file state until
after the callback had completed. This is too late, as the client should be
able to perform another file operation during the callback.
Changeset #1 is the original patch. The fix is in change set #2
Original author=Victor Hsieh
BUG=none
TEST=browser_tests --gtest_filter=PPAPINaClNewlibTest.FileIO*
Review URL: https://chromiumcodereview.appspot.com/11941022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177830 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/file_io_resource.h')
-rw-r--r-- | ppapi/proxy/file_io_resource.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/ppapi/proxy/file_io_resource.h b/ppapi/proxy/file_io_resource.h new file mode 100644 index 0000000..f5a1aa8 --- /dev/null +++ b/ppapi/proxy/file_io_resource.h @@ -0,0 +1,95 @@ +// Copyright (c) 2012 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. + +#ifndef PPAPI_PROXY_FILE_IO_RESOURCE_H_ +#define PPAPI_PROXY_FILE_IO_RESOURCE_H_ + +#include <string> + +#include "ppapi/proxy/connection.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/shared_impl/file_io_state_manager.h" +#include "ppapi/thunk/ppb_file_io_api.h" + +namespace ppapi { + +class TrackedCallback; + +namespace proxy { + +class PPAPI_PROXY_EXPORT FileIOResource + : public PluginResource, + public thunk::PPB_FileIO_API { + public: + FileIOResource(Connection connection, PP_Instance instance); + virtual ~FileIOResource(); + + // Resource overrides. + virtual thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE; + + // PPB_FileIO_API implementation. + virtual int32_t Open(PP_Resource file_ref, + int32_t open_flags, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Query(PP_FileInfo* info, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Touch(PP_Time last_access_time, + PP_Time last_modified_time, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Read(int64_t offset, + char* buffer, + int32_t bytes_to_read, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t ReadToArray(int64_t offset, + int32_t max_read_length, + PP_ArrayOutput* array_output, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Write(int64_t offset, + const char* buffer, + int32_t bytes_to_write, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t SetLength(int64_t length, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual void Close() OVERRIDE; + virtual int32_t GetOSFileDescriptor() OVERRIDE; + virtual int32_t WillWrite(int64_t offset, + int32_t bytes_to_write, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t WillSetLength( + int64_t length, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + + private: + int32_t ReadValidated(int64_t offset, + int32_t bytes_to_read, + const PP_ArrayOutput& array_output, + scoped_refptr<TrackedCallback> callback); + + // Handlers of reply messages. Note that all of them have a callback + // parameters bound when call to the host. + void OnPluginMsgGeneralComplete(scoped_refptr<TrackedCallback> callback, + const ResourceMessageReplyParams& params); + void OnPluginMsgOpenFileComplete(scoped_refptr<TrackedCallback> callback, + const ResourceMessageReplyParams& params); + void OnPluginMsgQueryComplete(scoped_refptr<TrackedCallback> callback, + PP_FileInfo* output_info_, + const ResourceMessageReplyParams& params, + const PP_FileInfo& info); + void OnPluginMsgReadComplete(scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::string& data); + + FileIOStateManager state_manager_; + + DISALLOW_COPY_AND_ASSIGN(FileIOResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_FILE_IO_RESOURCE_H_ + |