device_monitor_mac.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.
  4. #ifndef MEDIA_DEVICE_MONITORS_DEVICE_MONITOR_MAC_H_
  5. #define MEDIA_DEVICE_MONITORS_DEVICE_MONITOR_MAC_H_
  6. #include <memory>
  7. #include "base/system/system_monitor.h"
  8. #include "base/task/single_thread_task_runner.h"
  9. #include "base/threading/thread_checker.h"
  10. #include "media/base/media_export.h"
  11. namespace {
  12. class DeviceMonitorMacImpl;
  13. }
  14. namespace media {
  15. // Class to track video devices removal or addition via callback to
  16. // base::SystemMonitor ProcessDevicesChanged(). A single object of this class
  17. // is created from the browser main process and lives as long as this one.
  18. class MEDIA_EXPORT DeviceMonitorMac {
  19. public:
  20. // The |device_task_runner| argument represents the thread on which device
  21. // enumeration will occur.
  22. explicit DeviceMonitorMac(
  23. scoped_refptr<base::SingleThreadTaskRunner> device_task_runner);
  24. DeviceMonitorMac(const DeviceMonitorMac&) = delete;
  25. DeviceMonitorMac& operator=(const DeviceMonitorMac&) = delete;
  26. ~DeviceMonitorMac();
  27. // Registers the observers for the video device removal, connection and
  28. // suspension. The AVFoundation library is also loaded and initialised if the
  29. // OS supports it.
  30. void StartMonitoring();
  31. // Method called by the internal DeviceMonitorMacImpl object
  32. // |device_monitor_impl_| when a device of type |type| has been added to or
  33. // removed from the system. This code executes in the notification thread.
  34. void NotifyDeviceChanged(base::SystemMonitor::DeviceType type);
  35. private:
  36. scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_;
  37. std::unique_ptr<DeviceMonitorMacImpl> device_monitor_impl_;
  38. // |thread_checker_| is used to check that constructor and StartMonitoring()
  39. // are called in the correct thread, the UI thread, that also owns the object.
  40. base::ThreadChecker thread_checker_;
  41. };
  42. } // namespace media
  43. #endif // MEDIA_DEVICE_MONITORS_DEVICE_MONITOR_MAC_H_