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 "device/power_save_blocker/power_save_blocker.h" | 21 #include "device/power_save_blocker/power_save_blocker.h" |
21 #include "ipc/ipc_platform_file.h" | 22 #include "ipc/ipc_platform_file.h" |
(...skipping 12 matching lines...) Expand all Loading... |
34 namespace content { | 35 namespace content { |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals = | 39 base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals = |
39 LAZY_INSTANCE_INITIALIZER; | 40 LAZY_INSTANCE_INITIALIZER; |
40 | 41 |
41 // Makes sure that |dict| has a ListValue under path "log". | 42 // Makes sure that |dict| has a ListValue under path "log". |
42 base::ListValue* EnsureLogList(base::DictionaryValue* dict) { | 43 base::ListValue* EnsureLogList(base::DictionaryValue* dict) { |
43 base::ListValue* log = NULL; | 44 base::ListValue* log = NULL; |
44 if (!dict->GetList("log", &log)) { | 45 if (!dict->GetList("log", &log)) |
45 log = new base::ListValue(); | 46 log = dict->SetList("log", base::MakeUnique<base::ListValue>()); |
46 dict->Set("log", log); | |
47 } | |
48 return log; | 47 return log; |
49 } | 48 } |
50 | 49 |
51 // Removes the log entry associated with a given record. | 50 // Removes the log entry associated with a given record. |
52 void FreeLogList(base::Value* value) { | 51 void FreeLogList(base::Value* value) { |
53 DCHECK(value->IsType(base::Value::Type::DICTIONARY)); | 52 DCHECK(value->IsType(base::Value::Type::DICTIONARY)); |
54 auto* dict = static_cast<base::DictionaryValue*>(value); | 53 auto* dict = static_cast<base::DictionaryValue*>(value); |
55 dict->Remove("log", nullptr); | 54 dict->Remove("log", nullptr); |
56 } | 55 } |
57 | 56 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 if (!record) | 180 if (!record) |
182 return; | 181 return; |
183 | 182 |
184 if (type == "stop") | 183 if (type == "stop") |
185 MaybeClosePeerConnection(record); | 184 MaybeClosePeerConnection(record); |
186 | 185 |
187 // Don't update entries if there aren't any observers. | 186 // Don't update entries if there aren't any observers. |
188 if (!observers_.might_have_observers()) | 187 if (!observers_.might_have_observers()) |
189 return; | 188 return; |
190 | 189 |
191 std::unique_ptr<base::DictionaryValue> log_entry(new base::DictionaryValue()); | 190 auto log_entry = base::MakeUnique<base::DictionaryValue>(); |
192 | 191 |
193 double epoch_time = base::Time::Now().ToJsTime(); | 192 double epoch_time = base::Time::Now().ToJsTime(); |
194 string time = base::DoubleToString(epoch_time); | 193 string time = base::DoubleToString(epoch_time); |
195 log_entry->SetString("time", time); | 194 log_entry->SetString("time", time); |
196 log_entry->SetString("type", type); | 195 log_entry->SetString("type", type); |
197 log_entry->SetString("value", value); | 196 log_entry->SetString("value", value); |
198 | 197 |
199 std::unique_ptr<base::DictionaryValue> update(new base::DictionaryValue()); | 198 auto update = base::MakeUnique<base::DictionaryValue>(); |
200 update->SetInteger("pid", static_cast<int>(pid)); | 199 update->SetInteger("pid", static_cast<int>(pid)); |
201 update->SetInteger("lid", lid); | 200 update->SetInteger("lid", lid); |
202 update->MergeDictionary(log_entry.get()); | 201 update->MergeDictionary(log_entry.get()); |
203 | 202 |
204 SendUpdate("updatePeerConnection", std::move(update)); | 203 SendUpdate("updatePeerConnection", std::move(update)); |
205 | 204 |
206 // Append the update to the end of the log. | 205 // Append the update to the end of the log. |
207 EnsureLogList(record)->Append(std::move(log_entry)); | 206 EnsureLogList(record)->Append(std::move(log_entry)); |
208 } | 207 } |
209 | 208 |
210 void WebRTCInternals::OnAddStats(base::ProcessId pid, int lid, | 209 void WebRTCInternals::OnAddStats(base::ProcessId pid, int lid, |
211 const base::ListValue& value) { | 210 const base::ListValue& value) { |
212 if (!observers_.might_have_observers()) | 211 if (!observers_.might_have_observers()) |
213 return; | 212 return; |
214 | 213 |
215 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 214 auto dict = base::MakeUnique<base::DictionaryValue>(); |
216 dict->SetInteger("pid", static_cast<int>(pid)); | 215 dict->SetInteger("pid", static_cast<int>(pid)); |
217 dict->SetInteger("lid", lid); | 216 dict->SetInteger("lid", lid); |
218 | 217 |
219 dict->Set("reports", value.CreateDeepCopy()); | 218 dict->Set("reports", base::MakeUnique<base::Value>(value)); |
220 | 219 |
221 SendUpdate("addStats", std::move(dict)); | 220 SendUpdate("addStats", std::move(dict)); |
222 } | 221 } |
223 | 222 |
224 void WebRTCInternals::OnGetUserMedia(int rid, | 223 void WebRTCInternals::OnGetUserMedia(int rid, |
225 base::ProcessId pid, | 224 base::ProcessId pid, |
226 const std::string& origin, | 225 const std::string& origin, |
227 bool audio, | 226 bool audio, |
228 bool video, | 227 bool video, |
229 const std::string& audio_constraints, | 228 const std::string& audio_constraints, |
230 const std::string& video_constraints) { | 229 const std::string& video_constraints) { |
231 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 230 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
232 | 231 |
233 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 232 auto dict = base::MakeUnique<base::DictionaryValue>(); |
234 dict->SetInteger("rid", rid); | 233 dict->SetInteger("rid", rid); |
235 dict->SetInteger("pid", static_cast<int>(pid)); | 234 dict->SetInteger("pid", static_cast<int>(pid)); |
236 dict->SetString("origin", origin); | 235 dict->SetString("origin", origin); |
237 if (audio) | 236 if (audio) |
238 dict->SetString("audio", audio_constraints); | 237 dict->SetString("audio", audio_constraints); |
239 if (video) | 238 if (video) |
240 dict->SetString("video", video_constraints); | 239 dict->SetString("video", video_constraints); |
241 | 240 |
242 if (observers_.might_have_observers()) | 241 if (observers_.might_have_observers()) |
243 SendUpdate("addGetUserMedia", dict->CreateDeepCopy()); | 242 SendUpdate("addGetUserMedia", dict->CreateDeepCopy()); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 | 583 |
585 if (this_pid == static_cast<int>(pid) && this_lid == lid) { | 584 if (this_pid == static_cast<int>(pid) && this_lid == lid) { |
586 if (index) | 585 if (index) |
587 *index = i; | 586 *index = i; |
588 return record; | 587 return record; |
589 } | 588 } |
590 } | 589 } |
591 return nullptr; | 590 return nullptr; |
592 } | 591 } |
593 } // namespace content | 592 } // namespace content |
OLD | NEW |