Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: components/cronet/android/url_request_adapter.h

Issue 470443005: Cronet modifications to support AGSA. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "net/base/request_priority.h" 15 #include "net/base/request_priority.h"
16 #include "net/base/upload_data_stream.h"
mef 2014/08/15 13:30:22 not needed?
mdumitrescu 2014/08/15 15:23:13 Done.
16 #include "net/http/http_request_headers.h" 17 #include "net/http/http_request_headers.h"
17 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
18 19
19 namespace net { 20 namespace net {
20 class GrowableIOBuffer; 21 class GrowableIOBuffer;
21 class HttpResponseHeaders; 22 class HttpResponseHeaders;
22 class UploadDataStream; 23 class UploadDataStream;
23 } // namespace net 24 } // namespace net
24 25
25 namespace cronet { 26 namespace cronet {
26 27
27 class URLRequestContextAdapter; 28 class URLRequestContextAdapter;
28 29
29 // An adapter from the JNI |UrlRequest| object and the Chromium |URLRequest| 30 // An adapter from the JNI |UrlRequest| object and the Chromium |URLRequest|
30 // object. 31 // object.
31 class URLRequestAdapter : public net::URLRequest::Delegate { 32 class URLRequestAdapter : public net::URLRequest::Delegate {
32 public: 33 public:
33 // The delegate which is called when the request finishes. 34 // The delegate which is called when the request finishes.
34 class URLRequestAdapterDelegate 35 class URLRequestAdapterDelegate
35 : public base::RefCountedThreadSafe<URLRequestAdapterDelegate> { 36 : public base::RefCountedThreadSafe<URLRequestAdapterDelegate> {
36 public: 37 public:
38 virtual void OnAppendChunkCompleted(URLRequestAdapter* request) = 0;
37 virtual void OnResponseStarted(URLRequestAdapter* request) = 0; 39 virtual void OnResponseStarted(URLRequestAdapter* request) = 0;
38 virtual void OnBytesRead(URLRequestAdapter* request) = 0; 40 virtual void OnBytesRead(URLRequestAdapter* request) = 0;
39 virtual void OnRequestFinished(URLRequestAdapter* request) = 0; 41 virtual void OnRequestFinished(URLRequestAdapter* request) = 0;
40 virtual int ReadFromUploadChannel(net::IOBuffer* buf, int buf_length) = 0; 42 virtual int ReadFromUploadChannel(net::IOBuffer* buf, int buf_length) = 0;
41 43
42 protected: 44 protected:
43 friend class base::RefCountedThreadSafe<URLRequestAdapterDelegate>; 45 friend class base::RefCountedThreadSafe<URLRequestAdapterDelegate>;
44 virtual ~URLRequestAdapterDelegate() {} 46 virtual ~URLRequestAdapterDelegate() {}
45 }; 47 };
46 48
47 URLRequestAdapter(URLRequestContextAdapter* context, 49 URLRequestAdapter(URLRequestContextAdapter* context,
48 URLRequestAdapterDelegate* delegate, 50 URLRequestAdapterDelegate* delegate,
49 GURL url, 51 GURL url,
50 net::RequestPriority priority); 52 net::RequestPriority priority);
51 virtual ~URLRequestAdapter(); 53 virtual ~URLRequestAdapter();
52 54
53 // Sets the request method GET, POST etc 55 // Sets the request method GET, POST etc
54 void SetMethod(const std::string& method); 56 void SetMethod(const std::string& method);
55 57
56 // Adds a header to the request 58 // Adds a header to the request
57 void AddHeader(const std::string& name, const std::string& value); 59 void AddHeader(const std::string& name, const std::string& value);
58 60
59 // Sets the contents of the POST or PUT request 61 // Sets the contents of the POST or PUT request
60 void SetUploadContent(const char* bytes, int bytes_len); 62 void SetUploadContent(const char* bytes, int bytes_len);
61 63
62 // Sets the request to streaming upload. 64 // Sets the request to streaming upload.
63 void SetUploadChannel(JNIEnv* env, int64 content_length); 65 void SetUploadChannel(JNIEnv* env, int64 content_length);
64 66
67 // Indicates that the request body will be streamed by calling AppendChunk()
68 // repeatedly. This must be called before Start().
69 void EnableChunkedUpload();
70
71 // Appends a chunk to the POST body
72 // This must be called after EnableChunkedUpload() and Start().
73 void AppendChunk(const char* bytes, int bytes_len, bool is_last_chunk);
74
65 // Starts the request. 75 // Starts the request.
66 void Start(); 76 void Start();
67 77
68 // Cancels the request. 78 // Cancels the request.
69 void Cancel(); 79 void Cancel();
70 80
71 // Releases all resources for the request and deletes the object itself. 81 // Releases all resources for the request and deletes the object itself.
72 void Destroy(); 82 void Destroy();
73 83
74 // Returns the URL of the request. 84 // Returns the URL of the request.
(...skipping 13 matching lines...) Expand all
88 98
89 // Returns the value of the content-type response header. 99 // Returns the value of the content-type response header.
90 std::string content_type() const { return content_type_; } 100 std::string content_type() const { return content_type_; }
91 101
92 // Returns the value of the specified response header. 102 // Returns the value of the specified response header.
93 std::string GetHeader(const std::string& name) const; 103 std::string GetHeader(const std::string& name) const;
94 104
95 // Get all response headers, as a HttpResponseHeaders object. 105 // Get all response headers, as a HttpResponseHeaders object.
96 net::HttpResponseHeaders* GetResponseHeaders() const; 106 net::HttpResponseHeaders* GetResponseHeaders() const;
97 107
108 // Gets all headers.
109 bool GetFullRequestHeaders(net::HttpRequestHeaders* headers) const;
mef 2014/08/15 13:30:22 This is already there (see 'ChromiumUrlRequest.get
mdumitrescu 2014/08/15 15:23:13 That returns the response headers. We need the req
mef 2014/08/15 15:42:52 Could you elaborate? What's your scenario and what
110
98 // Returns the overall number of bytes read. 111 // Returns the overall number of bytes read.
99 size_t bytes_read() const { return bytes_read_; } 112 size_t bytes_read() const { return bytes_read_; }
100 113
101 // Returns a pointer to the downloaded data. 114 // Returns a pointer to the downloaded data.
102 unsigned char* Data() const; 115 unsigned char* Data() const;
103 116
104 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; 117 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE;
105 118
106 virtual void OnReadCompleted(net::URLRequest* request, 119 virtual void OnReadCompleted(net::URLRequest* request,
107 int bytes_read) OVERRIDE; 120 int bytes_read) OVERRIDE;
(...skipping 21 matching lines...) Expand all
129 net::URLRequest* url_request_; 142 net::URLRequest* url_request_;
130 scoped_ptr<net::UploadDataStream> upload_data_stream_; 143 scoped_ptr<net::UploadDataStream> upload_data_stream_;
131 scoped_refptr<net::GrowableIOBuffer> read_buffer_; 144 scoped_refptr<net::GrowableIOBuffer> read_buffer_;
132 int bytes_read_; 145 int bytes_read_;
133 int total_bytes_read_; 146 int total_bytes_read_;
134 int error_code_; 147 int error_code_;
135 int http_status_code_; 148 int http_status_code_;
136 std::string content_type_; 149 std::string content_type_;
137 bool canceled_; 150 bool canceled_;
138 int64 expected_size_; 151 int64 expected_size_;
152 bool chunked_upload_;
139 153
140 DISALLOW_COPY_AND_ASSIGN(URLRequestAdapter); 154 DISALLOW_COPY_AND_ASSIGN(URLRequestAdapter);
141 }; 155 };
142 156
143 } // namespace cronet 157 } // namespace cronet
144 158
145 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_ 159 #endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698