From adabb62712f972e63fb19afc727093b2008d82ad Mon Sep 17 00:00:00 2001 From: "fischman@chromium.org" Date: Thu, 29 Sep 2011 22:36:38 +0000 Subject: Convert all of media/ over to the new base::{Bind,Callback} hotness. Mostly this was a rote conversion, replacing: - Pass-by-pointer CallbackN<>'s become pass-by-const-ref Callback<>'s. - scoped_ptr> members become Callback<> members. - several dedicated FooCallback typedefs became base::Closure. Because it was only used in a small handful of places and only in one place profitably, I deleted AutoCallbackRunner. Because it tickles a Bind bug I disabled mfdecoder in .gyp (about to get deleted in a scherkus CL). BUG=none TEST=media_tests, trybots Review URL: http://codereview.chromium.org/8071007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103376 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/glue/media/buffered_data_source.cc | 78 ++++++++++------------ webkit/glue/media/buffered_data_source.h | 8 +-- webkit/glue/media/buffered_data_source_unittest.cc | 55 ++++++++------- webkit/glue/media/buffered_resource_loader.cc | 14 ++-- webkit/glue/media/buffered_resource_loader.h | 6 +- .../media/buffered_resource_loader_unittest.cc | 4 +- webkit/glue/media/simple_data_source.cc | 25 +++---- webkit/glue/media/simple_data_source.h | 6 +- webkit/glue/media/simple_data_source_unittest.cc | 3 +- webkit/glue/media/video_renderer_impl.cc | 8 +-- webkit/glue/media/video_renderer_impl.h | 2 +- webkit/glue/media/web_data_source.h | 4 +- webkit/glue/media/web_data_source_factory.cc | 18 ++--- webkit/glue/media/web_data_source_factory.h | 6 +- 14 files changed, 116 insertions(+), 121 deletions(-) (limited to 'webkit/glue/media') diff --git a/webkit/glue/media/buffered_data_source.cc b/webkit/glue/media/buffered_data_source.cc index 29df58f..4f90442 100644 --- a/webkit/glue/media/buffered_data_source.cc +++ b/webkit/glue/media/buffered_data_source.cc @@ -4,6 +4,7 @@ #include "webkit/glue/media/buffered_data_source.h" +#include "base/bind.h" #include "media/base/filter_host.h" #include "media/base/media_log.h" #include "net/base/net_errors.h" @@ -34,7 +35,7 @@ media::DataSourceFactory* BufferedDataSource::CreateFactory( MessageLoop* render_loop, WebKit::WebFrame* frame, media::MediaLog* media_log, - WebDataSourceBuildObserverHack* build_observer) { + const WebDataSourceBuildObserverHack& build_observer) { return new WebDataSourceFactory(render_loop, frame, media_log, &NewBufferedDataSource, build_observer); } @@ -50,7 +51,6 @@ BufferedDataSource::BufferedDataSource( frame_(frame), loader_(NULL), network_activity_(false), - read_callback_(NULL), read_position_(0), read_size_(0), read_buffer_(NULL), @@ -113,7 +113,7 @@ void BufferedDataSource::Initialize(const std::string& url, // Post a task to complete the initialization task. render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &BufferedDataSource::InitializeTask)); + base::Bind(&BufferedDataSource::InitializeTask, this)); } void BufferedDataSource::CancelInitialize() { @@ -123,66 +123,61 @@ void BufferedDataSource::CancelInitialize() { initialize_cb_.Reset(); render_loop_->PostTask( - FROM_HERE, NewRunnableMethod(this, &BufferedDataSource::CleanupTask)); + FROM_HERE, base::Bind(&BufferedDataSource::CleanupTask, this)); } ///////////////////////////////////////////////////////////////////////////// // media::Filter implementation. -void BufferedDataSource::Stop(media::FilterCallback* callback) { +void BufferedDataSource::Stop(const base::Closure& callback) { { base::AutoLock auto_lock(lock_); stop_signal_received_ = true; } - if (callback) { - callback->Run(); - delete callback; - } + if (!callback.is_null()) + callback.Run(); render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &BufferedDataSource::CleanupTask)); + base::Bind(&BufferedDataSource::CleanupTask, this)); } void BufferedDataSource::SetPlaybackRate(float playback_rate) { - render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &BufferedDataSource::SetPlaybackRateTask, - playback_rate)); + render_loop_->PostTask(FROM_HERE, base::Bind( + &BufferedDataSource::SetPlaybackRateTask, this, playback_rate)); } void BufferedDataSource::SetPreload(media::Preload preload) { - render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &BufferedDataSource::SetPreloadTask, - preload)); + render_loop_->PostTask(FROM_HERE, base::Bind( + &BufferedDataSource::SetPreloadTask, this, preload)); } void BufferedDataSource::SetBitrate(int bitrate) { - render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &BufferedDataSource::SetBitrateTask, bitrate)); + render_loop_->PostTask(FROM_HERE, base::Bind( + &BufferedDataSource::SetBitrateTask, this, bitrate)); } ///////////////////////////////////////////////////////////////////////////// // media::DataSource implementation. -void BufferedDataSource::Read(int64 position, size_t size, uint8* data, - media::DataSource::ReadCallback* read_callback) { +void BufferedDataSource::Read( + int64 position, size_t size, uint8* data, + const media::DataSource::ReadCallback& read_callback) { VLOG(1) << "Read: " << position << " offset, " << size << " bytes"; - DCHECK(read_callback); + DCHECK(!read_callback.is_null()); { base::AutoLock auto_lock(lock_); - DCHECK(!read_callback_.get()); + DCHECK(read_callback_.is_null()); if (stop_signal_received_ || stopped_on_render_loop_) { - read_callback->RunWithParams( - Tuple1(static_cast(media::DataSource::kReadError))); - delete read_callback; + read_callback.Run(kReadError); return; } - read_callback_.reset(read_callback); + read_callback_ = read_callback; } - render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &BufferedDataSource::ReadTask, - position, static_cast(size), data)); + render_loop_->PostTask(FROM_HERE, base::Bind( + &BufferedDataSource::ReadTask, this, + position, static_cast(size), data)); } bool BufferedDataSource::GetSize(int64* size_out) { @@ -230,7 +225,7 @@ void BufferedDataSource::InitializeTask() { loader_ = CreateResourceLoader(0, kPositionNotSpecified); loader_->Start( NewCallback(this, &BufferedDataSource::HttpInitialStartCallback), - NewCallback(this, &BufferedDataSource::NetworkEventCallback), + base::Bind(&BufferedDataSource::NetworkEventCallback, this), frame_); } else { // For all other protocols, assume they support range request. We fetch @@ -240,7 +235,7 @@ void BufferedDataSource::InitializeTask() { kPositionNotSpecified); loader_->Start( NewCallback(this, &BufferedDataSource::NonHttpInitialStartCallback), - NewCallback(this, &BufferedDataSource::NetworkEventCallback), + base::Bind(&BufferedDataSource::NetworkEventCallback, this), frame_); } } @@ -255,7 +250,7 @@ void BufferedDataSource::ReadTask( if (stopped_on_render_loop_) return; - DCHECK(read_callback_.get()); + DCHECK(!read_callback_.is_null()); } // Saves the read parameters. @@ -282,7 +277,7 @@ void BufferedDataSource::CleanupTask() { // before registering a new |read_callback_| (which is cleared below). stopped_on_render_loop_ = true; - if (read_callback_.get()) + if (!read_callback_.is_null()) DoneRead_Locked(net::ERR_FAILED); } @@ -304,7 +299,7 @@ void BufferedDataSource::RestartLoadingTask() { { // If there's no outstanding read then return early. base::AutoLock auto_lock(lock_); - if (!read_callback_.get()) + if (read_callback_.is_null()) return; } @@ -313,7 +308,7 @@ void BufferedDataSource::RestartLoadingTask() { loader_->UpdateDeferStrategy(strategy); loader_->Start( NewCallback(this, &BufferedDataSource::PartialReadStartCallback), - NewCallback(this, &BufferedDataSource::NetworkEventCallback), + base::Bind(&BufferedDataSource::NetworkEventCallback, this), frame_); } @@ -389,17 +384,16 @@ void BufferedDataSource::DoneRead_Locked(int error) { VLOG(1) << "DoneRead: " << error << " bytes"; DCHECK(MessageLoop::current() == render_loop_); - DCHECK(read_callback_.get()); + DCHECK(!read_callback_.is_null()); lock_.AssertAcquired(); if (error >= 0) { - read_callback_->RunWithParams(Tuple1(error)); + read_callback_.Run(static_cast(error)); } else { - read_callback_->RunWithParams( - Tuple1(static_cast(media::DataSource::kReadError))); + read_callback_.Run(kReadError); } - read_callback_.reset(); + read_callback_.Reset(); read_position_ = 0; read_size_ = 0; read_buffer_ = 0; @@ -455,7 +449,7 @@ void BufferedDataSource::HttpInitialStartCallback(int error) { kPositionNotSpecified); loader_->Start( NewCallback(this, &BufferedDataSource::HttpInitialStartCallback), - NewCallback(this, &BufferedDataSource::NetworkEventCallback), + base::Bind(&BufferedDataSource::NetworkEventCallback, this), frame_); return; } @@ -583,7 +577,7 @@ void BufferedDataSource::ReadCallback(int error) { if (error == net::ERR_CACHE_MISS && cache_miss_retries_left_ > 0) { cache_miss_retries_left_--; render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &BufferedDataSource::RestartLoadingTask)); + base::Bind(&BufferedDataSource::RestartLoadingTask, this)); return; } } diff --git a/webkit/glue/media/buffered_data_source.h b/webkit/glue/media/buffered_data_source.h index fd20e64..48cde3a 100644 --- a/webkit/glue/media/buffered_data_source.h +++ b/webkit/glue/media/buffered_data_source.h @@ -29,7 +29,7 @@ class BufferedDataSource : public WebDataSource { MessageLoop* render_loop, WebKit::WebFrame* frame, media::MediaLog* media_log, - WebDataSourceBuildObserverHack* build_observer); + const WebDataSourceBuildObserverHack& build_observer); BufferedDataSource(MessageLoop* render_loop, WebKit::WebFrame* frame, @@ -39,14 +39,14 @@ class BufferedDataSource : public WebDataSource { // media::Filter implementation. virtual void set_host(media::FilterHost* host); - virtual void Stop(media::FilterCallback* callback); + virtual void Stop(const base::Closure& callback); virtual void SetPlaybackRate(float playback_rate); // media::DataSource implementation. // Called from demuxer thread. virtual void Read(int64 position, size_t size, uint8* data, - media::DataSource::ReadCallback* read_callback); + const media::DataSource::ReadCallback& read_callback); virtual bool GetSize(int64* size_out); virtual bool IsStreaming(); virtual void SetPreload(media::Preload preload); @@ -163,7 +163,7 @@ class BufferedDataSource : public WebDataSource { media::PipelineStatusCB initialize_cb_; // Read parameters received from the Read() method call. - scoped_ptr read_callback_; + media::DataSource::ReadCallback read_callback_; int64 read_position_; int read_size_; uint8* read_buffer_; diff --git a/webkit/glue/media/buffered_data_source_unittest.cc b/webkit/glue/media/buffered_data_source_unittest.cc index fb0529b..cd6d005 100644 --- a/webkit/glue/media/buffered_data_source_unittest.cc +++ b/webkit/glue/media/buffered_data_source_unittest.cc @@ -4,6 +4,7 @@ #include +#include "base/bind.h" #include "base/test/test_timeouts.h" #include "media/base/media_log.h" #include "media/base/mock_callback.h" @@ -74,7 +75,7 @@ class MockBufferedResourceLoader : public BufferedResourceLoader { } MOCK_METHOD3(Start, void(net::CompletionCallback* read_callback, - NetworkEventCallback* network_callback, + const base::Closure& network_callback, WebFrame* frame)); MOCK_METHOD0(Stop, void()); MOCK_METHOD4(Read, void(int64 position, int read_size, uint8* buffer, @@ -113,7 +114,7 @@ class BufferedDataSourceTest : public testing::Test { EXPECT_CALL(*data_source_, CreateResourceLoader(_, _)) .WillOnce(Return(loader_.get())); - EXPECT_CALL(*loader_, Start(NotNull(), NotNull(), NotNull())) + EXPECT_CALL(*loader_, Start(NotNull(), _, NotNull())) .WillOnce( DoAll(Assign(&error_, start_error), Invoke(this, @@ -225,12 +226,11 @@ class BufferedDataSourceTest : public testing::Test { void InvokeStartCallback( net::CompletionCallback* callback, - BufferedResourceLoader::NetworkEventCallback* network_callback, + const base::Closure& network_callback, WebFrame* frame) { callback->RunWithParams(Tuple1(error_)); delete callback; - // TODO(hclam): Save this callback. - delete network_callback; + // TODO(hclam): Save network_callback. } void InvokeReadCallback(int64 position, int size, uint8* buffer, @@ -256,7 +256,8 @@ class BufferedDataSourceTest : public testing::Test { data_source_->Read( position, size, buffer_, - NewCallback(this, &BufferedDataSourceTest::ReadCallback)); + base::Bind(&BufferedDataSourceTest::ReadCallback, + base::Unretained(this))); message_loop_->RunAllPending(); // Make sure data is correct. @@ -271,7 +272,8 @@ class BufferedDataSourceTest : public testing::Test { EXPECT_CALL(*loader_, Read(position, size, NotNull(), NotNull())); data_source_->Read( position, size, buffer_, - NewCallback(this, &BufferedDataSourceTest::ReadCallback)); + base::Bind(&BufferedDataSourceTest::ReadCallback, + base::Unretained(this))); message_loop_->RunAllPending(); // Now expect the read to return after aborting the data source. @@ -305,7 +307,7 @@ class BufferedDataSourceTest : public testing::Test { .WillOnce(Return(new_loader)); // 3. Then the new loader will be started. - EXPECT_CALL(*new_loader, Start(NotNull(), NotNull(), NotNull())) + EXPECT_CALL(*new_loader, Start(NotNull(), _, NotNull())) .WillOnce(DoAll(Assign(&error_, start_error), Invoke(this, &BufferedDataSourceTest::InvokeStartCallback))); @@ -329,7 +331,8 @@ class BufferedDataSourceTest : public testing::Test { data_source_->Read( position, size, buffer_, - NewCallback(this, &BufferedDataSourceTest::ReadCallback)); + base::Bind(&BufferedDataSourceTest::ReadCallback, + base::Unretained(this))); message_loop_->RunAllPending(); // Make sure data is correct. @@ -356,7 +359,8 @@ class BufferedDataSourceTest : public testing::Test { data_source_->Read( position, size, buffer_, - NewCallback(this, &BufferedDataSourceTest::ReadCallback)); + base::Bind(&BufferedDataSourceTest::ReadCallback, + base::Unretained(this))); message_loop_->RunAllPending(); } @@ -366,7 +370,7 @@ class BufferedDataSourceTest : public testing::Test { NiceMock* new_loader = new NiceMock(); - EXPECT_CALL(*new_loader, Start(NotNull(), NotNull(), NotNull())) + EXPECT_CALL(*new_loader, Start(NotNull(), _, NotNull())) .WillOnce(DoAll(Assign(&error_, net::OK), Invoke(this, &BufferedDataSourceTest::InvokeStartCallback))); @@ -406,7 +410,8 @@ class BufferedDataSourceTest : public testing::Test { data_source_->Read( position, size, buffer_, - NewCallback(this, &BufferedDataSourceTest::ReadCallback)); + base::Bind(&BufferedDataSourceTest::ReadCallback, + base::Unretained(this))); message_loop_->RunAllPending(); @@ -509,6 +514,11 @@ TEST_F(BufferedDataSourceTest, ReadFailed) { StopDataSource(); } +// Helper that sets |*value| to true. Useful for binding into a Closure. +static void SetTrue(bool* value) { + *value = true; +} + // This test makes sure that Stop() does not require a task to run on // |message_loop_| before it calls its callback. This prevents accidental // introduction of a pipeline teardown deadlock. The pipeline owner blocks @@ -518,16 +528,11 @@ TEST_F(BufferedDataSourceTest, ReadFailed) { TEST_F(BufferedDataSourceTest, StopDoesNotUseMessageLoopForCallback) { InitializeDataSource(kFileUrl, net::OK, true, 1024, LOADED); - // Create a callback that lets us verify that it was called before - // Stop() returns. This is to make sure that the callback does not - // require |message_loop_| to execute tasks before being called. - media::MockCallback* stop_callback = media::NewExpectedCallback(); + // Stop() the data source, using a callback that lets us verify that it was + // called before Stop() returns. This is to make sure that the callback does + // not require |message_loop_| to execute tasks before being called. bool stop_done_called = false; - ON_CALL(*stop_callback, RunWithParams(_)) - .WillByDefault(Assign(&stop_done_called, true)); - - // Stop() the data source like normal. - data_source_->Stop(stop_callback); + data_source_->Stop(base::Bind(&SetTrue, &stop_done_called)); // Verify that the callback was called inside the Stop() call. EXPECT_TRUE(stop_done_called); @@ -550,8 +555,8 @@ TEST_F(BufferedDataSourceTest, AbortDuringPendingRead) { // message loop to run. data_source_->Read( 0, 10, buffer_, - NewCallback(static_cast(this), - &BufferedDataSourceTest::ReadCallback)); + base::Bind(&BufferedDataSourceTest::ReadCallback, + base::Unretained(static_cast(this)))); // Call Abort() with the read pending. EXPECT_CALL(*this, ReadCallback(-1)); @@ -562,8 +567,8 @@ TEST_F(BufferedDataSourceTest, AbortDuringPendingRead) { EXPECT_CALL(*this, ReadCallback(-1)); data_source_->Read( 0, 10, buffer_, - NewCallback(static_cast(this), - &BufferedDataSourceTest::ReadCallback)); + base::Bind(&BufferedDataSourceTest::ReadCallback, + base::Unretained(static_cast(this)))); // Stop() the data source like normal. data_source_->Stop(media::NewExpectedCallback()); diff --git a/webkit/glue/media/buffered_resource_loader.cc b/webkit/glue/media/buffered_resource_loader.cc index b5a660d..44ebc75 100644 --- a/webkit/glue/media/buffered_resource_loader.cc +++ b/webkit/glue/media/buffered_resource_loader.cc @@ -90,17 +90,17 @@ BufferedResourceLoader::~BufferedResourceLoader() { } void BufferedResourceLoader::Start(net::CompletionCallback* start_callback, - NetworkEventCallback* event_callback, + const base::Closure& event_callback, WebFrame* frame) { // Make sure we have not started. DCHECK(!start_callback_.get()); - DCHECK(!event_callback_.get()); + DCHECK(event_callback_.is_null()); DCHECK(start_callback); - DCHECK(event_callback); + DCHECK(!event_callback.is_null()); CHECK(frame); start_callback_.reset(start_callback); - event_callback_.reset(event_callback); + event_callback_ = event_callback; if (first_byte_position_ != kPositionNotSpecified) { // TODO(hclam): server may not support range request so |offset_| may not @@ -146,7 +146,7 @@ void BufferedResourceLoader::Start(net::CompletionCallback* start_callback, void BufferedResourceLoader::Stop() { // Reset callbacks. start_callback_.reset(); - event_callback_.reset(); + event_callback_.Reset(); read_callback_.reset(); // Use the internal buffer to signal that we have been stopped. @@ -759,8 +759,8 @@ void BufferedResourceLoader::DoneStart(int error) { } void BufferedResourceLoader::NotifyNetworkEvent() { - if (event_callback_.get()) - event_callback_->Run(); + if (!event_callback_.is_null()) + event_callback_.Run(); } bool BufferedResourceLoader::IsRangeRequest() const { diff --git a/webkit/glue/media/buffered_resource_loader.h b/webkit/glue/media/buffered_resource_loader.h index 8aac3da..0d1a4dd 100644 --- a/webkit/glue/media/buffered_resource_loader.h +++ b/webkit/glue/media/buffered_resource_loader.h @@ -49,8 +49,6 @@ class BufferedResourceLoader kThresholdDefer, }; - typedef Callback0::Type NetworkEventCallback; - // |url| - URL for the resource to be loaded. // |first_byte_position| - First byte to start loading from, // |kPositionNotSpecified| for not specified. @@ -76,7 +74,7 @@ class BufferedResourceLoader // |event_callback| is called when the response is completed, data is // received, the request is suspended or resumed. virtual void Start(net::CompletionCallback* callback, - NetworkEventCallback* event_callback, + const base::Closure& event_callback, WebKit::WebFrame* frame); // Stop this loader, cancels and request and release internal buffer. @@ -260,7 +258,7 @@ class BufferedResourceLoader bool single_origin_; // Callback method that listens to network events. - scoped_ptr event_callback_; + base::Closure event_callback_; // Members used during request start. scoped_ptr start_callback_; diff --git a/webkit/glue/media/buffered_resource_loader_unittest.cc b/webkit/glue/media/buffered_resource_loader_unittest.cc index 44c84ec..39a62a9 100644 --- a/webkit/glue/media/buffered_resource_loader_unittest.cc +++ b/webkit/glue/media/buffered_resource_loader_unittest.cc @@ -5,6 +5,7 @@ #include #include +#include "base/bind.h" #include "base/format_macros.h" #include "base/stringprintf.h" #include "media/base/media_log.h" @@ -116,7 +117,8 @@ class BufferedResourceLoaderTest : public testing::Test { loader_.get())); loader_->Start( NewCallback(this, &BufferedResourceLoaderTest::StartCallback), - NewCallback(this, &BufferedResourceLoaderTest::NetworkCallback), + base::Bind(&BufferedResourceLoaderTest::NetworkCallback, + base::Unretained(this)), view_->mainFrame()); } diff --git a/webkit/glue/media/simple_data_source.cc b/webkit/glue/media/simple_data_source.cc index 33ba7ee..09736a5 100644 --- a/webkit/glue/media/simple_data_source.cc +++ b/webkit/glue/media/simple_data_source.cc @@ -4,6 +4,7 @@ #include "webkit/glue/media/simple_data_source.h" +#include "base/bind.h" #include "base/message_loop.h" #include "base/process_util.h" #include "media/base/filter_host.h" @@ -37,7 +38,7 @@ media::DataSourceFactory* SimpleDataSource::CreateFactory( MessageLoop* render_loop, WebKit::WebFrame* frame, media::MediaLog* media_log, - WebDataSourceBuildObserverHack* build_observer) { + const WebDataSourceBuildObserverHack& build_observer) { return new WebDataSourceFactory(render_loop, frame, media_log, &NewSimpleDataSource, build_observer); } @@ -68,17 +69,15 @@ void SimpleDataSource::set_host(media::FilterHost* host) { } } -void SimpleDataSource::Stop(media::FilterCallback* callback) { +void SimpleDataSource::Stop(const base::Closure& callback) { base::AutoLock auto_lock(lock_); state_ = STOPPED; - if (callback) { - callback->Run(); - delete callback; - } + if (!callback.is_null()) + callback.Run(); // Post a task to the render thread to cancel loading the resource. render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &SimpleDataSource::CancelTask)); + base::Bind(&SimpleDataSource::CancelTask, this)); } void SimpleDataSource::Initialize( @@ -104,7 +103,7 @@ void SimpleDataSource::Initialize( // Post a task to the render thread to start loading the resource. render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &SimpleDataSource::StartTask)); + base::Bind(&SimpleDataSource::StartTask, this)); } } @@ -116,22 +115,20 @@ void SimpleDataSource::CancelInitialize() { // Post a task to the render thread to cancel loading the resource. render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &SimpleDataSource::CancelTask)); + base::Bind(&SimpleDataSource::CancelTask, this)); } void SimpleDataSource::Read(int64 position, size_t size, uint8* data, - ReadCallback* read_callback) { + const DataSource::ReadCallback& read_callback) { DCHECK_GE(size_, 0); if (position >= size_) { - read_callback->RunWithParams(Tuple1(0)); - delete read_callback; + read_callback.Run(0); } else { size_t copied = std::min(size, static_cast(size_ - position)); memcpy(data, data_.c_str() + position, copied); - read_callback->RunWithParams(Tuple1(copied)); - delete read_callback; + read_callback.Run(copied); } } diff --git a/webkit/glue/media/simple_data_source.h b/webkit/glue/media/simple_data_source.h index 6ccf38e..77dc35c 100644 --- a/webkit/glue/media/simple_data_source.h +++ b/webkit/glue/media/simple_data_source.h @@ -42,18 +42,18 @@ class SimpleDataSource MessageLoop* render_loop, WebKit::WebFrame* frame, media::MediaLog* media_log, - WebDataSourceBuildObserverHack* build_observer); + const WebDataSourceBuildObserverHack& build_observer); SimpleDataSource(MessageLoop* render_loop, WebKit::WebFrame* frame); virtual ~SimpleDataSource(); // media::Filter implementation. virtual void set_host(media::FilterHost* host); - virtual void Stop(media::FilterCallback* callback); + virtual void Stop(const base::Closure& callback); // media::DataSource implementation. virtual void Read(int64 position, size_t size, - uint8* data, ReadCallback* read_callback); + uint8* data, const DataSource::ReadCallback& read_callback); virtual bool GetSize(int64* size_out); virtual bool IsStreaming(); virtual void SetPreload(media::Preload preload); diff --git a/webkit/glue/media/simple_data_source_unittest.cc b/webkit/glue/media/simple_data_source_unittest.cc index f099826..813f2f0 100644 --- a/webkit/glue/media/simple_data_source_unittest.cc +++ b/webkit/glue/media/simple_data_source_unittest.cc @@ -141,7 +141,8 @@ class SimpleDataSourceTest : public testing::Test { EXPECT_CALL(*this, ReadCallback(1)); data_source_->Read( i, 1, buffer, - NewCallback(this, &SimpleDataSourceTest::ReadCallback)); + base::Bind(&SimpleDataSourceTest::ReadCallback, + base::Unretained(this))); EXPECT_EQ(static_cast(data_[i]), buffer[0]); } } diff --git a/webkit/glue/media/video_renderer_impl.cc b/webkit/glue/media/video_renderer_impl.cc index 4532935..b3bf063 100644 --- a/webkit/glue/media/video_renderer_impl.cc +++ b/webkit/glue/media/video_renderer_impl.cc @@ -30,11 +30,9 @@ bool VideoRendererImpl::OnInitialize(media::VideoDecoder* decoder) { return true; } -void VideoRendererImpl::OnStop(media::FilterCallback* callback) { - if (callback) { - callback->Run(); - delete callback; - } +void VideoRendererImpl::OnStop(const base::Closure& callback) { + if (!callback.is_null()) + callback.Run(); } void VideoRendererImpl::OnFrameAvailable() { diff --git a/webkit/glue/media/video_renderer_impl.h b/webkit/glue/media/video_renderer_impl.h index aedadf2..c69e085 100644 --- a/webkit/glue/media/video_renderer_impl.h +++ b/webkit/glue/media/video_renderer_impl.h @@ -32,7 +32,7 @@ class VideoRendererImpl : public WebVideoRenderer { protected: // VideoRendererBase implementation. virtual bool OnInitialize(media::VideoDecoder* decoder) OVERRIDE; - virtual void OnStop(media::FilterCallback* callback) OVERRIDE; + virtual void OnStop(const base::Closure& callback) OVERRIDE; virtual void OnFrameAvailable() OVERRIDE; private: diff --git a/webkit/glue/media/web_data_source.h b/webkit/glue/media/web_data_source.h index 3e5869d..c972a66 100644 --- a/webkit/glue/media/web_data_source.h +++ b/webkit/glue/media/web_data_source.h @@ -5,7 +5,7 @@ #ifndef WEBKIT_GLUE_MEDIA_WEB_DATA_SOURCE_H_ #define WEBKIT_GLUE_MEDIA_WEB_DATA_SOURCE_H_ -#include "base/callback_old.h" +#include "base/callback.h" #include "media/base/filters.h" #include "media/base/pipeline_status.h" @@ -52,7 +52,7 @@ class WebDataSource : public media::DataSource { // on them at shutdown. Once cancellation is added to DataSource and pause // support in Demuxers cancel pending reads, Proxy shouldn't have to keep // a WebDataSource list or call Abort(). -typedef Callback1::Type WebDataSourceBuildObserverHack; +typedef base::Callback WebDataSourceBuildObserverHack; } // namespace webkit_glue diff --git a/webkit/glue/media/web_data_source_factory.cc b/webkit/glue/media/web_data_source_factory.cc index fb8b21e..ba77bb4 100644 --- a/webkit/glue/media/web_data_source_factory.cc +++ b/webkit/glue/media/web_data_source_factory.cc @@ -13,9 +13,9 @@ namespace webkit_glue { class WebDataSourceFactory::BuildRequest : public media::AsyncDataSourceFactoryBase::BuildRequest { public: - BuildRequest(const std::string& url, BuildCallback* callback, + BuildRequest(const std::string& url, const BuildCallback& callback, WebDataSource* data_source, - WebDataSourceBuildObserverHack* build_observer); + const WebDataSourceBuildObserverHack& build_observer); virtual ~BuildRequest(); protected: @@ -26,7 +26,7 @@ class WebDataSourceFactory::BuildRequest void InitDone(media::PipelineStatus status); scoped_refptr data_source_; - WebDataSourceBuildObserverHack* build_observer_; + WebDataSourceBuildObserverHack build_observer_; DISALLOW_COPY_AND_ASSIGN(BuildRequest); }; @@ -36,7 +36,7 @@ WebDataSourceFactory::WebDataSourceFactory( WebKit::WebFrame* frame, media::MediaLog* media_log, FactoryFunction factory_function, - WebDataSourceBuildObserverHack* build_observer) + const WebDataSourceBuildObserverHack& build_observer) : render_loop_(render_loop), frame_(frame), media_log_(media_log), @@ -61,7 +61,7 @@ bool WebDataSourceFactory::AllowRequests() const { media::AsyncDataSourceFactoryBase::BuildRequest* WebDataSourceFactory::CreateRequest(const std::string& url, - BuildCallback* callback) { + const BuildCallback& callback) { WebDataSource* data_source = factory_function_(render_loop_, frame_, media_log_); @@ -71,9 +71,9 @@ WebDataSourceFactory::CreateRequest(const std::string& url, WebDataSourceFactory::BuildRequest::BuildRequest( const std::string& url, - BuildCallback* callback, + const BuildCallback& callback, WebDataSource* data_source, - WebDataSourceBuildObserverHack* build_observer) + const WebDataSourceBuildObserverHack& build_observer) : AsyncDataSourceFactoryBase::BuildRequest(url, callback), data_source_(data_source), build_observer_(build_observer) { @@ -98,8 +98,8 @@ void WebDataSourceFactory::BuildRequest::InitDone( data_source = (status == media::PIPELINE_OK) ? data_source_ : NULL; data_source_ = NULL; - if (build_observer_ && data_source.get()) { - build_observer_->Run(data_source.get()); + if (!build_observer_.is_null() && data_source.get()) { + build_observer_.Run(data_source.get()); } RequestComplete(status, data_source); diff --git a/webkit/glue/media/web_data_source_factory.h b/webkit/glue/media/web_data_source_factory.h index f685953..0e32621 100644 --- a/webkit/glue/media/web_data_source_factory.h +++ b/webkit/glue/media/web_data_source_factory.h @@ -30,7 +30,7 @@ class WebDataSourceFactory : public media::AsyncDataSourceFactoryBase { WebDataSourceFactory(MessageLoop* render_loop, WebKit::WebFrame* frame, media::MediaLog* media_log, FactoryFunction factory_function, - WebDataSourceBuildObserverHack* build_observer); + const WebDataSourceBuildObserverHack& build_observer); virtual ~WebDataSourceFactory(); // DataSourceFactory method. @@ -40,7 +40,7 @@ class WebDataSourceFactory : public media::AsyncDataSourceFactoryBase { // AsyncDataSourceFactoryBase methods. virtual bool AllowRequests() const; virtual AsyncDataSourceFactoryBase::BuildRequest* CreateRequest( - const std::string& url, BuildCallback* callback); + const std::string& url, const BuildCallback& callback); private: class BuildRequest; @@ -49,7 +49,7 @@ class WebDataSourceFactory : public media::AsyncDataSourceFactoryBase { WebKit::WebFrame* frame_; scoped_refptr media_log_; FactoryFunction factory_function_; - WebDataSourceBuildObserverHack* build_observer_; + WebDataSourceBuildObserverHack build_observer_; DISALLOW_COPY_AND_ASSIGN(WebDataSourceFactory); }; -- cgit v1.1