Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #include "chrome/renderer/pepper_plugin_delegate_impl.h" | 7 #include "chrome/renderer/pepper_plugin_delegate_impl.h" |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/surface/transport_dib.h" | 10 #include "app/surface/transport_dib.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 | 116 |
| 117 private: | 117 private: |
| 118 WebKit::WebView* web_view_; | 118 WebKit::WebView* web_view_; |
| 119 ggl::Context* context_; | 119 ggl::Context* context_; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 #endif // ENABLE_GPU | 122 #endif // ENABLE_GPU |
| 123 | 123 |
| 124 class PlatformAudioImpl | 124 class PlatformAudioImpl |
| 125 : public pepper::PluginDelegate::PlatformAudio, | 125 : public pepper::PluginDelegate::PlatformAudio, |
| 126 public AudioMessageFilter::Delegate { | 126 public AudioMessageFilter::Delegate, |
| 127 public base::RefCountedThreadSafe<PlatformAudioImpl> { | |
| 127 public: | 128 public: |
| 128 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) | 129 explicit PlatformAudioImpl(scoped_refptr<AudioMessageFilter> filter) |
| 129 : client_(NULL), filter_(filter), stream_id_(0) { | 130 : client_(NULL), filter_(filter), stream_id_(0), |
| 131 main_message_loop_(MessageLoop::current()) { | |
| 130 DCHECK(filter_); | 132 DCHECK(filter_); |
| 131 } | 133 } |
| 132 | 134 |
| 133 virtual ~PlatformAudioImpl() { | 135 virtual ~PlatformAudioImpl() { |
| 134 // Make sure we have been shut down. | 136 // Make sure we have been shut down. |
| 135 DCHECK_EQ(0, stream_id_); | 137 DCHECK_EQ(0, stream_id_); |
| 136 DCHECK(!client_); | 138 DCHECK(!client_); |
| 137 } | 139 } |
| 138 | 140 |
| 139 // Initialize this audio context. StreamCreated() will be called when the | 141 // Initialize this audio context. StreamCreated() will be called when the |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 170 | 172 |
| 171 virtual void OnVolume(double volume) { } | 173 virtual void OnVolume(double volume) { } |
| 172 | 174 |
| 173 // The client to notify when the stream is created. | 175 // The client to notify when the stream is created. |
| 174 pepper::PluginDelegate::PlatformAudio::Client* client_; | 176 pepper::PluginDelegate::PlatformAudio::Client* client_; |
| 175 // MessageFilter used to send/receive IPC. | 177 // MessageFilter used to send/receive IPC. |
| 176 scoped_refptr<AudioMessageFilter> filter_; | 178 scoped_refptr<AudioMessageFilter> filter_; |
| 177 // Our ID on the MessageFilter. | 179 // Our ID on the MessageFilter. |
| 178 int32 stream_id_; | 180 int32 stream_id_; |
| 179 | 181 |
| 182 MessageLoop* main_message_loop_; | |
|
neb
2010/11/22 19:48:26
I'm not convinced you need to store this since thi
nfullagar
2010/11/23 02:48:58
Printing out filter_->message_loop() and main_mess
| |
| 183 | |
| 180 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); | 184 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); |
| 181 }; | 185 }; |
| 182 | 186 |
| 183 #ifdef ENABLE_GPU | 187 #ifdef ENABLE_GPU |
| 184 | 188 |
| 185 bool PlatformContext3DImpl::Init() { | 189 bool PlatformContext3DImpl::Init() { |
| 186 // Ignore initializing more than once. | 190 // Ignore initializing more than once. |
| 187 if (context_) | 191 if (context_) |
| 188 return true; | 192 return true; |
| 189 | 193 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 client_ = client; | 278 client_ = client; |
| 275 | 279 |
| 276 ViewHostMsg_Audio_CreateStream_Params params; | 280 ViewHostMsg_Audio_CreateStream_Params params; |
| 277 params.params.format = AudioParameters::AUDIO_PCM_LINEAR; | 281 params.params.format = AudioParameters::AUDIO_PCM_LINEAR; |
| 278 params.params.channels = 2; | 282 params.params.channels = 2; |
| 279 params.params.sample_rate = sample_rate; | 283 params.params.sample_rate = sample_rate; |
| 280 params.params.bits_per_sample = 16; | 284 params.params.bits_per_sample = 16; |
| 281 params.params.samples_per_packet = sample_count; | 285 params.params.samples_per_packet = sample_count; |
| 282 | 286 |
| 283 stream_id_ = filter_->AddDelegate(this); | 287 stream_id_ = filter_->AddDelegate(this); |
| 288 AddRef(); // Take a reference for the filter. | |
| 289 | |
| 284 return filter_->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, | 290 return filter_->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, |
| 285 true)); | 291 true)); |
| 286 } | 292 } |
| 287 | 293 |
| 288 void PlatformAudioImpl::OnLowLatencyCreated( | 294 void PlatformAudioImpl::OnLowLatencyCreated( |
| 289 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, | 295 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, |
| 290 uint32 length) { | 296 uint32 length) { |
| 291 #if defined(OS_WIN) | 297 #if defined(OS_WIN) |
| 292 DCHECK(handle); | 298 DCHECK(handle); |
| 293 DCHECK(socket_handle); | 299 DCHECK(socket_handle); |
| 294 #else | 300 #else |
| 295 DCHECK_NE(-1, handle.fd); | 301 DCHECK_NE(-1, handle.fd); |
| 296 DCHECK_NE(-1, socket_handle); | 302 DCHECK_NE(-1, socket_handle); |
| 297 #endif | 303 #endif |
| 298 DCHECK(length); | 304 DCHECK(length); |
| 299 | 305 |
| 300 client_->StreamCreated(handle, length, socket_handle); | 306 if (MessageLoop::current() == main_message_loop_) { |
| 307 if (client_) { | |
| 308 client_->StreamCreated(handle, length, socket_handle); | |
|
neb
2010/11/22 19:48:26
If the reference was taken to ensure that the obje
nfullagar
2010/11/23 02:48:58
What is here seems to be working, but I'd like to
| |
| 309 } | |
| 310 } else { | |
| 311 main_message_loop_->PostTask(FROM_HERE, | |
| 312 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated, | |
| 313 handle, socket_handle, length)); | |
| 314 } | |
| 301 } | 315 } |
| 302 | 316 |
| 303 void PlatformAudioImpl::ShutDown() { | 317 void PlatformAudioImpl::ShutDown() { |
| 304 // Make sure we don't call shutdown more than once. | 318 // Make sure we don't call shutdown more than once. |
| 305 if (!stream_id_) { | 319 if (!stream_id_) { |
| 306 return; | 320 return; |
| 307 } | 321 } |
| 322 | |
| 308 filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); | 323 filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); |
| 309 filter_->RemoveDelegate(stream_id_); | 324 filter_->RemoveDelegate(stream_id_); |
|
neb
2010/11/22 19:48:26
I think a way to avoid the race would be to move R
| |
| 325 | |
| 326 // Release reference taken for the filter on the IO thread so that | |
| 327 // we avoid race problems with OnLowLatencyCreated. | |
| 328 filter_->message_loop()->ReleaseSoon(FROM_HERE, this); | |
|
neb
2010/11/22 19:48:26
You are releasing twice, it seams?
nfullagar
2010/11/23 02:48:58
There's an extra AddRef() above (line 288.) If I
| |
| 329 | |
| 310 stream_id_ = 0; | 330 stream_id_ = 0; |
| 311 client_ = NULL; | 331 client_ = NULL; |
| 332 | |
| 333 Release(); // May end up deleting ourselves. | |
|
neb
2010/11/22 19:48:26
I think this Release() doesn't belong here.
| |
| 312 } | 334 } |
| 313 | 335 |
| 314 // Implements the VideoDecoder. | 336 // Implements the VideoDecoder. |
| 315 class PlatformVideoDecoderImpl | 337 class PlatformVideoDecoderImpl |
| 316 : public pepper::PluginDelegate::PlatformVideoDecoder { | 338 : public pepper::PluginDelegate::PlatformVideoDecoder { |
| 317 public: | 339 public: |
| 318 PlatformVideoDecoderImpl() | 340 PlatformVideoDecoderImpl() |
| 319 : input_buffer_size_(0), | 341 : input_buffer_size_(0), |
| 320 next_dib_id_(0), | 342 next_dib_id_(0), |
| 321 dib_(NULL) { | 343 dib_(NULL) { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 | 575 |
| 554 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, | 576 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, |
| 555 int index) { | 577 int index) { |
| 556 render_view_->reportFindInPageSelection( | 578 render_view_->reportFindInPageSelection( |
| 557 identifier, index + 1, WebKit::WebRect()); | 579 identifier, index + 1, WebKit::WebRect()); |
| 558 } | 580 } |
| 559 | 581 |
| 560 pepper::PluginDelegate::PlatformAudio* PepperPluginDelegateImpl::CreateAudio( | 582 pepper::PluginDelegate::PlatformAudio* PepperPluginDelegateImpl::CreateAudio( |
| 561 uint32_t sample_rate, uint32_t sample_count, | 583 uint32_t sample_rate, uint32_t sample_count, |
| 562 pepper::PluginDelegate::PlatformAudio::Client* client) { | 584 pepper::PluginDelegate::PlatformAudio::Client* client) { |
| 563 scoped_ptr<PlatformAudioImpl> audio( | 585 scoped_refptr<PlatformAudioImpl> audio( |
| 564 new PlatformAudioImpl(render_view_->audio_message_filter())); | 586 new PlatformAudioImpl(render_view_->audio_message_filter())); |
| 565 if (audio->Initialize(sample_rate, sample_count, client)) { | 587 if (audio->Initialize(sample_rate, sample_count, client)) { |
| 566 return audio.release(); | 588 return audio.release(); |
| 567 } else { | 589 } else { |
| 568 return NULL; | 590 return NULL; |
| 569 } | 591 } |
| 570 } | 592 } |
| 571 | 593 |
| 572 bool PepperPluginDelegateImpl::RunFileChooser( | 594 bool PepperPluginDelegateImpl::RunFileChooser( |
| 573 const WebKit::WebFileChooserParams& params, | 595 const WebKit::WebFileChooserParams& params, |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 824 } | 846 } |
| 825 | 847 |
| 826 void PepperPluginDelegateImpl::DidStopLoading() { | 848 void PepperPluginDelegateImpl::DidStopLoading() { |
| 827 render_view_->DidStopLoadingForPlugin(); | 849 render_view_->DidStopLoadingForPlugin(); |
| 828 } | 850 } |
| 829 | 851 |
| 830 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { | 852 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { |
| 831 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( | 853 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( |
| 832 render_view_->routing_id(), restrictions)); | 854 render_view_->routing_id(), restrictions)); |
| 833 } | 855 } |
| OLD | NEW |