Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / media / webrtc_internals_message_handler.cc
blobbffd5098bfacc108f3acfec489f678ff39f6e9fa
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 #include "content/browser/media/webrtc_internals_message_handler.h"
7 #include "content/browser/media/webrtc_internals.h"
8 #include "content/common/media/peer_connection_tracker_messages.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_ui.h"
15 namespace content {
17 WebRTCInternalsMessageHandler::WebRTCInternalsMessageHandler() {
18 WebRTCInternals::GetInstance()->AddObserver(this);
21 WebRTCInternalsMessageHandler::~WebRTCInternalsMessageHandler() {
22 WebRTCInternals::GetInstance()->RemoveObserver(this);
25 void WebRTCInternalsMessageHandler::RegisterMessages() {
26 web_ui()->RegisterMessageCallback("getAllStats",
27 base::Bind(&WebRTCInternalsMessageHandler::OnGetAllStats,
28 base::Unretained(this)));
30 web_ui()->RegisterMessageCallback("enableAecRecording",
31 base::Bind(&WebRTCInternalsMessageHandler::OnSetAecRecordingEnabled,
32 base::Unretained(this), true));
34 web_ui()->RegisterMessageCallback("disableAecRecording",
35 base::Bind(&WebRTCInternalsMessageHandler::OnSetAecRecordingEnabled,
36 base::Unretained(this), false));
38 web_ui()->RegisterMessageCallback("finishedDOMLoad",
39 base::Bind(&WebRTCInternalsMessageHandler::OnDOMLoadDone,
40 base::Unretained(this)));
43 void WebRTCInternalsMessageHandler::OnGetAllStats(
44 const base::ListValue* /* unused_list */) {
45 for (RenderProcessHost::iterator i(
46 content::RenderProcessHost::AllHostsIterator());
47 !i.IsAtEnd(); i.Advance()) {
48 i.GetCurrentValue()->Send(new PeerConnectionTracker_GetAllStats());
52 void WebRTCInternalsMessageHandler::OnSetAecRecordingEnabled(
53 bool enable, const base::ListValue* /* unused_list */) {
54 if (enable)
55 WebRTCInternals::GetInstance()->EnableAecDump(web_ui()->GetWebContents());
56 else
57 WebRTCInternals::GetInstance()->DisableAecDump();
60 void WebRTCInternalsMessageHandler::OnDOMLoadDone(
61 const base::ListValue* /* unused_list */) {
62 WebRTCInternals::GetInstance()->UpdateObserver(this);
64 if (WebRTCInternals::GetInstance()->aec_dump_enabled()) {
65 std::vector<const base::Value*> args_vector;
66 base::string16 script = WebUI::GetJavascriptCall("setAecRecordingEnabled",
67 args_vector);
68 RenderFrameHost* host = web_ui()->GetWebContents()->GetMainFrame();
69 if (host)
70 host->ExecuteJavaScript(script);
74 void WebRTCInternalsMessageHandler::OnUpdate(const std::string& command,
75 const base::Value* args) {
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
77 std::vector<const base::Value*> args_vector;
78 if (args)
79 args_vector.push_back(args);
80 base::string16 update = WebUI::GetJavascriptCall(command, args_vector);
82 RenderFrameHost* host = web_ui()->GetWebContents()->GetMainFrame();
83 if (host)
84 host->ExecuteJavaScript(update);
87 } // namespace content