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

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: 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/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 namespace webkit { 10 namespace webkit {
11 namespace ppapi { 11 namespace ppapi {
12 12
13 // AudioHelper ----------------------------------------------------------------- 13 // AudioHelper -----------------------------------------------------------------
14 14
15 AudioHelper::AudioHelper() 15 AudioHelper::AudioHelper() {
16 : create_callback_pending_(false),
17 shared_memory_size_for_create_callback_(0) {
18 create_callback_ = PP_MakeCompletionCallback(NULL, NULL);
19 } 16 }
20 17
21 AudioHelper::~AudioHelper() { 18 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 } 19 }
29 20
30 int32_t AudioHelper::GetSyncSocketImpl(int* sync_socket) { 21 int32_t AudioHelper::GetSyncSocketImpl(int* sync_socket) {
31 if (socket_for_create_callback_.get()) { 22 if (socket_for_create_callback_.get()) {
32 #if defined(OS_POSIX) 23 #if defined(OS_POSIX)
33 *sync_socket = socket_for_create_callback_->handle(); 24 *sync_socket = socket_for_create_callback_->handle();
34 #elif defined(OS_WIN) 25 #elif defined(OS_WIN)
35 *sync_socket = reinterpret_cast<int>(socket_for_create_callback_->handle()); 26 *sync_socket = reinterpret_cast<int>(socket_for_create_callback_->handle());
36 #else 27 #else
37 #error "Platform not supported." 28 #error "Platform not supported."
(...skipping 16 matching lines...) Expand all
54 *shm_size = shared_memory_size_for_create_callback_; 45 *shm_size = shared_memory_size_for_create_callback_;
55 return PP_OK; 46 return PP_OK;
56 } 47 }
57 return PP_ERROR_FAILED; 48 return PP_ERROR_FAILED;
58 } 49 }
59 50
60 void AudioHelper::StreamCreated( 51 void AudioHelper::StreamCreated(
61 base::SharedMemoryHandle shared_memory_handle, 52 base::SharedMemoryHandle shared_memory_handle,
62 size_t shared_memory_size, 53 size_t shared_memory_size,
63 base::SyncSocket::Handle socket_handle) { 54 base::SyncSocket::Handle socket_handle) {
64 if (create_callback_pending_) { 55 if (create_callback_.get()) {
65 // Trusted side of proxy can specify a callback to recieve handles. In 56 // 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 57 // this case we don't need to map any data or start the thread since it
67 // will be handled by the proxy. 58 // will be handled by the proxy.
68 shared_memory_for_create_callback_.reset( 59 shared_memory_for_create_callback_.reset(
69 new base::SharedMemory(shared_memory_handle, false)); 60 new base::SharedMemory(shared_memory_handle, false));
70 shared_memory_size_for_create_callback_ = shared_memory_size; 61 shared_memory_size_for_create_callback_ = shared_memory_size;
71 socket_for_create_callback_.reset(new base::SyncSocket(socket_handle)); 62 socket_for_create_callback_.reset(new base::SyncSocket(socket_handle));
72 63
73 PP_RunCompletionCallback(&create_callback_, 0); 64 ::ppapi::TrackedCallback::ClearAndRun(&create_callback_, PP_OK);
74 create_callback_pending_ = false;
75 65
76 // It might be nice to close the handles here to free up some system 66 // 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 67 // 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 68 // 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 69 // 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 70 // 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 71 // the I/O thread and back, but this extra complexity doesn't seem worth it
82 // just to clean up these handles faster. 72 // just to clean up these handles faster.
83 } else { 73 } else {
84 OnSetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); 74 OnSetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle);
85 } 75 }
86 } 76 }
87 77
88 void AudioHelper::SetCallbackInfo(bool create_callback_pending, 78 void AudioHelper::SetCreateCallback(
89 PP_CompletionCallback create_callback) { 79 scoped_refptr< ::ppapi::TrackedCallback> create_callback) {
90 create_callback_pending_ = create_callback_pending; 80 DCHECK(!create_callback_.get());
91 create_callback_ = create_callback; 81 create_callback_ = create_callback;
92 } 82 }
93 83
94 } // namespace ppapi 84 } // namespace ppapi
95 } // namespace webkit 85 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698