1 // Copyright (c) 2012 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_DISPATCHER_HOST_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_DISPATCHER_HOST_H_ 7 8 #include <map> 9 #include <string> 10 #include <utility> 11 12 #include "content/browser/renderer_host/media/media_stream_manager.h" 13 #include "content/browser/renderer_host/media/media_stream_requester.h" 14 #include "content/common/content_export.h" 15 #include "content/common/media/media_stream_options.h" 16 #include "content/public/browser/browser_message_filter.h" 17 #include "content/public/browser/resource_context.h" 18 19 namespace content { 20 21 class MediaStreamManager; 22 23 // MediaStreamDispatcherHost is a delegate for Media Stream API messages used by 24 // MediaStreamImpl. It's the complement of MediaStreamDispatcher 25 // (owned by RenderView). 26 class CONTENT_EXPORT MediaStreamDispatcherHost : public BrowserMessageFilter, 27 public MediaStreamRequester { 28 public: 29 MediaStreamDispatcherHost( 30 int render_process_id, 31 const ResourceContext::SaltCallback& salt_callback, 32 MediaStreamManager* media_stream_manager); 33 34 // MediaStreamRequester implementation. 35 virtual void StreamGenerated( 36 int render_view_id, 37 int page_request_id, 38 const std::string& label, 39 const StreamDeviceInfoArray& audio_devices, 40 const StreamDeviceInfoArray& video_devices) OVERRIDE; 41 virtual void StreamGenerationFailed(int render_view_id, 42 int page_request_id) OVERRIDE; 43 virtual void DeviceStopped(int render_view_id, 44 const std::string& label, 45 const StreamDeviceInfo& device) OVERRIDE; 46 virtual void DevicesEnumerated(int render_view_id, 47 int page_request_id, 48 const std::string& label, 49 const StreamDeviceInfoArray& devices) OVERRIDE; 50 virtual void DeviceOpened(int render_view_id, 51 int page_request_id, 52 const std::string& label, 53 const StreamDeviceInfo& video_device) OVERRIDE; 54 55 // BrowserMessageFilter implementation. 56 virtual bool OnMessageReceived(const IPC::Message& message, 57 bool* message_was_ok) OVERRIDE; 58 virtual void OnChannelClosing() OVERRIDE; 59 60 protected: 61 virtual ~MediaStreamDispatcherHost(); 62 63 private: 64 friend class MockMediaStreamDispatcherHost; 65 66 void OnGenerateStream(int render_view_id, 67 int page_request_id, 68 const StreamOptions& components, 69 const GURL& security_origin); 70 void OnCancelGenerateStream(int render_view_id, 71 int page_request_id); 72 void OnStopStreamDevice(int render_view_id, 73 const std::string& device_id); 74 75 void OnEnumerateDevices(int render_view_id, 76 int page_request_id, 77 MediaStreamType type, 78 const GURL& security_origin); 79 80 void OnCancelEnumerateDevices(int render_view_id, 81 int page_request_id); 82 83 void OnOpenDevice(int render_view_id, 84 int page_request_id, 85 const std::string& device_id, 86 MediaStreamType type, 87 const GURL& security_origin); 88 89 void OnCloseDevice(int render_view_id, 90 const std::string& label); 91 92 void StoreRequest(int render_view_id, 93 int page_request_id, 94 const std::string& label);; 95 96 int render_process_id_; 97 ResourceContext::SaltCallback salt_callback_; 98 MediaStreamManager* media_stream_manager_; 99 100 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcherHost); 101 }; 102 103 } // namespace content 104 105 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_DISPATCHER_HOST_H_ 106