| 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 <stddef.h> | 7 #include <stddef.h> | 
| 8 | 8 | 
| 9 #include <memory> | 9 #include <memory> | 
| 10 #include <tuple> | 10 #include <tuple> | 
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 772     int status; | 772     int status; | 
| 773     if (!event.params.GetInteger("pipeline_error", &status) || | 773     if (!event.params.GetInteger("pipeline_error", &status) || | 
| 774         status < static_cast<int>(media::PIPELINE_OK) || | 774         status < static_cast<int>(media::PIPELINE_OK) || | 
| 775         status > static_cast<int>(media::PIPELINE_STATUS_MAX)) { | 775         status > static_cast<int>(media::PIPELINE_STATUS_MAX)) { | 
| 776       return false; | 776       return false; | 
| 777     } | 777     } | 
| 778     media::PipelineStatus error = static_cast<media::PipelineStatus>(status); | 778     media::PipelineStatus error = static_cast<media::PipelineStatus>(status); | 
| 779     dict.SetString("params.pipeline_error", | 779     dict.SetString("params.pipeline_error", | 
| 780                    media::MediaLog::PipelineStatusToString(error)); | 780                    media::MediaLog::PipelineStatusToString(error)); | 
| 781   } else { | 781   } else { | 
| 782     dict.Set("params", event.params.DeepCopy()); | 782     dict.Set("params", base::MakeUnique<base::Value>(event.params)); | 
| 783   } | 783   } | 
| 784 | 784 | 
| 785   *update = SerializeUpdate("media.onMediaEvent", &dict); | 785   *update = SerializeUpdate("media.onMediaEvent", &dict); | 
| 786   return true; | 786   return true; | 
| 787 } | 787 } | 
| 788 | 788 | 
| 789 void MediaInternals::OnMediaEvents( | 789 void MediaInternals::OnMediaEvents( | 
| 790     int render_process_id, const std::vector<media::MediaLogEvent>& events) { | 790     int render_process_id, const std::vector<media::MediaLogEvent>& events) { | 
| 791   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 791   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
| 792   // Notify observers that |event| has occurred. | 792   // Notify observers that |event| has occurred. | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 864 } | 864 } | 
| 865 | 865 | 
| 866 void MediaInternals::UpdateVideoCaptureDeviceCapabilities( | 866 void MediaInternals::UpdateVideoCaptureDeviceCapabilities( | 
| 867     const std::vector<std::tuple<media::VideoCaptureDeviceDescriptor, | 867     const std::vector<std::tuple<media::VideoCaptureDeviceDescriptor, | 
| 868                                  media::VideoCaptureFormats>>& | 868                                  media::VideoCaptureFormats>>& | 
| 869         descriptors_and_formats) { | 869         descriptors_and_formats) { | 
| 870   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 870   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
| 871   video_capture_capabilities_cached_data_.Clear(); | 871   video_capture_capabilities_cached_data_.Clear(); | 
| 872 | 872 | 
| 873   for (const auto& device_format_pair : descriptors_and_formats) { | 873   for (const auto& device_format_pair : descriptors_and_formats) { | 
| 874     base::ListValue* format_list = new base::ListValue(); | 874     auto format_list = base::MakeUnique<base::ListValue>(); | 
| 875     // TODO(nisse): Representing format information as a string, to be | 875     // TODO(nisse): Representing format information as a string, to be | 
| 876     // parsed by the javascript handler, is brittle. Consider passing | 876     // parsed by the javascript handler, is brittle. Consider passing | 
| 877     // a list of mappings instead. | 877     // a list of mappings instead. | 
| 878 | 878 | 
| 879     const media::VideoCaptureDeviceDescriptor& descriptor = | 879     const media::VideoCaptureDeviceDescriptor& descriptor = | 
| 880         std::get<0>(device_format_pair); | 880         std::get<0>(device_format_pair); | 
| 881     const media::VideoCaptureFormats& supported_formats = | 881     const media::VideoCaptureFormats& supported_formats = | 
| 882         std::get<1>(device_format_pair); | 882         std::get<1>(device_format_pair); | 
| 883     for (const auto& format : supported_formats) | 883     for (const auto& format : supported_formats) | 
| 884       format_list->AppendString(media::VideoCaptureFormat::ToString(format)); | 884       format_list->AppendString(media::VideoCaptureFormat::ToString(format)); | 
| 885 | 885 | 
| 886     std::unique_ptr<base::DictionaryValue> device_dict( | 886     std::unique_ptr<base::DictionaryValue> device_dict( | 
| 887         new base::DictionaryValue()); | 887         new base::DictionaryValue()); | 
| 888     device_dict->SetString("id", descriptor.device_id); | 888     device_dict->SetString("id", descriptor.device_id); | 
| 889     device_dict->SetString("name", descriptor.GetNameAndModel()); | 889     device_dict->SetString("name", descriptor.GetNameAndModel()); | 
| 890     device_dict->Set("formats", format_list); | 890     device_dict->Set("formats", std::move(format_list)); | 
| 891 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ | 891 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \ | 
| 892     defined(OS_ANDROID) | 892     defined(OS_ANDROID) | 
| 893     device_dict->SetString("captureApi", descriptor.GetCaptureApiTypeString()); | 893     device_dict->SetString("captureApi", descriptor.GetCaptureApiTypeString()); | 
| 894 #endif | 894 #endif | 
| 895     video_capture_capabilities_cached_data_.Append(std::move(device_dict)); | 895     video_capture_capabilities_cached_data_.Append(std::move(device_dict)); | 
| 896   } | 896   } | 
| 897 | 897 | 
| 898   SendVideoCaptureDeviceCapabilities(); | 898   SendVideoCaptureDeviceCapabilities(); | 
| 899 } | 899 } | 
| 900 | 900 | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 963                                     const std::string& cache_key, | 963                                     const std::string& cache_key, | 
| 964                                     const std::string& function, | 964                                     const std::string& function, | 
| 965                                     const base::DictionaryValue* value) { | 965                                     const base::DictionaryValue* value) { | 
| 966   { | 966   { | 
| 967     base::AutoLock auto_lock(lock_); | 967     base::AutoLock auto_lock(lock_); | 
| 968     const bool has_entry = audio_streams_cached_data_.HasKey(cache_key); | 968     const bool has_entry = audio_streams_cached_data_.HasKey(cache_key); | 
| 969     if ((type == UPDATE_IF_EXISTS || type == UPDATE_AND_DELETE) && !has_entry) { | 969     if ((type == UPDATE_IF_EXISTS || type == UPDATE_AND_DELETE) && !has_entry) { | 
| 970       return; | 970       return; | 
| 971     } else if (!has_entry) { | 971     } else if (!has_entry) { | 
| 972       DCHECK_EQ(type, CREATE); | 972       DCHECK_EQ(type, CREATE); | 
| 973       audio_streams_cached_data_.Set(cache_key, value->DeepCopy()); | 973       audio_streams_cached_data_.Set(cache_key, | 
|  | 974                                      base::MakeUnique<base::Value>(*value)); | 
| 974     } else if (type == UPDATE_AND_DELETE) { | 975     } else if (type == UPDATE_AND_DELETE) { | 
| 975       std::unique_ptr<base::Value> out_value; | 976       std::unique_ptr<base::Value> out_value; | 
| 976       CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value)); | 977       CHECK(audio_streams_cached_data_.Remove(cache_key, &out_value)); | 
| 977     } else { | 978     } else { | 
| 978       base::DictionaryValue* existing_dict = NULL; | 979       base::DictionaryValue* existing_dict = NULL; | 
| 979       CHECK( | 980       CHECK( | 
| 980           audio_streams_cached_data_.GetDictionary(cache_key, &existing_dict)); | 981           audio_streams_cached_data_.GetDictionary(cache_key, &existing_dict)); | 
| 981       existing_dict->MergeDictionary(value); | 982       existing_dict->MergeDictionary(value); | 
| 982     } | 983     } | 
| 983   } | 984   } | 
| 984 | 985 | 
| 985   if (CanUpdate()) | 986   if (CanUpdate()) | 
| 986     SendUpdate(SerializeUpdate(function, value)); | 987     SendUpdate(SerializeUpdate(function, value)); | 
| 987 } | 988 } | 
| 988 | 989 | 
| 989 std::unique_ptr<ukm::UkmEntryBuilder> MediaInternals::CreateUkmBuilder( | 990 std::unique_ptr<ukm::UkmEntryBuilder> MediaInternals::CreateUkmBuilder( | 
| 990     const GURL& url, | 991     const GURL& url, | 
| 991     const char* event_name) { | 992     const char* event_name) { | 
| 992   // UKM is unavailable in builds w/o chrome/ code (e.g., content_shell). | 993   // UKM is unavailable in builds w/o chrome/ code (e.g., content_shell). | 
| 993   ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get(); | 994   ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get(); | 
| 994   if (!ukm_recorder) | 995   if (!ukm_recorder) | 
| 995     return nullptr; | 996     return nullptr; | 
| 996 | 997 | 
| 997   const int32_t source_id = ukm_recorder->GetNewSourceID(); | 998   const int32_t source_id = ukm_recorder->GetNewSourceID(); | 
| 998   ukm_recorder->UpdateSourceURL(source_id, url); | 999   ukm_recorder->UpdateSourceURL(source_id, url); | 
| 999   return ukm_recorder->GetEntryBuilder(source_id, event_name); | 1000   return ukm_recorder->GetEntryBuilder(source_id, event_name); | 
| 1000 } | 1001 } | 
| 1001 | 1002 | 
| 1002 }  // namespace content | 1003 }  // namespace content | 
| OLD | NEW | 
|---|