Migrate MediaResponseCallback to OnceCallback

https://chromium-review.googlesource.com/c/chromium/src/+/1093052
This commit is contained in:
Jeremy Apthorp 2018-10-02 11:09:25 -07:00
Родитель 3ded109c2e
Коммит 90aa277c26
8 изменённых файлов: 32 добавлений и 35 удалений

Просмотреть файл

@ -734,10 +734,10 @@ bool WebContents::CheckMediaAccessPermission(
void WebContents::RequestMediaAccessPermission(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback) {
content::MediaResponseCallback callback) {
auto* permission_helper =
WebContentsPermissionHelper::FromWebContents(web_contents);
permission_helper->RequestMediaAccessPermission(request, callback);
permission_helper->RequestMediaAccessPermission(request, std::move(callback));
}
void WebContents::RequestToLockMouse(content::WebContents* web_contents,

Просмотреть файл

@ -351,7 +351,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
void RequestMediaAccessPermission(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback) override;
content::MediaResponseCallback callback) override;
void RequestToLockMouse(content::WebContents* web_contents,
bool user_gesture,
bool last_unlocked_by_target) override;

Просмотреть файл

@ -111,7 +111,7 @@ int AtomPermissionManager::RequestPermission(
content::RenderFrameHost* render_frame_host,
const GURL& requesting_origin,
bool user_gesture,
const StatusCallback& response_callback) {
const base::Callback<void(blink::mojom::PermissionStatus)>& response_callback) {
return RequestPermissionWithDetails(permission, render_frame_host,
requesting_origin, user_gesture, nullptr,
response_callback);
@ -222,7 +222,7 @@ int AtomPermissionManager::SubscribePermissionStatusChange(
content::PermissionType permission,
const GURL& requesting_origin,
const GURL& embedding_origin,
const StatusCallback& callback) {
const base::Callback<void(blink::mojom::PermissionStatus)>& callback) {
return -1;
}

Просмотреть файл

@ -55,7 +55,7 @@ class AtomPermissionManager : public content::PermissionManager {
const GURL& requesting_origin,
bool user_gesture,
const base::DictionaryValue* details,
const base::Callback<void(blink::mojom::PermissionStatus)>& callback);
const StatusCallback& callback);
int RequestPermissions(
const std::vector<content::PermissionType>& permissions,
content::RenderFrameHost* render_frame_host,

Просмотреть файл

@ -36,9 +36,10 @@ namespace atom {
namespace {
void MediaAccessAllowed(const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback,
content::MediaResponseCallback callback,
bool allowed) {
brightray::MediaStreamDevicesController controller(request, callback);
brightray::MediaStreamDevicesController controller(request,
std::move(callback));
if (allowed)
controller.TakeAction();
else
@ -50,7 +51,7 @@ void OnPointerLockResponse(content::WebContents* web_contents, bool allowed) {
web_contents->GotResponseToLockMouseRequest(allowed);
}
void OnPermissionResponse(const base::Callback<void(bool)>& callback,
void OnPermissionResponse(base::Callback<void(bool)> callback,
blink::mojom::PermissionStatus status) {
if (status == blink::mojom::PermissionStatus::GRANTED)
callback.Run(true);
@ -77,7 +78,7 @@ void WebContentsPermissionHelper::RequestPermission(
auto origin = web_contents_->GetLastCommittedURL();
permission_manager->RequestPermissionWithDetails(
permission, rfh, origin, false, details,
base::Bind(&OnPermissionResponse, callback));
base::Bind(&OnPermissionResponse, std::move(callback)));
}
bool WebContentsPermissionHelper::CheckPermission(
@ -100,8 +101,9 @@ void WebContentsPermissionHelper::RequestFullscreenPermission(
void WebContentsPermissionHelper::RequestMediaAccessPermission(
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& response_callback) {
auto callback = base::Bind(&MediaAccessAllowed, request, response_callback);
content::MediaResponseCallback response_callback) {
auto callback = base::AdaptCallbackForRepeating(base::BindOnce(
&MediaAccessAllowed, request, std::move(response_callback)));
base::DictionaryValue details;
std::unique_ptr<base::ListValue> media_types(new base::ListValue);
@ -117,8 +119,8 @@ void WebContentsPermissionHelper::RequestMediaAccessPermission(
// The permission type doesn't matter here, AUDIO_CAPTURE/VIDEO_CAPTURE
// are presented as same type in content_converter.h.
RequestPermission(content::PermissionType::AUDIO_CAPTURE, callback, false,
&details);
RequestPermission(content::PermissionType::AUDIO_CAPTURE, std::move(callback),
false, &details);
}
void WebContentsPermissionHelper::RequestWebNotificationPermission(

Просмотреть файл

@ -27,7 +27,7 @@ class WebContentsPermissionHelper
void RequestFullscreenPermission(const base::Callback<void(bool)>& callback);
void RequestMediaAccessPermission(
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback);
content::MediaResponseCallback callback);
void RequestWebNotificationPermission(
const base::Callback<void(bool)>& callback);
void RequestPointerLockPermission(bool user_gesture);

Просмотреть файл

@ -5,6 +5,7 @@
#include "brightray/browser/media/media_stream_devices_controller.h"
#include <memory>
#include <utility>
#include "brightray/browser/media/media_capture_devices_dispatcher.h"
#include "content/public/browser/desktop_media_id.h"
@ -27,9 +28,9 @@ bool HasAnyAvailableDevice() {
MediaStreamDevicesController::MediaStreamDevicesController(
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback)
content::MediaResponseCallback callback)
: request_(request),
callback_(callback),
callback_(std::move(callback)),
// For MEDIA_OPEN_DEVICE requests (Pepper) we always request both webcam
// and microphone to avoid popping two infobars.
microphone_requested_(
@ -41,9 +42,9 @@ MediaStreamDevicesController::MediaStreamDevicesController(
MediaStreamDevicesController::~MediaStreamDevicesController() {
if (!callback_.is_null()) {
callback_.Run(content::MediaStreamDevices(),
content::MEDIA_DEVICE_INVALID_STATE,
std::unique_ptr<content::MediaStreamUI>());
std::move(callback_).Run(content::MediaStreamDevices(),
content::MEDIA_DEVICE_INVALID_STATE,
std::unique_ptr<content::MediaStreamUI>());
}
}
@ -140,18 +141,14 @@ void MediaStreamDevicesController::Accept() {
}
}
content::MediaResponseCallback cb = callback_;
callback_.Reset();
cb.Run(devices, content::MEDIA_DEVICE_OK,
std::unique_ptr<content::MediaStreamUI>());
std::move(callback_).Run(devices, content::MEDIA_DEVICE_OK,
std::unique_ptr<content::MediaStreamUI>());
}
void MediaStreamDevicesController::Deny(
content::MediaStreamRequestResult result) {
content::MediaResponseCallback cb = callback_;
callback_.Reset();
cb.Run(content::MediaStreamDevices(), result,
std::unique_ptr<content::MediaStreamUI>());
std::move(callback_).Run(content::MediaStreamDevices(), result,
std::unique_ptr<content::MediaStreamUI>());
}
void MediaStreamDevicesController::HandleUserMediaRequest() {
@ -185,12 +182,10 @@ void MediaStreamDevicesController::HandleUserMediaRequest() {
content::MEDIA_DESKTOP_VIDEO_CAPTURE, screen_id.ToString(), "Screen"));
}
content::MediaResponseCallback cb = callback_;
callback_.Reset();
cb.Run(devices,
devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE
: content::MEDIA_DEVICE_OK,
std::unique_ptr<content::MediaStreamUI>());
std::move(callback_).Run(devices,
devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE
: content::MEDIA_DEVICE_OK,
std::unique_ptr<content::MediaStreamUI>());
}
} // namespace brightray

Просмотреть файл

@ -12,7 +12,7 @@ namespace brightray {
class MediaStreamDevicesController {
public:
MediaStreamDevicesController(const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback);
content::MediaResponseCallback callback);
virtual ~MediaStreamDevicesController();