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/common/media_stream_request.h"
16 class RenderViewHostDelegate
;
18 // MediaStreamUIProxy proxies calls to media stream UI between IO thread and UI
19 // thread. One instance of this class is create per MediaStream object. It must
20 // be create, used and destroyed on IO thread.
21 class CONTENT_EXPORT MediaStreamUIProxy
{
23 typedef base::Callback
<
24 void (const MediaStreamDevices
& devices
,
25 content::MediaStreamRequestResult result
)>
28 typedef base::Callback
<void(gfx::NativeViewId window_id
)> WindowIdCallback
;
30 static scoped_ptr
<MediaStreamUIProxy
> Create();
31 static scoped_ptr
<MediaStreamUIProxy
> CreateForTests(
32 RenderViewHostDelegate
* render_delegate
);
34 virtual ~MediaStreamUIProxy();
36 // Requests access for the MediaStream by calling
37 // WebContentsDelegate::RequestMediaAccessPermission(). The specified
38 // |response_callback| is called when the WebContentsDelegate approves or
40 virtual void RequestAccess(const MediaStreamRequest
& request
,
41 const ResponseCallback
& response_callback
);
43 // Notifies the UI that the MediaStream has been started. Must be called after
44 // access has been approved using RequestAccess(). |stop_callback| is be
45 // called on the IO thread after the user has requests the stream to be
46 // stopped. |window_id_callback| is called on the IO thread with the platform-
47 // dependent window ID of the UI.
48 virtual void OnStarted(const base::Closure
& stop_callback
,
49 const WindowIdCallback
& window_id_callback
);
51 void SetRenderViewHostDelegateForTests(RenderViewHostDelegate
* delegate
);
54 MediaStreamUIProxy(RenderViewHostDelegate
* test_render_delegate
);
59 friend class FakeMediaStreamUIProxy
;
61 void ProcessAccessRequestResponse(
62 const MediaStreamDevices
& devices
,
63 content::MediaStreamRequestResult result
);
64 void ProcessStopRequestFromUI();
65 void OnWindowId(const WindowIdCallback
& window_id_callback
,
66 gfx::NativeViewId
* window_id
);
68 scoped_ptr
<Core
> core_
;
69 ResponseCallback response_callback_
;
70 base::Closure stop_callback_
;
72 base::WeakPtrFactory
<MediaStreamUIProxy
> weak_factory_
;
74 DISALLOW_COPY_AND_ASSIGN(MediaStreamUIProxy
);
77 class CONTENT_EXPORT FakeMediaStreamUIProxy
: public MediaStreamUIProxy
{
79 explicit FakeMediaStreamUIProxy();
80 virtual ~FakeMediaStreamUIProxy();
82 void SetAvailableDevices(const MediaStreamDevices
& devices
);
84 // MediaStreamUIProxy overrides.
85 virtual void RequestAccess(
86 const MediaStreamRequest
& request
,
87 const ResponseCallback
& response_callback
) OVERRIDE
;
88 virtual void OnStarted(const base::Closure
& stop_callback
,
89 const WindowIdCallback
& window_id_callback
) OVERRIDE
;
92 MediaStreamDevices devices_
;
94 DISALLOW_COPY_AND_ASSIGN(FakeMediaStreamUIProxy
);
97 } // namespace content
99 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_