| 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 20 matching lines...) Expand all Loading... |
| 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 OnResponseStarted(URLRequestAdapter* request) = 0; | 37 virtual void OnResponseStarted(URLRequestAdapter* request) = 0; |
| 38 virtual void OnBytesRead(URLRequestAdapter* request) = 0; | 38 virtual void OnBytesRead(URLRequestAdapter* request) = 0; |
| 39 virtual void OnRequestFinished(URLRequestAdapter* request) = 0; | 39 virtual void OnRequestFinished(URLRequestAdapter* request) = 0; |
| 40 virtual int ReadFromUploadChannel(net::IOBuffer* buf, int buf_length) = 0; | 40 virtual int ReadFromUploadChannel(net::IOBuffer* buf, int buf_length) = 0; |
| 41 virtual void OnAppendChunkCompleted(URLRequestAdapter* request) = 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 |
| 67 // AppendChunkToUpload() repeatedly. This must be called before Start(). |
| 68 void EnableChunkedUpload(); |
| 69 |
| 70 // Appends a chunk to the upload. |
| 71 // This must be called after EnableChunkedUpload() and Start(). |
| 72 void AppendChunkToUpload(const char* bytes, |
| 73 int bytes_len, |
| 74 bool is_last_chunk); |
| 75 |
| 65 // Starts the request. | 76 // Starts the request. |
| 66 void Start(); | 77 void Start(); |
| 67 | 78 |
| 68 // Cancels the request. | 79 // Cancels the request. |
| 69 void Cancel(); | 80 void Cancel(); |
| 70 | 81 |
| 71 // Releases all resources for the request and deletes the object itself. | 82 // Releases all resources for the request and deletes the object itself. |
| 72 void Destroy(); | 83 void Destroy(); |
| 73 | 84 |
| 74 // Returns the URL of the request. | 85 // Returns the URL of the request. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 net::URLRequest* url_request_; | 140 net::URLRequest* url_request_; |
| 130 scoped_ptr<net::UploadDataStream> upload_data_stream_; | 141 scoped_ptr<net::UploadDataStream> upload_data_stream_; |
| 131 scoped_refptr<net::GrowableIOBuffer> read_buffer_; | 142 scoped_refptr<net::GrowableIOBuffer> read_buffer_; |
| 132 int bytes_read_; | 143 int bytes_read_; |
| 133 int total_bytes_read_; | 144 int total_bytes_read_; |
| 134 int error_code_; | 145 int error_code_; |
| 135 int http_status_code_; | 146 int http_status_code_; |
| 136 std::string content_type_; | 147 std::string content_type_; |
| 137 bool canceled_; | 148 bool canceled_; |
| 138 int64 expected_size_; | 149 int64 expected_size_; |
| 150 bool chunked_upload_; |
| 139 | 151 |
| 140 DISALLOW_COPY_AND_ASSIGN(URLRequestAdapter); | 152 DISALLOW_COPY_AND_ASSIGN(URLRequestAdapter); |
| 141 }; | 153 }; |
| 142 | 154 |
| 143 } // namespace cronet | 155 } // namespace cronet |
| 144 | 156 |
| 145 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_ | 157 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_ |
| OLD | NEW |