Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/media/media_internals_proxy.h" | 5 #include "content/browser/media/media_internals_proxy.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
|
Dan Beam
2016/06/21 00:54:12
#include <utility>
dcheng
2016/06/21 18:56:02
Done.
| |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | |
| 10 #include "base/location.h" | 11 #include "base/location.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "content/browser/media/media_internals_handler.h" | 15 #include "content/browser/media/media_internals_handler.h" |
| 15 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
| 16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 18 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 break; | 92 break; |
| 92 } | 93 } |
| 93 } | 94 } |
| 94 | 95 |
| 95 if (!is_event_interesting) | 96 if (!is_event_interesting) |
| 96 return; | 97 return; |
| 97 | 98 |
| 98 BrowserThread::PostTask( | 99 BrowserThread::PostTask( |
| 99 BrowserThread::UI, FROM_HERE, | 100 BrowserThread::UI, FROM_HERE, |
| 100 base::Bind(&MediaInternalsProxy::AddNetEventOnUIThread, this, | 101 base::Bind(&MediaInternalsProxy::AddNetEventOnUIThread, this, |
| 101 entry.ToValue())); | 102 base::Passed(entry.ToValue()))); |
| 102 } | 103 } |
| 103 | 104 |
| 104 MediaInternalsProxy::~MediaInternalsProxy() {} | 105 MediaInternalsProxy::~MediaInternalsProxy() {} |
| 105 | 106 |
| 106 base::Value* MediaInternalsProxy::GetConstants() { | 107 base::Value* MediaInternalsProxy::GetConstants() { |
| 107 base::DictionaryValue* event_phases = new base::DictionaryValue(); | 108 base::DictionaryValue* event_phases = new base::DictionaryValue(); |
| 108 event_phases->SetInteger( | 109 event_phases->SetInteger( |
| 109 net::NetLog::EventPhaseToString(net::NetLog::PHASE_NONE), | 110 net::NetLog::EventPhaseToString(net::NetLog::PHASE_NONE), |
| 110 net::NetLog::PHASE_NONE); | 111 net::NetLog::PHASE_NONE); |
| 111 event_phases->SetInteger( | 112 event_phases->SetInteger( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 MediaInternals::GetInstance()->SendVideoCaptureDeviceCapabilities(); | 147 MediaInternals::GetInstance()->SendVideoCaptureDeviceCapabilities(); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void MediaInternalsProxy::UpdateUIOnUIThread(const base::string16& update) { | 150 void MediaInternalsProxy::UpdateUIOnUIThread(const base::string16& update) { |
| 150 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 151 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 151 // Don't forward updates to a destructed UI. | 152 // Don't forward updates to a destructed UI. |
| 152 if (handler_) | 153 if (handler_) |
| 153 handler_->OnUpdate(update); | 154 handler_->OnUpdate(update); |
| 154 } | 155 } |
| 155 | 156 |
| 156 void MediaInternalsProxy::AddNetEventOnUIThread(base::Value* entry) { | 157 void MediaInternalsProxy::AddNetEventOnUIThread( |
| 158 std::unique_ptr<base::Value> entry) { | |
| 157 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 159 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 158 | 160 |
| 159 // Send the updates to the page in kMediaInternalsProxyEventDelayMilliseconds | 161 // Send the updates to the page in kMediaInternalsProxyEventDelayMilliseconds |
| 160 // if an update is not already pending. | 162 // if an update is not already pending. |
| 161 if (!pending_net_updates_) { | 163 if (!pending_net_updates_) { |
| 162 pending_net_updates_.reset(new base::ListValue()); | 164 pending_net_updates_.reset(new base::ListValue()); |
| 163 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 165 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 164 FROM_HERE, | 166 FROM_HERE, |
| 165 base::Bind(&MediaInternalsProxy::SendNetEventsOnUIThread, this), | 167 base::Bind(&MediaInternalsProxy::SendNetEventsOnUIThread, this), |
| 166 base::TimeDelta::FromMilliseconds( | 168 base::TimeDelta::FromMilliseconds( |
| 167 kMediaInternalsProxyEventDelayMilliseconds)); | 169 kMediaInternalsProxyEventDelayMilliseconds)); |
| 168 } | 170 } |
| 169 pending_net_updates_->Append(entry); | 171 pending_net_updates_->Append(std::move(entry)); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void MediaInternalsProxy::SendNetEventsOnUIThread() { | 174 void MediaInternalsProxy::SendNetEventsOnUIThread() { |
| 173 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 175 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 174 CallJavaScriptFunctionOnUIThread("media.onNetUpdate", | 176 CallJavaScriptFunctionOnUIThread("media.onNetUpdate", |
| 175 pending_net_updates_.release()); | 177 pending_net_updates_.release()); |
| 176 } | 178 } |
| 177 | 179 |
| 178 void MediaInternalsProxy::CallJavaScriptFunctionOnUIThread( | 180 void MediaInternalsProxy::CallJavaScriptFunctionOnUIThread( |
| 179 const std::string& function, base::Value* args) { | 181 const std::string& function, base::Value* args) { |
| 180 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 182 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 181 std::unique_ptr<base::Value> args_value(args); | 183 std::unique_ptr<base::Value> args_value(args); |
| 182 std::vector<const base::Value*> args_vector; | 184 std::vector<const base::Value*> args_vector; |
| 183 args_vector.push_back(args_value.get()); | 185 args_vector.push_back(args_value.get()); |
| 184 base::string16 update = WebUI::GetJavascriptCall(function, args_vector); | 186 base::string16 update = WebUI::GetJavascriptCall(function, args_vector); |
| 185 UpdateUIOnUIThread(update); | 187 UpdateUIOnUIThread(update); |
| 186 } | 188 } |
| 187 | 189 |
| 188 } // namespace content | 190 } // namespace content |
| OLD | NEW |