LoginHandler::LoginHandler(net::AuthChallengeInfo* auth_info,
net::URLRequest* request)
- : auth_info_(auth_info),
+ : handled_auth_(false),
+ auth_info_(auth_info),
request_(request),
render_process_host_id_(0),
render_frame_id_(0) {
void LoginHandler::Login(const base::string16& username,
const base::string16& password) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ if (TestAndSetAuthHandled())
+ return;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&LoginHandler::DoLogin, this, username, password));
void LoginHandler::CancelAuth() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ if (TestAndSetAuthHandled())
+ return;
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&LoginHandler::DoCancelAuth, this));
}
void LoginHandler::OnRequestCancelled() {
+ TestAndSetAuthHandled();
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() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
#define ATOM_BROWSER_LOGIN_HANDLER_H_
#include "base/strings/string16.h"
+#include "base/synchronization/lock.h"
#include "content/public/browser/resource_dispatcher_host_login_delegate.h"
namespace content {
void DoCancelAuth();
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.
scoped_refptr<net::AuthChallengeInfo> auth_info_;