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

Side by Side Diff: content/browser/media/media_internals_proxy.cc

Issue 12153002: Move chrome://media-internals to content. This allows us to hide implementation details from the pu… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 10 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/media_internals_proxy.h" 5 #include "content/browser/media/media_internals_proxy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/browser_process.h" 8 #include "base/message_loop.h"
9 #include "chrome/browser/io_thread.h" 9 #include "content/browser/media/media_internals_handler.h"
10 #include "chrome/browser/media/media_internals.h" 10 #include "content/public/browser/content_browser_client.h"
11 #include "chrome/browser/net/chrome_net_log.h"
12 #include "chrome/browser/ui/webui/media/media_internals_handler.h"
13 #include "content/public/browser/notification_service.h" 11 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/notification_types.h" 12 #include "content/public/browser/notification_types.h"
15 #include "content/public/browser/render_process_host.h" 13 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/web_ui.h" 14 #include "content/public/browser/web_ui.h"
17 15
18 using content::BrowserThread; 16 namespace content {
19 17
20 static const int kMediaInternalsProxyEventDelayMilliseconds = 100; 18 static const int kMediaInternalsProxyEventDelayMilliseconds = 100;
21 19
22 static const net::NetLog::EventType kNetEventTypeFilter[] = { 20 static const net::NetLog::EventType kNetEventTypeFilter[] = {
23 net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, 21 net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL,
24 net::NetLog::TYPE_SPARSE_READ, 22 net::NetLog::TYPE_SPARSE_READ,
25 net::NetLog::TYPE_SPARSE_WRITE, 23 net::NetLog::TYPE_SPARSE_WRITE,
26 net::NetLog::TYPE_URL_REQUEST_START_JOB, 24 net::NetLog::TYPE_URL_REQUEST_START_JOB,
27 net::NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, 25 net::NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS,
28 }; 26 };
29 27
30 MediaInternalsProxy::MediaInternalsProxy() { 28 MediaInternalsProxy::MediaInternalsProxy() {
31 io_thread_ = g_browser_process->io_thread(); 29 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED,
32 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 30 NotificationService::AllBrowserContextsAndSources());
33 content::NotificationService::AllBrowserContextsAndSources());
34 } 31 }
35 32
36 void MediaInternalsProxy::Observe(int type, 33 void MediaInternalsProxy::Observe(int type,
37 const content::NotificationSource& source, 34 const NotificationSource& source,
38 const content::NotificationDetails& details) { 35 const NotificationDetails& details) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40 DCHECK_EQ(type, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); 37 DCHECK_EQ(type, NOTIFICATION_RENDERER_PROCESS_TERMINATED);
41 content::RenderProcessHost* process = 38 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr();
42 content::Source<content::RenderProcessHost>(source).ptr();
43 CallJavaScriptFunctionOnUIThread("media.onRendererTerminated", 39 CallJavaScriptFunctionOnUIThread("media.onRendererTerminated",
44 base::Value::CreateIntegerValue(process->GetID())); 40 base::Value::CreateIntegerValue(process->GetID()));
45 } 41 }
46 42
47 void MediaInternalsProxy::Attach(MediaInternalsMessageHandler* handler) { 43 void MediaInternalsProxy::Attach(MediaInternalsMessageHandler* handler) {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49 handler_ = handler; 45 handler_ = handler;
50 BrowserThread::PostTask( 46 BrowserThread::PostTask(
51 BrowserThread::IO, FROM_HERE, 47 BrowserThread::IO, FROM_HERE,
52 base::Bind(&MediaInternalsProxy::ObserveMediaInternalsOnIOThread, this)); 48 base::Bind(&MediaInternalsProxy::ObserveMediaInternalsOnIOThread, this));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 110
115 DictionaryValue* constants = new DictionaryValue(); 111 DictionaryValue* constants = new DictionaryValue();
116 constants->Set("eventTypes", net::NetLog::GetEventTypesAsValue()); 112 constants->Set("eventTypes", net::NetLog::GetEventTypesAsValue());
117 constants->Set("eventPhases", event_phases); 113 constants->Set("eventPhases", event_phases);
118 114
119 return constants; 115 return constants;
120 } 116 }
121 117
122 void MediaInternalsProxy::ObserveMediaInternalsOnIOThread() { 118 void MediaInternalsProxy::ObserveMediaInternalsOnIOThread() {
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
124 MediaInternals::GetInstance()->AddObserver(this); 120 update_callback_ = base::Bind(&MediaInternalsProxy::OnUpdate,
125 io_thread_->net_log()->AddThreadSafeObserver(this, 121 base::Unretained(this));
126 net::NetLog::LOG_ALL_BUT_BYTES); 122 MediaInternals::GetInstance()->AddUpdateCallback(update_callback_);
123 if (GetContentClient()->browser()->GetNetLog()) {
124 net::NetLog* net_log = GetContentClient()->browser()->GetNetLog();
125 net_log->AddThreadSafeObserver(this, net::NetLog::LOG_ALL_BUT_BYTES);
126 }
127 } 127 }
128 128
129 void MediaInternalsProxy::StopObservingMediaInternalsOnIOThread() { 129 void MediaInternalsProxy::StopObservingMediaInternalsOnIOThread() {
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
131 MediaInternals::GetInstance()->RemoveObserver(this); 131 MediaInternals::GetInstance()->RemoveUpdateCallback(update_callback_);
132 io_thread_->net_log()->RemoveThreadSafeObserver(this); 132 if (GetContentClient()->browser()->GetNetLog()) {
133 net::NetLog* net_log = GetContentClient()->browser()->GetNetLog();
134 net_log->RemoveThreadSafeObserver(this);
135 }
133 } 136 }
134 137
135 void MediaInternalsProxy::GetEverythingOnIOThread() { 138 void MediaInternalsProxy::GetEverythingOnIOThread() {
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
137 MediaInternals::GetInstance()->SendEverything(); 140 MediaInternals::GetInstance()->SendEverything();
138 } 141 }
139 142
140 void MediaInternalsProxy::UpdateUIOnUIThread(const string16& update) { 143 void MediaInternalsProxy::UpdateUIOnUIThread(const string16& update) {
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
142 // Don't forward updates to a destructed UI. 145 // Don't forward updates to a destructed UI.
(...skipping 23 matching lines...) Expand all
166 CallJavaScriptFunctionOnUIThread("media.onNetUpdate", 169 CallJavaScriptFunctionOnUIThread("media.onNetUpdate",
167 pending_net_updates_.release()); 170 pending_net_updates_.release());
168 } 171 }
169 172
170 void MediaInternalsProxy::CallJavaScriptFunctionOnUIThread( 173 void MediaInternalsProxy::CallJavaScriptFunctionOnUIThread(
171 const std::string& function, Value* args) { 174 const std::string& function, Value* args) {
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
173 scoped_ptr<Value> args_value(args); 176 scoped_ptr<Value> args_value(args);
174 std::vector<const Value*> args_vector; 177 std::vector<const Value*> args_vector;
175 args_vector.push_back(args_value.get()); 178 args_vector.push_back(args_value.get());
176 string16 update = content::WebUI::GetJavascriptCall(function, args_vector); 179 string16 update = WebUI::GetJavascriptCall(function, args_vector);
177 UpdateUIOnUIThread(update); 180 UpdateUIOnUIThread(update);
178 } 181 }
182
183 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698