Unrefcount AuthChallengeInfo

This class is not ref-counted for any particular reason and the shared
ownership is confusing/unnecessary. This CL removes its refcounting;
it is now passed around mostly as a const ref, and copied where
necessary, as described in detail below.

The AuthChallengeInfo for a request is created and populated by
HttpAuthController, and ownership is then handed off to HttpResponseInfo.
HttpResponseInfo stores the AuthChallengeInfo inside a base::Optional
rather than a unique_ptr so that HttpResponseInfo remains copyable (and
rather than as a member field directly because consumers need to tell when
the auth_challenge has been set or not).

The AuthChallengeInfo is then passed to delegates as a const ref so it
is clear that delegates don't own it and can't modify it. It is copied on
the UI thread when we get to the point of creating the LoginDelegate/
LoginHandler.

Bug: 949197
Change-Id: I8b91fd80d20b4771c38cf4785ea0ca33ddb25ab5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1550631
Reviewed-by: Reilly Grant <[email protected]>
Reviewed-by: Wez <[email protected]>
Reviewed-by: Elly Fong-Jones <[email protected]>
Reviewed-by: Avi Drissman <[email protected]>
Reviewed-by: Asanka Herath <[email protected]>
Reviewed-by: Bo <[email protected]>
Reviewed-by: Eugene But <[email protected]>
Reviewed-by: Luke Halliwell <[email protected]>
Commit-Queue: Emily Stark <[email protected]>
Cr-Commit-Position: refs/heads/master@{#649143}
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index 3b187a9..4f1fa6e0 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -411,7 +411,6 @@
   // of sending authorization information. Each time it restarts, we get
   // notified of the headers completion so that we can update the cookie store.
   if (transaction_->IsReadyToRestartForAuth()) {
-    DCHECK(!response_info_->auth_challenge.get());
     // TODO(battre): This breaks the webrequest API for
     // URLRequestTestHTTP.BasicAuthWithCookies
     // where OnBeforeStartTransaction -> OnStartTransaction ->
@@ -1126,8 +1125,7 @@
   return false;
 }
 
-void URLRequestHttpJob::GetAuthChallengeInfo(
-    scoped_refptr<AuthChallengeInfo>* result) {
+std::unique_ptr<AuthChallengeInfo> URLRequestHttpJob::GetAuthChallengeInfo() {
   DCHECK(transaction_.get());
   DCHECK(response_info_);
 
@@ -1138,7 +1136,10 @@
          (GetResponseHeaders()->response_code() ==
           HTTP_PROXY_AUTHENTICATION_REQUIRED));
 
-  *result = response_info_->auth_challenge;
+  if (!response_info_->auth_challenge.has_value())
+    return nullptr;
+  return std::make_unique<AuthChallengeInfo>(
+      response_info_->auth_challenge.value());
 }
 
 void URLRequestHttpJob::SetAuth(const AuthCredentials& credentials) {