Index: chrome/browser/media/media_internals.cc |
diff --git a/chrome/browser/media/media_internals.cc b/chrome/browser/media/media_internals.cc |
index a563db36f399cb951e392e9e7aec3ae7cd0589f9..913146cb6cda881c77f7e072b57f2ba7645b1709 100644 |
--- a/chrome/browser/media/media_internals.cc |
+++ b/chrome/browser/media/media_internals.cc |
@@ -10,11 +10,14 @@ |
#include "chrome/browser/media/media_internals_observer.h" |
#include "content/browser/browser_thread.h" |
#include "content/browser/webui/web_ui.h" |
+#include "media/base/media_log.h" |
#include "media/base/media_log_event.h" |
// The names of the javascript functions to call with updates. |
-static const char kDeleteItemFunction[] = "media.onItemDeleted"; |
static const char kAudioUpdateFunction[] = "media.addAudioStream"; |
+static const char kDeleteItemFunction[] = "media.onItemDeleted"; |
+static const char kMediaEventFunction[] = "media.onMediaEvent"; |
+static const char kMediaPlayerUpdateFunction[] = "media.addMediaPlayer"; |
static const char kSendEverythingFunction[] = "media.onReceiveEverything"; |
MediaInternals::~MediaInternals() {} |
@@ -50,8 +53,41 @@ void MediaInternals::OnSetAudioStreamVolume( |
void MediaInternals::OnMediaEvent( |
int render_process_id, const media::MediaLogEvent& event) { |
DCHECK(CalledOnValidThread()); |
- // TODO(scottfr): Handle |event|. Record status information in data_ and pass |
- // |event| along to observers. |
+ std::string source = base::StringPrintf("media_players.%d.%d", |
+ render_process_id, event.id); |
+ |
+ // Notify observers that |event| has occured. |
+ DictionaryValue dict; |
+ dict.SetString("source", source); |
+ dict.SetString("type", media::MediaLog::EventTypeToString(event.type)); |
+ dict.SetDouble("time", event.time.ToDoubleT()); |
+ dict.Set("params", event.params.DeepCopy()); |
+ SendUpdate(kMediaEventFunction, &dict); |
+ |
+ // Handle parameterless events specially, but otherwise just add parameters |
+ // to this.details_ and send an updated property list to any obsevers. |
scherkus (not reviewing)
2011/08/10 16:00:37
ack should have clarified my comment
I don't see
Scott Franklin
2011/08/10 22:26:51
oh wow, s/details_/data_/. I imagine it would be h
|
+ switch (event.type) { |
+ case media::MediaLogEvent::WEBMEDIAPLAYER_CREATED: |
+ SetItemProperty(kMediaPlayerUpdateFunction, source, "player_state", |
+ base::Value::CreateStringValue("created")); |
+ break; |
+ case media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED: |
+ SetItemProperty(kMediaPlayerUpdateFunction, source, "player_state", |
+ base::Value::CreateStringValue("destroyed")); |
+ break; |
+ case media::MediaLogEvent::PLAY: |
+ SetItemProperty(kMediaPlayerUpdateFunction, source, "player_state", |
+ base::Value::CreateStringValue("playing")); |
+ break; |
+ case media::MediaLogEvent::PAUSE: |
+ SetItemProperty(kMediaPlayerUpdateFunction, source, "player_state", |
+ base::Value::CreateStringValue("paused")); |
+ break; |
+ default: |
+ SetItemProperties(kMediaPlayerUpdateFunction, source, |
+ event.params.DeepCopy()); |
+ break; |
+ } |
} |
void MediaInternals::AddObserver(MediaInternalsObserver* observer) { |
@@ -75,7 +111,7 @@ void MediaInternals::UpdateAudioStream( |
void* host, int stream_id, const std::string& property, Value* value) { |
std::string stream = base::StringPrintf("audio_streams.%p:%d", |
host, stream_id); |
- UpdateItem(kAudioUpdateFunction, stream, property, value); |
+ SetItemProperty(kAudioUpdateFunction, stream, property, value); |
} |
void MediaInternals::DeleteItem(const std::string& item) { |
@@ -84,16 +120,24 @@ void MediaInternals::DeleteItem(const std::string& item) { |
SendUpdate(kDeleteItemFunction, value.get()); |
} |
-void MediaInternals::UpdateItem( |
+void MediaInternals::SetItemProperty( |
const std::string& update_fn, const std::string& id, |
const std::string& property, Value* value) { |
+ DictionaryValue* properties = new DictionaryValue(); |
+ properties->Set(property, value); |
+ SetItemProperties(update_fn, id, properties); |
+} |
+ |
+void MediaInternals::SetItemProperties( |
+ const std::string& update_fn, const std::string& id, |
+ DictionaryValue* properties) { |
DictionaryValue* item_properties; |
if (!data_.GetDictionary(id, &item_properties)) { |
item_properties = new DictionaryValue(); |
data_.Set(id, item_properties); |
item_properties->SetString("id", id); |
} |
- item_properties->Set(property, value); |
+ item_properties->MergeDictionary(properties); |
SendUpdate(update_fn, item_properties); |
} |