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