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

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: Address review comments. Created 6 years, 2 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 51%
copy from components/cronet/android/url_request_adapter.h
copy to components/cronet/android/cronet_url_request_adapter.h
index aad1893e6d1961004ee00828f9dda36d8edefbc9..8141cfaae4f0f47c6f87bba866ec7232ab8df96e 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,35 @@ 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 {
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;
+ virtual void OnError(CronetURLRequestAdapter* request, int error) = 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 +60,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();
@@ -87,9 +83,7 @@ class URLRequestAdapter : public net::URLRequest::Delegate {
int error_code() const { return error_code_; }
mmenke 2014/10/06 18:28:44 Not used.
mef 2014/10/07 00:45:17 Done.
// Returns the HTTP status code.
- int http_status_code() const {
- return http_status_code_;
- };
+ int http_status_code() const { return http_status_code_; };
// Returns the value of the content-length response header.
int64 content_length() const { return expected_size_; }
mmenke 2014/10/06 18:28:44 Can tear this out, all the way up through nativeGe
mef 2014/10/07 00:45:17 Done.
@@ -112,35 +106,41 @@ 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();
+ // Check status of the request, return true if |is_success()| is true,
+ // otherwise report error and cancel request.
+ bool CheckStatus(net::URLRequest* request);
+
+ CronetURLRequestContextAdapter* context_;
+ scoped_refptr<CronetURLRequestAdapterDelegate> delegate_;
GURL url_;
net::RequestPriority priority_;
std::string method_;
net::HttpRequestHeaders headers_;
mmenke 2014/10/06 18:28:44 Suggest renaming this, and associated functions, t
mef 2014/10/07 00:45:17 Done.
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_;
mmenke 2014/10/06 18:28:44 These two are not used.
mef 2014/10/07 00:45:17 Done.
int error_code_;
mmenke 2014/10/06 18:28:44 Not used.
mef 2014/10/07 00:45:17 Done.
@@ -150,9 +150,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