Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / media / webrtc_internals.h
blobdb8693ab3eb2436af4302b31b51f04eaca464753
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/lazy_instance.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h"
12 #include "base/process/process.h"
13 #include "base/values.h"
14 #include "content/common/content_export.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 {
21 class PowerSaveBlocker;
22 class WebContents;
23 class WebRTCInternalsUIObserver;
25 // This is a singleton class running in the browser UI thread.
26 // It collects peer connection infomation from the renderers,
27 // forwards the data to WebRTCInternalsUIObserver and
28 // sends data collecting commands to the renderers.
29 class CONTENT_EXPORT WebRTCInternals : public NotificationObserver,
30 public ui::SelectFileDialog::Listener {
31 public:
32 static WebRTCInternals* GetInstance();
34 // This method is called when a PeerConnection is created.
35 // |render_process_id| is the id of the render process (not OS pid), which is
36 // needed because we might not be able to get the OS process id when the
37 // render process terminates and we want to clean up.
38 // |pid| is the renderer process id, |lid| is the renderer local id used to
39 // identify a PeerConnection, |url| is the url of the tab owning the
40 // PeerConnection, |rtc_configuration| is the serialized RTCConfiguration,
41 // |constraints| is the media constraints used to initialize the
42 // PeerConnection.
43 void OnAddPeerConnection(int render_process_id,
44 base::ProcessId pid,
45 int lid,
46 const std::string& url,
47 const std::string& rtc_configuration,
48 const std::string& constraints);
50 // This method is called when PeerConnection is destroyed.
51 // |pid| is the renderer process id, |lid| is the renderer local id.
52 void OnRemovePeerConnection(base::ProcessId pid, int lid);
54 // This method is called when a PeerConnection is updated.
55 // |pid| is the renderer process id, |lid| is the renderer local id,
56 // |type| is the update type, |value| is the detail of the update.
57 void OnUpdatePeerConnection(base::ProcessId pid,
58 int lid,
59 const std::string& type,
60 const std::string& value);
62 // This method is called when results from PeerConnectionInterface::GetStats
63 // are available. |pid| is the renderer process id, |lid| is the renderer
64 // local id, |value| is the list of stats reports.
65 void OnAddStats(base::ProcessId pid, int lid, const base::ListValue& value);
67 // This method is called when getUserMedia is called. |render_process_id| is
68 // the id of the render process (not OS pid), which is needed because we might
69 // not be able to get the OS process id when the render process terminates and
70 // we want to clean up. |pid| is the renderer OS process id, |origin| is the
71 // security origin of the getUserMedia call, |audio| is true if audio stream
72 // is requested, |video| is true if the video stream is requested,
73 // |audio_constraints| is the constraints for the audio, |video_constraints|
74 // is the constraints for the video.
75 void OnGetUserMedia(int render_process_id,
76 base::ProcessId pid,
77 const std::string& origin,
78 bool audio,
79 bool video,
80 const std::string& audio_constraints,
81 const std::string& video_constraints);
83 // Methods for adding or removing WebRTCInternalsUIObserver.
84 void AddObserver(WebRTCInternalsUIObserver *observer);
85 void RemoveObserver(WebRTCInternalsUIObserver *observer);
87 // Sends all update data to |observer|.
88 void UpdateObserver(WebRTCInternalsUIObserver* observer);
90 // Enables or disables AEC dump (diagnostic echo canceller recording).
91 void EnableAecDump(content::WebContents* web_contents);
92 void DisableAecDump();
94 bool aec_dump_enabled() {
95 return aec_dump_enabled_;
98 base::FilePath aec_dump_file_path() {
99 return aec_dump_file_path_;
102 void ResetForTesting();
104 private:
105 friend struct base::DefaultLazyInstanceTraits<WebRTCInternals>;
106 FRIEND_TEST_ALL_PREFIXES(WebRtcAecDumpBrowserTest, CallWithAecDump);
107 FRIEND_TEST_ALL_PREFIXES(WebRtcAecDumpBrowserTest,
108 CallWithAecDumpEnabledThenDisabled);
109 FRIEND_TEST_ALL_PREFIXES(WebRtcAecDumpBrowserTest, TwoCallsWithAecDump);
110 FRIEND_TEST_ALL_PREFIXES(WebRTCInternalsTest,
111 AecRecordingFileSelectionCanceled);
113 WebRTCInternals();
114 ~WebRTCInternals() override;
116 void SendUpdate(const std::string& command, base::Value* value);
118 // NotificationObserver implementation.
119 void Observe(int type,
120 const NotificationSource& source,
121 const NotificationDetails& details) override;
123 // ui::SelectFileDialog::Listener implementation.
124 void FileSelected(const base::FilePath& path,
125 int index,
126 void* unused_params) override;
127 void FileSelectionCanceled(void* params) override;
129 // Called when a renderer exits (including crashes).
130 void OnRendererExit(int render_process_id);
132 #if defined(ENABLE_WEBRTC)
133 // Enables AEC dump on all render process hosts using |aec_dump_file_path_|.
134 void EnableAecDumpOnAllRenderProcessHosts();
135 #endif
137 // Called whenever an element is added to or removed from
138 // |peer_connection_data_| to impose/release a block on suspending the current
139 // application for power-saving.
140 void CreateOrReleasePowerSaveBlocker();
142 ObserverList<WebRTCInternalsUIObserver> observers_;
144 // |peer_connection_data_| is a list containing all the PeerConnection
145 // updates.
146 // Each item of the list represents the data for one PeerConnection, which
147 // contains these fields:
148 // "rid" -- the renderer id.
149 // "pid" -- OS process id of the renderer that creates the PeerConnection.
150 // "lid" -- local Id assigned to the PeerConnection.
151 // "url" -- url of the web page that created the PeerConnection.
152 // "servers" and "constraints" -- server configuration and media constraints
153 // used to initialize the PeerConnection respectively.
154 // "log" -- a ListValue contains all the updates for the PeerConnection. Each
155 // list item is a DictionaryValue containing "time", which is the number of
156 // milliseconds since epoch as a string, and "type" and "value", both of which
157 // are strings representing the event.
158 base::ListValue peer_connection_data_;
160 // A list of getUserMedia requests. Each item is a DictionaryValue that
161 // contains these fields:
162 // "rid" -- the renderer id.
163 // "pid" -- proceddId of the renderer.
164 // "origin" -- the security origin of the request.
165 // "audio" -- the serialized audio constraints if audio is requested.
166 // "video" -- the serialized video constraints if video is requested.
167 base::ListValue get_user_media_requests_;
169 NotificationRegistrar registrar_;
171 // For managing select file dialog.
172 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
174 // AEC dump (diagnostic echo canceller recording) state.
175 bool aec_dump_enabled_;
176 base::FilePath aec_dump_file_path_;
178 // While |peer_connection_data_| is non-empty, hold an instance of
179 // PowerSaveBlocker. This prevents the application from being suspended while
180 // remoting.
181 scoped_ptr<PowerSaveBlocker> power_save_blocker_;
184 } // namespace content
186 #endif // CONTENT_BROWSER_MEDIA_WEBRTC_INTERNALS_H_