Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / renderer_host / media / media_stream_ui_proxy.h
blob62bbeb8449594648198b8e75c6bc01c750fa90dd
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"
14 namespace content {
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 {
22 public:
23 typedef base::Callback<
24 void (const MediaStreamDevices& devices)> ResponseCallback;
26 static scoped_ptr<MediaStreamUIProxy> Create();
27 static scoped_ptr<MediaStreamUIProxy> CreateForTests(
28 RenderViewHostDelegate* render_delegate);
30 virtual ~MediaStreamUIProxy();
32 // Requests access for the MediaStream by calling
33 // WebContentsDelegate::RequestMediaAccessPermission(). The specified
34 // |response_callback| is called when the WebContentsDelegate approves or
35 // denies request.
36 virtual void RequestAccess(const MediaStreamRequest& request,
37 const ResponseCallback& response_callback);
39 // Notifies the UI that the MediaStream has been started. Must be called after
40 // access has been approved using RequestAccess(). |stop_callback| is be
41 // called on the IO thread after the user has requests the stream to be
42 // stopped.
43 virtual void OnStarted(const base::Closure& stop_callback);
45 void SetRenderViewHostDelegateForTests(RenderViewHostDelegate* delegate);
47 protected:
48 MediaStreamUIProxy(RenderViewHostDelegate* test_render_delegate);
50 private:
51 class Core;
52 friend class Core;
53 friend class FakeMediaStreamUIProxy;
55 void ProcessAccessRequestResponse(const MediaStreamDevices& devices);
56 void ProcessStopRequestFromUI();
58 scoped_ptr<Core> core_;
59 ResponseCallback response_callback_;
60 base::Closure stop_callback_;
62 base::WeakPtrFactory<MediaStreamUIProxy> weak_factory_;
64 DISALLOW_COPY_AND_ASSIGN(MediaStreamUIProxy);
67 class CONTENT_EXPORT FakeMediaStreamUIProxy : public MediaStreamUIProxy {
68 public:
69 explicit FakeMediaStreamUIProxy();
70 virtual ~FakeMediaStreamUIProxy();
72 void SetAvailableDevices(const MediaStreamDevices& devices);
74 // MediaStreamUIProxy overrides.
75 virtual void RequestAccess(
76 const MediaStreamRequest& request,
77 const ResponseCallback& response_callback) OVERRIDE;
78 virtual void OnStarted(const base::Closure& stop_callback) OVERRIDE;
80 private:
81 MediaStreamDevices devices_;
83 DISALLOW_COPY_AND_ASSIGN(FakeMediaStreamUIProxy);
86 } // namespace content
88 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_UI_PROXY_H_