Commit a4d8c399 authored by Boris Yusupov's avatar Boris Yusupov Committed by Commit Bot

Avoid Bind() without reference to ref-counted

Bug: 866456

R=tzik@chromium.org

Change-Id: I54b1192a65e9646b5177ce5fcfd15e5fdb735058
Reviewed-on: https://chromium-review.googlesource.com/1206335Reviewed-by: default avatarTaiju Tsuiki <tzik@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarJinho Bang <jinho.bang@samsung.com>
Commit-Queue: Boris Yusupov <boriay@yandex-team.ru>
Cr-Commit-Position: refs/heads/master@{#589111}
parent 26007adf
......@@ -4,6 +4,8 @@
#include "content/browser/payments/payment_app_installer.h"
#include <utility>
#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
......@@ -26,12 +28,10 @@ class SelfDeleteInstaller
: public WebContentsObserver,
public base::RefCountedThreadSafe<SelfDeleteInstaller> {
public:
SelfDeleteInstaller(WebContents* web_contents,
const std::string& app_name,
SelfDeleteInstaller(const std::string& app_name,
const std::string& app_icon,
const GURL& sw_url,
const GURL& scope,
bool use_cache,
const std::string& method,
PaymentAppInstaller::InstallPaymentAppCallback callback)
: app_name_(app_name),
......@@ -41,6 +41,10 @@ class SelfDeleteInstaller
method_(method),
callback_(std::move(callback)) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
void Init(WebContents* web_contents, bool use_cache) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// TODO(crbug.com/782270): Listen for web contents events to terminate
// installation early.
......@@ -66,7 +70,7 @@ class SelfDeleteInstaller
blink::mojom::ServiceWorkerUpdateViaCache::kNone;
}
service_worker_context->RegisterServiceWorker(
sw_url, option,
sw_url_, option,
base::BindOnce(&SelfDeleteInstaller::OnRegisterServiceWorkerResult,
this));
}
......@@ -212,8 +216,9 @@ void PaymentAppInstaller::Install(WebContents* web_contents,
InstallPaymentAppCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
new SelfDeleteInstaller(web_contents, app_name, app_icon, sw_url, scope,
use_cache, method, std::move(callback));
auto installer = base::MakeRefCounted<SelfDeleteInstaller>(
app_name, app_icon, sw_url, scope, method, std::move(callback));
installer->Init(web_contents, use_cache);
}
} // namespace content
......@@ -386,8 +386,7 @@ scoped_refptr<LoginDelegate> ShellContentBrowserClient::CreateLoginDelegate(
// TODO: implement ShellLoginDialog for other platforms, drop this #if
return nullptr;
#else
return base::MakeRefCounted<ShellLoginDialog>(
auth_info, std::move(auth_required_callback));
return ShellLoginDialog::Create(auth_info, std::move(auth_required_callback));
#endif
}
......
......@@ -15,11 +15,23 @@
namespace content {
ShellLoginDialog::ShellLoginDialog(
// static
scoped_refptr<ShellLoginDialog> ShellLoginDialog::Create(
net::AuthChallengeInfo* auth_info,
LoginAuthRequiredCallback auth_required_callback) {
auto ret = base::WrapRefCounted(
new ShellLoginDialog(std::move(auth_required_callback)));
ret->Init(auth_info);
return ret;
}
ShellLoginDialog::ShellLoginDialog(
LoginAuthRequiredCallback auth_required_callback)
: auth_required_callback_(std::move(auth_required_callback)) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
}
void ShellLoginDialog::Init(net::AuthChallengeInfo* auth_info) {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::BindOnce(
......
......@@ -31,11 +31,9 @@ namespace content {
// ResourceDispatcherHostDelegate::CreateLoginDelegate.
class ShellLoginDialog : public LoginDelegate {
public:
// Threading: IO thread.
ShellLoginDialog(
static scoped_refptr<ShellLoginDialog> Create(
net::AuthChallengeInfo* auth_info,
base::OnceCallback<void(const base::Optional<net::AuthCredentials>&)>
auth_required_callback);
LoginAuthRequiredCallback auth_required_callback);
// LoginDelegate implementation:
// Threading: IO thread.
......@@ -50,9 +48,16 @@ class ShellLoginDialog : public LoginDelegate {
void UserCancelledAuth();
protected:
// Threading: IO thread.
ShellLoginDialog(
base::OnceCallback<void(const base::Optional<net::AuthCredentials>&)>
auth_required_callback);
// Threading: any
~ShellLoginDialog() override;
void Init(net::AuthChallengeInfo* auth_info);
private:
// All the methods that begin with Platform need to be implemented by the
// platform specific LoginDialog implementation.
......
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