| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/common/media_stream_request.h" | 14 #include "content/public/common/media_stream_request.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 class RenderFrameHostDelegate; | 18 class RenderFrameHostDelegate; |
| 19 | 19 |
| 20 // MediaStreamUIProxy proxies calls to media stream UI between IO thread and UI | 20 // MediaStreamUIProxy proxies calls to media stream UI between IO thread and UI |
| 21 // thread. One instance of this class is create per MediaStream object. It must | 21 // thread. One instance of this class is create per MediaStream object. It must |
| 22 // be created, used and destroyed on IO thread. | 22 // be created, used and destroyed on IO thread. |
| 23 class CONTENT_EXPORT MediaStreamUIProxy { | 23 class CONTENT_EXPORT MediaStreamUIProxy { |
| 24 public: | 24 public: |
| 25 typedef base::Callback< | 25 using ResponseCallback = |
| 26 void(const MediaStreamDevices& devices, | 26 base::OnceCallback<void(const MediaStreamDevices& devices, |
| 27 content::MediaStreamRequestResult result)> | 27 content::MediaStreamRequestResult result)>; |
| 28 ResponseCallback; | |
| 29 | 28 |
| 30 typedef base::Callback<void(gfx::NativeViewId window_id)> WindowIdCallback; | 29 using WindowIdCallback = |
| 30 base::OnceCallback<void(gfx::NativeViewId window_id)>; |
| 31 | 31 |
| 32 static std::unique_ptr<MediaStreamUIProxy> Create(); | 32 static std::unique_ptr<MediaStreamUIProxy> Create(); |
| 33 static std::unique_ptr<MediaStreamUIProxy> CreateForTests( | 33 static std::unique_ptr<MediaStreamUIProxy> CreateForTests( |
| 34 RenderFrameHostDelegate* render_delegate); | 34 RenderFrameHostDelegate* render_delegate); |
| 35 | 35 |
| 36 virtual ~MediaStreamUIProxy(); | 36 virtual ~MediaStreamUIProxy(); |
| 37 | 37 |
| 38 // Requests access for the MediaStream by calling | 38 // Requests access for the MediaStream by calling |
| 39 // WebContentsDelegate::RequestMediaAccessPermission(). The specified | 39 // WebContentsDelegate::RequestMediaAccessPermission(). The specified |
| 40 // |response_callback| is called when the WebContentsDelegate approves or | 40 // |response_callback| is called when the WebContentsDelegate approves or |
| 41 // denies request. | 41 // denies request. |
| 42 virtual void RequestAccess(std::unique_ptr<MediaStreamRequest> request, | 42 virtual void RequestAccess(std::unique_ptr<MediaStreamRequest> request, |
| 43 const ResponseCallback& response_callback); | 43 ResponseCallback response_callback); |
| 44 | 44 |
| 45 // Notifies the UI that the MediaStream has been started. Must be called after | 45 // Notifies the UI that the MediaStream has been started. Must be called after |
| 46 // access has been approved using RequestAccess(). |stop_callback| is be | 46 // access has been approved using RequestAccess(). |stop_callback| is be |
| 47 // called on the IO thread after the user has requests the stream to be | 47 // called on the IO thread after the user has requests the stream to be |
| 48 // stopped. |window_id_callback| is called on the IO thread with the platform- | 48 // stopped. |window_id_callback| is called on the IO thread with the platform- |
| 49 // dependent window ID of the UI. | 49 // dependent window ID of the UI. |
| 50 virtual void OnStarted(const base::Closure& stop_callback, | 50 virtual void OnStarted(base::OnceClosure stop_callback, |
| 51 const WindowIdCallback& window_id_callback); | 51 WindowIdCallback window_id_callback); |
| 52 | 52 |
| 53 void SetRenderFrameHostDelegateForTests(RenderFrameHostDelegate* delegate); | 53 void SetRenderFrameHostDelegateForTests(RenderFrameHostDelegate* delegate); |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 56 explicit MediaStreamUIProxy(RenderFrameHostDelegate* test_render_delegate); | 56 explicit MediaStreamUIProxy(RenderFrameHostDelegate* test_render_delegate); |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 class Core; | 59 class Core; |
| 60 friend class Core; | 60 friend class Core; |
| 61 friend class FakeMediaStreamUIProxy; | 61 friend class FakeMediaStreamUIProxy; |
| 62 | 62 |
| 63 void ProcessAccessRequestResponse( | 63 void ProcessAccessRequestResponse( |
| 64 const MediaStreamDevices& devices, | 64 const MediaStreamDevices& devices, |
| 65 content::MediaStreamRequestResult result); | 65 content::MediaStreamRequestResult result); |
| 66 void ProcessStopRequestFromUI(); | 66 void ProcessStopRequestFromUI(); |
| 67 void OnWindowId(const WindowIdCallback& window_id_callback, | 67 void OnWindowId(WindowIdCallback window_id_callback, |
| 68 gfx::NativeViewId* window_id); | 68 gfx::NativeViewId* window_id); |
| 69 void OnCheckedAccess(const base::Callback<void(bool)>& callback, | 69 void OnCheckedAccess(base::Callback<void(bool)> callback, bool have_access); |
| 70 bool have_access); | |
| 71 | 70 |
| 72 std::unique_ptr<Core, content::BrowserThread::DeleteOnUIThread> core_; | 71 std::unique_ptr<Core, content::BrowserThread::DeleteOnUIThread> core_; |
| 73 ResponseCallback response_callback_; | 72 ResponseCallback response_callback_; |
| 74 base::Closure stop_callback_; | 73 base::OnceClosure stop_callback_; |
| 75 | 74 |
| 76 base::WeakPtrFactory<MediaStreamUIProxy> weak_factory_; | 75 base::WeakPtrFactory<MediaStreamUIProxy> weak_factory_; |
| 77 | 76 |
| 78 DISALLOW_COPY_AND_ASSIGN(MediaStreamUIProxy); | 77 DISALLOW_COPY_AND_ASSIGN(MediaStreamUIProxy); |
| 79 }; | 78 }; |
| 80 | 79 |
| 81 class CONTENT_EXPORT FakeMediaStreamUIProxy : public MediaStreamUIProxy { | 80 class CONTENT_EXPORT FakeMediaStreamUIProxy : public MediaStreamUIProxy { |
| 82 public: | 81 public: |
| 83 explicit FakeMediaStreamUIProxy(); | 82 FakeMediaStreamUIProxy(); |
| 84 ~FakeMediaStreamUIProxy() override; | 83 ~FakeMediaStreamUIProxy() override; |
| 85 | 84 |
| 86 void SetAvailableDevices(const MediaStreamDevices& devices); | 85 void SetAvailableDevices(const MediaStreamDevices& devices); |
| 87 void SetMicAccess(bool access); | 86 void SetMicAccess(bool access); |
| 88 void SetCameraAccess(bool access); | 87 void SetCameraAccess(bool access); |
| 89 | 88 |
| 90 // MediaStreamUIProxy overrides. | 89 // MediaStreamUIProxy overrides. |
| 91 void RequestAccess(std::unique_ptr<MediaStreamRequest> request, | 90 void RequestAccess(std::unique_ptr<MediaStreamRequest> request, |
| 92 const ResponseCallback& response_callback) override; | 91 ResponseCallback response_callback) override; |
| 93 void OnStarted(const base::Closure& stop_callback, | 92 void OnStarted(base::OnceClosure stop_callback, |
| 94 const WindowIdCallback& window_id_callback) override; | 93 WindowIdCallback window_id_callback) override; |
| 95 | 94 |
| 96 private: | 95 private: |
| 97 // This is used for RequestAccess(). | 96 // This is used for RequestAccess(). |
| 98 MediaStreamDevices devices_; | 97 MediaStreamDevices devices_; |
| 99 | 98 |
| 100 // These are used for CheckAccess(). | 99 // These are used for CheckAccess(). |
| 101 bool mic_access_; | 100 bool mic_access_; |
| 102 bool camera_access_; | 101 bool camera_access_; |
| 103 | 102 |
| 104 DISALLOW_COPY_AND_ASSIGN(FakeMediaStreamUIProxy); | 103 DISALLOW_COPY_AND_ASSIGN(FakeMediaStreamUIProxy); |
| 105 }; | 104 }; |
| 106 | 105 |
| 107 } // namespace content | 106 } // namespace content |
| 108 | 107 |
| 109 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ | 108 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ |
| OLD | NEW |