summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/renderer_host/media/audio_input_device_manager.cc51
-rw-r--r--content/browser/renderer_host/media/audio_input_device_manager_unittest.cc9
-rw-r--r--content/browser/renderer_host/media/audio_input_renderer_host.cc16
-rw-r--r--content/browser/renderer_host/media/audio_renderer_host.cc27
-rw-r--r--content/browser/renderer_host/media/audio_renderer_host_unittest.cc6
-rw-r--r--content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc8
-rw-r--r--content/browser/renderer_host/media/video_capture_controller.cc19
-rw-r--r--content/browser/renderer_host/media/video_capture_controller.h9
-rw-r--r--content/browser/renderer_host/media/video_capture_host.cc24
-rw-r--r--content/browser/renderer_host/media/video_capture_host_unittest.cc11
-rw-r--r--content/browser/renderer_host/media/video_capture_manager.cc63
-rw-r--r--content/browser/renderer_host/media/video_capture_manager.h7
-rw-r--r--content/browser/renderer_host/media/video_capture_manager_unittest.cc14
13 files changed, 124 insertions, 140 deletions
diff --git a/content/browser/renderer_host/media/audio_input_device_manager.cc b/content/browser/renderer_host/media/audio_input_device_manager.cc
index e1970c1..3ff3949 100644
--- a/content/browser/renderer_host/media/audio_input_device_manager.cc
+++ b/content/browser/renderer_host/media/audio_input_device_manager.cc
@@ -4,6 +4,7 @@
#include "content/browser/renderer_host/media/audio_input_device_manager.h"
+#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "content/browser/browser_thread.h"
#include "content/browser/renderer_host/media/audio_input_device_manager_event_handler.h"
@@ -70,8 +71,8 @@ void AudioInputDeviceManager::EnumerateDevices() {
audio_input_device_thread_.message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &AudioInputDeviceManager::EnumerateOnDeviceThread));
+ base::Bind(&AudioInputDeviceManager::EnumerateOnDeviceThread,
+ base::Unretained(this)));
}
int AudioInputDeviceManager::Open(const StreamDeviceInfo& device) {
@@ -82,10 +83,8 @@ int AudioInputDeviceManager::Open(const StreamDeviceInfo& device) {
audio_input_device_thread_.message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &AudioInputDeviceManager::OpenOnDeviceThread,
- audio_input_session_id,
- device));
+ base::Bind(&AudioInputDeviceManager::OpenOnDeviceThread,
+ base::Unretained(this), audio_input_session_id, device));
return audio_input_session_id;
}
@@ -96,9 +95,8 @@ void AudioInputDeviceManager::Close(int session_id) {
audio_input_device_thread_.message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &AudioInputDeviceManager::CloseOnDeviceThread,
- session_id));
+ base::Bind(&AudioInputDeviceManager::CloseOnDeviceThread,
+ base::Unretained(this), session_id));
}
void AudioInputDeviceManager::Start(
@@ -127,9 +125,8 @@ void AudioInputDeviceManager::Start(
audio_input_device_thread_.message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &AudioInputDeviceManager::StartOnDeviceThread,
- session_id));
+ base::Bind(&AudioInputDeviceManager::StartOnDeviceThread,
+ base::Unretained(this), session_id));
}
void AudioInputDeviceManager::Stop(int session_id) {
@@ -137,9 +134,8 @@ void AudioInputDeviceManager::Stop(int session_id) {
audio_input_device_thread_.message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &AudioInputDeviceManager::StopOnDeviceThread,
- session_id));
+ base::Bind(&AudioInputDeviceManager::StopOnDeviceThread,
+ base::Unretained(this), session_id));
}
void AudioInputDeviceManager::EnumerateOnDeviceThread() {
@@ -160,9 +156,8 @@ void AudioInputDeviceManager::EnumerateOnDeviceThread() {
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(this,
- &AudioInputDeviceManager::DevicesEnumeratedOnIOThread,
- devices));
+ base::Bind(&AudioInputDeviceManager::DevicesEnumeratedOnIOThread,
+ base::Unretained(this), devices));
}
void AudioInputDeviceManager::OpenOnDeviceThread(
@@ -184,9 +179,9 @@ void AudioInputDeviceManager::OpenOnDeviceThread(
devices_[session_id] = audio_input_device_name;
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(
- this,
+ base::Bind(
&AudioInputDeviceManager::OpenedOnIOThread,
+ base::Unretained(this),
session_id));
}
@@ -197,9 +192,9 @@ void AudioInputDeviceManager::CloseOnDeviceThread(int session_id) {
devices_.erase(session_id);
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(
- this,
+ base::Bind(
&AudioInputDeviceManager::ClosedOnIOThread,
+ base::Unretained(this),
session_id));
}
@@ -230,9 +225,9 @@ void AudioInputDeviceManager::StartOnDeviceThread(const int session_id) {
// Posts the index to AudioInputRenderHost through the event handler.
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(
- this,
+ base::Bind(
&AudioInputDeviceManager::StartedOnIOThread,
+ base::Unretained(this),
session_id,
device_index));
}
@@ -241,9 +236,9 @@ void AudioInputDeviceManager::StopOnDeviceThread(int session_id) {
DCHECK(IsOnCaptureDeviceThread());
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(
- this,
+ base::Bind(
&AudioInputDeviceManager::StoppedOnIOThread,
+ base::Unretained(this),
session_id));
}
@@ -300,9 +295,9 @@ void AudioInputDeviceManager::SignalError(int session_id,
MediaStreamProviderError error) {
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(
- this,
+ base::Bind(
&AudioInputDeviceManager::ErrorOnIOThread,
+ base::Unretained(this),
session_id,
error));
}
diff --git a/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc b/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc
index f7cc6ff..8892c93 100644
--- a/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc
+++ b/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc
@@ -4,6 +4,7 @@
#include <string>
+#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "content/browser/browser_thread.h"
@@ -111,7 +112,7 @@ class AudioInputDeviceManagerTest: public testing::Test {
static void PostQuitOnAudioInputDeviceManagerThread(
MessageLoop* message_loop, AudioInputDeviceManager* manager) {
manager->message_loop()->PostTask(
- FROM_HERE, NewRunnableFunction(&PostQuitMessageLoop, message_loop));
+ FROM_HERE, base::Bind(&PostQuitMessageLoop, message_loop));
}
// SyncWithAudioInputDeviceManagerThread() waits until all pending tasks on
@@ -120,9 +121,9 @@ class AudioInputDeviceManagerTest: public testing::Test {
void SyncWithAudioInputDeviceManagerThread() {
message_loop_->PostTask(
FROM_HERE,
- NewRunnableFunction(&PostQuitOnAudioInputDeviceManagerThread,
- message_loop_.get(),
- manager_.get()));
+ base::Bind(&PostQuitOnAudioInputDeviceManagerThread,
+ message_loop_.get(),
+ manager_.get()));
message_loop_->Run();
}
scoped_ptr<MessageLoop> message_loop_;
diff --git a/content/browser/renderer_host/media/audio_input_renderer_host.cc b/content/browser/renderer_host/media/audio_input_renderer_host.cc
index fd50045..f000a82 100644
--- a/content/browser/renderer_host/media/audio_input_renderer_host.cc
+++ b/content/browser/renderer_host/media/audio_input_renderer_host.cc
@@ -4,6 +4,7 @@
#include "content/browser/renderer_host/media/audio_input_renderer_host.h"
+#include "base/bind.h"
#include "base/metrics/histogram.h"
#include "base/process.h"
#include "base/shared_memory.h"
@@ -48,9 +49,9 @@ void AudioInputRendererHost::OnCreated(
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(
- this,
+ base::Bind(
&AudioInputRendererHost::DoCompleteCreation,
+ this,
make_scoped_refptr(controller)));
}
@@ -59,9 +60,9 @@ void AudioInputRendererHost::OnRecording(
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(
- this,
+ base::Bind(
&AudioInputRendererHost::DoSendRecordingMessage,
+ this,
make_scoped_refptr(controller)));
}
@@ -71,9 +72,8 @@ void AudioInputRendererHost::OnError(
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(this,
- &AudioInputRendererHost::DoHandleError,
- make_scoped_refptr(controller),
+ base::Bind(&AudioInputRendererHost::DoHandleError, this,
+ make_scoped_refptr(controller),
error_code));
}
@@ -389,7 +389,7 @@ void AudioInputRendererHost::OnStreamClosed(AudioEntry* entry) {
// Delete the entry after we've closed the stream.
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &AudioInputRendererHost::DeleteEntry, entry));
+ base::Bind(&AudioInputRendererHost::DeleteEntry, this, entry));
}
void AudioInputRendererHost::DeleteEntry(AudioEntry* entry) {
diff --git a/content/browser/renderer_host/media/audio_renderer_host.cc b/content/browser/renderer_host/media/audio_renderer_host.cc
index 4865cf5..9119b26 100644
--- a/content/browser/renderer_host/media/audio_renderer_host.cc
+++ b/content/browser/renderer_host/media/audio_renderer_host.cc
@@ -54,9 +54,9 @@ void AudioRendererHost::OnCreated(media::AudioOutputController* controller) {
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(
- this,
+ base::Bind(
&AudioRendererHost::DoCompleteCreation,
+ this,
make_scoped_refptr(controller)));
}
@@ -64,9 +64,9 @@ void AudioRendererHost::OnPlaying(media::AudioOutputController* controller) {
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(
- this,
+ base::Bind(
&AudioRendererHost::DoSendPlayingMessage,
+ this,
make_scoped_refptr(controller)));
}
@@ -74,9 +74,9 @@ void AudioRendererHost::OnPaused(media::AudioOutputController* controller) {
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(
- this,
+ base::Bind(
&AudioRendererHost::DoSendPausedMessage,
+ this,
make_scoped_refptr(controller)));
}
@@ -85,10 +85,8 @@ void AudioRendererHost::OnError(media::AudioOutputController* controller,
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(this,
- &AudioRendererHost::DoHandleError,
- make_scoped_refptr(controller),
- error_code));
+ base::Bind(&AudioRendererHost::DoHandleError,
+ this, make_scoped_refptr(controller), error_code));
}
void AudioRendererHost::OnMoreData(media::AudioOutputController* controller,
@@ -96,10 +94,9 @@ void AudioRendererHost::OnMoreData(media::AudioOutputController* controller,
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(this,
- &AudioRendererHost::DoRequestMoreData,
- make_scoped_refptr(controller),
- buffers_state));
+ base::Bind(&AudioRendererHost::DoRequestMoreData,
+ this, make_scoped_refptr(controller),
+ buffers_state));
}
void AudioRendererHost::DoCompleteCreation(
@@ -412,7 +409,7 @@ void AudioRendererHost::OnStreamClosed(AudioEntry* entry) {
// Delete the entry after we've closed the stream.
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &AudioRendererHost::DeleteEntry, entry));
+ base::Bind(&AudioRendererHost::DeleteEntry, this, entry));
}
void AudioRendererHost::DeleteEntry(AudioEntry* entry) {
diff --git a/content/browser/renderer_host/media/audio_renderer_host_unittest.cc b/content/browser/renderer_host/media/audio_renderer_host_unittest.cc
index 8a182e5..cbf28f1 100644
--- a/content/browser/renderer_host/media/audio_renderer_host_unittest.cc
+++ b/content/browser/renderer_host/media/audio_renderer_host_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind.h"
#include "base/environment.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
@@ -334,7 +335,7 @@ class AudioRendererHostTest : public testing::Test {
// Called on the main thread.
static void PostQuitOnAudioThread(MessageLoop* message_loop) {
AudioManager::GetAudioManager()->GetMessageLoop()->PostTask(
- FROM_HERE, NewRunnableFunction(&PostQuitMessageLoop, message_loop));
+ FROM_HERE, base::Bind(&PostQuitMessageLoop, message_loop));
}
// SyncWithAudioThread() waits until all pending tasks on the audio thread
@@ -343,8 +344,7 @@ class AudioRendererHostTest : public testing::Test {
// closing an audio stream.
void SyncWithAudioThread() {
message_loop_->PostTask(
- FROM_HERE, NewRunnableFunction(&PostQuitOnAudioThread,
- message_loop_.get()));
+ FROM_HERE, base::Bind(&PostQuitOnAudioThread, message_loop_.get()));
message_loop_->Run();
}
diff --git a/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc b/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc
index cb311f3..d9f7db7 100644
--- a/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc
+++ b/content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc
@@ -4,6 +4,7 @@
#include <string>
+#include "base/bind.h"
#include "base/message_loop.h"
#include "content/browser/mock_resource_context.h"
#include "content/browser/renderer_host/media/media_stream_dispatcher_host.h"
@@ -174,7 +175,7 @@ class MediaStreamDispatcherHostTest : public testing::Test {
media_stream::MediaStreamManager* media_stream_manager) {
media_stream_manager->video_capture_manager()->GetMessageLoop()->
PostTask(FROM_HERE,
- NewRunnableFunction(&PostQuitMessageLoop, message_loop));
+ base::Bind(&PostQuitMessageLoop, message_loop));
}
// SyncWithVideoCaptureManagerThread() waits until all pending tasks on the
@@ -185,9 +186,8 @@ class MediaStreamDispatcherHostTest : public testing::Test {
void SyncWithVideoCaptureManagerThread() {
message_loop_->PostTask(
FROM_HERE,
- NewRunnableFunction(&PostQuitOnVideoCaptureManagerThread,
- message_loop_.get(),
- media_stream_manager_.get()));
+ base::Bind(&PostQuitOnVideoCaptureManagerThread,
+ message_loop_.get(), media_stream_manager_.get()));
message_loop_->Run();
}
diff --git a/content/browser/renderer_host/media/video_capture_controller.cc b/content/browser/renderer_host/media/video_capture_controller.cc
index 82dbabb..f30f2d5 100644
--- a/content/browser/renderer_host/media/video_capture_controller.cc
+++ b/content/browser/renderer_host/media/video_capture_controller.cc
@@ -4,6 +4,7 @@
#include "content/browser/renderer_host/media/video_capture_controller.h"
+#include "base/bind.h"
#include "base/stl_util.h"
#include "content/browser/browser_thread.h"
#include "content/browser/renderer_host/media/media_stream_manager.h"
@@ -41,14 +42,11 @@ void VideoCaptureController::StartCapture(
video_capture_manager_->Start(params, this);
}
-void VideoCaptureController::StopCapture(Task* stopped_task) {
+void VideoCaptureController::StopCapture(base::Closure stopped_cb) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- video_capture_manager_->Stop(
- params_.session_id,
- NewRunnableMethod(this,
- &VideoCaptureController::OnDeviceStopped,
- stopped_task));
+ video_capture_manager_->Stop(params_.session_id,
+ base::Bind(&VideoCaptureController::OnDeviceStopped, this, stopped_cb));
}
void VideoCaptureController::ReturnBuffer(int buffer_id) {
@@ -194,7 +192,7 @@ void VideoCaptureController::OnFrameInfo(
// Called by VideoCaptureManager when a device have been stopped.
// This will report to the event handler that this object is ready to be deleted
// if all DIBS have been returned.
-void VideoCaptureController::OnDeviceStopped(Task* stopped_task) {
+void VideoCaptureController::OnDeviceStopped(base::Closure stopped_cb) {
bool ready_to_delete_now;
{
@@ -207,8 +205,7 @@ void VideoCaptureController::OnDeviceStopped(Task* stopped_task) {
if (ready_to_delete_now) {
event_handler_->OnReadyToDelete(id_);
}
- if (stopped_task) {
- stopped_task->Run();
- delete stopped_task;
- }
+
+ if (!stopped_cb.is_null())
+ stopped_cb.Run();
}
diff --git a/content/browser/renderer_host/media/video_capture_controller.h b/content/browser/renderer_host/media/video_capture_controller.h
index 0c760cb..1a9a4e9 100644
--- a/content/browser/renderer_host/media/video_capture_controller.h
+++ b/content/browser/renderer_host/media/video_capture_controller.h
@@ -52,9 +52,10 @@ class VideoCaptureController
// Stop video capture.
// When the capture is stopped and all TransportDIBS have been returned
// VideoCaptureControllerEventHandler::OnReadyToDelete will be called.
- // stopped_task may be null but it can be used to get a notification when the
- // device is stopped.
- void StopCapture(Task* stopped_task);
+ // |stopped_cb| may be NULL. But a non-NULL Closure can be used to get
+ // a notification when the device is stopped, regardless of
+ // VideoCaptureController's state.
+ void StopCapture(base::Closure stopped_cb);
// Return a buffer previously given in
// VideoCaptureControllerEventHandler::OnBufferReady.
@@ -69,7 +70,7 @@ class VideoCaptureController
private:
// Called by VideoCaptureManager when a device have been stopped.
- void OnDeviceStopped(Task* stopped_task);
+ void OnDeviceStopped(base::Closure stopped_cb);
// Lock to protect free_dibs_ and owned_dibs_.
base::Lock lock_;
diff --git a/content/browser/renderer_host/media/video_capture_host.cc b/content/browser/renderer_host/media/video_capture_host.cc
index 65be7a3..ef60b4b 100644
--- a/content/browser/renderer_host/media/video_capture_host.cc
+++ b/content/browser/renderer_host/media/video_capture_host.cc
@@ -4,6 +4,7 @@
#include "content/browser/renderer_host/media/video_capture_host.h"
+#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
#include "content/browser/renderer_host/media/media_stream_manager.h"
@@ -26,7 +27,7 @@ void VideoCaptureHost::OnChannelClosing() {
// Since the channel is closing we need a task to make sure VideoCaptureHost
// is not deleted before VideoCaptureController.
controller->StopCapture(
- NewRunnableMethod(this, &VideoCaptureHost::OnReadyToDelete, it->first));
+ base::Bind(&VideoCaptureHost::OnReadyToDelete, this, it->first));
}
}
@@ -40,7 +41,7 @@ void VideoCaptureHost::OnDestruct() const {
void VideoCaptureHost::OnError(const VideoCaptureControllerID& id) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &VideoCaptureHost::DoHandleError, id.device_id));
+ base::Bind(&VideoCaptureHost::DoHandleError, this, id.device_id));
}
void VideoCaptureHost::OnBufferCreated(
@@ -50,8 +51,8 @@ void VideoCaptureHost::OnBufferCreated(
int buffer_id) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &VideoCaptureHost::DoSendNewBuffer,
- id.device_id, handle, length, buffer_id));
+ base::Bind(&VideoCaptureHost::DoSendNewBuffer,
+ this, id.device_id, handle, length, buffer_id));
}
void VideoCaptureHost::OnBufferReady(
@@ -60,8 +61,8 @@ void VideoCaptureHost::OnBufferReady(
base::Time timestamp) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &VideoCaptureHost::DoSendFilledBuffer,
- id.device_id, buffer_id, timestamp));
+ base::Bind(&VideoCaptureHost::DoSendFilledBuffer,
+ this, id.device_id, buffer_id, timestamp));
}
void VideoCaptureHost::OnFrameInfo(const VideoCaptureControllerID& id,
@@ -70,15 +71,14 @@ void VideoCaptureHost::OnFrameInfo(const VideoCaptureControllerID& id,
int frame_per_second) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &VideoCaptureHost::DoSendFrameInfo,
- id.device_id, width, height, frame_per_second));
+ base::Bind(&VideoCaptureHost::DoSendFrameInfo,
+ this, id.device_id, width, height, frame_per_second));
}
void VideoCaptureHost::OnReadyToDelete(const VideoCaptureControllerID& id) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &VideoCaptureHost::DoDeleteVideoCaptureController,
- id));
+ base::Bind(&VideoCaptureHost::DoDeleteVideoCaptureController, this, id));
}
void VideoCaptureHost::DoSendNewBuffer(
@@ -108,7 +108,7 @@ void VideoCaptureHost::DoHandleError(int device_id) {
EntryMap::iterator it = entries_.find(id);
if (it != entries_.end()) {
VideoCaptureController* controller = it->second;
- controller->StopCapture(NULL);
+ controller->StopCapture(base::Closure());
}
}
@@ -166,7 +166,7 @@ void VideoCaptureHost::OnStopCapture(int device_id) {
EntryMap::iterator it = entries_.find(controller_id);
if (it != entries_.end()) {
scoped_refptr<VideoCaptureController> controller = it->second;
- controller->StopCapture(NULL);
+ controller->StopCapture(base::Closure());
} else {
// It does not exist so it must have been stopped already.
Send(new VideoCaptureMsg_StateChanged(device_id,
diff --git a/content/browser/renderer_host/media/video_capture_host_unittest.cc b/content/browser/renderer_host/media/video_capture_host_unittest.cc
index a526b04..cd8ac06 100644
--- a/content/browser/renderer_host/media/video_capture_host_unittest.cc
+++ b/content/browser/renderer_host/media/video_capture_host_unittest.cc
@@ -5,6 +5,7 @@
#include <map>
#include <string>
+#include "base/bind.h"
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
@@ -248,8 +249,8 @@ class VideoCaptureHostTest : public testing::Test {
MessageLoop* message_loop, content::ResourceContext* resource_context) {
resource_context->media_stream_manager()->video_capture_manager()->
GetMessageLoop()->PostTask(FROM_HERE,
- NewRunnableFunction(
- &PostQuitMessageLoop, message_loop));
+ base::Bind(&PostQuitMessageLoop,
+ message_loop));
}
// SyncWithVideoCaptureManagerThread() waits until all pending tasks on the
@@ -260,9 +261,9 @@ class VideoCaptureHostTest : public testing::Test {
void SyncWithVideoCaptureManagerThread() {
message_loop_->PostTask(
FROM_HERE,
- NewRunnableFunction(&PostQuitOnVideoCaptureManagerThread,
- message_loop_.get(),
- content::MockResourceContext::GetInstance()));
+ base::Bind(&PostQuitOnVideoCaptureManagerThread,
+ message_loop_.get(),
+ content::MockResourceContext::GetInstance()));
message_loop_->Run();
}
diff --git a/content/browser/renderer_host/media/video_capture_manager.cc b/content/browser/renderer_host/media/video_capture_manager.cc
index 14d561a..2143c91 100644
--- a/content/browser/renderer_host/media/video_capture_manager.cc
+++ b/content/browser/renderer_host/media/video_capture_manager.cc
@@ -4,6 +4,7 @@
#include "content/browser/renderer_host/media/video_capture_manager.h"
+#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "content/browser/browser_thread.h"
#include "media/video/capture/fake_video_capture_device.h"
@@ -57,8 +58,8 @@ void VideoCaptureManager::EnumerateDevices() {
vc_device_thread_.message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &VideoCaptureManager::OnEnumerateDevices));
+ base::Bind(&VideoCaptureManager::OnEnumerateDevices,
+ base::Unretained(this)));
}
int VideoCaptureManager::Open(const StreamDeviceInfo& device) {
@@ -70,10 +71,8 @@ int VideoCaptureManager::Open(const StreamDeviceInfo& device) {
vc_device_thread_.message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &VideoCaptureManager::OnOpen,
- video_capture_session_id,
- device));
+ base::Bind(&VideoCaptureManager::OnOpen, base::Unretained(this),
+ video_capture_session_id, device));
return video_capture_session_id;
}
@@ -84,9 +83,8 @@ void VideoCaptureManager::Close(int capture_session_id) {
vc_device_thread_.message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &VideoCaptureManager::OnClose,
- capture_session_id));
+ base::Bind(&VideoCaptureManager::OnClose, base::Unretained(this),
+ capture_session_id));
}
void VideoCaptureManager::Start(
@@ -96,23 +94,19 @@ void VideoCaptureManager::Start(
vc_device_thread_.message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &VideoCaptureManager::OnStart,
- capture_params,
- video_capture_receiver));
+ base::Bind(&VideoCaptureManager::OnStart, base::Unretained(this),
+ capture_params, video_capture_receiver));
}
void VideoCaptureManager::Stop(
const media::VideoCaptureSessionId& capture_session_id,
- Task* stopped_task) {
+ base::Closure stopped_cb) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
vc_device_thread_.message_loop()->PostTask(
FROM_HERE,
- NewRunnableMethod(this,
- &VideoCaptureManager::OnStop,
- capture_session_id,
- stopped_task));
+ base::Bind(&VideoCaptureManager::OnStop, base::Unretained(this),
+ capture_session_id, stopped_cb));
}
void VideoCaptureManager::Error(
@@ -236,7 +230,7 @@ void VideoCaptureManager::OnStart(
void VideoCaptureManager::OnStop(
const media::VideoCaptureSessionId capture_session_id,
- Task* stopped_task) {
+ base::Closure stopped_cb) {
DCHECK(IsOnCaptureDeviceThread());
VideoCaptureDevices::iterator it = devices_.find(capture_session_id);
@@ -248,10 +242,8 @@ void VideoCaptureManager::OnStop(
video_capture_device->DeAllocate();
}
- if (stopped_task) {
- stopped_task->Run();
- delete stopped_task;
- }
+ if (!stopped_cb.is_null())
+ stopped_cb.Run();
if (capture_session_id == kStartOpenSessionId) {
// This device was opened from Start(), not Open(). Close it!
@@ -301,18 +293,18 @@ void VideoCaptureManager::PostOnOpened(int capture_session_id) {
DCHECK(IsOnCaptureDeviceThread());
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(this,
- &VideoCaptureManager::OnOpened,
- capture_session_id));
+ base::Bind(&VideoCaptureManager::OnOpened,
+ base::Unretained(this),
+ capture_session_id));
}
void VideoCaptureManager::PostOnClosed(int capture_session_id) {
DCHECK(IsOnCaptureDeviceThread());
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(this,
- &VideoCaptureManager::OnClosed,
- capture_session_id));
+ base::Bind(&VideoCaptureManager::OnClosed,
+ base::Unretained(this),
+ capture_session_id));
}
void VideoCaptureManager::PostOnDevicesEnumerated(
@@ -320,10 +312,8 @@ void VideoCaptureManager::PostOnDevicesEnumerated(
DCHECK(IsOnCaptureDeviceThread());
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(
- this,
- &VideoCaptureManager::OnDevicesEnumerated,
- devices));
+ base::Bind(&VideoCaptureManager::OnDevicesEnumerated,
+ base::Unretained(this), devices));
}
void VideoCaptureManager::PostOnError(int capture_session_id,
@@ -332,10 +322,9 @@ void VideoCaptureManager::PostOnError(int capture_session_id,
// thread.
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
- NewRunnableMethod(this,
- &VideoCaptureManager::OnError,
- capture_session_id,
- error));
+ base::Bind(&VideoCaptureManager::OnError,
+ base::Unretained(this), capture_session_id,
+ error));
}
bool VideoCaptureManager::IsOnCaptureDeviceThread() const {
diff --git a/content/browser/renderer_host/media/video_capture_manager.h b/content/browser/renderer_host/media/video_capture_manager.h
index f5040d4..c7b3e31 100644
--- a/content/browser/renderer_host/media/video_capture_manager.h
+++ b/content/browser/renderer_host/media/video_capture_manager.h
@@ -51,9 +51,10 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
media::VideoCaptureDevice::EventHandler* video_capture_receiver);
// Stops capture device referenced by |capture_session_id|. No more frames
- // will be delivered to the frame receiver, and |stopped_task| will be called.
+ // will be delivered to the frame receiver, and |stopped_cb| will be called.
+ // |stopped_cb| can be NULL.
void Stop(const media::VideoCaptureSessionId& capture_session_id,
- Task* stopped_task);
+ base::Closure stopped_cb);
// A capture device error has occurred for |capture_session_id|. The device
// won't stream any more captured frames.
@@ -73,7 +74,7 @@ class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
void OnStart(const media::VideoCaptureParams capture_params,
media::VideoCaptureDevice::EventHandler* video_capture_receiver);
void OnStop(const media::VideoCaptureSessionId capture_session_id,
- Task* stopped_task);
+ base::Closure stopped_cb);
// Executed on Browser::IO thread to call Listener.
void OnOpened(int capture_session_id);
diff --git a/content/browser/renderer_host/media/video_capture_manager_unittest.cc b/content/browser/renderer_host/media/video_capture_manager_unittest.cc
index a93f183..e6ae7b2 100644
--- a/content/browser/renderer_host/media/video_capture_manager_unittest.cc
+++ b/content/browser/renderer_host/media/video_capture_manager_unittest.cc
@@ -6,6 +6,7 @@
#include <string>
+#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/process_util.h"
@@ -101,7 +102,7 @@ class VideoCaptureManagerTest : public testing::Test {
static void PostQuitOnVideoCaptureManagerThread(
MessageLoop* message_loop, media_stream::VideoCaptureManager* vcm) {
vcm->GetMessageLoop()->PostTask(
- FROM_HERE, NewRunnableFunction(&PostQuitMessageLoop, message_loop));
+ FROM_HERE, base::Bind(&PostQuitMessageLoop, message_loop));
}
// SyncWithVideoCaptureManagerThread() waits until all pending tasks on the
@@ -111,9 +112,9 @@ class VideoCaptureManagerTest : public testing::Test {
// video capture device.
void SyncWithVideoCaptureManagerThread() {
message_loop_->PostTask(
- FROM_HERE, NewRunnableFunction(&PostQuitOnVideoCaptureManagerThread,
- message_loop_.get(),
- vcm_.get()));
+ FROM_HERE, base::Bind(&PostQuitOnVideoCaptureManagerThread,
+ message_loop_.get(),
+ vcm_.get()));
message_loop_->Run();
}
scoped_ptr<media_stream::VideoCaptureManager> vcm_;
@@ -152,7 +153,7 @@ TEST_F(VideoCaptureManagerTest, CreateAndClose) {
capture_params.frame_per_second = 30;
vcm_->Start(capture_params, frame_observer_.get());
- vcm_->Stop(video_session_id, NULL);
+ vcm_->Stop(video_session_id, base::Closure());
vcm_->Close(video_session_id);
// Wait to check callbacks before removing the listener
@@ -266,7 +267,8 @@ TEST_F(VideoCaptureManagerTest, StartUsingId) {
vcm_->Start(capture_params, frame_observer_.get());
// Stop shall trigger the Close callback
- vcm_->Stop(media_stream::VideoCaptureManager::kStartOpenSessionId, NULL);
+ vcm_->Stop(media_stream::VideoCaptureManager::kStartOpenSessionId,
+ base::Closure());
// Wait to check callbacks before removing the listener
SyncWithVideoCaptureManagerThread();