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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/webui/media_internals_ui.h" 5 #include "chrome/browser/ui/webui/media_internals_ui.h"
6 6
7 #include "base/memory/ref_counted_memory.h" 7 #include "base/memory/ref_counted_memory.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/io_thread.h"
11 #include "chrome/browser/media/media_internals.h"
9 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
11 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
12 #include "chrome/common/jstemplate_builder.h" 15 #include "chrome/common/jstemplate_builder.h"
13 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
14 #include "grit/browser_resources.h" 17 #include "grit/browser_resources.h"
15 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
16 19
17 namespace { 20 namespace {
18 21
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 SendResponse(request_id, bytes); 67 SendResponse(request_id, bytes);
65 } 68 }
66 69
67 std::string MediaInternalsHTMLSource::GetMimeType( 70 std::string MediaInternalsHTMLSource::GetMimeType(
68 const std::string& path) const { 71 const std::string& path) const {
69 return "text/html"; 72 return "text/html";
70 } 73 }
71 74
72 } // namespace 75 } // namespace
73 76
77 ////////////////////////////////////////////////////////////////////////////////
78 //
79 // MediaInternalsProxy
80 //
81 ////////////////////////////////////////////////////////////////////////////////
82
83 MediaInternalsProxy::MediaInternalsProxy() {
84 io_thread_ = g_browser_process->io_thread();
85 };
86
87 void MediaInternalsProxy::SetUI(MediaInternalsUI* ui) {
88 ui_ = ui;
89 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
90 NewRunnableMethod(this,
91 &MediaInternalsProxy::ObserveMediaInternalsOnIOThread));
92 };
93
94 void MediaInternalsProxy::RemoveUI() {
95 ui_ = NULL;
96 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
97 NewRunnableMethod(this,
98 &MediaInternalsProxy::StopObservingMediaInternalsOnIOThread));
99 }
100
101 void MediaInternalsProxy::GetEverything() {
102 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
103 NewRunnableMethod(this, &MediaInternalsProxy::GetEverythingOnIOThread));
104 }
105
106 void MediaInternalsProxy::OnUpdate(const string16& update) {
107 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
108 NewRunnableMethod(this,
109 &MediaInternalsProxy::UpdateUIOnUIThread, update));
110 }
111
112 MediaInternalsProxy::~MediaInternalsProxy() {}
113
114 void MediaInternalsProxy::ObserveMediaInternalsOnIOThread() {
115 io_thread_->globals()->media.media_internals->AddUI(this);
116 }
117
118 void MediaInternalsProxy::StopObservingMediaInternalsOnIOThread() {
119 io_thread_->globals()->media.media_internals->RemoveUI(this);
120 }
121
122 void MediaInternalsProxy::GetEverythingOnIOThread() {
123 io_thread_->globals()->media.media_internals->SendEverything();
124 }
125
126 void MediaInternalsProxy::UpdateUIOnUIThread(const string16& update) {
127 // Don't forward updates to a destructed UI.
128 if (ui_)
129 ui_->OnUpdate(update);
130 }
74 131
75 //////////////////////////////////////////////////////////////////////////////// 132 ////////////////////////////////////////////////////////////////////////////////
76 // 133 //
77 // MediaInternalsUI 134 // MediaInternalsUI
78 // 135 //
79 //////////////////////////////////////////////////////////////////////////////// 136 ////////////////////////////////////////////////////////////////////////////////
80 137
81 MediaInternalsUI::MediaInternalsUI(TabContents* contents) 138 MediaInternalsUI::MediaInternalsUI(TabContents* contents)
82 : ChromeWebUI(contents) { 139 : ChromeWebUI(contents),
140 proxy_(new MediaInternalsProxy()){
83 contents->profile()->GetChromeURLDataManager()->AddDataSource( 141 contents->profile()->GetChromeURLDataManager()->AddDataSource(
84 new MediaInternalsHTMLSource()); 142 new MediaInternalsHTMLSource());
143 proxy_->SetUI(this);
85 } 144 }
86 145
146 MediaInternalsUI::~MediaInternalsUI() {
147 proxy_->RemoveUI();
148 }
149
150 void MediaInternalsUI::OnWebUISend(const GURL& source_url,
151 const std::string& name,
152 const ListValue& content) {
153 if (name == "getAll")
154 proxy_->GetEverything();
155 }
156
157 void MediaInternalsUI::OnUpdate(const string16& update) {
158 ExecuteJavascript(update);
159 }
OLDNEW
« 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