Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef NET_CRONET_ANDROID_URL_REQUEST_PEER_H_ | |
| 6 #define NET_CRONET_ANDROID_URL_REQUEST_PEER_H_ | |
| 7 | |
| 8 #include "net/base/upload_data_stream.h" | |
| 9 #include "net/cronet/android/url_request_context_peer.h" | |
| 10 #include "net/http/http_request_headers.h" | |
| 11 #include "net/url_request/url_request.h" | |
|
mmenke
2014/02/27 23:06:02
ref_ptr, request_priority, OVERRIDE, DISALLOW_COPY
mef
2014/03/03 19:15:13
Done.
| |
| 12 | |
| 13 // An adapter from the JNI |UrlRequest| object and the Chromium |URLRequest| | |
| 14 // object. | |
| 15 class URLRequestPeer : public net::URLRequest::Delegate { | |
| 16 public: | |
| 17 /* | |
| 18 * The delegate which is called when the request finishes. | |
| 19 */ | |
|
mmenke
2014/02/27 23:06:02
C++-style comments?
mef
2014/03/03 19:15:13
Done.
| |
| 20 class URLRequestPeerDelegate | |
| 21 : public base::RefCountedThreadSafe<URLRequestPeerDelegate> { | |
| 22 public: | |
| 23 virtual void OnAppendChunkCompleted(URLRequestPeer* request) = 0; | |
| 24 virtual void OnResponseStarted(URLRequestPeer* request) = 0; | |
| 25 virtual void OnBytesRead(URLRequestPeer* request) = 0; | |
| 26 virtual void OnRequestFinished(URLRequestPeer* request) = 0; | |
| 27 | |
| 28 protected: | |
| 29 friend class base::RefCountedThreadSafe<URLRequestPeerDelegate>; | |
| 30 virtual ~URLRequestPeerDelegate() {} | |
| 31 }; | |
| 32 | |
| 33 URLRequestPeer(URLRequestContextPeer* context, | |
| 34 URLRequestPeerDelegate* delegate, GURL url, | |
| 35 net::RequestPriority priority); | |
| 36 virtual ~URLRequestPeer(); | |
| 37 | |
| 38 // Sets the request method GET, POST etc | |
| 39 void SetMethod(const std::string& method); | |
| 40 | |
| 41 // Adds a header to the request | |
| 42 void AddHeader(const std::string& name, const std::string& value); | |
| 43 | |
| 44 // Sets the contents of the POST request | |
| 45 void SetPostContent(const char* bytes, int bytes_len); | |
| 46 | |
| 47 // Indicates that the request body will be streamed by calling AppendChunk() | |
| 48 // repeatedly. This must be called before Start(). | |
| 49 void EnableStreamingUpload(); | |
| 50 | |
| 51 // Appends a chunk to the POST body | |
| 52 // This must be called after EnableChunkedUpload() and Start(). | |
| 53 void AppendChunk(const char *bytes, int bytes_len, bool is_last_chunk); | |
| 54 | |
| 55 // Starts the request. | |
| 56 void Start(); | |
| 57 | |
| 58 // Cancels the request. | |
| 59 void Cancel(); | |
| 60 | |
| 61 // Releases all resources for the request and deletes the object itself. | |
| 62 void Destroy(); | |
| 63 | |
| 64 // Returns the URL of the request. | |
| 65 GURL url() const; | |
| 66 | |
| 67 // Returns the error code after the request is complete. | |
| 68 // Negative codes indicate system errors. | |
| 69 int error_code() const; | |
| 70 | |
| 71 // Returns the HTTP status code. | |
| 72 int http_status_code() const; | |
| 73 | |
| 74 // Returns the value of the content-length response header. | |
| 75 int64 content_length() const; | |
| 76 | |
| 77 // Returns the value of the content-type response header. | |
| 78 std::string content_type() const; | |
| 79 | |
| 80 // Returns the overall number of bytes read. | |
| 81 size_t BytesRead() const; | |
| 82 | |
| 83 // Returns a pointer to the downloaded data. | |
| 84 unsigned char* Data() const; | |
| 85 | |
| 86 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; | |
| 87 | |
| 88 virtual void OnReadCompleted(net::URLRequest* request, | |
| 89 int bytes_read) OVERRIDE; | |
| 90 | |
| 91 private: | |
| 92 typedef Delegate inherited; | |
|
mmenke
2014/02/27 23:06:02
?
mef
2014/03/03 19:15:13
Done.
| |
| 93 | |
| 94 URLRequestContextPeer* context_; | |
| 95 scoped_refptr<URLRequestPeerDelegate> delegate_; | |
| 96 GURL url_; | |
| 97 net::RequestPriority priority_; | |
| 98 std::string method_; | |
| 99 net::HttpRequestHeaders headers_; | |
| 100 net::URLRequest* url_request_; | |
| 101 scoped_ptr<net::UploadDataStream> upload_data_stream_; | |
| 102 scoped_refptr<net::GrowableIOBuffer> read_buffer_; | |
| 103 int bytes_read_; | |
| 104 int total_bytes_read_; | |
| 105 int error_code_; | |
| 106 int http_status_code_; | |
| 107 std::string content_type_; | |
| 108 bool canceled_; | |
| 109 int64 expected_size_; | |
| 110 bool streaming_upload_; | |
| 111 | |
| 112 static void OnInitiateConnectionWrapper(URLRequestPeer* self); | |
| 113 static void OnCancelRequestWrapper(URLRequestPeer* self); | |
| 114 static void OnDestroyRequest(URLRequestPeer* self); | |
| 115 static void OnAppendChunkWrapper(URLRequestPeer *self, const char *bytes, | |
| 116 int bytes_len, bool is_last_chunk); | |
| 117 | |
| 118 void OnInitiateConnection(); | |
| 119 void OnCancelRequest(); | |
| 120 void OnRequestSucceeded(); | |
| 121 void OnRequestFailed(); | |
| 122 void OnRequestCompleted(); | |
| 123 void OnRequestCanceled(); | |
| 124 void OnBytesRead(int bytes_read); | |
| 125 void OnAppendChunk(const char *bytes, int bytes_len, bool is_last_chunk); | |
| 126 | |
| 127 void Read(); | |
| 128 | |
| 129 DISALLOW_EVIL_CONSTRUCTORS(URLRequestPeer); | |
|
mmenke
2014/02/27 23:06:02
DISALLOW_COPY_AND_ASSIGN?
mef
2014/03/03 19:15:13
Done.
| |
| 130 }; | |
| 131 | |
| 132 #endif // NET_CRONET_ANDROID_URL_REQUEST_PEER_H_ | |
| OLD | NEW |