OLD | NEW |
---|---|
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 } |
(...skipping 13 matching lines...) Expand all Loading... | |
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. | 53 // The callbacks list should have been cleared by LastPluginRefWasDeleted. |
56 DCHECK(callbacks_.empty()); | 54 DCHECK(callbacks_.empty()); |
57 } | 55 } |
58 | 56 |
59 void PPB_FileIO_Shared::LastPluginRefWasDeleted() { | 57 void PPB_FileIO_Shared::LastPluginRefWasDeleted() { |
60 // Abort all pending callbacks. Do this by posting a task to avoid reentering | 58 // Abort all pending callbacks. Do this by posting a task to avoid reentering |
61 // the plugin's Release() call that probably deleted this object. | 59 // the plugin's Release() call that probably deleted this object. |
62 for (size_t i = 0; i < callbacks_.size(); i++) { | 60 for (size_t i = 0; i < callbacks_.size(); i++) |
viettrungluu
2012/01/03 22:43:46
I suppose you could also use PostAbortForResource(
brettw
2012/01/04 00:27:29
Actually I can just delete this code, it's already
| |
63 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 61 callbacks_[i].callback->PostAbort(); |
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()); | 62 callbacks_.erase(callbacks_.begin(), callbacks_.end()); |
68 } | 63 } |
69 | 64 |
70 thunk::PPB_FileIO_API* PPB_FileIO_Shared::AsPPB_FileIO_API() { | 65 thunk::PPB_FileIO_API* PPB_FileIO_Shared::AsPPB_FileIO_API() { |
71 return this; | 66 return this; |
72 } | 67 } |
73 | 68 |
74 int32_t PPB_FileIO_Shared::Open(PP_Resource file_ref, | 69 int32_t PPB_FileIO_Shared::Open(PP_Resource file_ref, |
75 int32_t open_flags, | 70 int32_t open_flags, |
76 PP_CompletionCallback callback) { | 71 PP_CompletionCallback callback) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 | 205 |
211 void PPB_FileIO_Shared::RegisterCallback(OperationType op, | 206 void PPB_FileIO_Shared::RegisterCallback(OperationType op, |
212 PP_CompletionCallback callback, | 207 PP_CompletionCallback callback, |
213 char* read_buffer, | 208 char* read_buffer, |
214 PP_FileInfo* info) { | 209 PP_FileInfo* info) { |
215 DCHECK(callback.func); | 210 DCHECK(callback.func); |
216 DCHECK(pending_op_ == OPERATION_NONE || | 211 DCHECK(pending_op_ == OPERATION_NONE || |
217 (pending_op_ != OPERATION_EXCLUSIVE && pending_op_ == op)); | 212 (pending_op_ != OPERATION_EXCLUSIVE && pending_op_ == op)); |
218 | 213 |
219 CallbackEntry entry; | 214 CallbackEntry entry; |
220 entry.callback = callback; | 215 entry.callback = new TrackedCallback(this, callback); |
221 entry.read_buffer = read_buffer; | 216 entry.read_buffer = read_buffer; |
222 entry.info = info; | 217 entry.info = info; |
223 callbacks_.push_back(entry); | 218 callbacks_.push_back(entry); |
224 | 219 |
225 pending_op_ = op; | 220 pending_op_ = op; |
226 } | 221 } |
227 | 222 |
228 void PPB_FileIO_Shared::RunAndRemoveFirstPendingCallback(int32_t result) { | 223 void PPB_FileIO_Shared::RunAndRemoveFirstPendingCallback(int32_t result) { |
229 DCHECK(!callbacks_.empty()); | 224 DCHECK(!callbacks_.empty()); |
230 | 225 |
231 CallbackEntry front = callbacks_.front(); | 226 CallbackEntry front = callbacks_.front(); |
232 callbacks_.pop_front(); | 227 callbacks_.pop_front(); |
233 if (callbacks_.empty()) | 228 if (callbacks_.empty()) |
234 pending_op_ = OPERATION_NONE; | 229 pending_op_ = OPERATION_NONE; |
235 | 230 |
236 PP_RunCompletionCallback(&front.callback, result); | 231 front.callback->Run(result); |
237 } | 232 } |
238 | 233 |
239 } // namespace ppapi | 234 } // namespace ppapi |
OLD | NEW |