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

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

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up for review. Created 8 years, 8 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_ 5 #ifndef PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_
6 #define PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_ 6 #define PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 14 matching lines...) Expand all
25 PPB_FileIO_Shared(PP_Instance instance); 25 PPB_FileIO_Shared(PP_Instance instance);
26 PPB_FileIO_Shared(const HostResource& host_resource); 26 PPB_FileIO_Shared(const HostResource& host_resource);
27 ~PPB_FileIO_Shared(); 27 ~PPB_FileIO_Shared();
28 28
29 // Resource overrides. 29 // Resource overrides.
30 virtual thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE; 30 virtual thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE;
31 31
32 // PPB_FileIO_API implementation. 32 // PPB_FileIO_API implementation.
33 virtual int32_t Open(PP_Resource file_ref, 33 virtual int32_t Open(PP_Resource file_ref,
34 int32_t open_flags, 34 int32_t open_flags,
35 PP_CompletionCallback callback) OVERRIDE; 35 ApiCallbackType callback) OVERRIDE;
36 virtual int32_t Query(PP_FileInfo* info, 36 virtual int32_t Query(PP_FileInfo* info,
37 PP_CompletionCallback callback) OVERRIDE; 37 ApiCallbackType callback) OVERRIDE;
38 virtual int32_t Touch(PP_Time last_access_time, 38 virtual int32_t Touch(PP_Time last_access_time,
39 PP_Time last_modified_time, 39 PP_Time last_modified_time,
40 PP_CompletionCallback callback) OVERRIDE; 40 ApiCallbackType callback) OVERRIDE;
41 virtual int32_t Read(int64_t offset, 41 virtual int32_t Read(int64_t offset,
42 char* buffer, 42 char* buffer,
43 int32_t bytes_to_read, 43 int32_t bytes_to_read,
44 PP_CompletionCallback callback) OVERRIDE; 44 ApiCallbackType callback) OVERRIDE;
45 virtual int32_t Write(int64_t offset, 45 virtual int32_t Write(int64_t offset,
46 const char* buffer, 46 const char* buffer,
47 int32_t bytes_to_write, 47 int32_t bytes_to_write,
48 PP_CompletionCallback callback) OVERRIDE; 48 ApiCallbackType callback) OVERRIDE;
49 virtual int32_t SetLength(int64_t length, 49 virtual int32_t SetLength(int64_t length,
50 PP_CompletionCallback callback) OVERRIDE; 50 ApiCallbackType callback) OVERRIDE;
51 virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE; 51 virtual int32_t Flush(ApiCallbackType callback) OVERRIDE;
52 52
53 // Callback handler for different types of operations. 53 // Callback handler for different types of operations.
54 void ExecuteGeneralCallback(int32_t pp_error); 54 void ExecuteGeneralCallback(int32_t pp_error);
55 void ExecuteOpenFileCallback(int32_t pp_error); 55 void ExecuteOpenFileCallback(int32_t pp_error);
56 void ExecuteQueryCallback(int32_t pp_error, const PP_FileInfo& info); 56 void ExecuteQueryCallback(int32_t pp_error, const PP_FileInfo& info);
57 void ExecuteReadCallback(int32_t pp_error, const char* data); 57 void ExecuteReadCallback(int32_t pp_error, const char* data);
58 58
59 protected: 59 protected:
60 struct CallbackEntry { 60 struct CallbackEntry {
61 CallbackEntry(); 61 CallbackEntry();
(...skipping 26 matching lines...) Expand all
88 // If there is a pending operation that is neither read nor write, no 88 // If there is a pending operation that is neither read nor write, no
89 // further async operation is allowed. 89 // further async operation is allowed.
90 OPERATION_EXCLUSIVE 90 OPERATION_EXCLUSIVE
91 }; 91 };
92 92
93 // Validated versions of the FileIO API. Subclasses in the proxy and impl 93 // Validated versions of the FileIO API. Subclasses in the proxy and impl
94 // implement these so the common error checking stays here. 94 // implement these so the common error checking stays here.
95 virtual int32_t OpenValidated(PP_Resource file_ref_resource, 95 virtual int32_t OpenValidated(PP_Resource file_ref_resource,
96 thunk::PPB_FileRef_API* file_ref_api, 96 thunk::PPB_FileRef_API* file_ref_api,
97 int32_t open_flags, 97 int32_t open_flags,
98 PP_CompletionCallback callback) = 0; 98 ApiCallbackType callback) = 0;
99 virtual int32_t QueryValidated(PP_FileInfo* info, 99 virtual int32_t QueryValidated(PP_FileInfo* info,
100 PP_CompletionCallback callback) = 0; 100 ApiCallbackType callback) = 0;
101 virtual int32_t TouchValidated(PP_Time last_access_time, 101 virtual int32_t TouchValidated(PP_Time last_access_time,
102 PP_Time last_modified_time, 102 PP_Time last_modified_time,
103 PP_CompletionCallback callback) = 0; 103 ApiCallbackType callback) = 0;
104 virtual int32_t ReadValidated(int64_t offset, 104 virtual int32_t ReadValidated(int64_t offset,
105 char* buffer, 105 char* buffer,
106 int32_t bytes_to_read, 106 int32_t bytes_to_read,
107 PP_CompletionCallback callback) = 0; 107 ApiCallbackType callback) = 0;
108 virtual int32_t WriteValidated(int64_t offset, 108 virtual int32_t WriteValidated(int64_t offset,
109 const char* buffer, 109 const char* buffer,
110 int32_t bytes_to_write, 110 int32_t bytes_to_write,
111 PP_CompletionCallback callback) = 0; 111 ApiCallbackType callback) = 0;
112 virtual int32_t SetLengthValidated(int64_t length, 112 virtual int32_t SetLengthValidated(int64_t length,
113 PP_CompletionCallback callback) = 0; 113 ApiCallbackType callback) = 0;
114 virtual int32_t FlushValidated(PP_CompletionCallback callback) = 0; 114 virtual int32_t FlushValidated(ApiCallbackType callback) = 0;
115 115
116 // Called for every "Validated" function. 116 // Called for every "Validated" function.
117 // 117 //
118 // This verifies that the callback is valid and that no callback is already 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 119 // pending, or it is a read(write) request and currently the pending
120 // operations are reads(writes). 120 // operations are reads(writes).
121 // 121 //
122 // Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if 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. 123 // the call should be aborted and that code returned to the plugin.
124 int32_t CommonCallValidation(bool should_be_open, 124 int32_t CommonCallValidation(bool should_be_open, OperationType new_op);
125 OperationType new_op,
126 PP_CompletionCallback callback);
127 125
128 // Sets up a pending callback. This should only be called once it is certain 126 // Sets up a pending callback. This should only be called once it is certain
129 // that |PP_OK_COMPLETIONPENDING| will be returned. 127 // that |PP_OK_COMPLETIONPENDING| will be returned.
130 // 128 //
131 // |read_buffer| is only used by read operations, |info| is used only by 129 // |read_buffer| is only used by read operations, |info| is used only by
132 // query operations. 130 // query operations.
133 void RegisterCallback(OperationType op, 131 void RegisterCallback(OperationType op,
134 PP_CompletionCallback callback, 132 scoped_refptr<TrackedCallback> callback,
135 char* read_buffer, 133 char* read_buffer,
136 PP_FileInfo* info); 134 PP_FileInfo* info);
137 135
138 // Pops the oldest callback from the queue and runs it. 136 // Pops the oldest callback from the queue and runs it.
139 void RunAndRemoveFirstPendingCallback(int32_t result); 137 void RunAndRemoveFirstPendingCallback(int32_t result);
140 138
141 // The file system type specified in the Open() call. This will be 139 // The file system type specified in the Open() call. This will be
142 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not 140 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not
143 // indicate that the open command actually succeeded. 141 // indicate that the open command actually succeeded.
144 PP_FileSystemType file_system_type_; 142 PP_FileSystemType file_system_type_;
145 143
146 // Set to true when the file has been successfully opened. 144 // Set to true when the file has been successfully opened.
147 bool file_open_; 145 bool file_open_;
148 146
149 std::deque<CallbackEntry> callbacks_; 147 std::deque<CallbackEntry> callbacks_;
150 OperationType pending_op_; 148 OperationType pending_op_;
151 149
152 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Shared); 150 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Shared);
153 }; 151 };
154 152
155 } // namespace ppapi 153 } // namespace ppapi
156 154
157 #endif // PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_ 155 #endif // PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698