Chromium Code Reviews| Index: ppapi/proxy/file_io_resource.h |
| diff --git a/ppapi/proxy/file_io_resource.h b/ppapi/proxy/file_io_resource.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dda998663afdaea8a5c1c89bc243cc04bff08f1f |
| --- /dev/null |
| +++ b/ppapi/proxy/file_io_resource.h |
| @@ -0,0 +1,117 @@ |
| +// 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 "ppapi/proxy/connection.h" |
| +#include "ppapi/proxy/plugin_resource.h" |
| +#include "ppapi/proxy/ppapi_proxy_export.h" |
| +#include "ppapi/shared_impl/ppb_file_io_shared.h" |
| +#include "ppapi/thunk/ppb_file_io_api.h" |
| + |
| +namespace ppapi { |
| + |
| +class TrackedCallback; |
| + |
| +namespace proxy { |
| + |
| +class PPAPI_PROXY_EXPORT FileIOResource |
| + : public PluginResource, |
| + public ppapi::PPB_FileIO_Shared, |
| + 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 implementations. |
|
raymes
2012/11/27 16:41:30
nit: implementations -> implementation
victorhsieh
2012/11/28 04:11:55
Done.
|
| + 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: |
| + // PPB_FileIO_Shared implementations. |
| + virtual int32_t CommonPreCondition(bool should_be_open, |
| + OperationType new_op) OVERRIDE; |
| + virtual void CommonPostCondition(OperationType new_op) OVERRIDE; |
| + virtual int32_t OpenValidated(PP_Resource file_ref_resource, |
| + thunk::PPB_FileRef_API* file_ref_api, |
| + int32_t open_flags) OVERRIDE; |
| + virtual int32_t QueryValidated() OVERRIDE; |
| + virtual int32_t TouchValidated(PP_Time last_access_time, |
| + PP_Time last_modified_time) OVERRIDE; |
| + virtual int32_t ReadValidated(int64_t offset, |
| + int32_t bytes_to_read) OVERRIDE; |
| + virtual int32_t WriteValidated(int64_t offset, |
| + const char* buffer, |
| + int32_t bytes_to_write) OVERRIDE; |
| + virtual int32_t SetLengthValidated(int64_t length) OVERRIDE; |
| + virtual int32_t FlushValidated() OVERRIDE; |
| + |
| + // 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); |
| + |
| + // Marks the state of current operations on started or finished. |
| + void SetOpInProgress(OperationType op); |
| + void SetOpFinished(); |
| + |
| + int num_pending_ops_; |
| + OperationType pending_op_; |
| + |
| + // Temporary variables just to pass from "OP" (e.g. Open) to "{OP}Validated" |
| + // (e.g. QueryValidated). These are short-living data and must be copied in |
| + // {OP}Validated immediately. In fact, they are copied to the closure of |
| + // OnPluginMsg* handler via Bind. |
| + PP_ArrayOutput temp_array_output_; |
| + PP_FileInfo* temp_info_; |
| + scoped_refptr<TrackedCallback> temp_callback_; |
| +}; |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |
| + |
| +#endif // PPAPI_PROXY_FILE_IO_RESOURCE_H_ |