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

Side by Side Diff: chrome/browser/media/media_internals.cc

Issue 7602021: Make MediaInternals handle MediaLogEvents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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/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/browser/browser_thread.h" 11 #include "content/browser/browser_thread.h"
12 #include "content/browser/webui/web_ui.h" 12 #include "content/browser/webui/web_ui.h"
13 #include "media/base/media_log.h"
13 #include "media/base/media_log_event.h" 14 #include "media/base/media_log_event.h"
14 15
15 // The names of the javascript functions to call with updates. 16 // The names of the javascript functions to call with updates.
17 static const char kAudioUpdateFunction[] = "media.addAudioStream";
16 static const char kDeleteItemFunction[] = "media.onItemDeleted"; 18 static const char kDeleteItemFunction[] = "media.onItemDeleted";
17 static const char kAudioUpdateFunction[] = "media.addAudioStream"; 19 static const char kMediaEventFunction[] = "media.onMediaEvent";
20 static const char kMediaUpdateFunction[] = "media.addMediaPlayer";
18 static const char kSendEverythingFunction[] = "media.onReceiveEverything"; 21 static const char kSendEverythingFunction[] = "media.onReceiveEverything";
19 22
20 MediaInternals::~MediaInternals() {} 23 MediaInternals::~MediaInternals() {}
21 24
22 void MediaInternals::OnDeleteAudioStream(void* host, int stream_id) { 25 void MediaInternals::OnDeleteAudioStream(void* host, int stream_id) {
23 DCHECK(CalledOnValidThread()); 26 DCHECK(CalledOnValidThread());
24 std::string stream = base::StringPrintf("audio_streams.%p:%d", 27 std::string stream = base::StringPrintf("audio_streams.%p:%d",
25 host, stream_id); 28 host, stream_id);
26 DeleteItem(stream); 29 DeleteItem(stream);
27 } 30 }
(...skipping 15 matching lines...) Expand all
43 void MediaInternals::OnSetAudioStreamVolume( 46 void MediaInternals::OnSetAudioStreamVolume(
44 void* host, int stream_id, double volume) { 47 void* host, int stream_id, double volume) {
45 DCHECK(CalledOnValidThread()); 48 DCHECK(CalledOnValidThread());
46 UpdateAudioStream(host, stream_id, 49 UpdateAudioStream(host, stream_id,
47 "volume", Value::CreateDoubleValue(volume)); 50 "volume", Value::CreateDoubleValue(volume));
48 } 51 }
49 52
50 void MediaInternals::OnMediaEvent( 53 void MediaInternals::OnMediaEvent(
51 int render_process_id, const media::MediaLogEvent& event) { 54 int render_process_id, const media::MediaLogEvent& event) {
52 DCHECK(CalledOnValidThread()); 55 DCHECK(CalledOnValidThread());
53 // TODO(scottfr): Handle |event|. Record status information in data_ and pass 56 std::string source= base::StringPrintf("media_players.%d.%d",
scherkus (not reviewing) 2011/08/09 20:41:10 space before =
Scott Franklin 2011/08/09 23:33:39 Done.
54 // |event| along to observers. 57 render_process_id, event.id);
58
59 // Notify observers that |event| has occured.
60 DictionaryValue dict;
61 dict.SetString("source", source);
62 dict.SetString("type", media::MediaLog::EventTypeToString(event.type));
63 dict.SetDouble("time", event.time.ToDoubleT());
64 dict.Set("params", event.params.DeepCopy());
65 SendUpdate(kMediaEventFunction, &dict);
66
67 // Handle parameterless events specially, but otherwise just add parameters
68 // to this.details_ and send it off to any obsevers.
scherkus (not reviewing) 2011/08/09 20:41:10 this.details_ ?
Scott Franklin 2011/08/09 23:33:39 Done.
69 switch (event.type) {
70 case media::MediaLogEvent::WEBMEDIAPLAYER_CREATED:
71 SetItemProperty(kMediaUpdateFunction, source, "player_state",
72 base::Value::CreateStringValue("creating"));
scherkus (not reviewing) 2011/08/09 20:41:10 creating vs created?
Scott Franklin 2011/08/09 23:33:39 Done.
73 break;
74 case media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED:
75 SetItemProperty(kMediaUpdateFunction, source, "player_state",
76 base::Value::CreateStringValue("destroyed"));
77 break;
78 case media::MediaLogEvent::PLAY:
79 SetItemProperty(kMediaUpdateFunction, source, "player_state",
80 base::Value::CreateStringValue("playing"));
81 break;
82 case media::MediaLogEvent::PAUSE:
83 SetItemProperty(kMediaUpdateFunction, source, "player_state",
84 base::Value::CreateStringValue("paused"));
85 break;
86 default:
87 SetItemProperties(kMediaUpdateFunction, source, event.params.DeepCopy());
scherkus (not reviewing) 2011/08/09 20:41:10 what's the difference between kMediaEventFunction
Scott Franklin 2011/08/09 23:33:39 Yes, it could (and I meant to leave a note to that
scherkus (not reviewing) 2011/08/10 16:00:37 Similar to web inspector we can only log+display e
Scott Franklin 2011/08/10 22:26:51 Huh? web inspector shows everything. I think Java
88 break;
89 }
55 } 90 }
56 91
57 void MediaInternals::AddObserver(MediaInternalsObserver* observer) { 92 void MediaInternals::AddObserver(MediaInternalsObserver* observer) {
58 DCHECK(CalledOnValidThread()); 93 DCHECK(CalledOnValidThread());
59 observers_.AddObserver(observer); 94 observers_.AddObserver(observer);
60 } 95 }
61 96
62 void MediaInternals::RemoveObserver(MediaInternalsObserver* observer) { 97 void MediaInternals::RemoveObserver(MediaInternalsObserver* observer) {
63 DCHECK(CalledOnValidThread()); 98 DCHECK(CalledOnValidThread());
64 observers_.RemoveObserver(observer); 99 observers_.RemoveObserver(observer);
65 } 100 }
66 101
67 void MediaInternals::SendEverything() { 102 void MediaInternals::SendEverything() {
68 DCHECK(CalledOnValidThread()); 103 DCHECK(CalledOnValidThread());
69 SendUpdate(kSendEverythingFunction, &data_); 104 SendUpdate(kSendEverythingFunction, &data_);
70 } 105 }
71 106
72 MediaInternals::MediaInternals() {} 107 MediaInternals::MediaInternals() {}
73 108
74 void MediaInternals::UpdateAudioStream( 109 void MediaInternals::UpdateAudioStream(
75 void* host, int stream_id, const std::string& property, Value* value) { 110 void* host, int stream_id, const std::string& property, Value* value) {
76 std::string stream = base::StringPrintf("audio_streams.%p:%d", 111 std::string stream = base::StringPrintf("audio_streams.%p:%d",
77 host, stream_id); 112 host, stream_id);
78 UpdateItem(kAudioUpdateFunction, stream, property, value); 113 SetItemProperty(kAudioUpdateFunction, stream, property, value);
79 } 114 }
80 115
81 void MediaInternals::DeleteItem(const std::string& item) { 116 void MediaInternals::DeleteItem(const std::string& item) {
82 data_.Remove(item, NULL); 117 data_.Remove(item, NULL);
83 scoped_ptr<Value> value(Value::CreateStringValue(item)); 118 scoped_ptr<Value> value(Value::CreateStringValue(item));
84 SendUpdate(kDeleteItemFunction, value.get()); 119 SendUpdate(kDeleteItemFunction, value.get());
85 } 120 }
86 121
87 void MediaInternals::UpdateItem( 122 void MediaInternals::SetItemProperty(
88 const std::string& update_fn, const std::string& id, 123 const std::string& update_fn, const std::string& id,
89 const std::string& property, Value* value) { 124 const std::string& property, Value* value) {
125 DictionaryValue* properties = new DictionaryValue();
126 properties->Set(property, value);
127 SetItemProperties(update_fn, id, properties);
128 }
129
130 void MediaInternals::SetItemProperties(
131 const std::string& update_fn, const std::string& id,
132 DictionaryValue* properties) {
90 DictionaryValue* item_properties; 133 DictionaryValue* item_properties;
91 if (!data_.GetDictionary(id, &item_properties)) { 134 if (!data_.GetDictionary(id, &item_properties)) {
92 item_properties = new DictionaryValue(); 135 item_properties = new DictionaryValue();
93 data_.Set(id, item_properties); 136 data_.Set(id, item_properties);
94 item_properties->SetString("id", id); 137 item_properties->SetString("id", id);
95 } 138 }
96 item_properties->Set(property, value); 139 item_properties->MergeDictionary(properties);
97 SendUpdate(update_fn, item_properties); 140 SendUpdate(update_fn, item_properties);
98 } 141 }
99 142
100 void MediaInternals::SendUpdate(const std::string& function, Value* value) { 143 void MediaInternals::SendUpdate(const std::string& function, Value* value) {
101 // Only bother serializing the update to JSON if someone is watching. 144 // Only bother serializing the update to JSON if someone is watching.
102 if (observers_.size()) { 145 if (observers_.size()) {
103 std::vector<const Value*> args; 146 std::vector<const Value*> args;
104 args.push_back(value); 147 args.push_back(value);
105 string16 update = WebUI::GetJavascriptCall(function, args); 148 string16 update = WebUI::GetJavascriptCall(function, args);
106 FOR_EACH_OBSERVER(MediaInternalsObserver, observers_, OnUpdate(update)); 149 FOR_EACH_OBSERVER(MediaInternalsObserver, observers_, OnUpdate(update));
107 } 150 }
108 } 151 }
OLDNEW
« no previous file with comments | « chrome/browser/media/media_internals.h ('k') | chrome/browser/media/media_internals_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698