Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / media / webrtc_internals.h
blob7ff95b9bca9d878703639b94e64b5a577a1a36b3
1 // Copyright (c) 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_MEDIA_WEBRTC_INTERNALS_H_
6 #define CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/singleton.h"
10 #include "base/observer_list.h"
11 #include "base/process/process.h"
12 #include "base/values.h"
13 #include "content/common/content_export.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "ui/shell_dialogs/select_file_dialog.h"
18 namespace content {
19 class WebContents;
20 class WebRTCInternalsUIObserver;
22 // This is a singleton class running in the browser UI thread.
23 // It collects peer connection infomation from the renderers,
24 // forwards the data to WebRTCInternalsUIObserver and
25 // sends data collecting commands to the renderers.
26 class CONTENT_EXPORT WebRTCInternals : public NotificationObserver,
27 public ui::SelectFileDialog::Listener {
28 public:
29 static WebRTCInternals* GetInstance();
31 // This method is called when a PeerConnection is created.
32 // |render_process_id| is the id of the render process (not OS pid), which is
33 // needed because we might not be able to get the OS process id when the
34 // render process terminates and we want to clean up.
35 // |pid| is the renderer process id, |lid| is the renderer local id used to
36 // identify a PeerConnection, |url| is the url of the tab owning the
37 // PeerConnection, |servers| is the servers configuration, |constraints| is
38 // the media constraints used to initialize the PeerConnection.
39 void OnAddPeerConnection(int render_process_id,
40 base::ProcessId pid,
41 int lid,
42 const std::string& url,
43 const std::string& servers,
44 const std::string& constraints);
46 // This method is called when PeerConnection is destroyed.
47 // |pid| is the renderer process id, |lid| is the renderer local id.
48 void OnRemovePeerConnection(base::ProcessId pid, int lid);
50 // This method is called when a PeerConnection is updated.
51 // |pid| is the renderer process id, |lid| is the renderer local id,
52 // |type| is the update type, |value| is the detail of the update.
53 void OnUpdatePeerConnection(base::ProcessId pid,
54 int lid,
55 const std::string& type,
56 const std::string& value);
58 // This method is called when results from PeerConnectionInterface::GetStats
59 // are available. |pid| is the renderer process id, |lid| is the renderer
60 // local id, |value| is the list of stats reports.
61 void OnAddStats(base::ProcessId pid, int lid, const base::ListValue& value);
63 // This method is called when getUserMedia is called. |render_process_id| is
64 // the id of the render process (not OS pid), which is needed because we might
65 // not be able to get the OS process id when the render process terminates and
66 // we want to clean up. |pid| is the renderer OS process id, |origin| is the
67 // security origin of the getUserMedia call, |audio| is true if audio stream
68 // is requested, |video| is true if the video stream is requested,
69 // |audio_constraints| is the constraints for the audio, |video_constraints|
70 // is the constraints for the video.
71 void OnGetUserMedia(int render_process_id,
72 base::ProcessId pid,
73 const std::string& origin,
74 bool audio,
75 bool video,
76 const std::string& audio_constraints,
77 const std::string& video_constraints);
79 // Methods for adding or removing WebRTCInternalsUIObserver.
80 void AddObserver(WebRTCInternalsUIObserver *observer);
81 void RemoveObserver(WebRTCInternalsUIObserver *observer);
83 // Sends all update data to |observer|.
84 void UpdateObserver(WebRTCInternalsUIObserver* observer);
86 // Enables or disables AEC dump (diagnostic echo canceller recording).
87 void EnableAecDump(content::WebContents* web_contents);
88 void DisableAecDump();
90 bool aec_dump_enabled() {
91 return aec_dump_enabled_;
94 base::FilePath aec_dump_file_path() {
95 return aec_dump_file_path_;
98 void ResetForTesting();
100 private:
101 friend struct DefaultSingletonTraits<WebRTCInternals>;
102 FRIEND_TEST_ALL_PREFIXES(WebRtcBrowserTest, CallWithAecDump);
103 FRIEND_TEST_ALL_PREFIXES(WebRtcBrowserTest,
104 CallWithAecDumpEnabledThenDisabled);
105 FRIEND_TEST_ALL_PREFIXES(WebRTCInternalsTest,
106 AecRecordingFileSelectionCanceled);
108 WebRTCInternals();
109 virtual ~WebRTCInternals();
111 void SendUpdate(const std::string& command, base::Value* value);
113 // NotificationObserver implementation.
114 virtual void Observe(int type,
115 const NotificationSource& source,
116 const NotificationDetails& details) OVERRIDE;
118 // ui::SelectFileDialog::Listener implementation.
119 virtual void FileSelected(const base::FilePath& path,
120 int index,
121 void* unused_params) OVERRIDE;
122 virtual void FileSelectionCanceled(void* params) OVERRIDE;
124 // Called when a renderer exits (including crashes).
125 void OnRendererExit(int render_process_id);
127 #if defined(ENABLE_WEBRTC)
128 // Enables AEC dump on all render process hosts using |aec_dump_file_path_|.
129 void EnableAecDumpOnAllRenderProcessHosts();
130 #endif
132 ObserverList<WebRTCInternalsUIObserver> observers_;
134 // |peer_connection_data_| is a list containing all the PeerConnection
135 // updates.
136 // Each item of the list represents the data for one PeerConnection, which
137 // contains these fields:
138 // "rid" -- the renderer id.
139 // "pid" -- OS process id of the renderer that creates the PeerConnection.
140 // "lid" -- local Id assigned to the PeerConnection.
141 // "url" -- url of the web page that created the PeerConnection.
142 // "servers" and "constraints" -- server configuration and media constraints
143 // used to initialize the PeerConnection respectively.
144 // "log" -- a ListValue contains all the updates for the PeerConnection. Each
145 // list item is a DictionaryValue containing "type" and "value", both of which
146 // are strings.
147 base::ListValue peer_connection_data_;
149 // A list of getUserMedia requests. Each item is a DictionaryValue that
150 // contains these fields:
151 // "rid" -- the renderer id.
152 // "pid" -- proceddId of the renderer.
153 // "origin" -- the security origin of the request.
154 // "audio" -- the serialized audio constraints if audio is requested.
155 // "video" -- the serialized video constraints if video is requested.
156 base::ListValue get_user_media_requests_;
158 NotificationRegistrar registrar_;
160 // For managing select file dialog.
161 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
163 // AEC dump (diagnostic echo canceller recording) state.
164 bool aec_dump_enabled_;
165 base::FilePath aec_dump_file_path_;
168 } // namespace content
170 #endif // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_