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