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

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: Don't use FileUtilProxy at all. Created 7 years, 4 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 "ipc/ipc_message.h" 8 #include "ipc/ipc_message.h"
9 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/proxy/plugin_globals.h"
10 #include "ppapi/proxy/ppapi_messages.h" 11 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/shared_impl/array_writer.h" 12 #include "ppapi/shared_impl/array_writer.h"
13 #include "ppapi/shared_impl/file_type_conversion.h"
12 #include "ppapi/shared_impl/ppapi_globals.h" 14 #include "ppapi/shared_impl/ppapi_globals.h"
15 #include "ppapi/shared_impl/proxy_lock.h"
13 #include "ppapi/shared_impl/resource_tracker.h" 16 #include "ppapi/shared_impl/resource_tracker.h"
14 #include "ppapi/thunk/enter.h" 17 #include "ppapi/thunk/enter.h"
15 #include "ppapi/thunk/ppb_file_ref_api.h" 18 #include "ppapi/thunk/ppb_file_ref_api.h"
16 19
17 using ppapi::thunk::EnterResourceNoLock; 20 using ppapi::thunk::EnterResourceNoLock;
18 using ppapi::thunk::PPB_FileIO_API; 21 using ppapi::thunk::PPB_FileIO_API;
19 using ppapi::thunk::PPB_FileRef_API; 22 using ppapi::thunk::PPB_FileRef_API;
20 23
21 namespace { 24 namespace {
22 25
23 // An adapter to let Read() share the same implementation with ReadToArray(). 26 // An adapter to let Read() share the same implementation with ReadToArray().
24 void* DummyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) { 27 void* DummyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) {
25 return user_data; 28 return user_data;
26 } 29 }
27 30
31 typedef base::Callback<void(base::PlatformFileError,
32 const base::PlatformFileInfo&)> QueryCallback;
33
34 // Reads from a file. This should only be called on the file thread.
35 void DoQuery(base::PlatformFile file,
36 const QueryCallback& callback) {
37 base::PlatformFileError error = base::PLATFORM_FILE_OK;
38 base::PlatformFileInfo file_info;
39 if (!GetPlatformFileInfo(file, &file_info))
40 error = base::PLATFORM_FILE_ERROR_FAILED;
41
42 // Detect whether this plugin is running out-of-process. If so, we can invoke
43 // the callback directly. If we are running in-process, we must post a task
44 // since there is no proxy lock and any resource access would be unsafe.
45 // TODO(bbudge) Remove this when in-process support is eliminated.
46 if (ppapi::PpapiGlobals::Get()->GetProxyLock()) {
47 callback.Run(error, file_info);
48 } else {
49 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
50 FROM_HERE,
51 Bind(callback, error, file_info));
52 }
53 }
54
55 typedef base::Callback<void(base::PlatformFileError,
56 const char* /* data */,
57 int /* bytes read */)> ReadCallback;
58
59 // Reads file info. This should only be called on the file thread.
60 void DoRead(base::PlatformFile file,
61 int64 offset,
62 int bytes_to_read,
63 const ReadCallback& callback) {
64 scoped_ptr<char[]> buffer(new char[bytes_to_read]);
65 int bytes_read =
66 base::ReadPlatformFile(file, offset, buffer.get(), bytes_to_read);
67 base::PlatformFileError error = (bytes_read < 0) ?
68 base::PLATFORM_FILE_ERROR_FAILED : base::PLATFORM_FILE_OK;
69
70 // Detect whether this plugin is running out-of-process. See note in DoQuery.
71 if (ppapi::PpapiGlobals::Get()->GetProxyLock()) {
72 callback.Run(error, buffer.get(), bytes_read);
73 } else {
74 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
75 FROM_HERE,
76 Bind(callback, error, base::Owned(buffer.release()), bytes_read));
dmichael (off chromium) 2013/08/02 22:28:16 nit: base::Passed is a slightly cleaner way to pas
bbudge 2013/08/03 02:20:28 Can't do it with RunWhileLocked yet, due to scoped
77 }
78 }
79
80 void DoClose(base::PlatformFile file) {
81 base::ClosePlatformFile(file);
82 }
83
28 } // namespace 84 } // namespace
29 85
30 namespace ppapi { 86 namespace ppapi {
31 namespace proxy { 87 namespace proxy {
32 88
33 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) 89 FileIOResource::FileIOResource(Connection connection, PP_Instance instance)
34 : PluginResource(connection, instance) { 90 : PluginResource(connection, instance),
91 file_handle_(PP_kInvalidFileHandle),
92 file_system_type_(PP_FILESYSTEMTYPE_INVALID) {
35 SendCreate(RENDERER, PpapiHostMsg_FileIO_Create()); 93 SendCreate(RENDERER, PpapiHostMsg_FileIO_Create());
36 } 94 }
37 95
38 FileIOResource::~FileIOResource() { 96 FileIOResource::~FileIOResource() {
97 CloseFileHandle();
39 } 98 }
40 99
41 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { 100 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() {
42 return this; 101 return this;
43 } 102 }
44 103
45 int32_t FileIOResource::Open(PP_Resource file_ref, 104 int32_t FileIOResource::Open(PP_Resource file_ref,
46 int32_t open_flags, 105 int32_t open_flags,
47 scoped_refptr<TrackedCallback> callback) { 106 scoped_refptr<TrackedCallback> callback) {
48 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true); 107 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true);
49 if (enter.failed()) 108 if (enter.failed())
50 return PP_ERROR_BADRESOURCE; 109 return PP_ERROR_BADRESOURCE;
51 110
111 PPB_FileRef_API* file_ref_api = enter.object();
112 PP_FileSystemType type = file_ref_api->GetFileSystemType();
113 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT &&
114 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY &&
115 type != PP_FILESYSTEMTYPE_EXTERNAL &&
116 type != PP_FILESYSTEMTYPE_ISOLATED) {
117 NOTREACHED();
118 return PP_ERROR_FAILED;
119 }
120 file_system_type_ = type;
121
52 int32_t rv = state_manager_.CheckOperationState( 122 int32_t rv = state_manager_.CheckOperationState(
53 FileIOStateManager::OPERATION_EXCLUSIVE, false); 123 FileIOStateManager::OPERATION_EXCLUSIVE, false);
54 if (rv != PP_OK) 124 if (rv != PP_OK)
55 return rv; 125 return rv;
56 126
57 Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER, 127 Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER,
58 PpapiHostMsg_FileIO_Open( 128 PpapiHostMsg_FileIO_Open(
59 enter.resource()->host_resource().host_resource(), 129 enter.resource()->host_resource().host_resource(),
60 open_flags), 130 open_flags),
61 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, 131 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this,
62 callback)); 132 callback));
63 133
64 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 134 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
65 return PP_OK_COMPLETIONPENDING; 135 return PP_OK_COMPLETIONPENDING;
66 } 136 }
67 137
68 int32_t FileIOResource::Query(PP_FileInfo* info, 138 int32_t FileIOResource::Query(PP_FileInfo* info,
69 scoped_refptr<TrackedCallback> callback) { 139 scoped_refptr<TrackedCallback> callback) {
70 int32_t rv = state_manager_.CheckOperationState( 140 int32_t rv = state_manager_.CheckOperationState(
71 FileIOStateManager::OPERATION_EXCLUSIVE, true); 141 FileIOStateManager::OPERATION_EXCLUSIVE, true);
72 if (rv != PP_OK) 142 if (rv != PP_OK)
73 return rv; 143 return rv;
74 144
75 Call<PpapiPluginMsg_FileIO_QueryReply>(RENDERER, 145 if (file_handle_ == base::kInvalidPlatformFileValue)
76 PpapiHostMsg_FileIO_Query(), 146 return PP_ERROR_FAILED;
77 base::Bind(&FileIOResource::OnPluginMsgQueryComplete, this, 147
78 callback, info)); 148 PpapiGlobals::Get()->GetFileTaskRunner(pp_instance())->PostTask(
149 FROM_HERE,
150 Bind(&DoQuery, file_handle_,
151 RunWhileLocked(base::Bind(&FileIOResource::OnQueryComplete, this,
152 callback, info))));
79 153
80 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 154 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
81 return PP_OK_COMPLETIONPENDING; 155 return PP_OK_COMPLETIONPENDING;
82 } 156 }
83 157
84 int32_t FileIOResource::Touch(PP_Time last_access_time, 158 int32_t FileIOResource::Touch(PP_Time last_access_time,
85 PP_Time last_modified_time, 159 PP_Time last_modified_time,
86 scoped_refptr<TrackedCallback> callback) { 160 scoped_refptr<TrackedCallback> callback) {
87 int32_t rv = state_manager_.CheckOperationState( 161 int32_t rv = state_manager_.CheckOperationState(
88 FileIOStateManager::OPERATION_EXCLUSIVE, true); 162 FileIOStateManager::OPERATION_EXCLUSIVE, true);
(...skipping 14 matching lines...) Expand all
103 int32_t bytes_to_read, 177 int32_t bytes_to_read,
104 scoped_refptr<TrackedCallback> callback) { 178 scoped_refptr<TrackedCallback> callback) {
105 int32_t rv = state_manager_.CheckOperationState( 179 int32_t rv = state_manager_.CheckOperationState(
106 FileIOStateManager::OPERATION_READ, true); 180 FileIOStateManager::OPERATION_READ, true);
107 if (rv != PP_OK) 181 if (rv != PP_OK)
108 return rv; 182 return rv;
109 183
110 PP_ArrayOutput output_adapter; 184 PP_ArrayOutput output_adapter;
111 output_adapter.GetDataBuffer = &DummyGetDataBuffer; 185 output_adapter.GetDataBuffer = &DummyGetDataBuffer;
112 output_adapter.user_data = buffer; 186 output_adapter.user_data = buffer;
113 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ);
114 return ReadValidated(offset, bytes_to_read, output_adapter, callback); 187 return ReadValidated(offset, bytes_to_read, output_adapter, callback);
115 } 188 }
116 189
117 int32_t FileIOResource::ReadToArray(int64_t offset, 190 int32_t FileIOResource::ReadToArray(int64_t offset,
118 int32_t max_read_length, 191 int32_t max_read_length,
119 PP_ArrayOutput* array_output, 192 PP_ArrayOutput* array_output,
120 scoped_refptr<TrackedCallback> callback) { 193 scoped_refptr<TrackedCallback> callback) {
121 DCHECK(array_output); 194 DCHECK(array_output);
122 int32_t rv = state_manager_.CheckOperationState( 195 int32_t rv = state_manager_.CheckOperationState(
123 FileIOStateManager::OPERATION_READ, true); 196 FileIOStateManager::OPERATION_READ, true);
124 if (rv != PP_OK) 197 if (rv != PP_OK)
125 return rv; 198 return rv;
126 199
127 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ);
128 return ReadValidated(offset, max_read_length, *array_output, callback); 200 return ReadValidated(offset, max_read_length, *array_output, callback);
129 } 201 }
130 202
131 int32_t FileIOResource::Write(int64_t offset, 203 int32_t FileIOResource::Write(int64_t offset,
132 const char* buffer, 204 const char* buffer,
133 int32_t bytes_to_write, 205 int32_t bytes_to_write,
134 scoped_refptr<TrackedCallback> callback) { 206 scoped_refptr<TrackedCallback> callback) {
135 int32_t rv = state_manager_.CheckOperationState( 207 int32_t rv = state_manager_.CheckOperationState(
136 FileIOStateManager::OPERATION_WRITE, true); 208 FileIOStateManager::OPERATION_WRITE, true);
137 if (rv != PP_OK) 209 if (rv != PP_OK)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, 246 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER,
175 PpapiHostMsg_FileIO_Flush(), 247 PpapiHostMsg_FileIO_Flush(),
176 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, 248 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this,
177 callback)); 249 callback));
178 250
179 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 251 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
180 return PP_OK_COMPLETIONPENDING; 252 return PP_OK_COMPLETIONPENDING;
181 } 253 }
182 254
183 void FileIOResource::Close() { 255 void FileIOResource::Close() {
256 CloseFileHandle();
184 Post(RENDERER, PpapiHostMsg_FileIO_Close()); 257 Post(RENDERER, PpapiHostMsg_FileIO_Close());
185 } 258 }
186 259
187 int32_t FileIOResource::GetOSFileDescriptor() { 260 int32_t FileIOResource::GetOSFileDescriptor() {
188 int32_t file_descriptor; 261 int32_t file_descriptor;
189 // Only available when running in process. 262 // Only available when running in process.
190 SyncCall<PpapiPluginMsg_FileIO_GetOSFileDescriptorReply>( 263 SyncCall<PpapiPluginMsg_FileIO_GetOSFileDescriptorReply>(
191 RENDERER, PpapiHostMsg_FileIO_GetOSFileDescriptor(), &file_descriptor); 264 RENDERER, PpapiHostMsg_FileIO_GetOSFileDescriptor(), &file_descriptor);
192 return file_descriptor; 265 return file_descriptor;
193 } 266 }
194 267
268 int32_t FileIOResource::RequestOSFileHandle(
269 PP_FileHandle* handle,
270 scoped_refptr<TrackedCallback> callback) {
271 int32_t rv = state_manager_.CheckOperationState(
272 FileIOStateManager::OPERATION_EXCLUSIVE, true);
273 if (rv != PP_OK)
274 return rv;
275
276 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER,
277 PpapiHostMsg_FileIO_RequestOSFileHandle(),
278 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this,
279 callback, handle));
280
281 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
282 return PP_OK_COMPLETIONPENDING;
283 }
284
195 int32_t FileIOResource::WillWrite(int64_t offset, 285 int32_t FileIOResource::WillWrite(int64_t offset,
196 int32_t bytes_to_write, 286 int32_t bytes_to_write,
197 scoped_refptr<TrackedCallback> callback) { 287 scoped_refptr<TrackedCallback> callback) {
198 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, 288 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER,
199 PpapiHostMsg_FileIO_WillWrite(offset, bytes_to_write), 289 PpapiHostMsg_FileIO_WillWrite(offset, bytes_to_write),
200 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, 290 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this,
201 callback)); 291 callback));
292
202 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 293 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
203 return PP_OK_COMPLETIONPENDING; 294 return PP_OK_COMPLETIONPENDING;
204 } 295 }
205 296
206 int32_t FileIOResource::WillSetLength(int64_t length, 297 int32_t FileIOResource::WillSetLength(int64_t length,
207 scoped_refptr<TrackedCallback> callback) { 298 scoped_refptr<TrackedCallback> callback) {
208 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, 299 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER,
209 PpapiHostMsg_FileIO_WillSetLength(length), 300 PpapiHostMsg_FileIO_WillSetLength(length),
210 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, 301 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this,
211 callback)); 302 callback));
303
212 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 304 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
213 return PP_OK_COMPLETIONPENDING; 305 return PP_OK_COMPLETIONPENDING;
214 } 306 }
215 307
216 int32_t FileIOResource::ReadValidated(int64_t offset, 308 int32_t FileIOResource::ReadValidated(int64_t offset,
217 int32_t bytes_to_read, 309 int32_t bytes_to_read,
218 const PP_ArrayOutput& array_output, 310 const PP_ArrayOutput& array_output,
219 scoped_refptr<TrackedCallback> callback) { 311 scoped_refptr<TrackedCallback> callback) {
220 Call<PpapiPluginMsg_FileIO_ReadReply>(RENDERER, 312 if (file_handle_ == base::kInvalidPlatformFileValue)
221 PpapiHostMsg_FileIO_Read(offset, bytes_to_read), 313 return PP_ERROR_FAILED;
222 base::Bind(&FileIOResource::OnPluginMsgReadComplete, this, 314 if (bytes_to_read < 0)
223 callback, array_output)); 315 return PP_ERROR_FAILED;
316
317 PpapiGlobals::Get()->GetFileTaskRunner(pp_instance())->PostTask(
318 FROM_HERE,
319 Bind(&DoRead, file_handle_, offset, bytes_to_read,
320 RunWhileLocked(base::Bind(&FileIOResource::OnReadComplete, this,
321 callback, array_output))));
322
323 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ);
224 return PP_OK_COMPLETIONPENDING; 324 return PP_OK_COMPLETIONPENDING;
225 } 325 }
226 326
227 int32_t FileIOResource::RequestOSFileHandle( 327 void FileIOResource::CloseFileHandle() {
228 PP_FileHandle* handle, 328 if (file_handle_ != base::kInvalidPlatformFileValue) {
229 scoped_refptr<TrackedCallback> callback) { 329 base::TaskRunner* file_task_runner =
230 int32_t rv = state_manager_.CheckOperationState( 330 PpapiGlobals::Get()->GetFileTaskRunner(pp_instance());
231 FileIOStateManager::OPERATION_EXCLUSIVE, true); 331 file_task_runner->PostTask(FROM_HERE,
232 if (rv != PP_OK) 332 base::Bind(&DoClose, file_handle_));
233 return rv;
234 333
235 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER, 334 file_handle_ = base::kInvalidPlatformFileValue;
236 PpapiHostMsg_FileIO_RequestOSFileHandle(), 335 }
237 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, 336 }
238 callback, handle));
239 337
240 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 338 void FileIOResource::OnQueryComplete(
241 return PP_OK_COMPLETIONPENDING; 339 scoped_refptr<TrackedCallback> callback,
340 PP_FileInfo* output_info,
341 base::PlatformFileError error_code,
342 const base::PlatformFileInfo& file_info) {
343 DCHECK(state_manager_.get_pending_operation() ==
344 FileIOStateManager::OPERATION_EXCLUSIVE);
345
346 if (!TrackedCallback::IsPending(callback)) {
347 state_manager_.SetOperationFinished();
348 return;
349 }
350
351 int32_t result = ::ppapi::PlatformFileErrorToPepperError(error_code);
352 if (result == PP_OK) {
353 ppapi::PlatformFileInfoToPepperFileInfo(file_info, file_system_type_,
354 output_info);
355 }
356
357 // End this operation now, so the user's callback can execute another FileIO
358 // operation, assuming there are no other pending operations.
359 state_manager_.SetOperationFinished();
360 callback->Run(result);
361 }
362
363 void FileIOResource::OnReadComplete(
364 scoped_refptr<TrackedCallback> callback,
365 PP_ArrayOutput array_output,
366 base::PlatformFileError error_code,
367 const char* data, int bytes_read) {
368 DCHECK(state_manager_.get_pending_operation() ==
369 FileIOStateManager::OPERATION_READ);
370
371 if (!TrackedCallback::IsPending(callback)) {
372 state_manager_.SetOperationFinished();
373 return;
374 }
375
376 int32_t result = ::ppapi::PlatformFileErrorToPepperError(error_code);
377 if (result == PP_OK) {
378 result = std::max(0, bytes_read);
379 ArrayWriter output;
380 output.set_pp_array_output(array_output);
381 if (output.is_valid())
382 output.StoreArray(data, result);
383 else
384 result = PP_ERROR_FAILED;
385 }
386
387 // End this operation now, so the user's callback can execute another FileIO
388 // operation, assuming there are no other pending operations.
389 state_manager_.SetOperationFinished();
390 callback->Run(result);
242 } 391 }
243 392
244 void FileIOResource::OnPluginMsgGeneralComplete( 393 void FileIOResource::OnPluginMsgGeneralComplete(
245 scoped_refptr<TrackedCallback> callback, 394 scoped_refptr<TrackedCallback> callback,
246 const ResourceMessageReplyParams& params) { 395 const ResourceMessageReplyParams& params) {
247 DCHECK(state_manager_.get_pending_operation() == 396 DCHECK(state_manager_.get_pending_operation() ==
248 FileIOStateManager::OPERATION_EXCLUSIVE || 397 FileIOStateManager::OPERATION_EXCLUSIVE ||
249 state_manager_.get_pending_operation() == 398 state_manager_.get_pending_operation() ==
250 FileIOStateManager::OPERATION_WRITE); 399 FileIOStateManager::OPERATION_WRITE);
251 // End the operation now. The callback may perform another file operation. 400 // End this operation now, so the user's callback can execute another FileIO
401 // operation, assuming there are no other pending operations.
252 state_manager_.SetOperationFinished(); 402 state_manager_.SetOperationFinished();
253 callback->Run(params.result()); 403 callback->Run(params.result());
254 } 404 }
255 405
256 void FileIOResource::OnPluginMsgOpenFileComplete( 406 void FileIOResource::OnPluginMsgOpenFileComplete(
257 scoped_refptr<TrackedCallback> callback, 407 scoped_refptr<TrackedCallback> callback,
258 const ResourceMessageReplyParams& params) { 408 const ResourceMessageReplyParams& params) {
259 DCHECK(state_manager_.get_pending_operation() == 409 DCHECK(state_manager_.get_pending_operation() ==
260 FileIOStateManager::OPERATION_EXCLUSIVE); 410 FileIOStateManager::OPERATION_EXCLUSIVE);
261 if (params.result() == PP_OK) 411 if (params.result() == PP_OK)
262 state_manager_.SetOpenSucceed(); 412 state_manager_.SetOpenSucceed();
263 // End the operation now. The callback may perform another file operation. 413
414 int32_t result = params.result();
415 IPC::PlatformFileForTransit transit_file;
416 if (result == PP_OK && !params.TakeFileHandleAtIndex(0, &transit_file))
417 result = PP_ERROR_FAILED;
418 file_handle_ = IPC::PlatformFileForTransitToPlatformFile(transit_file);
419
420 // End this operation now, so the user's callback can execute another FileIO
421 // operation, assuming there are no other pending operations.
264 state_manager_.SetOperationFinished(); 422 state_manager_.SetOperationFinished();
265 callback->Run(params.result()); 423 callback->Run(params.result());
266 } 424 }
267 425
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( 426 void FileIOResource::OnPluginMsgRequestOSFileHandleComplete(
307 scoped_refptr<TrackedCallback> callback, 427 scoped_refptr<TrackedCallback> callback,
308 PP_FileHandle* output_handle, 428 PP_FileHandle* output_handle,
309 const ResourceMessageReplyParams& params) { 429 const ResourceMessageReplyParams& params) {
310 DCHECK(state_manager_.get_pending_operation() == 430 DCHECK(state_manager_.get_pending_operation() ==
311 FileIOStateManager::OPERATION_EXCLUSIVE); 431 FileIOStateManager::OPERATION_EXCLUSIVE);
312 432
313 if (!TrackedCallback::IsPending(callback)) { 433 if (!TrackedCallback::IsPending(callback)) {
314 state_manager_.SetOperationFinished(); 434 state_manager_.SetOperationFinished();
315 return; 435 return;
316 } 436 }
317 437
318 int32_t result = params.result(); 438 int32_t result = params.result();
319 IPC::PlatformFileForTransit transit_file; 439 IPC::PlatformFileForTransit transit_file;
320 if (!params.TakeFileHandleAtIndex(0, &transit_file)) 440 if (!params.TakeFileHandleAtIndex(0, &transit_file))
321 result = PP_ERROR_FAILED; 441 result = PP_ERROR_FAILED;
322 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); 442 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file);
323 443
324 // End the operation now. The callback may perform another file operation. 444 // End this operation now, so the user's callback can execute another FileIO
445 // operation, assuming there are no other pending operations.
325 state_manager_.SetOperationFinished(); 446 state_manager_.SetOperationFinished();
326 callback->Run(result); 447 callback->Run(result);
327 } 448 }
328 449
329 } // namespace proxy 450 } // namespace proxy
330 } // namespace ppapi 451 } // 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