Chromium Code Reviews| Index: components/cronet/android/cronet_url_request_adapter.h |
| diff --git a/components/cronet/android/cronet_url_request_adapter.h b/components/cronet/android/cronet_url_request_adapter.h |
| index 00726110b416e19e540385c16889de7b8c13bb7b..41333c919cd88843c440ad4a94ce1338c8cf28a4 100644 |
| --- a/components/cronet/android/cronet_url_request_adapter.h |
| +++ b/components/cronet/android/cronet_url_request_adapter.h |
| @@ -5,14 +5,17 @@ |
| #ifndef COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ |
| #define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ |
| +#include <jni.h> |
| #include <string> |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/android/scoped_java_ref.h" |
| #include "base/callback.h" |
| #include "base/location.h" |
| #include "base/macros.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "net/base/request_priority.h" |
| -#include "net/http/http_request_headers.h" |
| #include "net/url_request/url_request.h" |
| #include "url/gurl.h" |
| @@ -22,6 +25,7 @@ class SingleThreadTaskRunner; |
| namespace net { |
| class GrowableIOBuffer; |
| +class HttpRequestHeaders; |
| class HttpResponseHeaders; |
| class UploadDataStream; |
| } // namespace net |
| @@ -30,6 +34,8 @@ namespace cronet { |
| class CronetURLRequestContextAdapter; |
| +bool CronetUrlRequestAdapterRegisterJni(JNIEnv* env); |
| + |
| // An adapter from the JNI CronetUrlRequest object to the Chromium URLRequest. |
| // Created and configured from random thread. Start is posted to network |
| // thread and all callbacks into CronetURLRequestAdapterDelegate are done on |
| @@ -38,98 +44,70 @@ class CronetURLRequestContextAdapter; |
| // to set up a request must be called exclusively on the network thread. |
|
mmenke
2015/04/02 21:07:05
Update docs.
xunjieli
2015/04/02 21:50:13
Done.
|
| class CronetURLRequestAdapter : public net::URLRequest::Delegate { |
| public: |
| - // The delegate which is called when the request adapter completes a step. |
| - // Always called on network thread. |
| - class CronetURLRequestAdapterDelegate { |
| - public: |
| - // Called on redirect. Consumer should either destroy the request, or |
| - // call FollowDeferredRedirect. |
| - virtual void OnRedirect(const GURL& newLocation, int http_status_code) = 0; |
| - // Called when response has started and headers have been received. Consumer |
| - // should either destroy the request, or call ReadData. |
| - virtual void OnResponseStarted(int http_status_code) = 0; |
| - // Called when response bytes were read. Consumer should consume data and |
| - // either destroy the request, or call ReadData. The request may only be |
| - // destroyed after the embedder is done with |bytes|, as deleting the |
| - // request frees the buffer. |
| - virtual void OnBytesRead(unsigned char* bytes, |
| - int bytes_read) = 0; |
| - // Called when response has finished successfully. Consumer should destroy |
| - // the request. |
| - virtual void OnRequestFinished() = 0; |
| - // Called when response has finished with error. Consumer should destroy |
| - // the request. |
| - virtual void OnError(int net_error) = 0; |
| - |
| - virtual ~CronetURLRequestAdapterDelegate() {} |
| - }; |
| - |
| - CronetURLRequestAdapter( |
| - CronetURLRequestContextAdapter* context, |
| - scoped_ptr<CronetURLRequestAdapterDelegate> delegate, |
| - const GURL& url, |
| - net::RequestPriority priority); |
| + CronetURLRequestAdapter(CronetURLRequestContextAdapter* context, |
| + JNIEnv* env, |
| + jobject jurl_request, |
| + const GURL& url, |
| + net::RequestPriority priority); |
| ~CronetURLRequestAdapter() override; |
| // Methods called prior to Start are never called on network thread. |
| // Sets the request method GET, POST etc. |
| - void set_method(const std::string& method) { |
| - initial_method_ = method; |
| - } |
| + jboolean SetHttpMethod(JNIEnv* env, jobject jcaller, jstring jmethod); |
| // Adds a header to the request before it starts. |
| - void AddRequestHeader(const std::string& name, const std::string& value); |
| + jboolean AddRequestHeader(JNIEnv* env, |
| + jobject jcaller, |
| + jstring jname, |
| + jstring jvalue); |
| // Adds a request body to the request before it starts. |
| void SetUpload(scoped_ptr<net::UploadDataStream> upload); |
| - // Methods called on any thread. |
| - |
| - // Posts tasks to network thread. |
| - void PostTaskToNetworkThread(const tracked_objects::Location& from_here, |
| - const base::Closure& task); |
| + // Starts the request. |
| + void Start(JNIEnv* env, jobject jcaller); |
| - // Returns true if called on network thread. |
| - bool IsOnNetworkThread() const; |
| + // Reads more data. |
| + void ReadData(JNIEnv* env, jobject jcaller); |
| - // Methods called only on network thread. |
| + // Releases all resources for the request and deletes the object itself. |
| + void Destroy(JNIEnv* env, jobject jcaller); |
| - // Starts the request. |
| - void Start(); |
| + // Populate response headers on network thread. |
| + void PopulateResponseHeaders(JNIEnv* env, |
| + jobject jcaller, |
| + jobject jheaders_list); |
| // Follows redirect. |
| - void FollowDeferredRedirect(); |
| - |
| - // Reads more data. |
| - void ReadData(); |
| + void FollowDeferredRedirect(JNIEnv* env, jobject jcaller); |
|
mmenke
2015/04/02 21:07:05
Suggest putting this between Start and ReadData, t
xunjieli
2015/04/02 21:50:13
Done.
|
| - // Releases all resources for the request and deletes the object itself. |
| - void Destroy(); |
| + // Bypasses cache. If context is not set up to use cache, this call has no |
| + // effect. |
| + void DisableCache(JNIEnv* env, jobject jcaller); |
|
mmenke
2015/04/02 21:07:05
This should go up with the other ones that must be
xunjieli
2015/04/02 21:50:13
Done. Good rule for ordering. Thanks!
|
| // When called during a OnRedirect or OnResponseStarted callback, these |
| // methods return the corresponding response information. |
| - // Gets all response headers, as a HttpResponseHeaders object. Returns NULL |
| - // if the last attempted request received no headers. |
| - const net::HttpResponseHeaders* GetResponseHeaders() const; |
| + base::android::ScopedJavaLocalRef<jstring> GetHttpStatusText( |
| + JNIEnv* env, |
| + jobject jcaller) const; |
| // Gets NPN or ALPN Negotiated Protocol (if any) from HttpResponseInfo. |
| - const std::string& GetNegotiatedProtocol() const; |
| + base::android::ScopedJavaLocalRef<jstring> GetNegotiatedProtocol( |
| + JNIEnv* env, |
| + jobject jcaller) const; |
| // Returns true if response is coming from the cache. |
| - bool GetWasCached() const; |
| + jboolean GetWasCached(JNIEnv* env, jobject jcaller) const; |
| // Gets the total amount of body data received from network after |
| // SSL/SPDY/QUIC decoding and proxy handling. Basically the size of the body |
| // prior to decompression. |
| - int64 GetTotalReceivedBytes() const; |
| + int64 GetTotalReceivedBytes(JNIEnv* env, jobject jcaller) const; |
| - // Bypasses cache. If context is not set up to use cache, this call has no |
| - // effect. |
| - void DisableCache(); |
| + // net::URLRequest::Delegate implementations: |
| - // net::URLRequest::Delegate overrides. |
| void OnReceivedRedirect(net::URLRequest* request, |
| const net::RedirectInfo& redirect_info, |
| bool* defer_redirect) override; |
| @@ -137,12 +115,18 @@ class CronetURLRequestAdapter : public net::URLRequest::Delegate { |
| void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
| private: |
| + void StartOnNetworkThread(); |
| + void ReadDataOnNetworkThread(); |
| + void DestroyOnNetworkThread(); |
| + |
| // Checks status of the request_adapter, return false if |is_success()| is |
| // true, otherwise report error and cancel request_adapter. |
| bool MaybeReportError(net::URLRequest* request) const; |
| CronetURLRequestContextAdapter* context_; |
| - scoped_ptr<CronetURLRequestAdapterDelegate> delegate_; |
| + |
| + // Java object that owns the CronetURLRequestContextAdapter. |
| + base::android::ScopedJavaGlobalRef<jobject> owner_; |
| const GURL initial_url_; |
| const net::RequestPriority initial_priority_; |