Fix build break
[chromium-blink-merge.git] / content / renderer / media / video_capture_impl_manager.cc
blobb2702966d5c410a45b318368aea74f79655dd16f
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/media/video_capture_impl_manager.h"
7 #include "base/bind.h"
8 #include "base/stl_util.h"
9 #include "content/renderer/media/video_capture_impl.h"
10 #include "content/renderer/media/video_capture_message_filter.h"
12 namespace content {
14 VideoCaptureImplManager::VideoCaptureImplManager()
15 : thread_("VC manager") {
16 thread_.Start();
17 message_loop_proxy_ = thread_.message_loop_proxy();
18 filter_ = new VideoCaptureMessageFilter();
21 media::VideoCapture* VideoCaptureImplManager::AddDevice(
22 media::VideoCaptureSessionId id,
23 media::VideoCapture::EventHandler* handler) {
24 DCHECK(handler);
26 base::AutoLock auto_lock(lock_);
27 Devices::iterator it = devices_.find(id);
28 if (it == devices_.end()) {
29 VideoCaptureImpl* vc =
30 new VideoCaptureImpl(id, message_loop_proxy_, filter_);
31 devices_[id] = new Device(vc, handler);
32 vc->Init();
33 return vc;
36 devices_[id]->clients.push_front(handler);
37 return it->second->vc;
40 void VideoCaptureImplManager::SuspendDevices(bool suspend) {
41 base::AutoLock auto_lock(lock_);
42 for (Devices::iterator it = devices_.begin(); it != devices_.end(); ++it)
43 it->second->vc->SuspendCapture(suspend);
46 void VideoCaptureImplManager::RemoveDevice(
47 media::VideoCaptureSessionId id,
48 media::VideoCapture::EventHandler* handler) {
49 DCHECK(handler);
51 base::AutoLock auto_lock(lock_);
52 Devices::iterator it = devices_.find(id);
53 if (it == devices_.end())
54 return;
56 size_t size = it->second->clients.size();
57 it->second->clients.remove(handler);
59 if (size == it->second->clients.size() || size > 1)
60 return;
62 devices_[id]->vc->DeInit(base::Bind(&VideoCaptureImplManager::FreeDevice,
63 this, devices_[id]->vc));
64 delete devices_[id];
65 devices_.erase(id);
68 void VideoCaptureImplManager::FreeDevice(VideoCaptureImpl* vc) {
69 delete vc;
72 VideoCaptureImplManager::~VideoCaptureImplManager() {
73 thread_.Stop();
74 // TODO(wjia): uncomment the line below after collecting enough info for
75 // crbug.com/152418.
76 // STLDeleteContainerPairSecondPointers(devices_.begin(), devices_.end());
79 VideoCaptureImplManager::Device::Device(
80 VideoCaptureImpl* device,
81 media::VideoCapture::EventHandler* handler)
82 : vc(device) {
83 clients.push_front(handler);
86 VideoCaptureImplManager::Device::~Device() {}
88 } // namespace content