| OLD | NEW |
| 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/interfaces/network_service.mojom.h" | 9 #include "mojo/services/network/interfaces/network_service.mojom.h" |
| 10 | 10 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 auth_header->value = "Bearer " + token; | 178 auth_header->value = "Bearer " + token; |
| 179 headers.push_back(auth_header.Pass()); | 179 headers.push_back(auth_header.Pass()); |
| 180 } | 180 } |
| 181 | 181 |
| 182 URLRequestPtr request(mojo::URLRequest::New()); | 182 URLRequestPtr request(mojo::URLRequest::New()); |
| 183 request->url = url_.spec(); | 183 request->url = url_.spec(); |
| 184 request->auto_follow_redirects = false; | 184 request->auto_follow_redirects = false; |
| 185 request->cache_mode = cache_mode_; | 185 request->cache_mode = cache_mode_; |
| 186 request->headers = headers.Pass(); | 186 request->headers = headers.Pass(); |
| 187 | 187 |
| 188 return request.Pass(); | 188 return request; |
| 189 } | 189 } |
| 190 | 190 |
| 191 void AuthenticatingURLLoaderInterceptor::StartRequest( | 191 void AuthenticatingURLLoaderInterceptor::StartRequest( |
| 192 mojo::URLRequestPtr request) { | 192 mojo::URLRequestPtr request) { |
| 193 URLLoaderInterceptorResponsePtr interceptor_response = | 193 URLLoaderInterceptorResponsePtr interceptor_response = |
| 194 URLLoaderInterceptorResponse::New(); | 194 URLLoaderInterceptorResponse::New(); |
| 195 interceptor_response->request = request.Pass(); | 195 interceptor_response->request = request.Pass(); |
| 196 pending_interception_callback_.Run(interceptor_response.Pass()); | 196 pending_interception_callback_.Run(interceptor_response.Pass()); |
| 197 pending_interception_callback_.reset(); | 197 pending_interception_callback_.reset(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void AuthenticatingURLLoaderInterceptor::OnOAuth2TokenReceived( | 200 void AuthenticatingURLLoaderInterceptor::OnOAuth2TokenReceived( |
| 201 std::string token) { | 201 std::string token) { |
| 202 URLLoaderInterceptorResponsePtr interceptor_response = | 202 URLLoaderInterceptorResponsePtr interceptor_response = |
| 203 URLLoaderInterceptorResponse::New(); | 203 URLLoaderInterceptorResponse::New(); |
| 204 | 204 |
| 205 if (token.empty()) { | 205 if (token.empty()) { |
| 206 LOG(ERROR) << "Error while getting token"; | 206 LOG(ERROR) << "Error while getting token"; |
| 207 interceptor_response->response = pending_response_.Pass(); | 207 interceptor_response->response = pending_response_.Pass(); |
| 208 } else { | 208 } else { |
| 209 interceptor_response->request = BuildRequest(token); | 209 interceptor_response->request = BuildRequest(token); |
| 210 } | 210 } |
| 211 | 211 |
| 212 pending_interception_callback_.Run(interceptor_response.Pass()); | 212 pending_interception_callback_.Run(interceptor_response.Pass()); |
| 213 pending_interception_callback_.reset(); | 213 pending_interception_callback_.reset(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 } // namespace mojo | 216 } // namespace mojo |
| OLD | NEW |