OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 #ifndef PPAPI_PROXY_FILE_IO_RESOURCE_H_ |
| 6 #define PPAPI_PROXY_FILE_IO_RESOURCE_H_ |
| 7 |
| 8 #include "ppapi/proxy/connection.h" |
| 9 #include "ppapi/proxy/plugin_resource.h" |
| 10 #include "ppapi/proxy/ppapi_proxy_export.h" |
| 11 #include "ppapi/shared_impl/ppb_file_io_shared.h" |
| 12 #include "ppapi/thunk/ppb_file_io_api.h" |
| 13 |
| 14 namespace ppapi { |
| 15 |
| 16 class TrackedCallback; |
| 17 |
| 18 namespace proxy { |
| 19 |
| 20 class PPAPI_PROXY_EXPORT FileIOResource |
| 21 : public PluginResource, |
| 22 public ppapi::PPB_FileIO_Shared, |
| 23 public thunk::PPB_FileIO_API { |
| 24 public: |
| 25 FileIOResource(Connection connection, PP_Instance instance); |
| 26 virtual ~FileIOResource(); |
| 27 |
| 28 // Resource overrides. |
| 29 virtual thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE; |
| 30 |
| 31 // PPB_FileIO_API implementations. |
| 32 virtual int32_t Open(PP_Resource file_ref, |
| 33 int32_t open_flags, |
| 34 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 35 virtual int32_t Query(PP_FileInfo* info, |
| 36 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 37 virtual int32_t Touch(PP_Time last_access_time, |
| 38 PP_Time last_modified_time, |
| 39 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 40 virtual int32_t Read(int64_t offset, |
| 41 char* buffer, |
| 42 int32_t bytes_to_read, |
| 43 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 44 virtual int32_t ReadToArray(int64_t offset, |
| 45 int32_t max_read_length, |
| 46 PP_ArrayOutput* array_output, |
| 47 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 48 virtual int32_t Write(int64_t offset, |
| 49 const char* buffer, |
| 50 int32_t bytes_to_write, |
| 51 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 52 virtual int32_t SetLength(int64_t length, |
| 53 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 54 virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 55 virtual void Close() OVERRIDE; |
| 56 virtual int32_t GetOSFileDescriptor() OVERRIDE; |
| 57 virtual int32_t WillWrite(int64_t offset, |
| 58 int32_t bytes_to_write, |
| 59 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 60 virtual int32_t WillSetLength( |
| 61 int64_t length, |
| 62 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 63 |
| 64 private: |
| 65 // PPB_FileIO_Shared implementations. |
| 66 virtual int32_t CommonPreCondition(bool should_be_open, |
| 67 OperationType new_op) OVERRIDE; |
| 68 virtual void CommonPostCondition(OperationType new_op) OVERRIDE; |
| 69 virtual int32_t OpenValidated(PP_Resource file_ref_resource, |
| 70 thunk::PPB_FileRef_API* file_ref_api, |
| 71 int32_t open_flags) OVERRIDE; |
| 72 virtual int32_t QueryValidated() OVERRIDE; |
| 73 virtual int32_t TouchValidated(PP_Time last_access_time, |
| 74 PP_Time last_modified_time) OVERRIDE; |
| 75 virtual int32_t ReadValidated(int64_t offset, |
| 76 int32_t bytes_to_read) OVERRIDE; |
| 77 virtual int32_t WriteValidated(int64_t offset, |
| 78 const char* buffer, |
| 79 int32_t bytes_to_write) OVERRIDE; |
| 80 virtual int32_t SetLengthValidated(int64_t length) OVERRIDE; |
| 81 virtual int32_t FlushValidated() OVERRIDE; |
| 82 |
| 83 // Handlers of reply messages. Note that all of them have a callback |
| 84 // parameters bound when call to the host. |
| 85 void OnPluginMsgGeneralComplete(scoped_refptr<TrackedCallback> callback, |
| 86 const ResourceMessageReplyParams& params); |
| 87 void OnPluginMsgOpenFileComplete(scoped_refptr<TrackedCallback> callback, |
| 88 const ResourceMessageReplyParams& params); |
| 89 void OnPluginMsgQueryComplete(scoped_refptr<TrackedCallback> callback, |
| 90 PP_FileInfo* output_info_, |
| 91 const ResourceMessageReplyParams& params, |
| 92 const PP_FileInfo& info); |
| 93 void OnPluginMsgReadComplete(scoped_refptr<TrackedCallback> callback, |
| 94 PP_ArrayOutput array_output, |
| 95 const ResourceMessageReplyParams& params, |
| 96 const std::string& data); |
| 97 |
| 98 // Marks the state of current operations on started or finished. |
| 99 void SetOpInProgress(OperationType op); |
| 100 void SetOpFinished(); |
| 101 |
| 102 int num_pending_ops_; |
| 103 OperationType pending_op_; |
| 104 |
| 105 // Temporary variables just to pass from "OP" (e.g. Open) to "{OP}Validated" |
| 106 // (e.g. QueryValidated). These are short-living data and must be copied in |
| 107 // {OP}Validated immediately. In fact, they are copied to the closure of |
| 108 // OnPluginMsg* handler via Bind. |
| 109 PP_ArrayOutput temp_array_output_; |
| 110 PP_FileInfo* temp_info_; |
| 111 scoped_refptr<TrackedCallback> temp_callback_; |
| 112 }; |
| 113 |
| 114 } // namespace proxy |
| 115 } // namespace ppapi |
| 116 |
| 117 #endif // PPAPI_PROXY_FILE_IO_RESOURCE_H_ |
OLD | NEW |