Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Unified Diff: chrome/browser/ui/webui/media_internals_ui.cc

Issue 7272036: Make MediaInternalsUI talk to MediaInternals. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/media_internals_ui.cc
diff --git a/chrome/browser/ui/webui/media_internals_ui.cc b/chrome/browser/ui/webui/media_internals_ui.cc
index de2f4227113effe68db6fbd58a91fd8c1faac324..161cdf6cb9584c93e2a918416d0254ac33935108 100644
--- a/chrome/browser/ui/webui/media_internals_ui.cc
+++ b/chrome/browser/ui/webui/media_internals_ui.cc
@@ -6,6 +6,9 @@
#include "base/memory/ref_counted_memory.h"
#include "base/values.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/io_thread.h"
+#include "chrome/browser/media/media_internals.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
@@ -71,6 +74,60 @@ std::string MediaInternalsHTMLSource::GetMimeType(
} // namespace
+////////////////////////////////////////////////////////////////////////////////
+//
+// MediaInternalsProxy
+//
+////////////////////////////////////////////////////////////////////////////////
+
+MediaInternalsProxy::MediaInternalsProxy() {
+ io_thread_ = g_browser_process->io_thread();
+};
+
+void MediaInternalsProxy::SetUI(MediaInternalsUI* ui) {
+ ui_ = ui;
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(this,
+ &MediaInternalsProxy::ObserveMediaInternalsOnIOThread));
+};
+
+void MediaInternalsProxy::RemoveUI() {
+ ui_ = NULL;
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(this,
+ &MediaInternalsProxy::StopObservingMediaInternalsOnIOThread));
+}
+
+void MediaInternalsProxy::GetEverything() {
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &MediaInternalsProxy::GetEverythingOnIOThread));
+}
+
+void MediaInternalsProxy::OnUpdate(const string16& update) {
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this,
+ &MediaInternalsProxy::UpdateUIOnUIThread, update));
+}
+
+MediaInternalsProxy::~MediaInternalsProxy() {}
+
+void MediaInternalsProxy::ObserveMediaInternalsOnIOThread() {
+ io_thread_->globals()->media.media_internals->AddUI(this);
+}
+
+void MediaInternalsProxy::StopObservingMediaInternalsOnIOThread() {
+ io_thread_->globals()->media.media_internals->RemoveUI(this);
+}
+
+void MediaInternalsProxy::GetEverythingOnIOThread() {
+ io_thread_->globals()->media.media_internals->SendEverything();
+}
+
+void MediaInternalsProxy::UpdateUIOnUIThread(const string16& update) {
+ // Don't forward updates to a destructed UI.
+ if (ui_)
+ ui_->OnUpdate(update);
+}
////////////////////////////////////////////////////////////////////////////////
//
@@ -79,8 +136,24 @@ std::string MediaInternalsHTMLSource::GetMimeType(
////////////////////////////////////////////////////////////////////////////////
MediaInternalsUI::MediaInternalsUI(TabContents* contents)
- : ChromeWebUI(contents) {
+ : ChromeWebUI(contents),
+ proxy_(new MediaInternalsProxy()){
contents->profile()->GetChromeURLDataManager()->AddDataSource(
new MediaInternalsHTMLSource());
+ proxy_->SetUI(this);
+}
+
+MediaInternalsUI::~MediaInternalsUI() {
+ proxy_->RemoveUI();
}
+void MediaInternalsUI::OnWebUISend(const GURL& source_url,
+ const std::string& name,
+ const ListValue& content) {
+ if (name == "getAll")
+ proxy_->GetEverything();
+}
+
+void MediaInternalsUI::OnUpdate(const string16& update) {
+ ExecuteJavascript(update);
+}
« chrome/browser/ui/webui/media_internals_ui.h ('K') | « chrome/browser/ui/webui/media_internals_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698