Fix race condition in gyp/ninja builds.
[chromium-blink-merge.git] / android_webview / browser / aw_web_resource_response.cc
blob412d9c2a04f7d956d9094b3cc5139f685174734e
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
3 // found in the LICENSE file.
5 #include "android_webview/browser/aw_web_resource_response.h"
7 #include "android_webview/browser/input_stream.h"
8 #include "android_webview/browser/net/android_stream_reader_url_request_job.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "net/http/http_response_headers.h"
12 namespace android_webview {
14 namespace {
16 class StreamReaderJobDelegateImpl
17 : public AndroidStreamReaderURLRequestJob::Delegate {
18 public:
19 StreamReaderJobDelegateImpl(
20 scoped_ptr<AwWebResourceResponse> aw_web_resource_response)
21 : aw_web_resource_response_(aw_web_resource_response.Pass()) {
22 DCHECK(aw_web_resource_response_);
25 virtual scoped_ptr<InputStream> OpenInputStream(JNIEnv* env,
26 const GURL& url) OVERRIDE {
27 return aw_web_resource_response_->GetInputStream(env).Pass();
30 virtual void OnInputStreamOpenFailed(net::URLRequest* request,
31 bool* restart) OVERRIDE {
32 *restart = false;
35 virtual bool GetMimeType(JNIEnv* env,
36 net::URLRequest* request,
37 android_webview::InputStream* stream,
38 std::string* mime_type) OVERRIDE {
39 return aw_web_resource_response_->GetMimeType(env, mime_type);
42 virtual bool GetCharset(JNIEnv* env,
43 net::URLRequest* request,
44 android_webview::InputStream* stream,
45 std::string* charset) OVERRIDE {
46 return aw_web_resource_response_->GetCharset(env, charset);
49 virtual void AppendResponseHeaders(
50 JNIEnv* env,
51 net::HttpResponseHeaders* headers) OVERRIDE {
52 int status_code;
53 std::string reason_phrase;
54 if (aw_web_resource_response_->GetStatusInfo(
55 env, &status_code, &reason_phrase)) {
56 std::string status_line("HTTP/1.1 ");
57 status_line.append(base::IntToString(status_code));
58 status_line.append(" ");
59 status_line.append(reason_phrase);
60 headers->ReplaceStatusLine(status_line);
62 aw_web_resource_response_->GetResponseHeaders(env, headers);
65 private:
66 scoped_ptr<AwWebResourceResponse> aw_web_resource_response_;
69 } // namespace
71 // static
72 net::URLRequestJob* AwWebResourceResponse::CreateJobFor(
73 scoped_ptr<AwWebResourceResponse> aw_web_resource_response,
74 net::URLRequest* request,
75 net::NetworkDelegate* network_delegate) {
76 DCHECK(aw_web_resource_response);
77 DCHECK(request);
78 DCHECK(network_delegate);
80 return new AndroidStreamReaderURLRequestJob(
81 request,
82 network_delegate,
83 make_scoped_ptr(
84 new StreamReaderJobDelegateImpl(aw_web_resource_response.Pass()))
85 .PassAs<AndroidStreamReaderURLRequestJob::Delegate>());
88 } // namespace android_webview