| 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/renderer_host/media/media_stream_manager.h" | 5 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 } | 1093 } |
| 1094 } | 1094 } |
| 1095 | 1095 |
| 1096 std::string MediaStreamManager::AddRequest(DeviceRequest* request) { | 1096 std::string MediaStreamManager::AddRequest(DeviceRequest* request) { |
| 1097 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1097 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1098 | 1098 |
| 1099 // Create a label for this request and verify it is unique. | 1099 // Create a label for this request and verify it is unique. |
| 1100 std::string unique_label; | 1100 std::string unique_label; |
| 1101 do { | 1101 do { |
| 1102 unique_label = RandomLabel(); | 1102 unique_label = RandomLabel(); |
| 1103 } while (requests_.find(unique_label) != requests_.end()); | 1103 } while (FindRequest(unique_label) != NULL); |
| 1104 | 1104 |
| 1105 requests_.insert(std::make_pair(unique_label, request)); | 1105 requests_.push_back(std::make_pair(unique_label, request)); |
| 1106 | 1106 |
| 1107 return unique_label; | 1107 return unique_label; |
| 1108 } | 1108 } |
| 1109 | 1109 |
| 1110 MediaStreamManager::DeviceRequest* | 1110 MediaStreamManager::DeviceRequest* |
| 1111 MediaStreamManager::FindRequest(const std::string& label) const { | 1111 MediaStreamManager::FindRequest(const std::string& label) const { |
| 1112 DeviceRequests::const_iterator request_it = requests_.find(label); | 1112 for (DeviceRequests::const_iterator request_it = requests_.begin(); |
| 1113 return request_it == requests_.end() ? NULL : request_it->second; | 1113 request_it != requests_.end(); ++request_it) { |
| 1114 if (request_it->first == label) |
| 1115 return request_it->second; |
| 1116 } |
| 1117 return NULL; |
| 1114 } | 1118 } |
| 1115 | 1119 |
| 1116 void MediaStreamManager::DeleteRequest(const std::string& label) { | 1120 void MediaStreamManager::DeleteRequest(const std::string& label) { |
| 1117 DVLOG(1) << "DeleteRequest({label= " << label << "})"; | 1121 DVLOG(1) << "DeleteRequest({label= " << label << "})"; |
| 1118 DeviceRequests::iterator it = requests_.find(label); | 1122 for (DeviceRequests::iterator request_it = requests_.begin(); |
| 1119 scoped_ptr<DeviceRequest> request(it->second); | 1123 request_it != requests_.end(); ++request_it) { |
| 1120 requests_.erase(it); | 1124 if (request_it->first == label) { |
| 1125 scoped_ptr<DeviceRequest> request(request_it->second); |
| 1126 requests_.erase(request_it); |
| 1127 return; |
| 1128 } |
| 1129 } |
| 1130 NOTREACHED(); |
| 1121 } | 1131 } |
| 1122 | 1132 |
| 1123 void MediaStreamManager::PostRequestToUI(const std::string& label, | 1133 void MediaStreamManager::PostRequestToUI(const std::string& label, |
| 1124 DeviceRequest* request) { | 1134 DeviceRequest* request) { |
| 1125 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1135 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1126 DCHECK(request->UIRequest()); | 1136 DCHECK(request->UIRequest()); |
| 1127 DVLOG(1) << "PostRequestToUI({label= " << label << "})"; | 1137 DVLOG(1) << "PostRequestToUI({label= " << label << "})"; |
| 1128 | 1138 |
| 1129 const MediaStreamType audio_type = request->audio_type(); | 1139 const MediaStreamType audio_type = request->audio_type(); |
| 1130 const MediaStreamType video_type = request->video_type(); | 1140 const MediaStreamType video_type = request->video_type(); |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1641 StreamDeviceInfo::IsEqual)) { | 1651 StreamDeviceInfo::IsEqual)) { |
| 1642 StopRemovedDevices(cache->devices, devices); | 1652 StopRemovedDevices(cache->devices, devices); |
| 1643 cache->devices = devices; | 1653 cache->devices = devices; |
| 1644 need_update_clients = true; | 1654 need_update_clients = true; |
| 1645 | 1655 |
| 1646 // The device might not be able to be enumerated when it is not warmed up, | 1656 // The device might not be able to be enumerated when it is not warmed up, |
| 1647 // for example, when the machine just wakes up from sleep. We set the cache | 1657 // for example, when the machine just wakes up from sleep. We set the cache |
| 1648 // to be invalid so that the next media request will trigger the | 1658 // to be invalid so that the next media request will trigger the |
| 1649 // enumeration again. See issue/317673. | 1659 // enumeration again. See issue/317673. |
| 1650 cache->valid = !devices.empty(); | 1660 cache->valid = !devices.empty(); |
| 1651 } | 1661 } |
| 1652 | 1662 |
| 1653 if (need_update_clients && monitoring_started_) | 1663 if (need_update_clients && monitoring_started_) |
| 1654 NotifyDevicesChanged(stream_type, devices); | 1664 NotifyDevicesChanged(stream_type, devices); |
| 1655 | 1665 |
| 1656 // Publish the result for all requests waiting for device list(s). | 1666 // Publish the result for all requests waiting for device list(s). |
| 1657 // Find the requests waiting for this device list, store their labels and | 1667 // Find the requests waiting for this device list, store their labels and |
| 1658 // release the iterator before calling device settings. We might get a call | 1668 // release the iterator before calling device settings. We might get a call |
| 1659 // back from device_settings that will need to iterate through devices. | 1669 // back from device_settings that will need to iterate through devices. |
| 1660 std::list<std::string> label_list; | 1670 std::list<std::string> label_list; |
| 1661 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); | 1671 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2022 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { | 2032 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
| 2023 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, | 2033 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, |
| 2024 window_id); | 2034 window_id); |
| 2025 break; | 2035 break; |
| 2026 } | 2036 } |
| 2027 } | 2037 } |
| 2028 } | 2038 } |
| 2029 } | 2039 } |
| 2030 | 2040 |
| 2031 } // namespace content | 2041 } // namespace content |
| OLD | NEW |