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/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/web_ui.h" | 10 #include "content/public/browser/web_ui.h" |
11 #include "media/audio/audio_parameters.h" | 11 #include "media/audio/audio_parameters.h" |
12 #include "media/base/media_log.h" | 12 #include "media/base/media_log.h" |
13 #include "media/base/media_log_event.h" | 13 #include "media/base/media_log_event.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 static base::LazyInstance<content::MediaInternals>::Leaky g_media_internals = | 17 static base::LazyInstance<content::MediaInternals>::Leaky g_media_internals = |
18 LAZY_INSTANCE_INITIALIZER; | 18 LAZY_INSTANCE_INITIALIZER; |
19 | 19 |
20 string16 SerializeUpdate(const std::string& function, | 20 base::string16 SerializeUpdate(const std::string& function, |
21 const base::Value* value) { | 21 const base::Value* value) { |
22 return content::WebUI::GetJavascriptCall( | 22 return content::WebUI::GetJavascriptCall( |
23 function, std::vector<const base::Value*>(1, value)); | 23 function, std::vector<const base::Value*>(1, value)); |
24 } | 24 } |
25 | 25 |
26 const char kAudioLogStatusKey[] = "status"; | 26 const char kAudioLogStatusKey[] = "status"; |
27 const char kAudioLogUpdateFunction[] = "media.updateAudioComponent"; | 27 const char kAudioLogUpdateFunction[] = "media.updateAudioComponent"; |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 namespace content { | 31 namespace content { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 for (size_t i = 0; i < update_callbacks_.size(); ++i) { | 178 for (size_t i = 0; i < update_callbacks_.size(); ++i) { |
179 if (update_callbacks_[i].Equals(callback)) { | 179 if (update_callbacks_[i].Equals(callback)) { |
180 update_callbacks_.erase(update_callbacks_.begin() + i); | 180 update_callbacks_.erase(update_callbacks_.begin() + i); |
181 return; | 181 return; |
182 } | 182 } |
183 } | 183 } |
184 NOTREACHED(); | 184 NOTREACHED(); |
185 } | 185 } |
186 | 186 |
187 void MediaInternals::SendEverything() { | 187 void MediaInternals::SendEverything() { |
188 string16 everything_update; | 188 base::string16 everything_update; |
189 { | 189 { |
190 base::AutoLock auto_lock(lock_); | 190 base::AutoLock auto_lock(lock_); |
191 everything_update = SerializeUpdate( | 191 everything_update = SerializeUpdate( |
192 "media.onReceiveEverything", &cached_data_); | 192 "media.onReceiveEverything", &cached_data_); |
193 } | 193 } |
194 SendUpdate(everything_update); | 194 SendUpdate(everything_update); |
195 } | 195 } |
196 | 196 |
197 void MediaInternals::SendUpdate(const string16& update) { | 197 void MediaInternals::SendUpdate(const base::string16& update) { |
198 // SendUpdate() may be called from any thread, but must run on the IO thread. | 198 // SendUpdate() may be called from any thread, but must run on the IO thread. |
199 // TODO(dalecurtis): This is pretty silly since the update callbacks simply | 199 // TODO(dalecurtis): This is pretty silly since the update callbacks simply |
200 // forward the calls to the UI thread. We should avoid the extra hop. | 200 // forward the calls to the UI thread. We should avoid the extra hop. |
201 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 201 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
202 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 202 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( |
203 &MediaInternals::SendUpdate, base::Unretained(this), update)); | 203 &MediaInternals::SendUpdate, base::Unretained(this), update)); |
204 return; | 204 return; |
205 } | 205 } |
206 | 206 |
207 for (size_t i = 0; i < update_callbacks_.size(); i++) | 207 for (size_t i = 0; i < update_callbacks_.size(); i++) |
(...skipping 28 matching lines...) Expand all Loading... |
236 const std::string& function, | 236 const std::string& function, |
237 const base::DictionaryValue* value) { | 237 const base::DictionaryValue* value) { |
238 SendUpdate(SerializeUpdate(function, value)); | 238 SendUpdate(SerializeUpdate(function, value)); |
239 | 239 |
240 base::AutoLock auto_lock(lock_); | 240 base::AutoLock auto_lock(lock_); |
241 scoped_ptr<base::Value> out_value; | 241 scoped_ptr<base::Value> out_value; |
242 CHECK(cached_data_.Remove(cache_key, &out_value)); | 242 CHECK(cached_data_.Remove(cache_key, &out_value)); |
243 } | 243 } |
244 | 244 |
245 } // namespace content | 245 } // namespace content |
OLD | NEW |