diff options
author | wjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-27 17:42:11 +0000 |
---|---|---|
committer | wjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-27 17:42:11 +0000 |
commit | 80b161a1954b9a3e8c9efe43c2d82488be7b9081 (patch) | |
tree | 4d8bb0452cabc5bff5e31ab202253e4ac50ba061 /content/renderer | |
parent | 5c18c409e1164c4320788dcd4f6a48d4ee590e4d (diff) | |
download | chromium_src-80b161a1954b9a3e8c9efe43c2d82488be7b9081.zip chromium_src-80b161a1954b9a3e8c9efe43c2d82488be7b9081.tar.gz chromium_src-80b161a1954b9a3e8c9efe43c2d82488be7b9081.tar.bz2 |
move VideoCaptureImplManager from singleton to a member of RenderThread.
fix some comments.
BUG=none
TEST=try bots
Review URL: http://codereview.chromium.org/7265004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90605 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer')
-rw-r--r-- | content/renderer/media/video_capture_impl_manager.cc | 68 | ||||
-rw-r--r-- | content/renderer/media/video_capture_impl_manager.h | 33 | ||||
-rw-r--r-- | content/renderer/media/video_capture_message_filter_creator.cc | 26 | ||||
-rw-r--r-- | content/renderer/media/video_capture_message_filter_creator.h | 35 | ||||
-rw-r--r-- | content/renderer/render_thread.cc | 13 | ||||
-rw-r--r-- | content/renderer/render_thread.h | 8 |
6 files changed, 60 insertions, 123 deletions
diff --git a/content/renderer/media/video_capture_impl_manager.cc b/content/renderer/media/video_capture_impl_manager.cc index 62b3915..558d28d 100644 --- a/content/renderer/media/video_capture_impl_manager.cc +++ b/content/renderer/media/video_capture_impl_manager.cc @@ -4,74 +4,67 @@ #include "content/renderer/media/video_capture_impl_manager.h" -#include "base/memory/singleton.h" -#include "content/renderer/media/video_capture_message_filter_creator.h" -#include "media/base/message_loop_factory_impl.h" - -VideoCaptureImplManager::VideoCaptureImplManager() { - ml_factory_.reset(new media::MessageLoopFactoryImpl()); - ml_proxy_ = ml_factory_->GetMessageLoopProxy("VC manager"); +#include "base/stl_util-inl.h" +#include "content/renderer/media/video_capture_impl.h" +#include "content/renderer/media/video_capture_message_filter.h" + +VideoCaptureImplManager::VideoCaptureImplManager() + : thread_("VC manager") { + thread_.Start(); + message_loop_proxy_ = thread_.message_loop_proxy(); + filter_ = new VideoCaptureMessageFilter(); } -VideoCaptureImplManager::~VideoCaptureImplManager() {} +VideoCaptureImplManager::~VideoCaptureImplManager() { + STLDeleteContainerPairSecondPointers(devices_.begin(), devices_.end()); + thread_.Stop(); +} -// static media::VideoCapture* VideoCaptureImplManager::AddDevice( media::VideoCaptureSessionId id, media::VideoCapture::EventHandler* handler) { DCHECK(handler); - VideoCaptureImplManager* manager = GetInstance(); - base::AutoLock auto_lock(manager->lock_); - Devices::iterator it = manager->devices_.find(id); - if (it == manager->devices_.end()) { + base::AutoLock auto_lock(lock_); + Devices::iterator it = devices_.find(id); + if (it == devices_.end()) { VideoCaptureImpl* vc = - new VideoCaptureImpl(id, manager->ml_proxy_, - VideoCaptureMessageFilterCreator::SharedFilter()); - manager->devices_[id] = Device(vc, handler); + new VideoCaptureImpl(id, message_loop_proxy_, filter_); + devices_[id] = new Device(vc, handler); vc->Init(); return vc; } - manager->devices_[id].clients.push_front(handler); - return it->second.vc; + devices_[id]->clients.push_front(handler); + return it->second->vc; } -// static void VideoCaptureImplManager::RemoveDevice( media::VideoCaptureSessionId id, media::VideoCapture::EventHandler* handler) { DCHECK(handler); - VideoCaptureImplManager* manager = GetInstance(); - base::AutoLock auto_lock(manager->lock_); - Devices::iterator it = manager->devices_.find(id); - if (it == manager->devices_.end()) + base::AutoLock auto_lock(lock_); + Devices::iterator it = devices_.find(id); + if (it == devices_.end()) return; - size_t size = it->second.clients.size(); - it->second.clients.remove(handler); + size_t size = it->second->clients.size(); + it->second->clients.remove(handler); - if (size == it->second.clients.size() || size > 1) + if (size == it->second->clients.size() || size > 1) return; - manager->devices_[id].vc->DeInit(NewRunnableMethod(manager, - &VideoCaptureImplManager::FreeDevice, manager->devices_[id].vc)); - manager->devices_.erase(id); - return; -} - -// static -VideoCaptureImplManager* VideoCaptureImplManager::GetInstance() { - return Singleton<VideoCaptureImplManager>::get(); + devices_[id]->vc->DeInit(NewRunnableMethod(this, + &VideoCaptureImplManager::FreeDevice, devices_[id]->vc)); + delete devices_[id]; + devices_.erase(id); } void VideoCaptureImplManager::FreeDevice(VideoCaptureImpl* vc) { delete vc; } -VideoCaptureImplManager::Device::Device() : vc(NULL) {} - VideoCaptureImplManager::Device::Device( VideoCaptureImpl* device, media::VideoCapture::EventHandler* handler) @@ -80,4 +73,3 @@ VideoCaptureImplManager::Device::Device( } VideoCaptureImplManager::Device::~Device() {} - diff --git a/content/renderer/media/video_capture_impl_manager.h b/content/renderer/media/video_capture_impl_manager.h index c562740..28c0e42 100644 --- a/content/renderer/media/video_capture_impl_manager.h +++ b/content/renderer/media/video_capture_impl_manager.h @@ -13,37 +13,39 @@ #include <list> #include <map> +#include "base/threading/thread.h" #include "base/message_loop_proxy.h" #include "base/synchronization/lock.h" -#include "content/renderer/media/video_capture_impl.h" -#include "content/renderer/media/video_capture_message_filter.h" -#include "media/base/callback.h" -#include "media/base/message_loop_factory.h" #include "media/video/capture/video_capture.h" -class VideoCaptureImplManager { +class VideoCaptureImpl; +class VideoCaptureMessageFilter; + +class VideoCaptureImplManager + : public base::RefCountedThreadSafe<VideoCaptureImplManager> { public: VideoCaptureImplManager(); - ~VideoCaptureImplManager(); + virtual ~VideoCaptureImplManager(); // Called by video capture client |handler| to add device referenced // by |id| to VideoCaptureImplManager's list of opened device list. // A pointer to VideoCapture is returned to client so that client can // operate on that pointer, such as StartCaptrue, StopCapture. - static media::VideoCapture* AddDevice( + media::VideoCapture* AddDevice( media::VideoCaptureSessionId id, media::VideoCapture::EventHandler* handler); // Called by video capture client |handler| to remove device referenced // by |id| from VideoCaptureImplManager's list of opened device list. - static void RemoveDevice(media::VideoCaptureSessionId id, - media::VideoCapture::EventHandler* handler); + void RemoveDevice(media::VideoCaptureSessionId id, + media::VideoCapture::EventHandler* handler); - static VideoCaptureImplManager* GetInstance(); + VideoCaptureMessageFilter* video_capture_message_filter() const { + return filter_; + } private: struct Device { - Device(); Device(VideoCaptureImpl* device, media::VideoCapture::EventHandler* handler); ~Device(); @@ -54,15 +56,14 @@ class VideoCaptureImplManager { void FreeDevice(VideoCaptureImpl* vc); - typedef std::map<media::VideoCaptureSessionId, Device> Devices; + typedef std::map<media::VideoCaptureSessionId, Device*> Devices; Devices devices_; base::Lock lock_; - scoped_refptr<base::MessageLoopProxy> ml_proxy_; - scoped_ptr<media::MessageLoopFactory> ml_factory_; + scoped_refptr<VideoCaptureMessageFilter> filter_; + base::Thread thread_; + scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); }; -DISABLE_RUNNABLE_METHOD_REFCOUNT(VideoCaptureImplManager); - #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ diff --git a/content/renderer/media/video_capture_message_filter_creator.cc b/content/renderer/media/video_capture_message_filter_creator.cc deleted file mode 100644 index b166f80..0000000 --- a/content/renderer/media/video_capture_message_filter_creator.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/renderer/media/video_capture_message_filter_creator.h" - -#include "content/renderer/media/video_capture_message_filter.h" - -VideoCaptureMessageFilterCreator::VideoCaptureMessageFilterCreator() { - filter_ = new VideoCaptureMessageFilter(); -} - -VideoCaptureMessageFilterCreator::~VideoCaptureMessageFilterCreator() { -} - -// static -VideoCaptureMessageFilter* VideoCaptureMessageFilterCreator::SharedFilter() { - return GetInstance()->filter_.get(); -} - -// static -VideoCaptureMessageFilterCreator* - VideoCaptureMessageFilterCreator::GetInstance() { - return Singleton<VideoCaptureMessageFilterCreator>::get(); -} - diff --git a/content/renderer/media/video_capture_message_filter_creator.h b/content/renderer/media/video_capture_message_filter_creator.h deleted file mode 100644 index 1424408..0000000 --- a/content/renderer/media/video_capture_message_filter_creator.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_MESSAGE_FILTER_CREATOR_H_ -#define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_MESSAGE_FILTER_CREATOR_H_ - -#include "base/memory/ref_counted.h" -#include "base/memory/singleton.h" - -class VideoCaptureMessageFilter; - -// VideoCaptureMessageFilterCreator is to be used as a singleton so we can get -// access to a shared VideoCaptureMessageFilter. -// Example usage: -// VideoCaptureMessageFilter* filter = -// VideoCaptureMessageFilterCreator::SharedFilter(); - -class VideoCaptureMessageFilterCreator { - public: - static VideoCaptureMessageFilter* SharedFilter(); - static VideoCaptureMessageFilterCreator* GetInstance(); - - private: - VideoCaptureMessageFilterCreator(); - ~VideoCaptureMessageFilterCreator(); - friend struct DefaultSingletonTraits<VideoCaptureMessageFilterCreator>; - - scoped_refptr<VideoCaptureMessageFilter> filter_; - - DISALLOW_COPY_AND_ASSIGN(VideoCaptureMessageFilterCreator); -}; - -#endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_MESSAGE_FILTER_CREATOR_H_ - diff --git a/content/renderer/render_thread.cc b/content/renderer/render_thread.cc index 89f95d1..4dcc99b 100644 --- a/content/renderer/render_thread.cc +++ b/content/renderer/render_thread.cc @@ -37,8 +37,8 @@ #include "content/renderer/gpu/gpu_channel_host.h" #include "content/renderer/gpu/gpu_video_service_host.h" #include "content/renderer/indexed_db_dispatcher.h" +#include "content/renderer/media/video_capture_impl_manager.h" #include "content/renderer/media/video_capture_message_filter.h" -#include "content/renderer/media/video_capture_message_filter_creator.h" #include "content/renderer/plugin_channel_host.h" #include "content/renderer/render_process_impl.h" #include "content/renderer/render_process_observer.h" @@ -171,9 +171,8 @@ void RenderThread::Init() { db_message_filter_ = new DBMessageFilter(); AddFilter(db_message_filter_.get()); - VideoCaptureMessageFilter* video_capture_message_filter = - VideoCaptureMessageFilterCreator::SharedFilter(); - AddFilter(video_capture_message_filter); + vc_manager_ = new VideoCaptureImplManager(); + AddFilter(vc_manager_->video_capture_message_filter()); content::GetContentClient()->renderer()->RenderThreadStarted(); @@ -189,13 +188,11 @@ RenderThread::~RenderThread() { web_database_observer_impl_->WaitForAllDatabasesToClose(); // Shutdown in reverse of the initialization order. + RemoveFilter(vc_manager_->video_capture_message_filter()); + RemoveFilter(db_message_filter_.get()); db_message_filter_ = NULL; - VideoCaptureMessageFilter* video_capture_message_filter = - VideoCaptureMessageFilterCreator::SharedFilter(); - RemoveFilter(video_capture_message_filter); - // Shutdown the file thread if it's running. if (file_thread_.get()) file_thread_->Stop(); diff --git a/content/renderer/render_thread.h b/content/renderer/render_thread.h index 853fffe..e73d1c1 100644 --- a/content/renderer/render_thread.h +++ b/content/renderer/render_thread.h @@ -32,6 +32,7 @@ class RenderProcessObserver; class RendererNetPredictor; class RendererWebKitClientImpl; class SkBitmap; +class VideoCaptureImplManager; class WebDatabaseObserverImpl; struct RendererPreferences; @@ -164,6 +165,10 @@ class RenderThread : public RenderThreadBase, return indexed_db_dispatcher_.get(); } + VideoCaptureImplManager* video_capture_impl_manager() const { + return vc_manager_.get(); + } + bool plugin_refresh_allowed() const { return plugin_refresh_allowed_; } double idle_notification_delay_in_s() const { @@ -247,6 +252,9 @@ class RenderThread : public RenderThreadBase, // Used on the renderer and IPC threads. scoped_refptr<DBMessageFilter> db_message_filter_; + // Used on multiple threads. + scoped_refptr<VideoCaptureImplManager> vc_manager_; + // Used on multiple script execution context threads. scoped_ptr<WebDatabaseObserverImpl> web_database_observer_impl_; |