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

Side by Side Diff: webkit/plugins/ppapi/audio_helper.cc

Issue 9015013: Convert callers to use the new TrackedCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Foo 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
« no previous file with comments | « webkit/plugins/ppapi/audio_helper.h ('k') | webkit/plugins/ppapi/ppb_audio_impl.cc » ('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) 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/c/pp_completion_callback.h" 5 #include "ppapi/c/pp_completion_callback.h"
6 #include "webkit/plugins/ppapi/audio_helper.h" 6 #include "webkit/plugins/ppapi/audio_helper.h"
7 #include "webkit/plugins/ppapi/common.h" 7 #include "webkit/plugins/ppapi/common.h"
8 #include "webkit/plugins/ppapi/resource_helper.h" 8 #include "webkit/plugins/ppapi/resource_helper.h"
9 9
10 using ppapi::TrackedCallback;
11
10 namespace webkit { 12 namespace webkit {
11 namespace ppapi { 13 namespace ppapi {
12 14
13 // AudioHelper ----------------------------------------------------------------- 15 // AudioHelper -----------------------------------------------------------------
14 16
15 AudioHelper::AudioHelper() 17 AudioHelper::AudioHelper() {
16 : create_callback_pending_(false),
17 shared_memory_size_for_create_callback_(0) {
18 create_callback_ = PP_MakeCompletionCallback(NULL, NULL);
19 } 18 }
20 19
21 AudioHelper::~AudioHelper() { 20 AudioHelper::~AudioHelper() {
22 // If the completion callback hasn't fired yet, do so here
23 // with an error condition.
24 if (create_callback_pending_) {
25 PP_RunCompletionCallback(&create_callback_, PP_ERROR_ABORTED);
26 create_callback_pending_ = false;
27 }
28 } 21 }
29 22
30 int32_t AudioHelper::GetSyncSocketImpl(int* sync_socket) { 23 int32_t AudioHelper::GetSyncSocketImpl(int* sync_socket) {
31 if (socket_for_create_callback_.get()) { 24 if (socket_for_create_callback_.get()) {
32 #if defined(OS_POSIX) 25 #if defined(OS_POSIX)
33 *sync_socket = socket_for_create_callback_->handle(); 26 *sync_socket = socket_for_create_callback_->handle();
34 #elif defined(OS_WIN) 27 #elif defined(OS_WIN)
35 *sync_socket = reinterpret_cast<int>(socket_for_create_callback_->handle()); 28 *sync_socket = reinterpret_cast<int>(socket_for_create_callback_->handle());
36 #else 29 #else
37 #error "Platform not supported." 30 #error "Platform not supported."
(...skipping 16 matching lines...) Expand all
54 *shm_size = shared_memory_size_for_create_callback_; 47 *shm_size = shared_memory_size_for_create_callback_;
55 return PP_OK; 48 return PP_OK;
56 } 49 }
57 return PP_ERROR_FAILED; 50 return PP_ERROR_FAILED;
58 } 51 }
59 52
60 void AudioHelper::StreamCreated( 53 void AudioHelper::StreamCreated(
61 base::SharedMemoryHandle shared_memory_handle, 54 base::SharedMemoryHandle shared_memory_handle,
62 size_t shared_memory_size, 55 size_t shared_memory_size,
63 base::SyncSocket::Handle socket_handle) { 56 base::SyncSocket::Handle socket_handle) {
64 if (create_callback_pending_) { 57 if (TrackedCallback::IsPending(create_callback_)) {
65 // Trusted side of proxy can specify a callback to recieve handles. In 58 // Trusted side of proxy can specify a callback to recieve handles. In
66 // this case we don't need to map any data or start the thread since it 59 // this case we don't need to map any data or start the thread since it
67 // will be handled by the proxy. 60 // will be handled by the proxy.
68 shared_memory_for_create_callback_.reset( 61 shared_memory_for_create_callback_.reset(
69 new base::SharedMemory(shared_memory_handle, false)); 62 new base::SharedMemory(shared_memory_handle, false));
70 shared_memory_size_for_create_callback_ = shared_memory_size; 63 shared_memory_size_for_create_callback_ = shared_memory_size;
71 socket_for_create_callback_.reset(new base::SyncSocket(socket_handle)); 64 socket_for_create_callback_.reset(new base::SyncSocket(socket_handle));
72 65
73 PP_RunCompletionCallback(&create_callback_, 0); 66 ::ppapi::TrackedCallback::ClearAndRun(&create_callback_, PP_OK);
74 create_callback_pending_ = false;
75 67
76 // It might be nice to close the handles here to free up some system 68 // It might be nice to close the handles here to free up some system
77 // resources, but we can't since there's a race condition. The handles must 69 // resources, but we can't since there's a race condition. The handles must
78 // be valid until they're sent over IPC, which is done from the I/O thread 70 // be valid until they're sent over IPC, which is done from the I/O thread
79 // which will often get done after this code executes. We could do 71 // which will often get done after this code executes. We could do
80 // something more elaborate like an ACK from the plugin or post a task to 72 // something more elaborate like an ACK from the plugin or post a task to
81 // the I/O thread and back, but this extra complexity doesn't seem worth it 73 // the I/O thread and back, but this extra complexity doesn't seem worth it
82 // just to clean up these handles faster. 74 // just to clean up these handles faster.
83 } else { 75 } else {
84 OnSetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); 76 OnSetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle);
85 } 77 }
86 } 78 }
87 79
88 void AudioHelper::SetCallbackInfo(bool create_callback_pending, 80 void AudioHelper::SetCreateCallback(
89 PP_CompletionCallback create_callback) { 81 scoped_refptr< ::ppapi::TrackedCallback> create_callback) {
90 create_callback_pending_ = create_callback_pending; 82 DCHECK(!TrackedCallback::IsPending(create_callback_));
91 create_callback_ = create_callback; 83 create_callback_ = create_callback;
92 } 84 }
93 85
94 } // namespace ppapi 86 } // namespace ppapi
95 } // namespace webkit 87 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/audio_helper.h ('k') | webkit/plugins/ppapi/ppb_audio_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698