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 #ifndef COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_ | 5 #ifndef COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_ |
6 #define COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_ | 6 #define COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // Returns a pointer to the downloaded data. | 117 // Returns a pointer to the downloaded data. |
118 unsigned char* Data() const; | 118 unsigned char* Data() const; |
119 | 119 |
120 // Get NPN or ALPN Negotiated Protocol (if any) from HttpResponseInfo. | 120 // Get NPN or ALPN Negotiated Protocol (if any) from HttpResponseInfo. |
121 std::string GetNegotiatedProtocol() const; | 121 std::string GetNegotiatedProtocol() const; |
122 | 122 |
123 // Returns whether the response is serviced from cache. | 123 // Returns whether the response is serviced from cache. |
124 bool GetWasCached() const; | 124 bool GetWasCached() const; |
125 | 125 |
126 // net::URLRequest::Delegate implementation: | 126 // net::URLRequest::Delegate implementation: |
127 void OnResponseStarted(net::URLRequest* request) override; | 127 void OnResponseStarted(net::URLRequest* request, int net_error) override; |
128 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | 128 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
129 void OnReceivedRedirect(net::URLRequest* request, | 129 void OnReceivedRedirect(net::URLRequest* request, |
130 const net::RedirectInfo& redirect_info, | 130 const net::RedirectInfo& redirect_info, |
131 bool* defer_redirect) override; | 131 bool* defer_redirect) override; |
132 | 132 |
133 bool OnNetworkThread() const; | 133 bool OnNetworkThread() const; |
134 | 134 |
135 private: | 135 private: |
136 static void OnDestroyRequest(URLRequestAdapter* self); | 136 static void OnDestroyRequest(URLRequestAdapter* self); |
137 | 137 |
138 void OnInitiateConnection(); | 138 void OnInitiateConnection(); |
139 void OnCancelRequest(); | 139 void OnCancelRequest(); |
140 void OnRequestSucceeded(); | 140 void OnRequestSucceeded(); |
141 void OnRequestFailed(); | 141 void OnRequestFailed(int net_error); |
142 void OnRequestCompleted(); | 142 void OnRequestCompleted(); |
143 void OnAppendChunk(const std::unique_ptr<char[]> bytes, | 143 void OnAppendChunk(const std::unique_ptr<char[]> bytes, |
144 int bytes_len, | 144 int bytes_len, |
145 bool is_last_chunk); | 145 bool is_last_chunk); |
146 | 146 |
147 void Read(); | 147 void Read(); |
148 | 148 |
149 // Handles synchronous or asynchronous read result, calls |delegate_| with | 149 // Handles synchronous or asynchronous read result, calls |delegate_| with |
150 // bytes read and returns true unless request has succeeded or failed. | 150 // bytes read and returns true unless request has succeeded or failed. |
151 bool HandleReadResult(int bytes_read); | 151 bool HandleReadResult(int result); |
152 | 152 |
153 URLRequestContextAdapter* context_; | 153 URLRequestContextAdapter* context_; |
154 scoped_refptr<URLRequestAdapterDelegate> delegate_; | 154 scoped_refptr<URLRequestAdapterDelegate> delegate_; |
155 GURL url_; | 155 GURL url_; |
156 net::RequestPriority priority_; | 156 net::RequestPriority priority_; |
157 std::string method_; | 157 std::string method_; |
158 net::HttpRequestHeaders headers_; | 158 net::HttpRequestHeaders headers_; |
159 std::unique_ptr<net::URLRequest> url_request_; | 159 std::unique_ptr<net::URLRequest> url_request_; |
160 std::unique_ptr<net::UploadDataStream> upload_data_stream_; | 160 std::unique_ptr<net::UploadDataStream> upload_data_stream_; |
161 std::unique_ptr<net::ChunkedUploadDataStream::Writer> chunked_upload_writer_; | 161 std::unique_ptr<net::ChunkedUploadDataStream::Writer> chunked_upload_writer_; |
162 scoped_refptr<net::IOBufferWithSize> read_buffer_; | 162 scoped_refptr<net::IOBufferWithSize> read_buffer_; |
163 int total_bytes_read_; | 163 int total_bytes_read_; |
164 int error_code_; | 164 int error_code_; |
165 int http_status_code_; | 165 int http_status_code_; |
166 std::string http_status_text_; | 166 std::string http_status_text_; |
167 std::string content_type_; | 167 std::string content_type_; |
168 bool canceled_; | 168 bool canceled_; |
169 int64_t expected_size_; | 169 int64_t expected_size_; |
170 bool chunked_upload_; | 170 bool chunked_upload_; |
171 // Indicates whether redirect has been disabled. | 171 // Indicates whether redirect has been disabled. |
172 bool disable_redirect_; | 172 bool disable_redirect_; |
173 | 173 |
174 DISALLOW_COPY_AND_ASSIGN(URLRequestAdapter); | 174 DISALLOW_COPY_AND_ASSIGN(URLRequestAdapter); |
175 }; | 175 }; |
176 | 176 |
177 } // namespace cronet | 177 } // namespace cronet |
178 | 178 |
179 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_ | 179 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_ |
OLD | NEW |