IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / media / webrtc_internals.h
blob5355484c50b54968f8726fab116fe1446dc1f6d0
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/browser_child_process_observer.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "ui/shell_dialogs/select_file_dialog.h"
19 namespace content {
20 class WebContents;
21 class WebRTCInternalsUIObserver;
23 // This is a singleton class running in the browser UI thread.
24 // It collects peer connection infomation from the renderers,
25 // forwards the data to WebRTCInternalsUIObserver and
26 // sends data collecting commands to the renderers.
27 class CONTENT_EXPORT WebRTCInternals : public BrowserChildProcessObserver,
28 public NotificationObserver,
29 public ui::SelectFileDialog::Listener {
30 public:
31 static WebRTCInternals* GetInstance();
33 // This method is called when a PeerConnection is created.
34 // |render_process_id| is the id of the render process (not OS pid), which is
35 // needed because we might not be able to get the OS process id when the
36 // render process terminates and we want to clean up.
37 // |pid| is the renderer process id, |lid| is the renderer local id used to
38 // identify a PeerConnection, |url| is the url of the tab owning the
39 // PeerConnection, |servers| is the servers configuration, |constraints| is
40 // the media constraints used to initialize the PeerConnection.
41 void OnAddPeerConnection(int render_process_id,
42 base::ProcessId pid,
43 int lid,
44 const std::string& url,
45 const std::string& servers,
46 const std::string& constraints);
48 // This method is called when PeerConnection is destroyed.
49 // |pid| is the renderer process id, |lid| is the renderer local id.
50 void OnRemovePeerConnection(base::ProcessId pid, int lid);
52 // This method is called when a PeerConnection is updated.
53 // |pid| is the renderer process id, |lid| is the renderer local id,
54 // |type| is the update type, |value| is the detail of the update.
55 void OnUpdatePeerConnection(base::ProcessId pid,
56 int lid,
57 const std::string& type,
58 const std::string& value);
60 // This method is called when results from PeerConnectionInterface::GetStats
61 // are available. |pid| is the renderer process id, |lid| is the renderer
62 // local id, |value| is the list of stats reports.
63 void OnAddStats(base::ProcessId pid, int lid, const base::ListValue& value);
65 // This method is called when getUserMedia is called. |render_process_id| is
66 // the id of the render process (not OS pid), which is needed because we might
67 // not be able to get the OS process id when the render process terminates and
68 // we want to clean up. |pid| is the renderer OS process id, |origin| is the
69 // security origin of the getUserMedia call, |audio| is true if audio stream
70 // is requested, |video| is true if the video stream is requested,
71 // |audio_constraints| is the constraints for the audio, |video_constraints|
72 // is the constraints for the video.
73 void OnGetUserMedia(int render_process_id,
74 base::ProcessId pid,
75 const std::string& origin,
76 bool audio,
77 bool video,
78 const std::string& audio_constraints,
79 const std::string& video_constraints);
81 // Methods for adding or removing WebRTCInternalsUIObserver.
82 void AddObserver(WebRTCInternalsUIObserver *observer);
83 void RemoveObserver(WebRTCInternalsUIObserver *observer);
85 // Sends all update data to |observer|.
86 void UpdateObserver(WebRTCInternalsUIObserver* observer);
88 // Enables or disables AEC dump (diagnostic echo canceller recording).
89 void EnableAecDump(content::WebContents* web_contents);
90 void DisableAecDump();
92 bool aec_dump_enabled() {
93 return aec_dump_enabled_;
96 base::FilePath aec_dump_file_path() {
97 return aec_dump_file_path_;
100 void ResetForTesting();
102 private:
103 friend struct DefaultSingletonTraits<WebRTCInternals>;
104 FRIEND_TEST_ALL_PREFIXES(WebrtcBrowserTest, CallWithAecDump);
105 FRIEND_TEST_ALL_PREFIXES(WebrtcBrowserTest,
106 CallWithAecDumpEnabledThenDisabled);
108 WebRTCInternals();
109 virtual ~WebRTCInternals();
111 void SendUpdate(const std::string& command, base::Value* value);
113 // BrowserChildProcessObserver implementation.
114 virtual void BrowserChildProcessCrashed(
115 const ChildProcessData& data) OVERRIDE;
117 // NotificationObserver implementation.
118 virtual void Observe(int type,
119 const NotificationSource& source,
120 const NotificationDetails& details) OVERRIDE;
122 // ui::SelectFileDialog::Listener implementation.
123 virtual void FileSelected(const base::FilePath& path,
124 int index,
125 void* unused_params) OVERRIDE;
127 // Called when a renderer exits (including crashes).
128 void OnRendererExit(int render_process_id);
130 ObserverList<WebRTCInternalsUIObserver> observers_;
132 // |peer_connection_data_| is a list containing all the PeerConnection
133 // updates.
134 // Each item of the list represents the data for one PeerConnection, which
135 // contains these fields:
136 // "rid" -- the renderer id.
137 // "pid" -- OS process id of the renderer that creates the PeerConnection.
138 // "lid" -- local Id assigned to the PeerConnection.
139 // "url" -- url of the web page that created the PeerConnection.
140 // "servers" and "constraints" -- server configuration and media constraints
141 // used to initialize the PeerConnection respectively.
142 // "log" -- a ListValue contains all the updates for the PeerConnection. Each
143 // list item is a DictionaryValue containing "type" and "value", both of which
144 // are strings.
145 base::ListValue peer_connection_data_;
147 // A list of getUserMedia requests. Each item is a DictionaryValue that
148 // contains these fields:
149 // "rid" -- the renderer id.
150 // "pid" -- proceddId of the renderer.
151 // "origin" -- the security origin of the request.
152 // "audio" -- the serialized audio constraints if audio is requested.
153 // "video" -- the serialized video constraints if video is requested.
154 base::ListValue get_user_media_requests_;
156 NotificationRegistrar registrar_;
158 // For managing select file dialog.
159 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
161 // AEC dump (diagnostic echo canceller recording) state.
162 bool aec_dump_enabled_;
163 base::FilePath aec_dump_file_path_;
166 } // namespace content
168 #endif // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_