Guard against multiple calls of auth
This commit is contained in:
parent
862c3187f5
commit
51ba37440d
2 changed files with 24 additions and 1 deletions
|
@ -30,7 +30,8 @@ void ResetLoginHandlerForRequest(net::URLRequest* request) {
|
||||||
|
|
||||||
LoginHandler::LoginHandler(net::AuthChallengeInfo* auth_info,
|
LoginHandler::LoginHandler(net::AuthChallengeInfo* auth_info,
|
||||||
net::URLRequest* request)
|
net::URLRequest* request)
|
||||||
: auth_info_(auth_info),
|
: handled_auth_(false),
|
||||||
|
auth_info_(auth_info),
|
||||||
request_(request),
|
request_(request),
|
||||||
render_process_host_id_(0),
|
render_process_host_id_(0),
|
||||||
render_frame_id_(0) {
|
render_frame_id_(0) {
|
||||||
|
@ -56,6 +57,8 @@ content::WebContents* LoginHandler::GetWebContents() const {
|
||||||
void LoginHandler::Login(const base::string16& username,
|
void LoginHandler::Login(const base::string16& username,
|
||||||
const base::string16& password) {
|
const base::string16& password) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
if (TestAndSetAuthHandled())
|
||||||
|
return;
|
||||||
BrowserThread::PostTask(
|
BrowserThread::PostTask(
|
||||||
BrowserThread::IO, FROM_HERE,
|
BrowserThread::IO, FROM_HERE,
|
||||||
base::Bind(&LoginHandler::DoLogin, this, username, password));
|
base::Bind(&LoginHandler::DoLogin, this, username, password));
|
||||||
|
@ -63,14 +66,25 @@ void LoginHandler::Login(const base::string16& username,
|
||||||
|
|
||||||
void LoginHandler::CancelAuth() {
|
void LoginHandler::CancelAuth() {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
if (TestAndSetAuthHandled())
|
||||||
|
return;
|
||||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||||
base::Bind(&LoginHandler::DoCancelAuth, this));
|
base::Bind(&LoginHandler::DoCancelAuth, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginHandler::OnRequestCancelled() {
|
void LoginHandler::OnRequestCancelled() {
|
||||||
|
TestAndSetAuthHandled();
|
||||||
request_ = nullptr;
|
request_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Marks authentication as handled and returns the previous handled state.
|
||||||
|
bool LoginHandler::TestAndSetAuthHandled() {
|
||||||
|
base::AutoLock lock(handled_auth_lock_);
|
||||||
|
bool was_handled = handled_auth_;
|
||||||
|
handled_auth_ = true;
|
||||||
|
return was_handled;
|
||||||
|
}
|
||||||
|
|
||||||
void LoginHandler::DoCancelAuth() {
|
void LoginHandler::DoCancelAuth() {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define ATOM_BROWSER_LOGIN_HANDLER_H_
|
#define ATOM_BROWSER_LOGIN_HANDLER_H_
|
||||||
|
|
||||||
#include "base/strings/string16.h"
|
#include "base/strings/string16.h"
|
||||||
|
#include "base/synchronization/lock.h"
|
||||||
#include "content/public/browser/resource_dispatcher_host_login_delegate.h"
|
#include "content/public/browser/resource_dispatcher_host_login_delegate.h"
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
|
@ -48,6 +49,14 @@ class LoginHandler : public content::ResourceDispatcherHostLoginDelegate {
|
||||||
void DoCancelAuth();
|
void DoCancelAuth();
|
||||||
void DoLogin(const base::string16& username, const base::string16& password);
|
void DoLogin(const base::string16& username, const base::string16& password);
|
||||||
|
|
||||||
|
// Marks authentication as handled and returns the previous handled
|
||||||
|
// state.
|
||||||
|
bool TestAndSetAuthHandled();
|
||||||
|
|
||||||
|
// True if we've handled auth (Login or CancelAuth has been called).
|
||||||
|
bool handled_auth_;
|
||||||
|
mutable base::Lock handled_auth_lock_;
|
||||||
|
|
||||||
// Who/where/what asked for the authentication.
|
// Who/where/what asked for the authentication.
|
||||||
scoped_refptr<net::AuthChallengeInfo> auth_info_;
|
scoped_refptr<net::AuthChallengeInfo> auth_info_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue