OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ |
| 7 |
| 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" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 class RenderViewHostDelegate; |
| 17 |
| 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 { |
| 22 public: |
| 23 typedef base::Callback< |
| 24 void (const MediaStreamDevices& devices)> ResponseCallback; |
| 25 |
| 26 MediaStreamUIProxy(); |
| 27 virtual ~MediaStreamUIProxy(); |
| 28 |
| 29 // Requests access for the MediaStream by calling |
| 30 // WebContentsDelegate::RequestMediaAccessPermission(). The specified |
| 31 // |response_callback| is called when the WebContentsDelegate approves or |
| 32 // denies request. |
| 33 virtual void RequestAccess(const MediaStreamRequest& request, |
| 34 const ResponseCallback& response_callback); |
| 35 |
| 36 // Notifies the UI that the MediaStream has been started. Must be called after |
| 37 // access has been approved using RequestAccess(). |stop_callback| is be |
| 38 // called on the IO thread after the user has requests the stream to be |
| 39 // stopped. |
| 40 virtual void OnStarted(const base::Closure& stop_callback); |
| 41 |
| 42 void SetRenderViewHostDelegateForTests(RenderViewHostDelegate* delegate); |
| 43 |
| 44 private: |
| 45 class Core; |
| 46 friend class Core; |
| 47 friend class FakeMediaStreamUIProxy; |
| 48 |
| 49 void ProcessAccessRequestResponse(const MediaStreamDevices& devices); |
| 50 void ProcessStopRequestFromUI(); |
| 51 |
| 52 RenderViewHostDelegate* renderer_delegate_; |
| 53 |
| 54 scoped_ptr<Core> core_; |
| 55 ResponseCallback response_callback_; |
| 56 base::Closure stop_callback_; |
| 57 |
| 58 base::WeakPtrFactory<MediaStreamUIProxy> weak_factory_; |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(MediaStreamUIProxy); |
| 61 }; |
| 62 |
| 63 class CONTENT_EXPORT FakeMediaStreamUIProxy : public MediaStreamUIProxy { |
| 64 public: |
| 65 explicit FakeMediaStreamUIProxy(); |
| 66 virtual ~FakeMediaStreamUIProxy(); |
| 67 |
| 68 void SetAvailableDevices(const MediaStreamDevices& devices); |
| 69 |
| 70 // MediaStreamUIProxy overrides. |
| 71 virtual void RequestAccess( |
| 72 const MediaStreamRequest& request, |
| 73 const ResponseCallback& response_callback) OVERRIDE; |
| 74 virtual void OnStarted(const base::Closure& stop_callback) OVERRIDE; |
| 75 |
| 76 private: |
| 77 MediaStreamDevices devices_; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(FakeMediaStreamUIProxy); |
| 80 }; |
| 81 |
| 82 } // namespace content |
| 83 |
| 84 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_ |
OLD | NEW |