Commit 744ff3eb authored by perkj@chromium.org's avatar perkj@chromium.org

Make sure MediaStreamManager handles requests in order.

This cl changes MediaStreamManager to internally use a list of requests instead of a map. The purpose is to make sure requests are serviced in the order they are requested rather than be dependent on the map key.
This is to avoid that the requests are serviced out of order if several requests are waiting for a media device to be opened.

BUG=381893

Review URL: https://codereview.chromium.org/345713005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278453 0039d316-1c4b-4281-b951-d872f2087c98
parent 03b76471
......@@ -452,7 +452,7 @@ IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
expected_result);
}
}
IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
TwoGetUserMediaWithSecondVideoCropped) {
......@@ -464,7 +464,7 @@ IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
}
IN_PROC_BROWSER_TEST_P(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaWithFirstHdSecondVga) {
TwoGetUserMediaWithFirstHdSecondVga) {
std::string constraints1 =
"{video: {mandatory: {minWidth:1280 , minHeight: 720}}}";
std::string constraints2 =
......
......@@ -36,6 +36,7 @@
using ::testing::_;
using ::testing::DeleteArg;
using ::testing::DoAll;
using ::testing::InSequence;
using ::testing::Return;
using ::testing::SaveArg;
......@@ -567,12 +568,15 @@ TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithoutWaiting) {
// Generate first stream.
SetupFakeUI(true);
EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
// Generate second stream.
EXPECT_CALL(*host_.get(),
OnStreamGenerated(kRenderId, kPageRequestId + 1, 0, 1));
{
InSequence s;
EXPECT_CALL(*host_.get(),
OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
// Generate second stream.
EXPECT_CALL(*host_.get(),
OnStreamGenerated(kRenderId, kPageRequestId + 1, 0, 1));
}
base::RunLoop run_loop1;
base::RunLoop run_loop2;
host_->OnGenerateStream(kRenderId, kPageRequestId, options, origin_,
......
......@@ -1100,24 +1100,34 @@ std::string MediaStreamManager::AddRequest(DeviceRequest* request) {
std::string unique_label;
do {
unique_label = RandomLabel();
} while (requests_.find(unique_label) != requests_.end());
} while (FindRequest(unique_label) != NULL);
requests_.insert(std::make_pair(unique_label, request));
requests_.push_back(std::make_pair(unique_label, request));
return unique_label;
}
MediaStreamManager::DeviceRequest*
MediaStreamManager::FindRequest(const std::string& label) const {
DeviceRequests::const_iterator request_it = requests_.find(label);
return request_it == requests_.end() ? NULL : request_it->second;
for (DeviceRequests::const_iterator request_it = requests_.begin();
request_it != requests_.end(); ++request_it) {
if (request_it->first == label)
return request_it->second;
}
return NULL;
}
void MediaStreamManager::DeleteRequest(const std::string& label) {
DVLOG(1) << "DeleteRequest({label= " << label << "})";
DeviceRequests::iterator it = requests_.find(label);
scoped_ptr<DeviceRequest> request(it->second);
requests_.erase(it);
for (DeviceRequests::iterator request_it = requests_.begin();
request_it != requests_.end(); ++request_it) {
if (request_it->first == label) {
scoped_ptr<DeviceRequest> request(request_it->second);
requests_.erase(request_it);
return;
}
}
NOTREACHED();
}
void MediaStreamManager::PostRequestToUI(const std::string& label,
......@@ -1648,7 +1658,7 @@ void MediaStreamManager::DevicesEnumerated(
// to be invalid so that the next media request will trigger the
// enumeration again. See issue/317673.
cache->valid = !devices.empty();
}
}
if (need_update_clients && monitoring_started_)
NotifyDevicesChanged(stream_type, devices);
......
......@@ -26,9 +26,10 @@
#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
#include <map>
#include <list>
#include <set>
#include <string>
#include <utility>
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
......@@ -228,7 +229,10 @@ class CONTENT_EXPORT MediaStreamManager
StreamDeviceInfoArray devices;
};
typedef std::map<std::string, DeviceRequest*> DeviceRequests;
// |DeviceRequests| is a list to ensure requests are processed in the order
// they arrive. The first member of the pair is the label of the
// |DeviceRequest|.
typedef std::list<std::pair<std::string, DeviceRequest*> > DeviceRequests;
// Initializes the device managers on IO thread. Auto-starts the device
// thread and registers this as a listener with the device managers.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment