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

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

Issue 616833004: chrome://media-internals: update MediaInternals when devices capabilities are enumerated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
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/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
208 for (size_t i = 0; i < update_callbacks_.size(); ++i) { 208 for (size_t i = 0; i < update_callbacks_.size(); ++i) {
209 if (update_callbacks_[i].Equals(callback)) { 209 if (update_callbacks_[i].Equals(callback)) {
210 update_callbacks_.erase(update_callbacks_.begin() + i); 210 update_callbacks_.erase(update_callbacks_.begin() + i);
211 return; 211 return;
212 } 212 }
213 } 213 }
214 NOTREACHED(); 214 NOTREACHED();
215 } 215 }
216 216
217 void MediaInternals::SendEverything() { 217 void MediaInternals::SendEverything() {
burnik 2014/10/05 23:08:55 This is a bit unrelated at this point, but it shou
mcasas 2014/10/07 11:25:39 Done and cleaned up the "audio" parts of this clas
218 base::string16 everything_update; 218 base::string16 everything_update;
219 { 219 {
220 base::AutoLock auto_lock(lock_); 220 base::AutoLock auto_lock(lock_);
221 everything_update = SerializeUpdate( 221 everything_update = SerializeUpdate(
222 "media.onReceiveEverything", &cached_data_); 222 "media.onReceiveEverything", &audio_streams_cached_data_);
burnik 2014/10/05 23:08:55 Audio data is not everything. Not your doing, but
mcasas 2014/10/07 11:25:39 Done.
223 } 223 }
224 SendUpdate(everything_update); 224 SendUpdate(everything_update);
225 } 225 }
226 226
227 void MediaInternals::SendUpdate(const base::string16& update) { 227 void MediaInternals::SendUpdate(const base::string16& update) {
228 // SendUpdate() may be called from any thread, but must run on the IO thread. 228 // SendUpdate() may be called from any thread, but must run on the IO thread.
229 // TODO(dalecurtis): This is pretty silly since the update callbacks simply 229 // TODO(dalecurtis): This is pretty silly since the update callbacks simply
230 // forward the calls to the UI thread. We should avoid the extra hop. 230 // forward the calls to the UI thread. We should avoid the extra hop.
231 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 231 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
232 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( 232 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
(...skipping 11 matching lines...) Expand all
244 return scoped_ptr<media::AudioLog>(new AudioLogImpl( 244 return scoped_ptr<media::AudioLog>(new AudioLogImpl(
245 owner_ids_[component]++, component, this)); 245 owner_ids_[component]++, component, this));
246 } 246 }
247 247
248 void MediaInternals::SendUpdateAndCache(const std::string& cache_key, 248 void MediaInternals::SendUpdateAndCache(const std::string& cache_key,
249 const std::string& function, 249 const std::string& function,
250 const base::DictionaryValue* value) { 250 const base::DictionaryValue* value) {
251 SendUpdate(SerializeUpdate(function, value)); 251 SendUpdate(SerializeUpdate(function, value));
252 252
253 base::AutoLock auto_lock(lock_); 253 base::AutoLock auto_lock(lock_);
254 if (!cached_data_.HasKey(cache_key)) { 254 if (!audio_streams_cached_data_.HasKey(cache_key)) {
255 cached_data_.Set(cache_key, value->DeepCopy()); 255 audio_streams_cached_data_.Set(cache_key, value->DeepCopy());
256 return; 256 return;
257 } 257 }
258 258
259 base::DictionaryValue* existing_dict = NULL; 259 base::DictionaryValue* existing_dict = NULL;
260 CHECK(cached_data_.GetDictionary(cache_key, &existing_dict)); 260 CHECK(audio_streams_cached_data_.GetDictionary(cache_key, &existing_dict));
261 existing_dict->MergeDictionary(value); 261 existing_dict->MergeDictionary(value);
262 } 262 }
263 263
264 void MediaInternals::SendUpdateAndPurgeCache( 264 void MediaInternals::SendUpdateAndPurgeCache(
265 const std::string& cache_key, 265 const std::string& cache_key,
266 const std::string& function, 266 const std::string& function,
267 const base::DictionaryValue* value) { 267 const base::DictionaryValue* value) {
268 SendUpdate(SerializeUpdate(function, value)); 268 SendUpdate(SerializeUpdate(function, value));
269 269
270 base::AutoLock auto_lock(lock_); 270 base::AutoLock auto_lock(lock_);
271 scoped_ptr<base::Value> out_value; 271 scoped_ptr<base::Value> out_value;
272 CHECK(cached_data_.Remove(cache_key, &out_value)); 272 CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value));
273 }
274
275 void MediaInternals::UpdateVideoCaptureDeviceCapabilities(
276 const media::VideoCaptureDevice::Name& name,
277 const media::VideoCaptureFormats& formats) {
burnik 2014/10/05 23:08:55 ditto, add: const size_t num_devices
mcasas 2014/10/07 11:25:39 Done.
278 base::DictionaryValue* formats_dict = new base::DictionaryValue();
279 int cont = 0;
280 for (const auto &it : formats)
281 formats_dict->SetString(base::StringPrintf("[%3d]", cont++), it.ToString());
282 formats_dict->SetString("Unique ID", name.id());
283 #if defined(OS_WIN) || defined(OS_MACOSX)
284 formats_dict->SetString("Capture API:", name.capture_api_type());
285 #endif
286
287 video_devices_cached_data_.Set(name.GetNameAndModel(), formats_dict);
288 SendEverything();
burnik 2014/10/05 23:08:55 Two problems lie here: 1) You're calling MediaInte
mcasas 2014/10/07 11:25:40 Done.
289 }
290
291 void MediaInternals::PurgeVideoCaptureDeviceCapabilities() {
burnik 2014/10/05 23:08:55 We can probably avoid this method alltogether if w
mcasas 2014/10/07 11:25:39 Done.
292 video_devices_cached_data_.Clear();
273 } 293 }
274 294
275 } // namespace content 295 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698