| OLD | NEW |
| 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/media/media_internals.h" | 5 #include "chrome/browser/media/media_internals.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "chrome/browser/media/media_internals_observer.h" | 10 #include "chrome/browser/media/media_internals_observer.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/web_ui.h" | 12 #include "content/public/browser/web_ui.h" |
| 13 #include "media/base/media_log.h" | 13 #include "media/base/media_log.h" |
| 14 #include "media/base/media_log_event.h" | 14 #include "media/base/media_log_event.h" |
| 15 | 15 |
| 16 using content::BrowserThread; |
| 17 |
| 18 MediaInternals* MediaInternals::GetInstance() { |
| 19 return Singleton<MediaInternals>::get(); |
| 20 } |
| 21 |
| 16 MediaInternals::~MediaInternals() {} | 22 MediaInternals::~MediaInternals() {} |
| 17 | 23 |
| 18 void MediaInternals::OnDeleteAudioStream(void* host, int stream_id) { | 24 void MediaInternals::OnDeleteAudioStream(void* host, int stream_id) { |
| 19 DCHECK(CalledOnValidThread()); | 25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 20 std::string stream = base::StringPrintf("audio_streams.%p:%d", | 26 std::string stream = base::StringPrintf("audio_streams.%p:%d", |
| 21 host, stream_id); | 27 host, stream_id); |
| 22 DeleteItem(stream); | 28 DeleteItem(stream); |
| 23 } | 29 } |
| 24 | 30 |
| 25 void MediaInternals::OnSetAudioStreamPlaying( | 31 void MediaInternals::OnSetAudioStreamPlaying( |
| 26 void* host, int stream_id, bool playing) { | 32 void* host, int stream_id, bool playing) { |
| 27 DCHECK(CalledOnValidThread()); | 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 28 UpdateAudioStream(host, stream_id, | 34 UpdateAudioStream(host, stream_id, |
| 29 "playing", Value::CreateBooleanValue(playing)); | 35 "playing", Value::CreateBooleanValue(playing)); |
| 30 } | 36 } |
| 31 | 37 |
| 32 void MediaInternals::OnSetAudioStreamStatus( | 38 void MediaInternals::OnSetAudioStreamStatus( |
| 33 void* host, int stream_id, const std::string& status) { | 39 void* host, int stream_id, const std::string& status) { |
| 34 DCHECK(CalledOnValidThread()); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 35 UpdateAudioStream(host, stream_id, | 41 UpdateAudioStream(host, stream_id, |
| 36 "status", Value::CreateStringValue(status)); | 42 "status", Value::CreateStringValue(status)); |
| 37 } | 43 } |
| 38 | 44 |
| 39 void MediaInternals::OnSetAudioStreamVolume( | 45 void MediaInternals::OnSetAudioStreamVolume( |
| 40 void* host, int stream_id, double volume) { | 46 void* host, int stream_id, double volume) { |
| 41 DCHECK(CalledOnValidThread()); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 42 UpdateAudioStream(host, stream_id, | 48 UpdateAudioStream(host, stream_id, |
| 43 "volume", Value::CreateDoubleValue(volume)); | 49 "volume", Value::CreateDoubleValue(volume)); |
| 44 } | 50 } |
| 45 | 51 |
| 46 void MediaInternals::OnMediaEvent( | 52 void MediaInternals::OnMediaEvent( |
| 47 int render_process_id, const media::MediaLogEvent& event) { | 53 int render_process_id, const media::MediaLogEvent& event) { |
| 48 DCHECK(CalledOnValidThread()); | 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 49 | 55 |
| 50 // Notify observers that |event| has occured. | 56 // Notify observers that |event| has occured. |
| 51 DictionaryValue dict; | 57 DictionaryValue dict; |
| 52 dict.SetInteger("renderer", render_process_id); | 58 dict.SetInteger("renderer", render_process_id); |
| 53 dict.SetInteger("player", event.id); | 59 dict.SetInteger("player", event.id); |
| 54 dict.SetString("type", media::MediaLog::EventTypeToString(event.type)); | 60 dict.SetString("type", media::MediaLog::EventTypeToString(event.type)); |
| 55 dict.SetDouble("time", event.time.ToDoubleT()); | 61 dict.SetDouble("time", event.time.ToDoubleT()); |
| 56 dict.Set("params", event.params.DeepCopy()); | 62 dict.Set("params", event.params.DeepCopy()); |
| 57 SendUpdate("media.onMediaEvent", &dict); | 63 SendUpdate("media.onMediaEvent", &dict); |
| 58 } | 64 } |
| 59 | 65 |
| 60 void MediaInternals::AddObserver(MediaInternalsObserver* observer) { | 66 void MediaInternals::AddObserver(MediaInternalsObserver* observer) { |
| 61 DCHECK(CalledOnValidThread()); | 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 62 observers_.AddObserver(observer); | 68 observers_.AddObserver(observer); |
| 63 } | 69 } |
| 64 | 70 |
| 65 void MediaInternals::RemoveObserver(MediaInternalsObserver* observer) { | 71 void MediaInternals::RemoveObserver(MediaInternalsObserver* observer) { |
| 66 DCHECK(CalledOnValidThread()); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 67 observers_.RemoveObserver(observer); | 73 observers_.RemoveObserver(observer); |
| 68 } | 74 } |
| 69 | 75 |
| 70 void MediaInternals::SendEverything() { | 76 void MediaInternals::SendEverything() { |
| 71 DCHECK(CalledOnValidThread()); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 72 SendUpdate("media.onReceiveEverything", &data_); | 78 SendUpdate("media.onReceiveEverything", &data_); |
| 73 } | 79 } |
| 74 | 80 |
| 75 MediaInternals::MediaInternals() {} | 81 MediaInternals::MediaInternals() {} |
| 76 | 82 |
| 77 void MediaInternals::UpdateAudioStream( | 83 void MediaInternals::UpdateAudioStream( |
| 78 void* host, int stream_id, const std::string& property, Value* value) { | 84 void* host, int stream_id, const std::string& property, Value* value) { |
| 79 std::string stream = base::StringPrintf("audio_streams.%p:%d", | 85 std::string stream = base::StringPrintf("audio_streams.%p:%d", |
| 80 host, stream_id); | 86 host, stream_id); |
| 81 UpdateItem("media.addAudioStream", stream, property, value); | 87 UpdateItem("media.addAudioStream", stream, property, value); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 102 | 108 |
| 103 void MediaInternals::SendUpdate(const std::string& function, Value* value) { | 109 void MediaInternals::SendUpdate(const std::string& function, Value* value) { |
| 104 // Only bother serializing the update to JSON if someone is watching. | 110 // Only bother serializing the update to JSON if someone is watching. |
| 105 if (observers_.size()) { | 111 if (observers_.size()) { |
| 106 std::vector<const Value*> args; | 112 std::vector<const Value*> args; |
| 107 args.push_back(value); | 113 args.push_back(value); |
| 108 string16 update = content::WebUI::GetJavascriptCall(function, args); | 114 string16 update = content::WebUI::GetJavascriptCall(function, args); |
| 109 FOR_EACH_OBSERVER(MediaInternalsObserver, observers_, OnUpdate(update)); | 115 FOR_EACH_OBSERVER(MediaInternalsObserver, observers_, OnUpdate(update)); |
| 110 } | 116 } |
| 111 } | 117 } |
| OLD | NEW |