cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / proxy / file_io_resource.h
blob1a888d199d610b7ad2d1390a5fb6df75e681b15c
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_
8 #include <string>
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"
17 namespace ppapi {
19 class TrackedCallback;
21 namespace proxy {
23 class PPAPI_PROXY_EXPORT FileIOResource
24 : public PluginResource,
25 public thunk::PPB_FileIO_API {
26 public:
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,
35 int32_t open_flags,
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,
43 char* buffer,
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,
51 const char* buffer,
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(
66 int64_t length,
67 scoped_refptr<TrackedCallback> callback) OVERRIDE;
69 private:
70 // Class to perform file query operations across multiple threads.
71 class QueryOp : public base::RefCountedThreadSafe<QueryOp> {
72 public:
73 explicit QueryOp(PP_FileHandle file_handle);
75 // Queries the file. Called on the file thread (non-blocking) or the plugin
76 // thread (blocking). This should not be called when we hold the proxy lock.
77 int32_t DoWork();
79 const base::PlatformFileInfo& file_info() const { return file_info_; }
81 private:
82 friend class base::RefCountedThreadSafe<QueryOp>;
83 ~QueryOp();
85 PP_FileHandle file_handle_;
86 base::PlatformFileInfo file_info_;
89 // Class to perform file read operations across multiple threads.
90 class ReadOp : public base::RefCountedThreadSafe<ReadOp> {
91 public:
92 ReadOp(PP_FileHandle file_handle, int64_t offset, int32_t bytes_to_read);
94 // Reads the file. Called on the file thread (non-blocking) or the plugin
95 // thread (blocking). This should not be called when we hold the proxy lock.
96 int32_t DoWork();
98 char* buffer() const { return buffer_.get(); }
100 private:
101 friend class base::RefCountedThreadSafe<ReadOp>;
102 ~ReadOp();
104 PP_FileHandle file_handle_;
105 int64_t offset_;
106 int32_t bytes_to_read_;
107 scoped_ptr<char[]> buffer_;
110 int32_t ReadValidated(int64_t offset,
111 int32_t bytes_to_read,
112 const PP_ArrayOutput& array_output,
113 scoped_refptr<TrackedCallback> callback);
115 void CloseFileHandle();
118 // Completion tasks for file operations that are done in the plugin.
119 int32_t OnQueryComplete(scoped_refptr<QueryOp> query_op,
120 PP_FileInfo* info,
121 int32_t result);
122 int32_t OnReadComplete(scoped_refptr<ReadOp> read_op,
123 PP_ArrayOutput array_output,
124 int32_t result);
126 // Reply message handlers for operations that are done in the host.
127 void OnPluginMsgGeneralComplete(scoped_refptr<TrackedCallback> callback,
128 const ResourceMessageReplyParams& params);
129 void OnPluginMsgOpenFileComplete(scoped_refptr<TrackedCallback> callback,
130 const ResourceMessageReplyParams& params);
131 void OnPluginMsgRequestOSFileHandleComplete(
132 scoped_refptr<TrackedCallback> callback,
133 PP_FileHandle* output_handle,
134 const ResourceMessageReplyParams& params);
136 PP_FileHandle file_handle_;
137 PP_FileSystemType file_system_type_;
138 FileIOStateManager state_manager_;
140 DISALLOW_COPY_AND_ASSIGN(FileIOResource);
143 } // namespace proxy
144 } // namespace ppapi
146 #endif // PPAPI_PROXY_FILE_IO_RESOURCE_H_