Commit 5231c96c authored by Sky Malice's avatar Sky Malice Committed by Commit Bot

Migrate PermissionUpdatedCallback to OnceCallback.

Bug: 714018
Change-Id: Icf820390ed7ae7dd66219d9473dedae3e90e382a
Reviewed-on: https://chromium-review.googlesource.com/1117569
Commit-Queue: Sky Malice <skym@chromium.org>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarRaymes Khoury <raymes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571913}
parent cdff37ea
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "chrome/browser/android/vr/arcore_device/arcore_device.h" #include "chrome/browser/android/vr/arcore_device/arcore_device.h"
#include <jni.h>
#include "base/bind.h" #include "base/bind.h"
#include "base/numerics/math_constants.h" #include "base/numerics/math_constants.h"
#include "base/optional.h" #include "base/optional.h"
...@@ -368,8 +367,7 @@ void ARCoreDevice::OnRequestCameraPermissionResult( ...@@ -368,8 +367,7 @@ void ARCoreDevice::OnRequestCameraPermissionResult(
// Show the Android camera permission info bar. // Show the Android camera permission info bar.
PermissionUpdateInfoBarDelegate::Create( PermissionUpdateInfoBarDelegate::Create(
web_contents, content_settings_types, web_contents, content_settings_types,
base::BindRepeating( base::BindOnce(&ARCoreDevice::OnRequestAndroidCameraPermissionResult,
&ARCoreDevice::OnRequestAndroidCameraPermissionResult,
GetWeakPtr(), base::Passed(&callback))); GetWeakPtr(), base::Passed(&callback)));
return; return;
case ShowPermissionInfoBarState::CANNOT_SHOW_PERMISSION_INFOBAR: case ShowPermissionInfoBarState::CANNOT_SHOW_PERMISSION_INFOBAR:
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
#define CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_ARCORE_DEVICE_H_ #define CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_ARCORE_DEVICE_H_
#include <jni.h> #include <jni.h>
#include <memory>
#include <utility>
#include <vector>
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
......
...@@ -133,7 +133,7 @@ void GeolocationPermissionContextAndroid::RequestPermission( ...@@ -133,7 +133,7 @@ void GeolocationPermissionContextAndroid::RequestPermission(
ShowPermissionInfoBarState::SHOW_PERMISSION_INFOBAR) { ShowPermissionInfoBarState::SHOW_PERMISSION_INFOBAR) {
PermissionUpdateInfoBarDelegate::Create( PermissionUpdateInfoBarDelegate::Create(
web_contents, content_settings_types, web_contents, content_settings_types,
base::Bind(&GeolocationPermissionContextAndroid :: base::BindOnce(&GeolocationPermissionContextAndroid ::
HandleUpdateAndroidPermissions, HandleUpdateAndroidPermissions,
weak_factory_.GetWeakPtr(), id, requesting_frame_origin, weak_factory_.GetWeakPtr(), id, requesting_frame_origin,
embedding_origin, callback)); embedding_origin, callback));
......
...@@ -214,8 +214,7 @@ void MediaStreamDevicesController::RequestAndroidPermissionsIfNeeded( ...@@ -214,8 +214,7 @@ void MediaStreamDevicesController::RequestAndroidPermissionsIfNeeded(
case ShowPermissionInfoBarState::SHOW_PERMISSION_INFOBAR: case ShowPermissionInfoBarState::SHOW_PERMISSION_INFOBAR:
PermissionUpdateInfoBarDelegate::Create( PermissionUpdateInfoBarDelegate::Create(
web_contents, content_settings_types, web_contents, content_settings_types,
base::BindRepeating( base::BindOnce(&MediaStreamDevicesController::AndroidOSPromptAnswered,
&MediaStreamDevicesController::AndroidOSPromptAnswered,
base::Passed(&controller), responses)); base::Passed(&controller), responses));
return; return;
case ShowPermissionInfoBarState::CANNOT_SHOW_PERMISSION_INFOBAR: { case ShowPermissionInfoBarState::CANNOT_SHOW_PERMISSION_INFOBAR: {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/permissions/permission_update_infobar_delegate_android.h" #include "chrome/browser/permissions/permission_update_infobar_delegate_android.h"
#include <memory> #include <memory>
#include <utility>
#include "base/android/jni_array.h" #include "base/android/jni_array.h"
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
...@@ -25,7 +26,7 @@ using base::android::JavaParamRef; ...@@ -25,7 +26,7 @@ using base::android::JavaParamRef;
infobars::InfoBar* PermissionUpdateInfoBarDelegate::Create( infobars::InfoBar* PermissionUpdateInfoBarDelegate::Create(
content::WebContents* web_contents, content::WebContents* web_contents,
const std::vector<ContentSettingsType>& content_settings_types, const std::vector<ContentSettingsType>& content_settings_types,
const PermissionUpdatedCallback& callback) { PermissionUpdatedCallback callback) {
DCHECK(ShouldShowPermissionInfoBar(web_contents, content_settings_types) == DCHECK(ShouldShowPermissionInfoBar(web_contents, content_settings_types) ==
ShowPermissionInfoBarState::SHOW_PERMISSION_INFOBAR) ShowPermissionInfoBarState::SHOW_PERMISSION_INFOBAR)
<< "Caller should check ShouldShowPermissionInfobar before creating the " << "Caller should check ShouldShowPermissionInfobar before creating the "
...@@ -74,7 +75,7 @@ infobars::InfoBar* PermissionUpdateInfoBarDelegate::Create( ...@@ -74,7 +75,7 @@ infobars::InfoBar* PermissionUpdateInfoBarDelegate::Create(
} }
return PermissionUpdateInfoBarDelegate::Create( return PermissionUpdateInfoBarDelegate::Create(
web_contents, permissions, message_id, callback); web_contents, permissions, message_id, std::move(callback));
} }
// static // static
...@@ -82,18 +83,19 @@ infobars::InfoBar* PermissionUpdateInfoBarDelegate::Create( ...@@ -82,18 +83,19 @@ infobars::InfoBar* PermissionUpdateInfoBarDelegate::Create(
content::WebContents* web_contents, content::WebContents* web_contents,
const std::vector<std::string>& android_permissions, const std::vector<std::string>& android_permissions,
int permission_msg_id, int permission_msg_id,
const PermissionUpdatedCallback& callback) { PermissionUpdatedCallback callback) {
InfoBarService* infobar_service = InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents); InfoBarService::FromWebContents(web_contents);
if (!infobar_service) { if (!infobar_service) {
callback.Run(false); std::move(callback).Run(false);
return nullptr; return nullptr;
} }
return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
std::unique_ptr<ConfirmInfoBarDelegate>( std::unique_ptr<ConfirmInfoBarDelegate>(
new PermissionUpdateInfoBarDelegate(web_contents, android_permissions, new PermissionUpdateInfoBarDelegate(web_contents, android_permissions,
permission_msg_id, callback)))); permission_msg_id,
std::move(callback)))));
} }
// static // static
...@@ -126,7 +128,7 @@ void PermissionUpdateInfoBarDelegate::OnPermissionResult( ...@@ -126,7 +128,7 @@ void PermissionUpdateInfoBarDelegate::OnPermissionResult(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jobject>& obj, const JavaParamRef<jobject>& obj,
jboolean all_permissions_granted) { jboolean all_permissions_granted) {
base::ResetAndReturn(&callback_).Run(all_permissions_granted); std::move(callback_).Run(all_permissions_granted);
infobar()->RemoveSelf(); infobar()->RemoveSelf();
} }
...@@ -134,11 +136,11 @@ PermissionUpdateInfoBarDelegate::PermissionUpdateInfoBarDelegate( ...@@ -134,11 +136,11 @@ PermissionUpdateInfoBarDelegate::PermissionUpdateInfoBarDelegate(
content::WebContents* web_contents, content::WebContents* web_contents,
const std::vector<std::string>& android_permissions, const std::vector<std::string>& android_permissions,
int permission_msg_id, int permission_msg_id,
const PermissionUpdatedCallback& callback) PermissionUpdatedCallback callback)
: ConfirmInfoBarDelegate(), : ConfirmInfoBarDelegate(),
android_permissions_(android_permissions), android_permissions_(android_permissions),
permission_msg_id_(permission_msg_id), permission_msg_id_(permission_msg_id),
callback_(callback) { callback_(std::move(callback)) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
java_delegate_.Reset(Java_PermissionUpdateInfoBarDelegate_create( java_delegate_.Reset(Java_PermissionUpdateInfoBarDelegate_create(
env, reinterpret_cast<intptr_t>(this), web_contents->GetJavaWebContents(), env, reinterpret_cast<intptr_t>(this), web_contents->GetJavaWebContents(),
......
...@@ -35,7 +35,7 @@ enum class ShowPermissionInfoBarState { ...@@ -35,7 +35,7 @@ enum class ShowPermissionInfoBarState {
// permissions for previously allowed ContentSettingsTypes. // permissions for previously allowed ContentSettingsTypes.
class PermissionUpdateInfoBarDelegate : public ConfirmInfoBarDelegate { class PermissionUpdateInfoBarDelegate : public ConfirmInfoBarDelegate {
public: public:
using PermissionUpdatedCallback = base::Callback<void(bool)>; using PermissionUpdatedCallback = base::OnceCallback<void(bool)>;
// Creates an infobar to resolve conflicts in Android runtime permissions. // Creates an infobar to resolve conflicts in Android runtime permissions.
// The necessary runtime permissions are generated based on the list of // The necessary runtime permissions are generated based on the list of
...@@ -53,7 +53,7 @@ class PermissionUpdateInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -53,7 +53,7 @@ class PermissionUpdateInfoBarDelegate : public ConfirmInfoBarDelegate {
static infobars::InfoBar* Create( static infobars::InfoBar* Create(
content::WebContents* web_contents, content::WebContents* web_contents,
const std::vector<ContentSettingsType>& content_settings_types, const std::vector<ContentSettingsType>& content_settings_types,
const PermissionUpdatedCallback& callback); PermissionUpdatedCallback callback);
// Creates an infobar to resolve conflicts in Android runtime permissions. // Creates an infobar to resolve conflicts in Android runtime permissions.
// Returns the infobar if it was successfully added. // Returns the infobar if it was successfully added.
...@@ -63,7 +63,7 @@ class PermissionUpdateInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -63,7 +63,7 @@ class PermissionUpdateInfoBarDelegate : public ConfirmInfoBarDelegate {
content::WebContents* web_contents, content::WebContents* web_contents,
const std::vector<std::string>& android_permissions, const std::vector<std::string>& android_permissions,
int permission_msg_id, int permission_msg_id,
const PermissionUpdatedCallback& callback); PermissionUpdatedCallback callback);
// Returns an indicator of whether a permission infobar should be shown or // Returns an indicator of whether a permission infobar should be shown or
// not or cannot be shown. // not or cannot be shown.
...@@ -80,7 +80,7 @@ class PermissionUpdateInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -80,7 +80,7 @@ class PermissionUpdateInfoBarDelegate : public ConfirmInfoBarDelegate {
content::WebContents* web_contents, content::WebContents* web_contents,
const std::vector<std::string>& android_permissions, const std::vector<std::string>& android_permissions,
int permission_msg_id, int permission_msg_id,
const PermissionUpdatedCallback& callback); PermissionUpdatedCallback callback);
~PermissionUpdateInfoBarDelegate() override; ~PermissionUpdateInfoBarDelegate() override;
// InfoBarDelegate: // InfoBarDelegate:
......
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