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/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"; |
18 static const char kSendEverythingFunction[] = "media.onReceiveEverything"; | 20 static const char kSendEverythingFunction[] = "media.onReceiveEverything"; |
19 | 21 |
20 MediaInternals::~MediaInternals() {} | 22 MediaInternals::~MediaInternals() {} |
21 | 23 |
22 void MediaInternals::OnDeleteAudioStream(void* host, int stream_id) { | 24 void MediaInternals::OnDeleteAudioStream(void* host, int stream_id) { |
23 DCHECK(CalledOnValidThread()); | 25 DCHECK(CalledOnValidThread()); |
24 std::string stream = base::StringPrintf("audio_streams.%p:%d", | 26 std::string stream = base::StringPrintf("audio_streams.%p:%d", |
25 host, stream_id); | 27 host, stream_id); |
26 DeleteItem(stream); | 28 DeleteItem(stream); |
27 } | 29 } |
(...skipping 15 matching lines...) Expand all Loading... |
43 void MediaInternals::OnSetAudioStreamVolume( | 45 void MediaInternals::OnSetAudioStreamVolume( |
44 void* host, int stream_id, double volume) { | 46 void* host, int stream_id, double volume) { |
45 DCHECK(CalledOnValidThread()); | 47 DCHECK(CalledOnValidThread()); |
46 UpdateAudioStream(host, stream_id, | 48 UpdateAudioStream(host, stream_id, |
47 "volume", Value::CreateDoubleValue(volume)); | 49 "volume", Value::CreateDoubleValue(volume)); |
48 } | 50 } |
49 | 51 |
50 void MediaInternals::OnMediaEvent( | 52 void MediaInternals::OnMediaEvent( |
51 int render_process_id, const media::MediaLogEvent& event) { | 53 int render_process_id, const media::MediaLogEvent& event) { |
52 DCHECK(CalledOnValidThread()); | 54 DCHECK(CalledOnValidThread()); |
53 // TODO(scottfr): Handle |event|. Record status information in data_ and pass | 55 |
54 // |event| along to observers. | 56 // Notify observers that |event| has occured. |
| 57 DictionaryValue dict; |
| 58 dict.SetInteger("renderer", render_process_id); |
| 59 dict.SetInteger("player", event.id); |
| 60 dict.SetString("type", media::MediaLog::EventTypeToString(event.type)); |
| 61 dict.SetDouble("time", event.time.ToDoubleT()); |
| 62 dict.Set("params", event.params.DeepCopy()); |
| 63 SendUpdate(kMediaEventFunction, &dict); |
55 } | 64 } |
56 | 65 |
57 void MediaInternals::AddObserver(MediaInternalsObserver* observer) { | 66 void MediaInternals::AddObserver(MediaInternalsObserver* observer) { |
58 DCHECK(CalledOnValidThread()); | 67 DCHECK(CalledOnValidThread()); |
59 observers_.AddObserver(observer); | 68 observers_.AddObserver(observer); |
60 } | 69 } |
61 | 70 |
62 void MediaInternals::RemoveObserver(MediaInternalsObserver* observer) { | 71 void MediaInternals::RemoveObserver(MediaInternalsObserver* observer) { |
63 DCHECK(CalledOnValidThread()); | 72 DCHECK(CalledOnValidThread()); |
64 observers_.RemoveObserver(observer); | 73 observers_.RemoveObserver(observer); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 108 |
100 void MediaInternals::SendUpdate(const std::string& function, Value* value) { | 109 void MediaInternals::SendUpdate(const std::string& function, Value* value) { |
101 // Only bother serializing the update to JSON if someone is watching. | 110 // Only bother serializing the update to JSON if someone is watching. |
102 if (observers_.size()) { | 111 if (observers_.size()) { |
103 std::vector<const Value*> args; | 112 std::vector<const Value*> args; |
104 args.push_back(value); | 113 args.push_back(value); |
105 string16 update = WebUI::GetJavascriptCall(function, args); | 114 string16 update = WebUI::GetJavascriptCall(function, args); |
106 FOR_EACH_OBSERVER(MediaInternalsObserver, observers_, OnUpdate(update)); | 115 FOR_EACH_OBSERVER(MediaInternalsObserver, observers_, OnUpdate(update)); |
107 } | 116 } |
108 } | 117 } |
OLD | NEW |