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

Side by Side Diff: ppapi/proxy/file_io_resource.cc

Issue 18063005: Do PPB_FileIO Query and Read in the plugin process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to David's latest. Created 7 years, 5 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
« no previous file with comments | « ppapi/proxy/file_io_resource.h ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "ppapi/proxy/file_io_resource.h" 5 #include "ppapi/proxy/file_io_resource.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util_proxy.h"
8 #include "ipc/ipc_message.h" 9 #include "ipc/ipc_message.h"
9 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/proxy/plugin_globals.h"
10 #include "ppapi/proxy/ppapi_messages.h" 12 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/shared_impl/array_writer.h" 13 #include "ppapi/shared_impl/array_writer.h"
14 #include "ppapi/shared_impl/file_type_conversion.h"
12 #include "ppapi/shared_impl/ppapi_globals.h" 15 #include "ppapi/shared_impl/ppapi_globals.h"
16 #include "ppapi/shared_impl/proxy_lock.h"
13 #include "ppapi/shared_impl/resource_tracker.h" 17 #include "ppapi/shared_impl/resource_tracker.h"
14 #include "ppapi/thunk/enter.h" 18 #include "ppapi/thunk/enter.h"
15 #include "ppapi/thunk/ppb_file_ref_api.h" 19 #include "ppapi/thunk/ppb_file_ref_api.h"
16 20
17 using ppapi::thunk::EnterResourceNoLock; 21 using ppapi::thunk::EnterResourceNoLock;
18 using ppapi::thunk::PPB_FileIO_API; 22 using ppapi::thunk::PPB_FileIO_API;
19 using ppapi::thunk::PPB_FileRef_API; 23 using ppapi::thunk::PPB_FileRef_API;
20 24
21 namespace { 25 namespace {
22 26
23 // An adapter to let Read() share the same implementation with ReadToArray(). 27 // An adapter to let Read() share the same implementation with ReadToArray().
24 void* DummyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) { 28 void* DummyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) {
25 return user_data; 29 return user_data;
26 } 30 }
27 31
32 // Dummy close callback allows us to call CloseFileHandle in the destructor.
33 void DummyCloseCallback(base::PlatformFileError error_code) {
34 }
35
28 } // namespace 36 } // namespace
29 37
30 namespace ppapi { 38 namespace ppapi {
31 namespace proxy { 39 namespace proxy {
32 40
33 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) 41 FileIOResource::FileIOResource(Connection connection, PP_Instance instance)
34 : PluginResource(connection, instance) { 42 : PluginResource(connection, instance),
43 file_handle_(PP_kInvalidFileHandle),
44 file_system_type_(PP_FILESYSTEMTYPE_INVALID) {
35 SendCreate(RENDERER, PpapiHostMsg_FileIO_Create()); 45 SendCreate(RENDERER, PpapiHostMsg_FileIO_Create());
36 } 46 }
37 47
38 FileIOResource::~FileIOResource() { 48 FileIOResource::~FileIOResource() {
49 CloseFileHandle();
39 } 50 }
40 51
41 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { 52 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() {
42 return this; 53 return this;
43 } 54 }
44 55
45 int32_t FileIOResource::Open(PP_Resource file_ref, 56 int32_t FileIOResource::Open(PP_Resource file_ref,
46 int32_t open_flags, 57 int32_t open_flags,
47 scoped_refptr<TrackedCallback> callback) { 58 scoped_refptr<TrackedCallback> callback) {
48 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true); 59 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true);
49 if (enter.failed()) 60 if (enter.failed())
50 return PP_ERROR_BADRESOURCE; 61 return PP_ERROR_BADRESOURCE;
51 62
63 PPB_FileRef_API* file_ref_api = enter.object();
64 PP_FileSystemType type = file_ref_api->GetFileSystemType();
65 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT &&
66 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY &&
67 type != PP_FILESYSTEMTYPE_EXTERNAL &&
68 type != PP_FILESYSTEMTYPE_ISOLATED) {
69 NOTREACHED();
70 return PP_ERROR_FAILED;
71 }
72 file_system_type_ = type;
73
52 int32_t rv = state_manager_.CheckOperationState( 74 int32_t rv = state_manager_.CheckOperationState(
53 FileIOStateManager::OPERATION_EXCLUSIVE, false); 75 FileIOStateManager::OPERATION_EXCLUSIVE, false);
54 if (rv != PP_OK) 76 if (rv != PP_OK)
55 return rv; 77 return rv;
56 78
57 Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER, 79 Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER,
58 PpapiHostMsg_FileIO_Open( 80 PpapiHostMsg_FileIO_Open(
59 enter.resource()->host_resource().host_resource(), 81 enter.resource()->host_resource().host_resource(),
60 open_flags), 82 open_flags),
61 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, 83 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this,
62 callback)); 84 callback));
63 85
64 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 86 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
65 return PP_OK_COMPLETIONPENDING; 87 return PP_OK_COMPLETIONPENDING;
66 } 88 }
67 89
68 int32_t FileIOResource::Query(PP_FileInfo* info, 90 int32_t FileIOResource::Query(PP_FileInfo* info,
69 scoped_refptr<TrackedCallback> callback) { 91 scoped_refptr<TrackedCallback> callback) {
70 int32_t rv = state_manager_.CheckOperationState( 92 int32_t rv = state_manager_.CheckOperationState(
71 FileIOStateManager::OPERATION_EXCLUSIVE, true); 93 FileIOStateManager::OPERATION_EXCLUSIVE, true);
72 if (rv != PP_OK) 94 if (rv != PP_OK)
73 return rv; 95 return rv;
74 96
75 Call<PpapiPluginMsg_FileIO_QueryReply>(RENDERER, 97 if (file_handle_ == base::kInvalidPlatformFileValue)
76 PpapiHostMsg_FileIO_Query(), 98 return PP_ERROR_FAILED;
77 base::Bind(&FileIOResource::OnPluginMsgQueryComplete, this,
78 callback, info));
79 99
100 PassedRef passed_ref(new scoped_refptr<FileIOResource>(this));
101 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
102 PpapiGlobals::Get()->GetFileTaskRunner(pp_instance()),
103 file_handle_,
104 base::Bind(&QueryCallback, base::Passed(&passed_ref),
105 callback, info))) {
106 return PP_ERROR_FAILED;
107 }
80 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 108 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
81 return PP_OK_COMPLETIONPENDING; 109 return PP_OK_COMPLETIONPENDING;
82 } 110 }
83 111
84 int32_t FileIOResource::Touch(PP_Time last_access_time, 112 int32_t FileIOResource::Touch(PP_Time last_access_time,
85 PP_Time last_modified_time, 113 PP_Time last_modified_time,
86 scoped_refptr<TrackedCallback> callback) { 114 scoped_refptr<TrackedCallback> callback) {
87 int32_t rv = state_manager_.CheckOperationState( 115 int32_t rv = state_manager_.CheckOperationState(
88 FileIOStateManager::OPERATION_EXCLUSIVE, true); 116 FileIOStateManager::OPERATION_EXCLUSIVE, true);
89 if (rv != PP_OK) 117 if (rv != PP_OK)
(...skipping 13 matching lines...) Expand all
103 int32_t bytes_to_read, 131 int32_t bytes_to_read,
104 scoped_refptr<TrackedCallback> callback) { 132 scoped_refptr<TrackedCallback> callback) {
105 int32_t rv = state_manager_.CheckOperationState( 133 int32_t rv = state_manager_.CheckOperationState(
106 FileIOStateManager::OPERATION_READ, true); 134 FileIOStateManager::OPERATION_READ, true);
107 if (rv != PP_OK) 135 if (rv != PP_OK)
108 return rv; 136 return rv;
109 137
110 PP_ArrayOutput output_adapter; 138 PP_ArrayOutput output_adapter;
111 output_adapter.GetDataBuffer = &DummyGetDataBuffer; 139 output_adapter.GetDataBuffer = &DummyGetDataBuffer;
112 output_adapter.user_data = buffer; 140 output_adapter.user_data = buffer;
113 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ);
114 return ReadValidated(offset, bytes_to_read, output_adapter, callback); 141 return ReadValidated(offset, bytes_to_read, output_adapter, callback);
115 } 142 }
116 143
117 int32_t FileIOResource::ReadToArray(int64_t offset, 144 int32_t FileIOResource::ReadToArray(int64_t offset,
118 int32_t max_read_length, 145 int32_t max_read_length,
119 PP_ArrayOutput* array_output, 146 PP_ArrayOutput* array_output,
120 scoped_refptr<TrackedCallback> callback) { 147 scoped_refptr<TrackedCallback> callback) {
121 DCHECK(array_output); 148 DCHECK(array_output);
122 int32_t rv = state_manager_.CheckOperationState( 149 int32_t rv = state_manager_.CheckOperationState(
123 FileIOStateManager::OPERATION_READ, true); 150 FileIOStateManager::OPERATION_READ, true);
124 if (rv != PP_OK) 151 if (rv != PP_OK)
125 return rv; 152 return rv;
126 153
127 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ);
128 return ReadValidated(offset, max_read_length, *array_output, callback); 154 return ReadValidated(offset, max_read_length, *array_output, callback);
129 } 155 }
130 156
131 int32_t FileIOResource::Write(int64_t offset, 157 int32_t FileIOResource::Write(int64_t offset,
132 const char* buffer, 158 const char* buffer,
133 int32_t bytes_to_write, 159 int32_t bytes_to_write,
134 scoped_refptr<TrackedCallback> callback) { 160 scoped_refptr<TrackedCallback> callback) {
135 int32_t rv = state_manager_.CheckOperationState( 161 int32_t rv = state_manager_.CheckOperationState(
136 FileIOStateManager::OPERATION_WRITE, true); 162 FileIOStateManager::OPERATION_WRITE, true);
137 if (rv != PP_OK) 163 if (rv != PP_OK)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, 200 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER,
175 PpapiHostMsg_FileIO_Flush(), 201 PpapiHostMsg_FileIO_Flush(),
176 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, 202 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this,
177 callback)); 203 callback));
178 204
179 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 205 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
180 return PP_OK_COMPLETIONPENDING; 206 return PP_OK_COMPLETIONPENDING;
181 } 207 }
182 208
183 void FileIOResource::Close() { 209 void FileIOResource::Close() {
210 CloseFileHandle();
184 Post(RENDERER, PpapiHostMsg_FileIO_Close()); 211 Post(RENDERER, PpapiHostMsg_FileIO_Close());
185 } 212 }
186 213
187 int32_t FileIOResource::GetOSFileDescriptor() { 214 int32_t FileIOResource::GetOSFileDescriptor() {
188 int32_t file_descriptor; 215 int32_t file_descriptor;
189 // Only available when running in process. 216 // Only available when running in process.
190 SyncCall<PpapiPluginMsg_FileIO_GetOSFileDescriptorReply>( 217 SyncCall<PpapiPluginMsg_FileIO_GetOSFileDescriptorReply>(
191 RENDERER, PpapiHostMsg_FileIO_GetOSFileDescriptor(), &file_descriptor); 218 RENDERER, PpapiHostMsg_FileIO_GetOSFileDescriptor(), &file_descriptor);
192 return file_descriptor; 219 return file_descriptor;
193 } 220 }
194 221
222 int32_t FileIOResource::RequestOSFileHandle(
223 PP_FileHandle* handle,
224 scoped_refptr<TrackedCallback> callback) {
225 int32_t rv = state_manager_.CheckOperationState(
226 FileIOStateManager::OPERATION_EXCLUSIVE, true);
227 if (rv != PP_OK)
228 return rv;
229
230 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER,
231 PpapiHostMsg_FileIO_RequestOSFileHandle(),
232 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this,
233 callback, handle));
234
235 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
236 return PP_OK_COMPLETIONPENDING;
237 }
238
195 int32_t FileIOResource::WillWrite(int64_t offset, 239 int32_t FileIOResource::WillWrite(int64_t offset,
196 int32_t bytes_to_write, 240 int32_t bytes_to_write,
197 scoped_refptr<TrackedCallback> callback) { 241 scoped_refptr<TrackedCallback> callback) {
198 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, 242 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER,
199 PpapiHostMsg_FileIO_WillWrite(offset, bytes_to_write), 243 PpapiHostMsg_FileIO_WillWrite(offset, bytes_to_write),
200 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, 244 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this,
201 callback)); 245 callback));
202 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 246 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
203 return PP_OK_COMPLETIONPENDING; 247 return PP_OK_COMPLETIONPENDING;
204 } 248 }
205 249
206 int32_t FileIOResource::WillSetLength(int64_t length, 250 int32_t FileIOResource::WillSetLength(int64_t length,
207 scoped_refptr<TrackedCallback> callback) { 251 scoped_refptr<TrackedCallback> callback) {
208 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, 252 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER,
209 PpapiHostMsg_FileIO_WillSetLength(length), 253 PpapiHostMsg_FileIO_WillSetLength(length),
210 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, 254 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this,
211 callback)); 255 callback));
212 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 256 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
213 return PP_OK_COMPLETIONPENDING; 257 return PP_OK_COMPLETIONPENDING;
214 } 258 }
215 259
216 int32_t FileIOResource::ReadValidated(int64_t offset, 260 int32_t FileIOResource::ReadValidated(int64_t offset,
217 int32_t bytes_to_read, 261 int32_t bytes_to_read,
218 const PP_ArrayOutput& array_output, 262 const PP_ArrayOutput& array_output,
219 scoped_refptr<TrackedCallback> callback) { 263 scoped_refptr<TrackedCallback> callback) {
220 Call<PpapiPluginMsg_FileIO_ReadReply>(RENDERER, 264 if (file_handle_ == base::kInvalidPlatformFileValue)
221 PpapiHostMsg_FileIO_Read(offset, bytes_to_read), 265 return PP_ERROR_FAILED;
222 base::Bind(&FileIOResource::OnPluginMsgReadComplete, this, 266
223 callback, array_output)); 267 PassedRef passed_ref(new scoped_refptr<FileIOResource>(this));
268 if (!base::FileUtilProxy::Read(
269 PpapiGlobals::Get()->GetFileTaskRunner(pp_instance()),
270 file_handle_,
271 offset,
272 bytes_to_read,
273 base::Bind(&ReadCallback, base::Passed(&passed_ref),
274 callback, array_output))) {
275 return PP_ERROR_FAILED;
276 }
277
278 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ);
224 return PP_OK_COMPLETIONPENDING; 279 return PP_OK_COMPLETIONPENDING;
225 } 280 }
226 281
227 int32_t FileIOResource::RequestOSFileHandle( 282 void FileIOResource::CloseFileHandle() {
228 PP_FileHandle* handle, 283 if (file_handle_ != base::kInvalidPlatformFileValue) {
229 scoped_refptr<TrackedCallback> callback) { 284 base::FileUtilProxy::Close(
230 int32_t rv = state_manager_.CheckOperationState( 285 PpapiGlobals::Get()->GetFileTaskRunner(pp_instance()),
231 FileIOStateManager::OPERATION_EXCLUSIVE, true); 286 file_handle_,
232 if (rv != PP_OK) 287 base::Bind(&DummyCloseCallback));
233 return rv; 288 file_handle_ = base::kInvalidPlatformFileValue;
289 }
290 }
234 291
235 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER, 292 // static
236 PpapiHostMsg_FileIO_RequestOSFileHandle(), 293 void FileIOResource::QueryCallback(PassedRef file_io_ref,
237 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, 294 scoped_refptr<TrackedCallback> callback,
238 callback, handle)); 295 PP_FileInfo* output_info,
296 base::PlatformFileError error_code,
297 const base::PlatformFileInfo& file_info) {
298 ProxyAutoLock lock;
299 scoped_refptr<FileIOResource> file_io;
300 file_io.swap(*file_io_ref.get());
301 file_io->OnQueryComplete(callback, output_info, error_code, file_info);
302 }
239 303
240 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 304 // static
241 return PP_OK_COMPLETIONPENDING; 305 void FileIOResource::ReadCallback(PassedRef file_io_ref,
306 scoped_refptr<TrackedCallback> callback,
307 PP_ArrayOutput array_output,
308 base::PlatformFileError error_code,
309 const char* data, int bytes_read) {
310 ProxyAutoLock lock;
311 scoped_refptr<FileIOResource> file_io;
312 file_io.swap(*file_io_ref.get());
313 file_io->OnReadComplete(callback, array_output, error_code, data, bytes_read);
dmichael (off chromium) 2013/07/25 17:42:47 It looks like this stuff snuck back in. Was that o
bbudge 2013/07/25 17:56:26 No. I'm not sure what happened here.
314 }
315
316 void FileIOResource::OnQueryComplete(
317 scoped_refptr<TrackedCallback> callback,
318 PP_FileInfo* output_info,
319 base::PlatformFileError error_code,
320 const base::PlatformFileInfo& file_info) {
321 DCHECK(state_manager_.get_pending_operation() ==
322 FileIOStateManager::OPERATION_EXCLUSIVE);
323
324 if (!TrackedCallback::IsPending(callback)) {
325 state_manager_.SetOperationFinished();
326 return;
327 }
328
329 int32_t result = ::ppapi::PlatformFileErrorToPepperError(error_code);
330 if (result == PP_OK) {
331 ppapi::PlatformFileInfoToPepperFileInfo(file_info, file_system_type_,
332 output_info);
333 }
334
335 // End this operation now, so the user's callback can execute another FileIO
336 // operation, assuming there are no other pending operations.
337 state_manager_.SetOperationFinished();
338 callback->Run(result);
339 }
340
341 void FileIOResource::OnReadComplete(
342 scoped_refptr<TrackedCallback> callback,
343 PP_ArrayOutput array_output,
344 base::PlatformFileError error_code,
345 const char* data, int bytes_read) {
346 DCHECK(state_manager_.get_pending_operation() ==
347 FileIOStateManager::OPERATION_READ);
348
349 if (!TrackedCallback::IsPending(callback)) {
350 state_manager_.SetOperationFinished();
351 return;
352 }
353
354 int32_t result = ::ppapi::PlatformFileErrorToPepperError(error_code);
355 if (result == PP_OK) {
356 result = std::max(0, bytes_read);
357 ArrayWriter output;
358 output.set_pp_array_output(array_output);
359 if (output.is_valid())
360 output.StoreArray(data, result);
361 else
362 result = PP_ERROR_FAILED;
363 }
364
365 // End this operation now, so the user's callback can execute another FileIO
366 // operation, assuming there are no other pending operations.
367 state_manager_.SetOperationFinished();
368 callback->Run(result);
242 } 369 }
243 370
244 void FileIOResource::OnPluginMsgGeneralComplete( 371 void FileIOResource::OnPluginMsgGeneralComplete(
245 scoped_refptr<TrackedCallback> callback, 372 scoped_refptr<TrackedCallback> callback,
246 const ResourceMessageReplyParams& params) { 373 const ResourceMessageReplyParams& params) {
247 DCHECK(state_manager_.get_pending_operation() == 374 DCHECK(state_manager_.get_pending_operation() ==
248 FileIOStateManager::OPERATION_EXCLUSIVE || 375 FileIOStateManager::OPERATION_EXCLUSIVE ||
249 state_manager_.get_pending_operation() == 376 state_manager_.get_pending_operation() ==
250 FileIOStateManager::OPERATION_WRITE); 377 FileIOStateManager::OPERATION_WRITE);
251 // End the operation now. The callback may perform another file operation. 378 // End this operation now, so the user's callback can execute another FileIO
379 // operation, assuming there are no other pending operations.
252 state_manager_.SetOperationFinished(); 380 state_manager_.SetOperationFinished();
253 callback->Run(params.result()); 381 callback->Run(params.result());
254 } 382 }
255 383
256 void FileIOResource::OnPluginMsgOpenFileComplete( 384 void FileIOResource::OnPluginMsgOpenFileComplete(
257 scoped_refptr<TrackedCallback> callback, 385 scoped_refptr<TrackedCallback> callback,
258 const ResourceMessageReplyParams& params) { 386 const ResourceMessageReplyParams& params) {
259 DCHECK(state_manager_.get_pending_operation() == 387 DCHECK(state_manager_.get_pending_operation() ==
260 FileIOStateManager::OPERATION_EXCLUSIVE); 388 FileIOStateManager::OPERATION_EXCLUSIVE);
261 if (params.result() == PP_OK) 389 if (params.result() == PP_OK)
262 state_manager_.SetOpenSucceed(); 390 state_manager_.SetOpenSucceed();
263 // End the operation now. The callback may perform another file operation. 391
392 int32_t result = params.result();
393 IPC::PlatformFileForTransit transit_file;
394 if (result == PP_OK && !params.TakeFileHandleAtIndex(0, &transit_file))
395 result = PP_ERROR_FAILED;
396 file_handle_ = IPC::PlatformFileForTransitToPlatformFile(transit_file);
397
398 // End this operation now, so the user's callback can execute another FileIO
399 // operation, assuming there are no other pending operations.
264 state_manager_.SetOperationFinished(); 400 state_manager_.SetOperationFinished();
265 callback->Run(params.result()); 401 callback->Run(params.result());
266 } 402 }
267 403
268 void FileIOResource::OnPluginMsgQueryComplete(
269 scoped_refptr<TrackedCallback> callback,
270 PP_FileInfo* output_info,
271 const ResourceMessageReplyParams& params,
272 const PP_FileInfo& info) {
273 DCHECK(state_manager_.get_pending_operation() ==
274 FileIOStateManager::OPERATION_EXCLUSIVE);
275 *output_info = info;
276 // End the operation now. The callback may perform another file operation.
277 state_manager_.SetOperationFinished();
278 callback->Run(params.result());
279 }
280
281 void FileIOResource::OnPluginMsgReadComplete(
282 scoped_refptr<TrackedCallback> callback,
283 PP_ArrayOutput array_output,
284 const ResourceMessageReplyParams& params,
285 const std::string& data) {
286 DCHECK(state_manager_.get_pending_operation() ==
287 FileIOStateManager::OPERATION_READ);
288
289 // The result code should contain the data size if it's positive.
290 int32_t result = params.result();
291 DCHECK((result < 0 && data.size() == 0) ||
292 result == static_cast<int32_t>(data.size()));
293
294 ArrayWriter output;
295 output.set_pp_array_output(array_output);
296 if (output.is_valid())
297 output.StoreArray(data.data(), std::max(0, result));
298 else
299 result = PP_ERROR_FAILED;
300
301 // End the operation now. The callback may perform another file operation.
302 state_manager_.SetOperationFinished();
303 callback->Run(result);
304 }
305
306 void FileIOResource::OnPluginMsgRequestOSFileHandleComplete( 404 void FileIOResource::OnPluginMsgRequestOSFileHandleComplete(
307 scoped_refptr<TrackedCallback> callback, 405 scoped_refptr<TrackedCallback> callback,
308 PP_FileHandle* output_handle, 406 PP_FileHandle* output_handle,
309 const ResourceMessageReplyParams& params) { 407 const ResourceMessageReplyParams& params) {
310 DCHECK(state_manager_.get_pending_operation() == 408 DCHECK(state_manager_.get_pending_operation() ==
311 FileIOStateManager::OPERATION_EXCLUSIVE); 409 FileIOStateManager::OPERATION_EXCLUSIVE);
312 410
313 if (!TrackedCallback::IsPending(callback)) { 411 if (!TrackedCallback::IsPending(callback)) {
314 state_manager_.SetOperationFinished(); 412 state_manager_.SetOperationFinished();
315 return; 413 return;
316 } 414 }
317 415
318 int32_t result = params.result(); 416 int32_t result = params.result();
319 IPC::PlatformFileForTransit transit_file; 417 IPC::PlatformFileForTransit transit_file;
320 if (!params.TakeFileHandleAtIndex(0, &transit_file)) 418 if (!params.TakeFileHandleAtIndex(0, &transit_file))
321 result = PP_ERROR_FAILED; 419 result = PP_ERROR_FAILED;
322 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); 420 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file);
323 421
324 // End the operation now. The callback may perform another file operation. 422 // End this operation now, so the user's callback can execute another FileIO
423 // operation, assuming there are no other pending operations.
325 state_manager_.SetOperationFinished(); 424 state_manager_.SetOperationFinished();
326 callback->Run(result); 425 callback->Run(result);
327 } 426 }
328 427
329 } // namespace proxy 428 } // namespace proxy
330 } // namespace ppapi 429 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/file_io_resource.h ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698