Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: services/authenticating_url_loader_interceptor/authenticating_url_loader_interceptor.cc

Issue 1185563003: Move AuthenticatingURLLoader app from ErrorHandler to callbacks (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Response to review Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/authenticating_url_loader_interceptor/authenticating_url_load er_interceptor.h" 5 #include "services/authenticating_url_loader_interceptor/authenticating_url_load er_interceptor.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "mojo/services/network/public/interfaces/network_service.mojom.h" 9 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 12
13 AuthenticatingURLLoaderInterceptor::AuthenticatingURLLoaderInterceptor( 13 AuthenticatingURLLoaderInterceptor::AuthenticatingURLLoaderInterceptor(
14 mojo::InterfaceRequest<URLLoaderInterceptor> request, 14 mojo::InterfaceRequest<URLLoaderInterceptor> request,
15 AuthenticatingURLLoaderInterceptorFactory* factory) 15 AuthenticatingURLLoaderInterceptorFactory* factory)
16 : binding_(this, request.Pass()), 16 : binding_(this, request.Pass()),
17 factory_(factory), 17 factory_(factory),
18 add_authentication_(true), 18 add_authentication_(true),
19 request_authorization_state_(REQUEST_INITIAL) { 19 request_authorization_state_(REQUEST_INITIAL) {
20 binding_.set_error_handler(this);
21 } 20 }
22 21
23 AuthenticatingURLLoaderInterceptor::~AuthenticatingURLLoaderInterceptor() { 22 AuthenticatingURLLoaderInterceptor::~AuthenticatingURLLoaderInterceptor() {
24 } 23 }
25 24
25 void AuthenticatingURLLoaderInterceptor::set_connection_error_handler(
26 const Closure& error_handler) {
27 binding_.set_connection_error_handler(error_handler);
28 }
29
26 void AuthenticatingURLLoaderInterceptor::InterceptRequest( 30 void AuthenticatingURLLoaderInterceptor::InterceptRequest(
27 mojo::URLRequestPtr request, 31 mojo::URLRequestPtr request,
28 const InterceptRequestCallback& callback) { 32 const InterceptRequestCallback& callback) {
29 // TODO(blundell): If we need to handle requests with bodies, we'll need to 33 // TODO(blundell): If we need to handle requests with bodies, we'll need to
30 // do something here. 34 // do something here.
31 if (request->body) { 35 if (request->body) {
32 LOG(ERROR) << "Cannot pass a request to AuthenticatingURLLoaderInterceptor" 36 LOG(ERROR) << "Cannot pass a request to AuthenticatingURLLoaderInterceptor"
33 "that has a body"; 37 "that has a body";
34 callback.Run(nullptr); 38 callback.Run(nullptr);
35 return; 39 return;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 request_authorization_state_ = REQUEST_USED_CURRENT_AUTH_SERVICE_TOKEN; 153 request_authorization_state_ = REQUEST_USED_CURRENT_AUTH_SERVICE_TOKEN;
150 } else { 154 } else {
151 request_authorization_state_ = REQUEST_USED_FRESH_AUTH_SERVICE_TOKEN; 155 request_authorization_state_ = REQUEST_USED_FRESH_AUTH_SERVICE_TOKEN;
152 } 156 }
153 factory_->RetrieveToken( 157 factory_->RetrieveToken(
154 url_, 158 url_,
155 base::Bind(&AuthenticatingURLLoaderInterceptor::OnOAuth2TokenReceived, 159 base::Bind(&AuthenticatingURLLoaderInterceptor::OnOAuth2TokenReceived,
156 base::Unretained(this))); 160 base::Unretained(this)));
157 } 161 }
158 162
159 void AuthenticatingURLLoaderInterceptor::OnConnectionError() {
160 factory_->OnInterceptorError(this);
161 // The factory deleted this object.
162 }
163
164 URLRequestPtr AuthenticatingURLLoaderInterceptor::BuildRequest( 163 URLRequestPtr AuthenticatingURLLoaderInterceptor::BuildRequest(
165 std::string token) { 164 std::string token) {
166 // We should only be sending out a request with a token if the initial 165 // We should only be sending out a request with a token if the initial
167 // request did not come in with an authorization header. 166 // request did not come in with an authorization header.
168 DCHECK(add_authentication_); 167 DCHECK(add_authentication_);
169 Array<HttpHeaderPtr> headers; 168 Array<HttpHeaderPtr> headers;
170 if (headers_) 169 if (headers_)
171 headers = headers_.Clone(); 170 headers = headers_.Clone();
172 171
173 if (token == "") 172 if (token == "")
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 interceptor_response->response = pending_response_.Pass(); 207 interceptor_response->response = pending_response_.Pass();
209 } else { 208 } else {
210 interceptor_response->request = BuildRequest(token); 209 interceptor_response->request = BuildRequest(token);
211 } 210 }
212 211
213 pending_interception_callback_.Run(interceptor_response.Pass()); 212 pending_interception_callback_.Run(interceptor_response.Pass());
214 pending_interception_callback_.reset(); 213 pending_interception_callback_.reset();
215 } 214 }
216 215
217 } // namespace mojo 216 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698