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

Unified Diff: components/cronet/android/cronet_url_request_adapter.h

Issue 586143002: Initial implementation of Cronet Async API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move userAgent into config, introduce ExtendedResponseInfo. Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/cronet_url_request_adapter.h
diff --git a/components/cronet/android/url_request_adapter.h b/components/cronet/android/cronet_url_request_adapter.h
similarity index 55%
copy from components/cronet/android/url_request_adapter.h
copy to components/cronet/android/cronet_url_request_adapter.h
index aad1893e6d1961004ee00828f9dda36d8edefbc9..ef280d8dd27a72194d2a7546517bc9e5f78d48fe 100644
--- a/components/cronet/android/url_request_adapter.h
+++ b/components/cronet/android/cronet_url_request_adapter.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_
-#define COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_
+#ifndef COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_
+#define COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_
#include <jni.h>
@@ -24,31 +24,34 @@ class UploadDataStream;
namespace cronet {
-class URLRequestContextAdapter;
+class CronetURLRequestContextAdapter;
// An adapter from the JNI |UrlRequest| object and the Chromium |URLRequest|
// object.
-class URLRequestAdapter : public net::URLRequest::Delegate {
+class CronetURLRequestAdapter : public net::URLRequest::Delegate {
mmenke 2014/10/02 15:24:09 I think we should make the JniCronetURLRequestAdap
mef 2014/10/02 22:07:43 Acknowledged. Per conversation we've agreed to hav
public:
// The delegate which is called when the request finishes.
- class URLRequestAdapterDelegate
- : public base::RefCountedThreadSafe<URLRequestAdapterDelegate> {
+ class CronetURLRequestAdapterDelegate
+ : public base::RefCountedThreadSafe<CronetURLRequestAdapterDelegate> {
public:
- virtual void OnResponseStarted(URLRequestAdapter* request) = 0;
- virtual void OnBytesRead(URLRequestAdapter* request) = 0;
- virtual void OnRequestFinished(URLRequestAdapter* request) = 0;
- virtual int ReadFromUploadChannel(net::IOBuffer* buf, int buf_length) = 0;
+ virtual void OnRedirect(CronetURLRequestAdapter* request,
+ const GURL& newLocation) = 0;
+ virtual void OnResponseStarted(CronetURLRequestAdapter* request) = 0;
+ virtual void OnBytesRead(CronetURLRequestAdapter* request,
+ int bytes_read) = 0;
+ virtual void OnRequestFinished(CronetURLRequestAdapter* request,
+ bool cancelled) = 0;
protected:
- friend class base::RefCountedThreadSafe<URLRequestAdapterDelegate>;
- virtual ~URLRequestAdapterDelegate() {}
+ friend class base::RefCountedThreadSafe<CronetURLRequestAdapterDelegate>;
+ virtual ~CronetURLRequestAdapterDelegate() {}
};
- URLRequestAdapter(URLRequestContextAdapter* context,
- URLRequestAdapterDelegate* delegate,
- GURL url,
- net::RequestPriority priority);
- virtual ~URLRequestAdapter();
+ CronetURLRequestAdapter(CronetURLRequestContextAdapter* context,
+ CronetURLRequestAdapterDelegate* delegate,
+ GURL url,
+ net::RequestPriority priority);
+ virtual ~CronetURLRequestAdapter();
// Sets the request method GET, POST etc
void SetMethod(const std::string& method);
@@ -56,23 +59,15 @@ class URLRequestAdapter : public net::URLRequest::Delegate {
// Adds a header to the request
void AddHeader(const std::string& name, const std::string& value);
- // Sets the contents of the POST or PUT request
- void SetUploadContent(const char* bytes, int bytes_len);
-
- // Sets the request to streaming upload.
- void SetUploadChannel(JNIEnv* env, int64 content_length);
-
- // Indicates that the request body will be streamed by calling AppendChunk()
- // repeatedly. This must be called before Start().
- void EnableChunkedUpload();
-
- // Appends a chunk to the POST body.
- // This must be called after EnableChunkedUpload() and Start().
- void AppendChunk(const char* bytes, int bytes_len, bool is_last_chunk);
-
// Starts the request.
void Start();
+ // Follow redirect.
+ void FollowDeferredRedirect();
+
+ // Read more data.
+ void ReadData();
+
// Cancels the request.
void Cancel();
@@ -112,35 +107,38 @@ class URLRequestAdapter : public net::URLRequest::Delegate {
// Get NPN or ALPN Negotiated Protocol (if any) from HttpResponseInfo.
std::string GetNegotiatedProtocol() const;
+ // Returns true if response is coming from the cache.
+ bool GetWasCached() const;
+
+ // Gets the total amount of data received from network after SSL decoding and
+ // proxy handling.
+ int64 GetTotalReceivedBytes() const;
+
+ // net::URLRequest::Delegate overrides
+ virtual void OnReceivedRedirect(net::URLRequest* request,
+ const net::RedirectInfo& redirect_info,
+ bool* defer_redirect) OVERRIDE;
+
virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE;
virtual void OnReadCompleted(net::URLRequest* request,
int bytes_read) OVERRIDE;
private:
- static void OnDestroyRequest(URLRequestAdapter* self);
-
- void OnInitiateConnection();
- void OnCancelRequest();
- void OnRequestSucceeded();
- void OnRequestFailed();
- void OnRequestCompleted();
- void OnRequestCanceled();
- void OnBytesRead(int bytes_read);
- void OnAppendChunk(const scoped_ptr<char[]> bytes, int bytes_len,
- bool is_last_chunk);
-
- void Read();
-
- URLRequestContextAdapter* context_;
- scoped_refptr<URLRequestAdapterDelegate> delegate_;
+ static void DestroyOnNetworkThread(CronetURLRequestAdapter* self);
+ void StartOnNetworkThread();
+ void FollowDeferredRedirectOnNetworkThread();
+ void ReadDataOnNetworkThread();
+ void CancelOnNetworkThread();
+
+ CronetURLRequestContextAdapter* context_;
+ scoped_refptr<CronetURLRequestAdapterDelegate> delegate_;
GURL url_;
net::RequestPriority priority_;
std::string method_;
net::HttpRequestHeaders headers_;
scoped_ptr<net::URLRequest> url_request_;
- scoped_ptr<net::UploadDataStream> upload_data_stream_;
- scoped_refptr<net::GrowableIOBuffer> read_buffer_;
+ scoped_refptr<net::IOBufferWithSize> read_buffer_;
int bytes_read_;
int total_bytes_read_;
int error_code_;
@@ -150,9 +148,9 @@ class URLRequestAdapter : public net::URLRequest::Delegate {
int64 expected_size_;
bool chunked_upload_;
- DISALLOW_COPY_AND_ASSIGN(URLRequestAdapter);
+ DISALLOW_COPY_AND_ASSIGN(CronetURLRequestAdapter);
};
} // namespace cronet
-#endif // COMPONENTS_CRONET_ANDROID_URL_REQUEST_ADAPTER_H_
+#endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_

Powered by Google App Engine
This is Rietveld 408576698