• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #ifndef CEF_LIBCEF_BROWSER_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
6 #define CEF_LIBCEF_BROWSER_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
7 
8 #include "base/callback.h"
9 #include "base/memory/singleton.h"
10 #include "base/observer_list.h"
11 #include "content/public/browser/media_observer.h"
12 #include "content/public/browser/media_stream_request.h"
13 
14 class PrefRegistrySimple;
15 class PrefService;
16 
17 // This singleton is used to receive updates about media events from the content
18 // layer. Based on chrome/browser/media/media_capture_devices_dispatcher.[h|cc].
19 class CefMediaCaptureDevicesDispatcher : public content::MediaObserver {
20  public:
21   static CefMediaCaptureDevicesDispatcher* GetInstance();
22 
23   // Registers the preferences related to Media Stream default devices.
24   static void RegisterPrefs(PrefRegistrySimple* registry);
25 
26   // Helper to get the default devices which can be used by the media request,
27   // if the return list is empty, it means there is no available device on the
28   // OS. Called on the UI thread.
29   void GetDefaultDevices(PrefService* prefs,
30                          bool audio,
31                          bool video,
32                          blink::MediaStreamDevices* devices);
33 
34   // Helper for picking the device that was requested for an OpenDevice request.
35   // If the device requested is not available it will revert to using the first
36   // available one instead or will return an empty list if no devices of the
37   // requested kind are present. Called on the UI thread.
38   void GetRequestedDevice(const std::string& requested_device_id,
39                           bool audio,
40                           bool video,
41                           blink::MediaStreamDevices* devices);
42 
43   // Overridden from content::MediaObserver:
44   void OnAudioCaptureDevicesChanged() override;
45   void OnVideoCaptureDevicesChanged() override;
46   void OnMediaRequestStateChanged(int render_process_id,
47                                   int render_frame_id,
48                                   int page_request_id,
49                                   const GURL& security_origin,
50                                   blink::mojom::MediaStreamType stream_type,
51                                   content::MediaRequestState state) override;
52   void OnCreatingAudioStream(int render_process_id,
53                              int render_view_id) override;
54   void OnSetCapturingLinkSecured(int render_process_id,
55                                  int render_frame_id,
56                                  int page_request_id,
57                                  blink::mojom::MediaStreamType stream_type,
58                                  bool is_secure) override;
59 
60  private:
61   friend struct base::DefaultSingletonTraits<CefMediaCaptureDevicesDispatcher>;
62 
63   CefMediaCaptureDevicesDispatcher();
64   ~CefMediaCaptureDevicesDispatcher() override;
65 
66   const blink::MediaStreamDevices& GetAudioCaptureDevices();
67   const blink::MediaStreamDevices& GetVideoCaptureDevices();
68 };
69 
70 #endif  // CEF_LIBCEF_BROWSER_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
71