| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "android_webview/browser/net/android_stream_reader_url_request_job.h" | 5 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "android_webview/browser/input_stream.h" | 9 #include "android_webview/browser/input_stream.h" |
| 10 #include "android_webview/browser/net/input_stream_reader.h" | 10 #include "android_webview/browser/net/input_stream_reader.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 using android_webview::InputStreamReader; | 34 using android_webview::InputStreamReader; |
| 35 using base::android::AttachCurrentThread; | 35 using base::android::AttachCurrentThread; |
| 36 using base::PostTaskAndReplyWithResult; | 36 using base::PostTaskAndReplyWithResult; |
| 37 using content::BrowserThread; | 37 using content::BrowserThread; |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 const int kHTTPOk = 200; | 41 const int kHTTPOk = 200; |
| 42 const int kHTTPNotFound = 404; | 42 const int kHTTPNotFound = 404; |
| 43 | 43 |
| 44 const char kResponseHeaderViaShouldInterceptRequest[] = |
| 45 "Client-Via: shouldInterceptRequest"; |
| 44 const char kHTTPOkText[] = "OK"; | 46 const char kHTTPOkText[] = "OK"; |
| 45 const char kHTTPNotFoundText[] = "Not Found"; | 47 const char kHTTPNotFoundText[] = "Not Found"; |
| 46 | 48 |
| 47 } // namespace | 49 } // namespace |
| 48 | 50 |
| 49 // The requests posted to the worker thread might outlive the job. Thread-safe | 51 // The requests posted to the worker thread might outlive the job. Thread-safe |
| 50 // ref counting is used to ensure that the InputStream and InputStreamReader | 52 // ref counting is used to ensure that the InputStream and InputStreamReader |
| 51 // members of this class are still there when the closure is run on the worker | 53 // members of this class are still there when the closure is run on the worker |
| 52 // thread. | 54 // thread. |
| 53 class InputStreamReaderWrapper : | 55 class InputStreamReaderWrapper : |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 317 |
| 316 std::string mime_type; | 318 std::string mime_type; |
| 317 if (GetMimeType(&mime_type) && !mime_type.empty()) { | 319 if (GetMimeType(&mime_type) && !mime_type.empty()) { |
| 318 std::string content_type_header(net::HttpRequestHeaders::kContentType); | 320 std::string content_type_header(net::HttpRequestHeaders::kContentType); |
| 319 content_type_header.append(": "); | 321 content_type_header.append(": "); |
| 320 content_type_header.append(mime_type); | 322 content_type_header.append(mime_type); |
| 321 headers->AddHeader(content_type_header); | 323 headers->AddHeader(content_type_header); |
| 322 } | 324 } |
| 323 } | 325 } |
| 324 | 326 |
| 327 // Indicate that the response had been obtained via shouldInterceptRequest. |
| 328 headers->AddHeader(kResponseHeaderViaShouldInterceptRequest); |
| 329 |
| 325 response_info_.reset(new net::HttpResponseInfo()); | 330 response_info_.reset(new net::HttpResponseInfo()); |
| 326 response_info_->headers = headers; | 331 response_info_->headers = headers; |
| 327 | 332 |
| 328 NotifyHeadersComplete(); | 333 NotifyHeadersComplete(); |
| 329 } | 334 } |
| 330 | 335 |
| 331 int AndroidStreamReaderURLRequestJob::GetResponseCode() const { | 336 int AndroidStreamReaderURLRequestJob::GetResponseCode() const { |
| 332 if (response_info_) | 337 if (response_info_) |
| 333 return response_info_->headers->response_code(); | 338 return response_info_->headers->response_code(); |
| 334 return URLRequestJob::GetResponseCode(); | 339 return URLRequestJob::GetResponseCode(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 353 } else { | 358 } else { |
| 354 // We don't support multiple range requests in one single URL request, | 359 // We don't support multiple range requests in one single URL request, |
| 355 // because we need to do multipart encoding here. | 360 // because we need to do multipart encoding here. |
| 356 NotifyDone(net::URLRequestStatus( | 361 NotifyDone(net::URLRequestStatus( |
| 357 net::URLRequestStatus::FAILED, | 362 net::URLRequestStatus::FAILED, |
| 358 net::ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 363 net::ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
| 359 } | 364 } |
| 360 } | 365 } |
| 361 } | 366 } |
| 362 } | 367 } |
| OLD | NEW |