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