| 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_CRONET_URL_REQUEST_ADAPTER_H_ | 5 #ifndef COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ |
| 6 #define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ | 6 #define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "net/base/request_priority.h" | 14 #include "net/base/request_priority.h" |
| 15 #include "net/http/http_request_headers.h" | 15 #include "net/http/http_request_headers.h" |
| 16 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
| 21 } // namespace base | 21 } // namespace base |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 class GrowableIOBuffer; | 24 class GrowableIOBuffer; |
| 25 class HttpResponseHeaders; | 25 class HttpResponseHeaders; |
| 26 class UploadDataStream; |
| 26 } // namespace net | 27 } // namespace net |
| 27 | 28 |
| 28 namespace cronet { | 29 namespace cronet { |
| 29 | 30 |
| 30 class CronetURLRequestContextAdapter; | 31 class CronetURLRequestContextAdapter; |
| 31 | 32 |
| 32 // An adapter from the JNI CronetUrlRequest object to the Chromium URLRequest. | 33 // An adapter from the JNI CronetUrlRequest object to the Chromium URLRequest. |
| 33 // Created and configured from random thread. Start is posted to network | 34 // Created and configured from random thread. Start is posted to network |
| 34 // thread and all callbacks into CronetURLRequestAdapterDelegate are done on | 35 // thread and all callbacks into CronetURLRequestAdapterDelegate are done on |
| 35 // network thread. Each delegate callback is expected to initiate next step like | 36 // network thread. Each delegate callback is expected to initiate next step like |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // Methods called prior to Start are never called on network thread. | 74 // Methods called prior to Start are never called on network thread. |
| 74 | 75 |
| 75 // Sets the request method GET, POST etc. | 76 // Sets the request method GET, POST etc. |
| 76 void set_method(const std::string& method) { | 77 void set_method(const std::string& method) { |
| 77 initial_method_ = method; | 78 initial_method_ = method; |
| 78 } | 79 } |
| 79 | 80 |
| 80 // Adds a header to the request before it starts. | 81 // Adds a header to the request before it starts. |
| 81 void AddRequestHeader(const std::string& name, const std::string& value); | 82 void AddRequestHeader(const std::string& name, const std::string& value); |
| 82 | 83 |
| 84 // Adds a request body to the request before it starts. |
| 85 void SetUpload(scoped_ptr<net::UploadDataStream> upload); |
| 86 |
| 87 net::UploadDataStream* GetUpload(); |
| 88 |
| 83 // Methods called on any thread. | 89 // Methods called on any thread. |
| 84 | 90 |
| 85 // Posts tasks to network thread. | 91 // Posts tasks to network thread. |
| 86 bool PostTaskToNetworkThread(const tracked_objects::Location& from_here, | 92 bool PostTaskToNetworkThread(const tracked_objects::Location& from_here, |
| 87 const base::Closure& task); | 93 const base::Closure& task); |
| 88 | 94 |
| 89 // Returns true if called on network thread. | 95 // Returns true if called on network thread. |
| 90 bool IsOnNetworkThread() const; | 96 bool IsOnNetworkThread() const; |
| 91 | 97 |
| 92 // Methods called only on network thread. | 98 // Methods called only on network thread. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // true, otherwise report error and cancel request_adapter. | 139 // true, otherwise report error and cancel request_adapter. |
| 134 bool MaybeReportError(net::URLRequest* request) const; | 140 bool MaybeReportError(net::URLRequest* request) const; |
| 135 | 141 |
| 136 CronetURLRequestContextAdapter* context_; | 142 CronetURLRequestContextAdapter* context_; |
| 137 scoped_ptr<CronetURLRequestAdapterDelegate> delegate_; | 143 scoped_ptr<CronetURLRequestAdapterDelegate> delegate_; |
| 138 | 144 |
| 139 const GURL initial_url_; | 145 const GURL initial_url_; |
| 140 const net::RequestPriority initial_priority_; | 146 const net::RequestPriority initial_priority_; |
| 141 std::string initial_method_; | 147 std::string initial_method_; |
| 142 net::HttpRequestHeaders initial_request_headers_; | 148 net::HttpRequestHeaders initial_request_headers_; |
| 149 scoped_ptr<net::UploadDataStream> upload_; |
| 143 | 150 |
| 144 scoped_refptr<net::IOBufferWithSize> read_buffer_; | 151 scoped_refptr<net::IOBufferWithSize> read_buffer_; |
| 145 scoped_ptr<net::URLRequest> url_request_; | 152 scoped_ptr<net::URLRequest> url_request_; |
| 146 | 153 |
| 147 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestAdapter); | 154 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestAdapter); |
| 148 }; | 155 }; |
| 149 | 156 |
| 150 } // namespace cronet | 157 } // namespace cronet |
| 151 | 158 |
| 152 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ | 159 #endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ |
| OLD | NEW |