Commit 45c6a788 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Update WebMediaStreamDeviceObserver::AddStream() to take action callbacks

... rather than a weak pointer to UserMediaProcessor.

This is a preliminary step to mo UserMediaProcessor to be GC-able by
OilPan.

In a follow up, the WebPtrFactory in user_media_processor.h will be
completely removed, and UserMediaProcessor will be Oilpan GC-ed.

BUG=704136
R=guidou@chromium.org, haraken@chromium.org

Change-Id: I067ea8a4c58c8758c474d39a3d4d50c06821ad8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1757494
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688092}
parent dd0c019a
......@@ -15,7 +15,6 @@
namespace blink {
class MediaStreamDeviceObserver;
class UserMediaProcessor;
class WebLocalFrame;
class BLINK_MODULES_EXPORT WebMediaStreamDeviceObserver {
......@@ -25,10 +24,16 @@ class BLINK_MODULES_EXPORT WebMediaStreamDeviceObserver {
MediaStreamDevices GetNonScreenCaptureDevices();
using OnDeviceStoppedCb =
base::RepeatingCallback<void(const MediaStreamDevice& device)>;
using OnDeviceChangedCb =
base::RepeatingCallback<void(const MediaStreamDevice& old_device,
const MediaStreamDevice& new_device)>;
void AddStream(const WebString& label,
const MediaStreamDevices& audio_devices,
const MediaStreamDevices& video_devices,
const base::WeakPtr<UserMediaProcessor>& event_handler);
OnDeviceStoppedCb on_device_stopped_cb,
OnDeviceChangedCb on_device_changed_cb);
void AddStream(const WebString& label, const MediaStreamDevice& device);
bool RemoveStream(const WebString& label);
void RemoveStreamDevice(const MediaStreamDevice& device);
......
......@@ -36,7 +36,8 @@ bool RemoveStreamDeviceFromArray(const MediaStreamDevice& device,
struct MediaStreamDeviceObserver::Stream {
Stream() {}
~Stream() {}
base::WeakPtr<UserMediaProcessor> handler;
WebMediaStreamDeviceObserver::OnDeviceStoppedCb on_device_stopped_cb;
WebMediaStreamDeviceObserver::OnDeviceChangedCb on_device_changed_cb;
MediaStreamDevices audio_devices;
MediaStreamDevices video_devices;
};
......@@ -84,8 +85,8 @@ void MediaStreamDeviceObserver::OnDeviceStopped(
else
RemoveStreamDeviceFromArray(device, &stream->video_devices);
if (stream->handler.get())
stream->handler->OnDeviceStopped(device);
if (stream->on_device_stopped_cb)
stream->on_device_stopped_cb.Run(device);
// |it| could have already been invalidated in the function call above. So we
// need to check if |label| is still in |label_stream_map_| again.
......@@ -116,8 +117,8 @@ void MediaStreamDeviceObserver::OnDeviceChanged(
}
Stream* stream = &it->value;
if (stream->handler.get())
stream->handler->OnDeviceChanged(old_device, new_device);
if (stream->on_device_changed_cb)
stream->on_device_changed_cb.Run(old_device, new_device);
// Update device list only for device changing. Removing device will be
// handled in its own callback.
......@@ -140,13 +141,15 @@ void MediaStreamDeviceObserver::BindMediaStreamDeviceObserverRequest(
void MediaStreamDeviceObserver::AddStream(
const String& label,
const MediaStreamDevices& audio_devices,
const MediaStreamDevices& video_devices,
const base::WeakPtr<UserMediaProcessor>& event_handler) {
const blink::MediaStreamDevices& audio_devices,
const blink::MediaStreamDevices& video_devices,
WebMediaStreamDeviceObserver::OnDeviceStoppedCb on_device_stopped_cb,
WebMediaStreamDeviceObserver::OnDeviceChangedCb on_device_changed_cb) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
Stream stream;
stream.handler = event_handler;
stream.on_device_stopped_cb = std::move(on_device_stopped_cb);
stream.on_device_changed_cb = std::move(on_device_changed_cb);
stream.audio_devices = audio_devices;
stream.video_devices = video_devices;
......
......@@ -18,6 +18,7 @@
#include "mojo/public/cpp/bindings/binding.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink.h"
#include "third_party/blink/public/web/modules/mediastream/web_media_stream_device_observer.h"
#include "third_party/blink/renderer/modules/modules_export.h"
namespace blink {
......@@ -38,10 +39,12 @@ class MODULES_EXPORT MediaStreamDeviceObserver
// being shown to the user.
blink::MediaStreamDevices GetNonScreenCaptureDevices();
void AddStream(const String& label,
const blink::MediaStreamDevices& audio_devices,
const blink::MediaStreamDevices& video_devices,
const base::WeakPtr<blink::UserMediaProcessor>& event_handler);
void AddStream(
const String& label,
const blink::MediaStreamDevices& audio_devices,
const blink::MediaStreamDevices& video_devices,
WebMediaStreamDeviceObserver::OnDeviceStoppedCb on_device_stopped_cb,
WebMediaStreamDeviceObserver::OnDeviceChangedCb on_device_changed_cb);
void AddStream(const String& label, const blink::MediaStreamDevice& device);
bool RemoveStream(const String& label);
void RemoveStreamDevice(const blink::MediaStreamDevice& device);
......
......@@ -1218,7 +1218,10 @@ void UserMediaProcessor::StartTracks(const String& label) {
blink::WebString(label),
ToStdVector(current_request_info_->audio_devices()),
ToStdVector(current_request_info_->video_devices()),
weak_factory_.GetWeakPtr());
WTF::BindRepeating(&UserMediaProcessor::OnDeviceStopped,
weak_factory_.GetWeakPtr()),
WTF::BindRepeating(&UserMediaProcessor::OnDeviceChanged,
weak_factory_.GetWeakPtr()));
Vector<blink::WebMediaStreamTrack> audio_tracks(
current_request_info_->audio_devices().size());
......
......@@ -21,8 +21,11 @@ void WebMediaStreamDeviceObserver::AddStream(
const WebString& label,
const MediaStreamDevices& audio_devices,
const MediaStreamDevices& video_devices,
const base::WeakPtr<UserMediaProcessor>& event_handler) {
observer_->AddStream(label, audio_devices, video_devices, event_handler);
OnDeviceStoppedCb on_device_stopped_cb,
OnDeviceChangedCb on_device_changed_cb) {
observer_->AddStream(label, audio_devices, video_devices,
std::move(on_device_stopped_cb),
std::move(on_device_changed_cb));
}
void WebMediaStreamDeviceObserver::AddStream(const WebString& label,
......
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