Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: ppapi/shared_impl/ppb_file_io_shared.h

Issue 8764003: Implement a proxy for Pepper FileIO. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Homestarmy Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/file_type_conversion.cc ('k') | ppapi/shared_impl/ppb_file_io_shared.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_SHARED_IMPL_PPB_FILE_IO_SHARED_H_
6 #define PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_
7
8 #include <deque>
9
10 #include "base/compiler_specific.h"
11 #include "ppapi/shared_impl/ppapi_shared_export.h"
12 #include "ppapi/shared_impl/resource.h"
13 #include "ppapi/thunk/ppb_file_io_api.h"
14
15 namespace ppapi {
16
17 namespace thunk {
18 class PPB_FileRef_API;
19 }
20
21 class PPAPI_SHARED_EXPORT PPB_FileIO_Shared : public Resource,
22 public thunk::PPB_FileIO_API {
23 public:
24 PPB_FileIO_Shared(PP_Instance instance);
25 PPB_FileIO_Shared(const HostResource& host_resource);
26 ~PPB_FileIO_Shared();
27
28 // Resource overrides.
29 virtual void LastPluginRefWasDeleted() OVERRIDE;
30 virtual thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE;
31
32 // PPB_FileIO_API implementation.
33 virtual int32_t Open(PP_Resource file_ref,
34 int32_t open_flags,
35 PP_CompletionCallback callback) OVERRIDE;
36 virtual int32_t Query(PP_FileInfo* info,
37 PP_CompletionCallback callback) OVERRIDE;
38 virtual int32_t Touch(PP_Time last_access_time,
39 PP_Time last_modified_time,
40 PP_CompletionCallback callback) OVERRIDE;
41 virtual int32_t Read(int64_t offset,
42 char* buffer,
43 int32_t bytes_to_read,
44 PP_CompletionCallback callback) OVERRIDE;
45 virtual int32_t Write(int64_t offset,
46 const char* buffer,
47 int32_t bytes_to_write,
48 PP_CompletionCallback callback) OVERRIDE;
49 virtual int32_t SetLength(int64_t length,
50 PP_CompletionCallback callback) OVERRIDE;
51 virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE;
52
53 // Callback handler for different types of operations.
54 void ExecuteGeneralCallback(int32_t pp_error);
55 void ExecuteOpenFileCallback(int32_t pp_error);
56 void ExecuteQueryCallback(int32_t pp_error, const PP_FileInfo& info);
57 void ExecuteReadCallback(int32_t pp_error, const char* data);
58
59 protected:
60 struct CallbackEntry {
61 CallbackEntry();
62 CallbackEntry(const CallbackEntry& entry);
63 ~CallbackEntry();
64
65 PP_CompletionCallback callback;
66
67 // Pointer back to the caller's read buffer; only used by |Read()|, NULL
68 // for non-read operations. Not owned.
69 char* read_buffer;
70
71 // Pointer back to the caller's PP_FileInfo structure for Query operations.
72 // NULL for non-query operations. Not owned.
73 PP_FileInfo* info;
74 };
75
76 enum OperationType {
77 // There is no pending operation right now.
78 OPERATION_NONE,
79
80 // If there are pending reads, any other kind of async operation is not
81 // allowed.
82 OPERATION_READ,
83
84 // If there are pending writes, any other kind of async operation is not
85 // allowed.
86 OPERATION_WRITE,
87
88 // If there is a pending operation that is neither read nor write, no
89 // further async operation is allowed.
90 OPERATION_EXCLUSIVE
91 };
92
93 // Validated versions of the FileIO API. Subclasses in the proxy and impl
94 // implement these so the common error checking stays here.
95 virtual int32_t OpenValidated(PP_Resource file_ref_resource,
96 thunk::PPB_FileRef_API* file_ref_api,
97 int32_t open_flags,
98 PP_CompletionCallback callback) = 0;
99 virtual int32_t QueryValidated(PP_FileInfo* info,
100 PP_CompletionCallback callback) = 0;
101 virtual int32_t TouchValidated(PP_Time last_access_time,
102 PP_Time last_modified_time,
103 PP_CompletionCallback callback) = 0;
104 virtual int32_t ReadValidated(int64_t offset,
105 char* buffer,
106 int32_t bytes_to_read,
107 PP_CompletionCallback callback) = 0;
108 virtual int32_t WriteValidated(int64_t offset,
109 const char* buffer,
110 int32_t bytes_to_write,
111 PP_CompletionCallback callback) = 0;
112 virtual int32_t SetLengthValidated(int64_t length,
113 PP_CompletionCallback callback) = 0;
114 virtual int32_t FlushValidated(PP_CompletionCallback callback) = 0;
115
116 // Called for every "Validated" function.
117 //
118 // This verifies that the callback is valid and that no callback is already
119 // pending, or it is a read(write) request and currently the pending
120 // operations are reads(writes).
121 //
122 // Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if
123 // the call should be aborted and that code returned to the plugin.
124 int32_t CommonCallValidation(bool should_be_open,
125 OperationType new_op,
126 PP_CompletionCallback callback);
127
128 // Sets up a pending callback. This should only be called once it is certain
129 // that |PP_OK_COMPLETIONPENDING| will be returned.
130 //
131 // |read_buffer| is only used by read operations, |info| is used only by
132 // query operations.
133 void RegisterCallback(OperationType op,
134 PP_CompletionCallback callback,
135 char* read_buffer,
136 PP_FileInfo* info);
137
138 // Pops the oldest callback from the queue and runs it.
139 void RunAndRemoveFirstPendingCallback(int32_t result);
140
141 // The file system type specified in the Open() call. This will be
142 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not
143 // indicate that the open command actually succeeded.
144 PP_FileSystemType file_system_type_;
145
146 // Set to true when the file has been successfully opened.
147 bool file_open_;
148
149 std::deque<CallbackEntry> callbacks_;
150 OperationType pending_op_;
151
152 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Shared);
153 };
154
155 } // namespace ppapi
156
157 #endif // PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_
OLDNEW
« no previous file with comments | « ppapi/shared_impl/file_type_conversion.cc ('k') | ppapi/shared_impl/ppb_file_io_shared.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698