1 // Copyright 2013 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_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/common/media_stream_request.h"
17 class RenderFrameHostDelegate
;
19 // MediaStreamUIProxy proxies calls to media stream UI between IO thread and UI
20 // thread. One instance of this class is create per MediaStream object. It must
21 // be created, used and destroyed on IO thread.
22 class CONTENT_EXPORT MediaStreamUIProxy
{
24 typedef base::Callback
<
25 void (const MediaStreamDevices
& devices
,
26 content::MediaStreamRequestResult result
)>
29 typedef base::Callback
<void(gfx::NativeViewId window_id
)> WindowIdCallback
;
31 static scoped_ptr
<MediaStreamUIProxy
> Create();
32 static scoped_ptr
<MediaStreamUIProxy
> CreateForTests(
33 RenderFrameHostDelegate
* render_delegate
);
35 virtual ~MediaStreamUIProxy();
37 // Requests access for the MediaStream by calling
38 // WebContentsDelegate::RequestMediaAccessPermission(). The specified
39 // |response_callback| is called when the WebContentsDelegate approves or
41 virtual void RequestAccess(const MediaStreamRequest
& request
,
42 const ResponseCallback
& response_callback
);
44 // Notifies the UI that the MediaStream has been started. Must be called after
45 // access has been approved using RequestAccess(). |stop_callback| is be
46 // called on the IO thread after the user has requests the stream to be
47 // stopped. |window_id_callback| is called on the IO thread with the platform-
48 // dependent window ID of the UI.
49 virtual void OnStarted(const base::Closure
& stop_callback
,
50 const WindowIdCallback
& window_id_callback
);
52 void SetRenderFrameHostDelegateForTests(RenderFrameHostDelegate
* delegate
);
55 explicit MediaStreamUIProxy(RenderFrameHostDelegate
* test_render_delegate
);
60 friend class FakeMediaStreamUIProxy
;
62 void ProcessAccessRequestResponse(
63 const MediaStreamDevices
& devices
,
64 content::MediaStreamRequestResult result
);
65 void ProcessStopRequestFromUI();
66 void OnWindowId(const WindowIdCallback
& window_id_callback
,
67 gfx::NativeViewId
* window_id
);
69 scoped_ptr
<Core
, content::BrowserThread::DeleteOnUIThread
> core_
;
70 ResponseCallback response_callback_
;
71 base::Closure stop_callback_
;
73 base::WeakPtrFactory
<MediaStreamUIProxy
> weak_factory_
;
75 DISALLOW_COPY_AND_ASSIGN(MediaStreamUIProxy
);
78 class CONTENT_EXPORT FakeMediaStreamUIProxy
: public MediaStreamUIProxy
{
80 explicit FakeMediaStreamUIProxy();
81 virtual ~FakeMediaStreamUIProxy();
83 void SetAvailableDevices(const MediaStreamDevices
& devices
);
85 // MediaStreamUIProxy overrides.
86 virtual void RequestAccess(
87 const MediaStreamRequest
& request
,
88 const ResponseCallback
& response_callback
) OVERRIDE
;
89 virtual void OnStarted(const base::Closure
& stop_callback
,
90 const WindowIdCallback
& window_id_callback
) OVERRIDE
;
93 MediaStreamDevices devices_
;
95 DISALLOW_COPY_AND_ASSIGN(FakeMediaStreamUIProxy
);
98 } // namespace content
100 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_