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 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 16 matching lines...) Expand all Loading... |
27 class URLRequestContextAdapter; | 27 class URLRequestContextAdapter; |
28 | 28 |
29 // An adapter from the JNI |UrlRequest| object and the Chromium |URLRequest| | 29 // An adapter from the JNI |UrlRequest| object and the Chromium |URLRequest| |
30 // object. | 30 // object. |
31 class URLRequestAdapter : public net::URLRequest::Delegate { | 31 class URLRequestAdapter : public net::URLRequest::Delegate { |
32 public: | 32 public: |
33 // The delegate which is called when the request finishes. | 33 // The delegate which is called when the request finishes. |
34 class URLRequestAdapterDelegate | 34 class URLRequestAdapterDelegate |
35 : public base::RefCountedThreadSafe<URLRequestAdapterDelegate> { | 35 : public base::RefCountedThreadSafe<URLRequestAdapterDelegate> { |
36 public: | 36 public: |
| 37 virtual void OnAppendChunkCompleted(URLRequestAdapter* request) = 0; |
37 virtual void OnResponseStarted(URLRequestAdapter* request) = 0; | 38 virtual void OnResponseStarted(URLRequestAdapter* request) = 0; |
38 virtual void OnBytesRead(URLRequestAdapter* request) = 0; | 39 virtual void OnBytesRead(URLRequestAdapter* request) = 0; |
39 virtual void OnRequestFinished(URLRequestAdapter* request) = 0; | 40 virtual void OnRequestFinished(URLRequestAdapter* request) = 0; |
40 virtual int ReadFromUploadChannel(net::IOBuffer* buf, int buf_length) = 0; | 41 virtual int ReadFromUploadChannel(net::IOBuffer* buf, int buf_length) = 0; |
41 | 42 |
42 protected: | 43 protected: |
43 friend class base::RefCountedThreadSafe<URLRequestAdapterDelegate>; | 44 friend class base::RefCountedThreadSafe<URLRequestAdapterDelegate>; |
44 virtual ~URLRequestAdapterDelegate() {} | 45 virtual ~URLRequestAdapterDelegate() {} |
45 }; | 46 }; |
46 | 47 |
47 URLRequestAdapter(URLRequestContextAdapter* context, | 48 URLRequestAdapter(URLRequestContextAdapter* context, |
48 URLRequestAdapterDelegate* delegate, | 49 URLRequestAdapterDelegate* delegate, |
49 GURL url, | 50 GURL url, |
50 net::RequestPriority priority); | 51 net::RequestPriority priority); |
51 virtual ~URLRequestAdapter(); | 52 virtual ~URLRequestAdapter(); |
52 | 53 |
53 // Sets the request method GET, POST etc | 54 // Sets the request method GET, POST etc |
54 void SetMethod(const std::string& method); | 55 void SetMethod(const std::string& method); |
55 | 56 |
56 // Adds a header to the request | 57 // Adds a header to the request |
57 void AddHeader(const std::string& name, const std::string& value); | 58 void AddHeader(const std::string& name, const std::string& value); |
58 | 59 |
59 // Sets the contents of the POST or PUT request | 60 // Sets the contents of the POST or PUT request |
60 void SetUploadContent(const char* bytes, int bytes_len); | 61 void SetUploadContent(const char* bytes, int bytes_len); |
61 | 62 |
62 // Sets the request to streaming upload. | 63 // Sets the request to streaming upload. |
63 void SetUploadChannel(JNIEnv* env, int64 content_length); | 64 void SetUploadChannel(JNIEnv* env, int64 content_length); |
64 | 65 |
| 66 // Indicates that the request body will be streamed by calling AppendChunk() |
| 67 // repeatedly. This must be called before Start(). |
| 68 void EnableChunkedUpload(); |
| 69 |
| 70 // Appends a chunk to the POST body. |
| 71 // This must be called after EnableChunkedUpload() and Start(). |
| 72 void AppendChunk(const char* bytes, int bytes_len, bool is_last_chunk); |
| 73 |
65 // Starts the request. | 74 // Starts the request. |
66 void Start(); | 75 void Start(); |
67 | 76 |
68 // Cancels the request. | 77 // Cancels the request. |
69 void Cancel(); | 78 void Cancel(); |
70 | 79 |
71 // Releases all resources for the request and deletes the object itself. | 80 // Releases all resources for the request and deletes the object itself. |
72 void Destroy(); | 81 void Destroy(); |
73 | 82 |
74 // Returns the URL of the request. | 83 // Returns the URL of the request. |
(...skipping 13 matching lines...) Expand all Loading... |
88 | 97 |
89 // Returns the value of the content-type response header. | 98 // Returns the value of the content-type response header. |
90 std::string content_type() const { return content_type_; } | 99 std::string content_type() const { return content_type_; } |
91 | 100 |
92 // Returns the value of the specified response header. | 101 // Returns the value of the specified response header. |
93 std::string GetHeader(const std::string& name) const; | 102 std::string GetHeader(const std::string& name) const; |
94 | 103 |
95 // Get all response headers, as a HttpResponseHeaders object. | 104 // Get all response headers, as a HttpResponseHeaders object. |
96 net::HttpResponseHeaders* GetResponseHeaders() const; | 105 net::HttpResponseHeaders* GetResponseHeaders() const; |
97 | 106 |
| 107 // Gets all request headers, if possible. |
| 108 bool GetFullRequestHeaders(net::HttpRequestHeaders* headers) const; |
| 109 |
98 // Returns the overall number of bytes read. | 110 // Returns the overall number of bytes read. |
99 size_t bytes_read() const { return bytes_read_; } | 111 size_t bytes_read() const { return bytes_read_; } |
100 | 112 |
101 // Returns a pointer to the downloaded data. | 113 // Returns a pointer to the downloaded data. |
102 unsigned char* Data() const; | 114 unsigned char* Data() const; |
103 | 115 |
104 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; | 116 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; |
105 | 117 |
106 virtual void OnReadCompleted(net::URLRequest* request, | 118 virtual void OnReadCompleted(net::URLRequest* request, |
107 int bytes_read) OVERRIDE; | 119 int bytes_read) OVERRIDE; |
(...skipping 21 matching lines...) Expand all Loading... |
129 net::URLRequest* url_request_; | 141 net::URLRequest* url_request_; |
130 scoped_ptr<net::UploadDataStream> upload_data_stream_; | 142 scoped_ptr<net::UploadDataStream> upload_data_stream_; |
131 scoped_refptr<net::GrowableIOBuffer> read_buffer_; | 143 scoped_refptr<net::GrowableIOBuffer> read_buffer_; |
132 int bytes_read_; | 144 int bytes_read_; |
133 int total_bytes_read_; | 145 int total_bytes_read_; |
134 int error_code_; | 146 int error_code_; |
135 int http_status_code_; | 147 int http_status_code_; |
136 std::string content_type_; | 148 std::string content_type_; |
137 bool canceled_; | 149 bool canceled_; |
138 int64 expected_size_; | 150 int64 expected_size_; |
| 151 bool chunked_upload_; |
139 | 152 |
140 DISALLOW_COPY_AND_ASSIGN(URLRequestAdapter); | 153 DISALLOW_COPY_AND_ASSIGN(URLRequestAdapter); |
141 }; | 154 }; |
142 | 155 |
143 } // namespace cronet | 156 } // namespace cronet |
144 | 157 |
145 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_ | 158 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_ |
OLD | NEW |