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

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

Issue 9053003: Convert ppapi/shared to use TrackedCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comments Created 8 years, 11 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 #include "ppapi/shared_impl/ppb_file_io_shared.h" 5 #include "ppapi/shared_impl/ppb_file_io_shared.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/shared_impl/file_type_conversion.h" 13 #include "ppapi/shared_impl/file_type_conversion.h"
14 #include "ppapi/shared_impl/time_conversion.h" 14 #include "ppapi/shared_impl/time_conversion.h"
15 #include "ppapi/thunk/enter.h" 15 #include "ppapi/thunk/enter.h"
16 #include "ppapi/thunk/ppb_file_ref_api.h" 16 #include "ppapi/thunk/ppb_file_ref_api.h"
17 17
18 namespace ppapi { 18 namespace ppapi {
19 19
20 using thunk::EnterResourceNoLock; 20 using thunk::EnterResourceNoLock;
21 using thunk::PPB_FileIO_API; 21 using thunk::PPB_FileIO_API;
22 using thunk::PPB_FileRef_API; 22 using thunk::PPB_FileRef_API;
23 23
24 PPB_FileIO_Shared::CallbackEntry::CallbackEntry() 24 PPB_FileIO_Shared::CallbackEntry::CallbackEntry()
25 : read_buffer(NULL), 25 : read_buffer(NULL),
26 info(NULL) { 26 info(NULL) {
27 callback.func = NULL;
28 callback.user_data = NULL;
29 } 27 }
30 28
31 PPB_FileIO_Shared::CallbackEntry::CallbackEntry(const CallbackEntry& entry) 29 PPB_FileIO_Shared::CallbackEntry::CallbackEntry(const CallbackEntry& entry)
32 : callback(entry.callback), 30 : callback(entry.callback),
33 read_buffer(entry.read_buffer), 31 read_buffer(entry.read_buffer),
34 info(entry.info) { 32 info(entry.info) {
35 } 33 }
36 34
37 PPB_FileIO_Shared::CallbackEntry::~CallbackEntry() { 35 PPB_FileIO_Shared::CallbackEntry::~CallbackEntry() {
38 } 36 }
39 37
40 PPB_FileIO_Shared::PPB_FileIO_Shared(PP_Instance instance) 38 PPB_FileIO_Shared::PPB_FileIO_Shared(PP_Instance instance)
41 : Resource(instance), 39 : Resource(instance),
42 file_system_type_(PP_FILESYSTEMTYPE_INVALID), 40 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
43 file_open_(false), 41 file_open_(false),
44 pending_op_(OPERATION_NONE) { 42 pending_op_(OPERATION_NONE) {
45 } 43 }
46 44
47 PPB_FileIO_Shared::PPB_FileIO_Shared(const HostResource& host_resource) 45 PPB_FileIO_Shared::PPB_FileIO_Shared(const HostResource& host_resource)
48 : Resource(host_resource), 46 : Resource(host_resource),
49 file_system_type_(PP_FILESYSTEMTYPE_INVALID), 47 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
50 file_open_(false), 48 file_open_(false),
51 pending_op_(OPERATION_NONE) { 49 pending_op_(OPERATION_NONE) {
52 } 50 }
53 51
54 PPB_FileIO_Shared::~PPB_FileIO_Shared() { 52 PPB_FileIO_Shared::~PPB_FileIO_Shared() {
55 // The callbacks list should have been cleared by LastPluginRefWasDeleted.
56 DCHECK(callbacks_.empty());
57 }
58
59 void PPB_FileIO_Shared::LastPluginRefWasDeleted() {
60 // Abort all pending callbacks. Do this by posting a task to avoid reentering
61 // the plugin's Release() call that probably deleted this object.
62 for (size_t i = 0; i < callbacks_.size(); i++) {
63 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
64 callbacks_[i].callback.func, callbacks_[i].callback.user_data,
65 static_cast<int32_t>(PP_ERROR_ABORTED)));
66 }
67 callbacks_.erase(callbacks_.begin(), callbacks_.end());
68 } 53 }
69 54
70 thunk::PPB_FileIO_API* PPB_FileIO_Shared::AsPPB_FileIO_API() { 55 thunk::PPB_FileIO_API* PPB_FileIO_Shared::AsPPB_FileIO_API() {
71 return this; 56 return this;
72 } 57 }
73 58
74 int32_t PPB_FileIO_Shared::Open(PP_Resource file_ref, 59 int32_t PPB_FileIO_Shared::Open(PP_Resource file_ref,
75 int32_t open_flags, 60 int32_t open_flags,
76 PP_CompletionCallback callback) { 61 PP_CompletionCallback callback) {
77 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true); 62 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, true);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 195
211 void PPB_FileIO_Shared::RegisterCallback(OperationType op, 196 void PPB_FileIO_Shared::RegisterCallback(OperationType op,
212 PP_CompletionCallback callback, 197 PP_CompletionCallback callback,
213 char* read_buffer, 198 char* read_buffer,
214 PP_FileInfo* info) { 199 PP_FileInfo* info) {
215 DCHECK(callback.func); 200 DCHECK(callback.func);
216 DCHECK(pending_op_ == OPERATION_NONE || 201 DCHECK(pending_op_ == OPERATION_NONE ||
217 (pending_op_ != OPERATION_EXCLUSIVE && pending_op_ == op)); 202 (pending_op_ != OPERATION_EXCLUSIVE && pending_op_ == op));
218 203
219 CallbackEntry entry; 204 CallbackEntry entry;
220 entry.callback = callback; 205 entry.callback = new TrackedCallback(this, callback);
221 entry.read_buffer = read_buffer; 206 entry.read_buffer = read_buffer;
222 entry.info = info; 207 entry.info = info;
223 callbacks_.push_back(entry); 208 callbacks_.push_back(entry);
224 209
225 pending_op_ = op; 210 pending_op_ = op;
226 } 211 }
227 212
228 void PPB_FileIO_Shared::RunAndRemoveFirstPendingCallback(int32_t result) { 213 void PPB_FileIO_Shared::RunAndRemoveFirstPendingCallback(int32_t result) {
229 DCHECK(!callbacks_.empty()); 214 DCHECK(!callbacks_.empty());
230 215
231 CallbackEntry front = callbacks_.front(); 216 CallbackEntry front = callbacks_.front();
232 callbacks_.pop_front(); 217 callbacks_.pop_front();
233 if (callbacks_.empty()) 218 if (callbacks_.empty())
234 pending_op_ = OPERATION_NONE; 219 pending_op_ = OPERATION_NONE;
235 220
236 PP_RunCompletionCallback(&front.callback, result); 221 front.callback->Run(result);
237 } 222 }
238 223
239 } // namespace ppapi 224 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698