Commit dbce3023 authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

[WebView] Remove Bind on an ownerless refcounted instance.

CL https://chromium-review.googlesource.com/1144813 prevents ownerless
RefCounted receiver on base::Bind.

The class AwLoginDelegate does a PostTask in its constructor using
'this'. This violate a CHECK(...).

The CL makes the constructor private. It introduces the static method
Create(). It wraps the raw pointer in the scoped_refptr class first and
THEN call base::Bind on it.

Bug: 870479
Change-Id: Iebbd51e3136fb1a52962b8f5a0951f6b89145742
Reviewed-on: https://chromium-review.googlesource.com/1179758Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584092}
parent 3eb3b6ab
...@@ -714,8 +714,8 @@ AwContentBrowserClient::CreateLoginDelegate( ...@@ -714,8 +714,8 @@ AwContentBrowserClient::CreateLoginDelegate(
scoped_refptr<net::HttpResponseHeaders> response_headers, scoped_refptr<net::HttpResponseHeaders> response_headers,
bool first_auth_attempt, bool first_auth_attempt,
LoginAuthRequiredCallback auth_required_callback) { LoginAuthRequiredCallback auth_required_callback) {
return base::MakeRefCounted<AwLoginDelegate>( return AwLoginDelegate::Create(auth_info, web_contents_getter,
auth_info, web_contents_getter, first_auth_attempt, first_auth_attempt,
std::move(auth_required_callback)); std::move(auth_required_callback));
} }
......
...@@ -20,19 +20,27 @@ using content::WebContents; ...@@ -20,19 +20,27 @@ using content::WebContents;
namespace android_webview { namespace android_webview {
AwLoginDelegate::AwLoginDelegate( // static
scoped_refptr<AwLoginDelegate> AwLoginDelegate::Create(
net::AuthChallengeInfo* auth_info, net::AuthChallengeInfo* auth_info,
content::ResourceRequestInfo::WebContentsGetter web_contents_getter, content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
bool first_auth_attempt, bool first_auth_attempt,
LoginAuthRequiredCallback auth_required_callback) LoginAuthRequiredCallback auth_required_callback) {
: auth_info_(auth_info), scoped_refptr<AwLoginDelegate> instance(
auth_required_callback_(std::move(auth_required_callback)) { new AwLoginDelegate(auth_info, std::move(auth_required_callback)));
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce(&AwLoginDelegate::HandleHttpAuthRequestOnUIThread, this, base::BindOnce(&AwLoginDelegate::HandleHttpAuthRequestOnUIThread,
first_auth_attempt, web_contents_getter)); instance, first_auth_attempt, web_contents_getter));
return instance;
} }
AwLoginDelegate::AwLoginDelegate(
net::AuthChallengeInfo* auth_info,
LoginAuthRequiredCallback auth_required_callback)
: auth_info_(auth_info),
auth_required_callback_(std::move(auth_required_callback)) {}
AwLoginDelegate::~AwLoginDelegate() { AwLoginDelegate::~AwLoginDelegate() {
// The Auth handler holds a ref count back on |this| object, so it should be // The Auth handler holds a ref count back on |this| object, so it should be
// impossible to reach here while this object still owns an auth handler. // impossible to reach here while this object still owns an auth handler.
......
...@@ -24,7 +24,7 @@ namespace android_webview { ...@@ -24,7 +24,7 @@ namespace android_webview {
class AwLoginDelegate : public content::LoginDelegate { class AwLoginDelegate : public content::LoginDelegate {
public: public:
AwLoginDelegate( static scoped_refptr<AwLoginDelegate> Create(
net::AuthChallengeInfo* auth_info, net::AuthChallengeInfo* auth_info,
content::ResourceRequestInfo::WebContentsGetter web_contents_getter, content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
bool first_auth_attempt, bool first_auth_attempt,
...@@ -38,6 +38,8 @@ class AwLoginDelegate : public content::LoginDelegate { ...@@ -38,6 +38,8 @@ class AwLoginDelegate : public content::LoginDelegate {
void OnRequestCancelled() override; void OnRequestCancelled() override;
private: private:
AwLoginDelegate(net::AuthChallengeInfo* auth_info,
LoginAuthRequiredCallback auth_required_callback);
~AwLoginDelegate() override; ~AwLoginDelegate() override;
void HandleHttpAuthRequestOnUIThread( void HandleHttpAuthRequestOnUIThread(
bool first_auth_attempt, bool first_auth_attempt,
......
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