Refactor management of overview window copy lifetime into a separate class.
[chromium-blink-merge.git] / content / renderer / pepper / pepper_media_device_manager.h
blob67d8976e0d47d0e352b32666037a306a2ad7852b
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 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_
8 #include <map>
10 #include "base/memory/weak_ptr.h"
11 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h"
12 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h"
13 #include "content/public/renderer/render_view_observer_tracker.h"
14 #include "content/public/renderer/render_view_observer.h"
16 namespace content {
17 class RenderViewImpl;
19 class PepperMediaDeviceManager
20 : public MediaStreamDispatcherEventHandler,
21 public PepperDeviceEnumerationHostHelper::Delegate,
22 public RenderViewObserver,
23 public RenderViewObserverTracker<PepperMediaDeviceManager>,
24 public base::SupportsWeakPtr<PepperMediaDeviceManager> {
25 public:
26 static PepperMediaDeviceManager* GetForRenderView(RenderView* render_view);
27 virtual ~PepperMediaDeviceManager();
29 // PepperDeviceEnumerationHostHelper::Delegate implementation:
30 virtual int EnumerateDevices(
31 PP_DeviceType_Dev type,
32 const EnumerateDevicesCallback& callback) OVERRIDE;
33 virtual void StopEnumerateDevices(int request_id) OVERRIDE;
35 typedef base::Callback<void (int /* request_id */,
36 bool /* succeeded */,
37 const std::string& /* label */)>
38 OpenDeviceCallback;
40 // Opens the specified device. The request ID passed into the callback will be
41 // the same as the return value. If successful, the label passed into the
42 // callback identifies a audio/video steam, which can be used to call
43 // CloseDevice() and GetSesssionID().
44 int OpenDevice(PP_DeviceType_Dev type,
45 const std::string& device_id,
46 const GURL& document_url,
47 const OpenDeviceCallback& callback);
48 // Cancels an request to open device, using the request ID returned by
49 // OpenDevice(). It is guaranteed that the callback passed into OpenDevice()
50 // won't be called afterwards.
51 void CancelOpenDevice(int request_id);
52 void CloseDevice(const std::string& label);
53 // Gets audio/video session ID given a label.
54 int GetSessionID(PP_DeviceType_Dev type, const std::string& label);
56 // MediaStreamDispatcherEventHandler implementation.
57 virtual void OnStreamGenerated(
58 int request_id,
59 const std::string& label,
60 const StreamDeviceInfoArray& audio_device_array,
61 const StreamDeviceInfoArray& video_device_array) OVERRIDE;
62 virtual void OnStreamGenerationFailed(int request_id) OVERRIDE;
63 virtual void OnStopGeneratedStream(const std::string& label) OVERRIDE;
64 virtual void OnDevicesEnumerated(
65 int request_id,
66 const StreamDeviceInfoArray& device_array) OVERRIDE;
67 virtual void OnDevicesEnumerationFailed(int request_id) OVERRIDE;
68 virtual void OnDeviceOpened(
69 int request_id,
70 const std::string& label,
71 const StreamDeviceInfo& device_info) OVERRIDE;
72 virtual void OnDeviceOpenFailed(int request_id) OVERRIDE;
74 // Stream type conversion.
75 static MediaStreamType FromPepperDeviceType(PP_DeviceType_Dev type);
76 static PP_DeviceType_Dev FromMediaStreamType(MediaStreamType type);
78 private:
79 PepperMediaDeviceManager(RenderView* render_view);
81 void NotifyDevicesEnumerated(
82 int request_id,
83 bool succeeded,
84 const StreamDeviceInfoArray& device_array);
86 void NotifyDeviceOpened(int request_id,
87 bool succeeded,
88 const std::string& label);
90 RenderViewImpl* GetRenderViewImpl();
92 int next_id_;
94 typedef std::map<int, EnumerateDevicesCallback> EnumerateCallbackMap;
95 EnumerateCallbackMap enumerate_callbacks_;
97 typedef std::map<int, OpenDeviceCallback> OpenCallbackMap;
98 OpenCallbackMap open_callbacks_;
100 DISALLOW_COPY_AND_ASSIGN(PepperMediaDeviceManager);
103 } // namespace content
105 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_DEVICE_MANAGER_H_