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.
5 #ifndef PPAPI_PROXY_FILE_IO_RESOURCE_H_
6 #define PPAPI_PROXY_FILE_IO_RESOURCE_H_
10 #include "ppapi/c/private/pp_file_handle.h"
11 #include "ppapi/proxy/connection.h"
12 #include "ppapi/proxy/plugin_resource.h"
13 #include "ppapi/proxy/ppapi_proxy_export.h"
14 #include "ppapi/shared_impl/file_io_state_manager.h"
15 #include "ppapi/thunk/ppb_file_io_api.h"
19 class TrackedCallback
;
23 class PPAPI_PROXY_EXPORT FileIOResource
24 : public PluginResource
,
25 public thunk::PPB_FileIO_API
{
27 FileIOResource(Connection connection
, PP_Instance instance
);
28 virtual ~FileIOResource();
30 // Resource overrides.
31 virtual thunk::PPB_FileIO_API
* AsPPB_FileIO_API() OVERRIDE
;
33 // PPB_FileIO_API implementation.
34 virtual int32_t Open(PP_Resource file_ref
,
36 scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
37 virtual int32_t Query(PP_FileInfo
* info
,
38 scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
39 virtual int32_t Touch(PP_Time last_access_time
,
40 PP_Time last_modified_time
,
41 scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
42 virtual int32_t Read(int64_t offset
,
44 int32_t bytes_to_read
,
45 scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
46 virtual int32_t ReadToArray(int64_t offset
,
47 int32_t max_read_length
,
48 PP_ArrayOutput
* array_output
,
49 scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
50 virtual int32_t Write(int64_t offset
,
52 int32_t bytes_to_write
,
53 scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
54 virtual int32_t SetLength(int64_t length
,
55 scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
56 virtual int32_t Flush(scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
57 virtual void Close() OVERRIDE
;
58 virtual int32_t GetOSFileDescriptor() OVERRIDE
;
59 virtual int32_t RequestOSFileHandle(
60 PP_FileHandle
* handle
,
61 scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
62 virtual int32_t WillWrite(int64_t offset
,
63 int32_t bytes_to_write
,
64 scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
65 virtual int32_t WillSetLength(
67 scoped_refptr
<TrackedCallback
> callback
) OVERRIDE
;
70 int32_t ReadValidated(int64_t offset
,
71 int32_t bytes_to_read
,
72 const PP_ArrayOutput
& array_output
,
73 scoped_refptr
<TrackedCallback
> callback
);
74 void CloseFileHandle();
76 // Reply message handlers for operations that are done in the host.
77 void OnPluginMsgGeneralComplete(scoped_refptr
<TrackedCallback
> callback
,
78 const ResourceMessageReplyParams
& params
);
79 void OnPluginMsgOpenFileComplete(scoped_refptr
<TrackedCallback
> callback
,
80 const ResourceMessageReplyParams
& params
);
81 void OnPluginMsgRequestOSFileHandleComplete(
82 scoped_refptr
<TrackedCallback
> callback
,
83 PP_FileHandle
* output_handle
,
84 const ResourceMessageReplyParams
& params
);
86 // Reply message handlers for operations that are done in the plugin.
87 void OnQueryComplete(scoped_refptr
<TrackedCallback
> callback
,
88 PP_FileInfo
* output_info
,
89 base::PlatformFileError error_code
,
90 const base::PlatformFileInfo
& file_info
);
91 void OnReadComplete(scoped_refptr
<TrackedCallback
> callback
,
92 PP_ArrayOutput array_output
,
93 base::PlatformFileError error_code
,
94 const char* data
, int bytes_read
);
96 PP_FileHandle file_handle_
;
97 PP_FileSystemType file_system_type_
;
98 FileIOStateManager state_manager_
;
100 DISALLOW_COPY_AND_ASSIGN(FileIOResource
);
106 #endif // PPAPI_PROXY_FILE_IO_RESOURCE_H_