Chromium Code Reviews| Index: chrome/browser/media/chrome_webrtc_internals.cc |
| diff --git a/chrome/browser/media/chrome_webrtc_internals.cc b/chrome/browser/media/chrome_webrtc_internals.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e9731d232ea9d8f3a4c48454d7a64c3f8aa776ff |
| --- /dev/null |
| +++ b/chrome/browser/media/chrome_webrtc_internals.cc |
| @@ -0,0 +1,92 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/media/chrome_webrtc_internals.h" |
| + |
| +#include "chrome/browser/media/webrtc_internals_ui_observer.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +using base::DictionaryValue; |
| +using base::ProcessId; |
| +using content::BrowserThread; |
| +using std::string; |
| + |
| +ChromeWebRTCInternals::ChromeWebRTCInternals() { |
| +} |
| + |
| +ChromeWebRTCInternals::~ChromeWebRTCInternals() { |
| +} |
| + |
| +ChromeWebRTCInternals* ChromeWebRTCInternals::GetInstance() { |
| + return Singleton<ChromeWebRTCInternals>::get(); |
| +} |
| + |
| +void ChromeWebRTCInternals::AddPeerConnection(ProcessId pid, |
| + int lid, |
| + const string& url, |
| + const string& servers, |
| + const string& constraints) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + if (observers_.size()) { |
|
jam
2013/01/18 22:23:45
nit: early return here
jiayl
2013/01/18 22:39:51
I moved the check into SendUpdate and return early
jam
2013/01/18 22:52:01
why do this work when webrtc webui page isn't show
jiayl
2013/01/18 22:59:06
It's for sending the cached updates to a webrtc-in
jam
2013/01/22 07:03:13
i'm not sure i follow. what i mean is that this fu
|
| + DictionaryValue* dict = new DictionaryValue(); |
| + if (!dict) |
| + return; |
| + |
| + dict->SetInteger("pid", static_cast<int>(pid)); |
| + dict->SetInteger("lid", lid); |
| + dict->SetString("servers", servers); |
| + dict->SetString("constraints", constraints); |
| + dict->SetString("url", url); |
| + |
| + SendUpdate("addPeerConnection", dict); |
| + peer_connection_data_.Append(dict); |
| + } |
| +} |
| + |
| +void ChromeWebRTCInternals::RemovePeerConnection(ProcessId pid, int lid) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + if (observers_.size()) { |
|
jam
2013/01/18 22:23:45
ditto
jiayl
2013/01/18 22:39:51
Done.
|
| + for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { |
| + DictionaryValue* dict = NULL; |
| + peer_connection_data_.GetDictionary(i, &dict); |
| + |
| + int this_pid = 0; |
| + int this_lid = 0; |
| + dict->GetInteger("pid", &this_pid); |
| + dict->GetInteger("lid", &this_lid); |
| + |
| + if (this_pid != static_cast<int>(pid) || this_lid != lid) |
| + continue; |
| + |
| + peer_connection_data_.Remove(i, NULL); |
| + |
| + DictionaryValue id; |
| + id.SetInteger("pid", static_cast<int>(pid)); |
| + id.SetInteger("lid", lid); |
| + SendUpdate("removePeerConnection", &id); |
| + |
| + return; |
| + } |
| + } |
| +} |
| + |
| +void ChromeWebRTCInternals::AddObserver( |
| + WebRTCInternalsUIObserver *observer) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + observers_.AddObserver(observer); |
| +} |
| + |
| +void ChromeWebRTCInternals::RemoveObserver( |
| + WebRTCInternalsUIObserver *observer) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| +void ChromeWebRTCInternals::SendUpdate(const string& command, Value* value) { |
| + DCHECK(observers_.size()); |
| + |
| + FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
| + observers_, |
| + OnUpdate(command, value)); |
| +} |