OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/webrtc/webrtc_internals.h" | 5 #include "content/browser/webrtc/webrtc_internals.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
| 12 #include "base/memory/ptr_util.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "content/browser/renderer_host/render_process_host_impl.h" | 15 #include "content/browser/renderer_host/render_process_host_impl.h" |
15 #include "content/browser/web_contents/web_contents_view.h" | 16 #include "content/browser/web_contents/web_contents_view.h" |
16 #include "content/browser/webrtc/webrtc_internals_ui_observer.h" | 17 #include "content/browser/webrtc/webrtc_internals_ui_observer.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 #include "content/public/common/service_manager_connection.h" | 21 #include "content/public/common/service_manager_connection.h" |
21 #include "device/wake_lock/public/interfaces/wake_lock_provider.mojom.h" | 22 #include "device/wake_lock/public/interfaces/wake_lock_provider.mojom.h" |
(...skipping 15 matching lines...) Expand all Loading... |
37 namespace content { | 38 namespace content { |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals = | 42 base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals = |
42 LAZY_INSTANCE_INITIALIZER; | 43 LAZY_INSTANCE_INITIALIZER; |
43 | 44 |
44 // Makes sure that |dict| has a ListValue under path "log". | 45 // Makes sure that |dict| has a ListValue under path "log". |
45 base::ListValue* EnsureLogList(base::DictionaryValue* dict) { | 46 base::ListValue* EnsureLogList(base::DictionaryValue* dict) { |
46 base::ListValue* log = NULL; | 47 base::ListValue* log = NULL; |
47 if (!dict->GetList("log", &log)) { | 48 if (!dict->GetList("log", &log)) |
48 log = new base::ListValue(); | 49 log = dict->SetList("log", base::MakeUnique<base::ListValue>()); |
49 dict->Set("log", log); | |
50 } | |
51 return log; | 50 return log; |
52 } | 51 } |
53 | 52 |
54 // Removes the log entry associated with a given record. | 53 // Removes the log entry associated with a given record. |
55 void FreeLogList(base::Value* value) { | 54 void FreeLogList(base::Value* value) { |
56 DCHECK(value->IsType(base::Value::Type::DICTIONARY)); | 55 DCHECK(value->IsType(base::Value::Type::DICTIONARY)); |
57 auto* dict = static_cast<base::DictionaryValue*>(value); | 56 auto* dict = static_cast<base::DictionaryValue*>(value); |
58 dict->Remove("log", nullptr); | 57 dict->Remove("log", nullptr); |
59 } | 58 } |
60 | 59 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 if (!record) | 183 if (!record) |
185 return; | 184 return; |
186 | 185 |
187 if (type == "stop") | 186 if (type == "stop") |
188 MaybeClosePeerConnection(record); | 187 MaybeClosePeerConnection(record); |
189 | 188 |
190 // Don't update entries if there aren't any observers. | 189 // Don't update entries if there aren't any observers. |
191 if (!observers_.might_have_observers()) | 190 if (!observers_.might_have_observers()) |
192 return; | 191 return; |
193 | 192 |
194 std::unique_ptr<base::DictionaryValue> log_entry(new base::DictionaryValue()); | 193 auto log_entry = base::MakeUnique<base::DictionaryValue>(); |
195 | 194 |
196 double epoch_time = base::Time::Now().ToJsTime(); | 195 double epoch_time = base::Time::Now().ToJsTime(); |
197 string time = base::DoubleToString(epoch_time); | 196 string time = base::DoubleToString(epoch_time); |
198 log_entry->SetString("time", time); | 197 log_entry->SetString("time", time); |
199 log_entry->SetString("type", type); | 198 log_entry->SetString("type", type); |
200 log_entry->SetString("value", value); | 199 log_entry->SetString("value", value); |
201 | 200 |
202 std::unique_ptr<base::DictionaryValue> update(new base::DictionaryValue()); | 201 auto update = base::MakeUnique<base::DictionaryValue>(); |
203 update->SetInteger("pid", static_cast<int>(pid)); | 202 update->SetInteger("pid", static_cast<int>(pid)); |
204 update->SetInteger("lid", lid); | 203 update->SetInteger("lid", lid); |
205 update->MergeDictionary(log_entry.get()); | 204 update->MergeDictionary(log_entry.get()); |
206 | 205 |
207 SendUpdate("updatePeerConnection", std::move(update)); | 206 SendUpdate("updatePeerConnection", std::move(update)); |
208 | 207 |
209 // Append the update to the end of the log. | 208 // Append the update to the end of the log. |
210 EnsureLogList(record)->Append(std::move(log_entry)); | 209 EnsureLogList(record)->Append(std::move(log_entry)); |
211 } | 210 } |
212 | 211 |
213 void WebRTCInternals::OnAddStats(base::ProcessId pid, int lid, | 212 void WebRTCInternals::OnAddStats(base::ProcessId pid, int lid, |
214 const base::ListValue& value) { | 213 const base::ListValue& value) { |
215 if (!observers_.might_have_observers()) | 214 if (!observers_.might_have_observers()) |
216 return; | 215 return; |
217 | 216 |
218 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 217 auto dict = base::MakeUnique<base::DictionaryValue>(); |
219 dict->SetInteger("pid", static_cast<int>(pid)); | 218 dict->SetInteger("pid", static_cast<int>(pid)); |
220 dict->SetInteger("lid", lid); | 219 dict->SetInteger("lid", lid); |
221 | 220 |
222 dict->Set("reports", value.CreateDeepCopy()); | 221 dict->Set("reports", base::MakeUnique<base::Value>(value)); |
223 | 222 |
224 SendUpdate("addStats", std::move(dict)); | 223 SendUpdate("addStats", std::move(dict)); |
225 } | 224 } |
226 | 225 |
227 void WebRTCInternals::OnGetUserMedia(int rid, | 226 void WebRTCInternals::OnGetUserMedia(int rid, |
228 base::ProcessId pid, | 227 base::ProcessId pid, |
229 const std::string& origin, | 228 const std::string& origin, |
230 bool audio, | 229 bool audio, |
231 bool video, | 230 bool video, |
232 const std::string& audio_constraints, | 231 const std::string& audio_constraints, |
233 const std::string& video_constraints) { | 232 const std::string& video_constraints) { |
234 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 233 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
235 | 234 |
236 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 235 auto dict = base::MakeUnique<base::DictionaryValue>(); |
237 dict->SetInteger("rid", rid); | 236 dict->SetInteger("rid", rid); |
238 dict->SetInteger("pid", static_cast<int>(pid)); | 237 dict->SetInteger("pid", static_cast<int>(pid)); |
239 dict->SetString("origin", origin); | 238 dict->SetString("origin", origin); |
240 if (audio) | 239 if (audio) |
241 dict->SetString("audio", audio_constraints); | 240 dict->SetString("audio", audio_constraints); |
242 if (video) | 241 if (video) |
243 dict->SetString("video", video_constraints); | 242 dict->SetString("video", video_constraints); |
244 | 243 |
245 if (observers_.might_have_observers()) | 244 if (observers_.might_have_observers()) |
246 SendUpdate("addGetUserMedia", dict->CreateDeepCopy()); | 245 SendUpdate("addGetUserMedia", dict->CreateDeepCopy()); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 605 |
607 if (this_pid == static_cast<int>(pid) && this_lid == lid) { | 606 if (this_pid == static_cast<int>(pid) && this_lid == lid) { |
608 if (index) | 607 if (index) |
609 *index = i; | 608 *index = i; |
610 return record; | 609 return record; |
611 } | 610 } |
612 } | 611 } |
613 return nullptr; | 612 return nullptr; |
614 } | 613 } |
615 } // namespace content | 614 } // namespace content |
OLD | NEW |