[android_webview] Disable AwSettingsTest broken by Blink roll.
[chromium-blink-merge.git] / content / browser / device_monitor_mac.mm
blob7b12e91cbdf4ed8b57fc020d3b75c0579240d0ef
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/browser/device_monitor_mac.h"
7 #import <QTKit/QTKit.h>
9 #include "base/logging.h"
11 namespace content {
13 class DeviceMonitorMac::QTMonitorImpl {
14  public:
15   explicit QTMonitorImpl(DeviceMonitorMac* monitor);
16   virtual ~QTMonitorImpl() {}
18   void Start();
19   void Stop();
21  private:
22   void OnDeviceChanged();
24   DeviceMonitorMac* monitor_;
25   int number_audio_devices_;
26   int number_video_devices_;
27   id device_arrival_;
28   id device_removal_;
30   DISALLOW_COPY_AND_ASSIGN(QTMonitorImpl);
33 DeviceMonitorMac::QTMonitorImpl::QTMonitorImpl(DeviceMonitorMac* monitor)
34     : monitor_(monitor),
35       number_audio_devices_(0),
36       number_video_devices_(0),
37       device_arrival_(nil),
38       device_removal_(nil) {
39   DCHECK(monitor);
42 void DeviceMonitorMac::QTMonitorImpl::Start() {
43   NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
44   device_arrival_ =
45     [nc addObserverForName:QTCaptureDeviceWasConnectedNotification
46                     object:nil
47                      queue:nil
48                 usingBlock:^(NSNotification* notification) {
49                     OnDeviceChanged();}];
51   device_removal_ =
52       [nc addObserverForName:QTCaptureDeviceWasDisconnectedNotification
53                       object:nil
54                        queue:nil
55                   usingBlock:^(NSNotification* notification) {
56                       OnDeviceChanged();}];
59 void DeviceMonitorMac::QTMonitorImpl::Stop() {
60   if (!monitor_)
61     return;
63   NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
64   [nc removeObserver:device_arrival_];
65   [nc removeObserver:device_removal_];
68 void DeviceMonitorMac::QTMonitorImpl::OnDeviceChanged() {
69   NSArray* devices = [QTCaptureDevice inputDevices];
70   int number_video_devices = 0;
71   int number_audio_devices = 0;
72   for (QTCaptureDevice* device in devices) {
73     if ([device hasMediaType:QTMediaTypeVideo] ||
74         [device hasMediaType:QTMediaTypeMuxed])
75       ++number_video_devices;
77     if ([device hasMediaType:QTMediaTypeSound] ||
78         [device hasMediaType:QTMediaTypeMuxed])
79       ++number_audio_devices;
80   }
82   if (number_video_devices_ != number_video_devices) {
83     number_video_devices_ = number_video_devices;
84     monitor_->NotifyDeviceChanged(base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
85   }
87   if (number_audio_devices_ != number_audio_devices) {
88     number_audio_devices_ = number_audio_devices;
89     monitor_->NotifyDeviceChanged(base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE);
90   }
93 DeviceMonitorMac::DeviceMonitorMac() {
94   qt_monitor_.reset(new QTMonitorImpl(this));
95   qt_monitor_->Start();
98 DeviceMonitorMac::~DeviceMonitorMac() {
99   qt_monitor_->Stop();
102 void DeviceMonitorMac::NotifyDeviceChanged(
103     base::SystemMonitor::DeviceType type) {
104   // TODO(xians): Remove the global variable for SystemMonitor.
105   base::SystemMonitor::Get()->ProcessDevicesChanged(type);
108 }  // namespace content