OLD | NEW |
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 "content/browser/media/media_internals.h" | 5 #include "content/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 "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
25 std::string stream = base::StringPrintf("audio_streams.%p:%d", | 25 std::string stream = base::StringPrintf("audio_streams.%p:%d", |
26 host, stream_id); | 26 host, stream_id); |
27 DeleteItem(stream); | 27 DeleteItem(stream); |
28 } | 28 } |
29 | 29 |
30 void MediaInternals::OnSetAudioStreamPlaying( | 30 void MediaInternals::OnSetAudioStreamPlaying( |
31 void* host, int stream_id, bool playing) { | 31 void* host, int stream_id, bool playing) { |
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
33 UpdateAudioStream(host, stream_id, | 33 UpdateAudioStream(host, stream_id, |
34 "playing", Value::CreateBooleanValue(playing)); | 34 "playing", new base::FundamentalValue(playing)); |
35 } | 35 } |
36 | 36 |
37 void MediaInternals::OnSetAudioStreamStatus( | 37 void MediaInternals::OnSetAudioStreamStatus( |
38 void* host, int stream_id, const std::string& status) { | 38 void* host, int stream_id, const std::string& status) { |
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
40 UpdateAudioStream(host, stream_id, | 40 UpdateAudioStream(host, stream_id, |
41 "status", Value::CreateStringValue(status)); | 41 "status", new base::StringValue(status)); |
42 } | 42 } |
43 | 43 |
44 void MediaInternals::OnSetAudioStreamVolume( | 44 void MediaInternals::OnSetAudioStreamVolume( |
45 void* host, int stream_id, double volume) { | 45 void* host, int stream_id, double volume) { |
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
47 UpdateAudioStream(host, stream_id, | 47 UpdateAudioStream(host, stream_id, |
48 "volume", Value::CreateDoubleValue(volume)); | 48 "volume", new base::FundamentalValue(volume)); |
49 } | 49 } |
50 | 50 |
51 void MediaInternals::OnMediaEvent( | 51 void MediaInternals::OnMediaEvent( |
52 int render_process_id, const media::MediaLogEvent& event) { | 52 int render_process_id, const media::MediaLogEvent& event) { |
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
54 | 54 |
55 // Notify observers that |event| has occured. | 55 // Notify observers that |event| has occured. |
56 DictionaryValue dict; | 56 base::DictionaryValue dict; |
57 dict.SetInteger("renderer", render_process_id); | 57 dict.SetInteger("renderer", render_process_id); |
58 dict.SetInteger("player", event.id); | 58 dict.SetInteger("player", event.id); |
59 dict.SetString("type", media::MediaLog::EventTypeToString(event.type)); | 59 dict.SetString("type", media::MediaLog::EventTypeToString(event.type)); |
60 dict.SetDouble("time", event.time.ToDoubleT()); | 60 dict.SetDouble("time", event.time.ToDoubleT()); |
61 dict.Set("params", event.params.DeepCopy()); | 61 dict.Set("params", event.params.DeepCopy()); |
62 SendUpdate("media.onMediaEvent", &dict); | 62 SendUpdate("media.onMediaEvent", &dict); |
63 } | 63 } |
64 | 64 |
65 void MediaInternals::AddUpdateCallback(const UpdateCallback& callback) { | 65 void MediaInternals::AddUpdateCallback(const UpdateCallback& callback) { |
66 update_callbacks_.push_back(callback); | 66 update_callbacks_.push_back(callback); |
(...skipping 10 matching lines...) Expand all Loading... |
77 } | 77 } |
78 | 78 |
79 void MediaInternals::SendEverything() { | 79 void MediaInternals::SendEverything() { |
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
81 SendUpdate("media.onReceiveEverything", &data_); | 81 SendUpdate("media.onReceiveEverything", &data_); |
82 } | 82 } |
83 | 83 |
84 MediaInternals::MediaInternals() { | 84 MediaInternals::MediaInternals() { |
85 } | 85 } |
86 | 86 |
87 void MediaInternals::UpdateAudioStream( | 87 void MediaInternals::UpdateAudioStream(void* host, |
88 void* host, int stream_id, const std::string& property, Value* value) { | 88 int stream_id, |
| 89 const std::string& property, |
| 90 base::Value* value) { |
89 std::string stream = base::StringPrintf("audio_streams.%p:%d", | 91 std::string stream = base::StringPrintf("audio_streams.%p:%d", |
90 host, stream_id); | 92 host, stream_id); |
91 UpdateItem("media.addAudioStream", stream, property, value); | 93 UpdateItem("media.addAudioStream", stream, property, value); |
92 } | 94 } |
93 | 95 |
94 void MediaInternals::DeleteItem(const std::string& item) { | 96 void MediaInternals::DeleteItem(const std::string& item) { |
95 data_.Remove(item, NULL); | 97 data_.Remove(item, NULL); |
96 scoped_ptr<Value> value(Value::CreateStringValue(item)); | 98 scoped_ptr<base::Value> value(new base::StringValue(item)); |
97 SendUpdate("media.onItemDeleted", value.get()); | 99 SendUpdate("media.onItemDeleted", value.get()); |
98 } | 100 } |
99 | 101 |
100 void MediaInternals::UpdateItem( | 102 void MediaInternals::UpdateItem( |
101 const std::string& update_fn, const std::string& id, | 103 const std::string& update_fn, const std::string& id, |
102 const std::string& property, Value* value) { | 104 const std::string& property, base::Value* value) { |
103 DictionaryValue* item_properties; | 105 base::DictionaryValue* item_properties; |
104 if (!data_.GetDictionary(id, &item_properties)) { | 106 if (!data_.GetDictionary(id, &item_properties)) { |
105 item_properties = new DictionaryValue(); | 107 item_properties = new base::DictionaryValue(); |
106 data_.Set(id, item_properties); | 108 data_.Set(id, item_properties); |
107 item_properties->SetString("id", id); | 109 item_properties->SetString("id", id); |
108 } | 110 } |
109 item_properties->Set(property, value); | 111 item_properties->Set(property, value); |
110 SendUpdate(update_fn, item_properties); | 112 SendUpdate(update_fn, item_properties); |
111 } | 113 } |
112 | 114 |
113 void MediaInternals::SendUpdate(const std::string& function, Value* value) { | 115 void MediaInternals::SendUpdate(const std::string& function, |
| 116 base::Value* value) { |
114 // Only bother serializing the update to JSON if someone is watching. | 117 // Only bother serializing the update to JSON if someone is watching. |
115 if (update_callbacks_.empty()) | 118 if (update_callbacks_.empty()) |
116 return; | 119 return; |
117 | 120 |
118 std::vector<const Value*> args; | 121 std::vector<const base::Value*> args; |
119 args.push_back(value); | 122 args.push_back(value); |
120 string16 update = WebUI::GetJavascriptCall(function, args); | 123 string16 update = WebUI::GetJavascriptCall(function, args); |
121 for (size_t i = 0; i < update_callbacks_.size(); i++) | 124 for (size_t i = 0; i < update_callbacks_.size(); i++) |
122 update_callbacks_[i].Run(update); | 125 update_callbacks_[i].Run(update); |
123 } | 126 } |
124 | 127 |
125 } // namespace content | 128 } // namespace content |
OLD | NEW |