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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9b3f6bfab361ec616c26f02d01d062315394cf20 |
| --- /dev/null |
| +++ b/components/cronet/android/cronet_url_request_adapter.h |
| @@ -0,0 +1,150 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#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/macros.h" |
| +#include "base/memory/ref_counted.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" |
|
mmenke
2014/10/23 16:26:00
Need GURL header
mef
2014/10/24 03:31:43
Done.
|
| + |
| +namespace base { |
| +class SingleThreadTaskRunner; |
| +} // namespace base |
| + |
| +namespace net { |
| +class GrowableIOBuffer; |
| +class HttpResponseHeaders; |
| +class UploadDataStream; |
| +} // namespace net |
| + |
| +namespace cronet { |
| + |
| +class CronetURLRequestContextAdapter; |
| + |
| +// An adapter from the JNI |UrlRequest| object to the Chromium |URLRequest| |
|
mmenke
2014/10/23 16:26:00
+.
mmenke
2014/10/23 16:26:00
nit: Don't use || around class names, just variab
mmenke
2014/10/23 16:26:01
UrlRequest -> CronetUrlRequest?
mef
2014/10/24 03:31:43
Done.
mef
2014/10/24 03:31:43
Done.
mef
2014/10/24 03:31:43
Done.
|
| +// object. |
| +class CronetURLRequestAdapter : public net::URLRequest::Delegate { |
| + public: |
| + // The delegate which is called when the request_adapter finishes. |
| + class CronetURLRequestAdapterDelegate |
| + : public base::RefCountedThreadSafe<CronetURLRequestAdapterDelegate> { |
|
mmenke
2014/10/23 16:26:01
Does this need to be refcounted?
|
| + public: |
| + virtual void OnRedirect(CronetURLRequestAdapter* request_adapter, |
| + const GURL& newLocation) = 0; |
| + virtual void OnResponseStarted( |
| + CronetURLRequestAdapter* request_adapter) = 0; |
| + virtual void OnBytesRead(CronetURLRequestAdapter* request_adapter, |
| + int bytes_read) = 0; |
| + virtual void OnRequestCanceled( |
| + CronetURLRequestAdapter* request_adapter) = 0; |
| + virtual void OnRequestFinished( |
| + CronetURLRequestAdapter* request_adapter) = 0; |
| + virtual void OnError(CronetURLRequestAdapter* request_adapter, |
| + int error) = 0; |
| + |
| + protected: |
| + friend class base::RefCountedThreadSafe<CronetURLRequestAdapterDelegate>; |
| + virtual ~CronetURLRequestAdapterDelegate() {} |
| + }; |
| + |
| + CronetURLRequestAdapter(CronetURLRequestContextAdapter* context, |
| + CronetURLRequestAdapterDelegate* delegate, |
| + GURL url, |
|
mmenke
2014/10/23 16:26:01
const GURL&
mef
2014/10/24 03:31:43
Done.
|
| + net::RequestPriority priority); |
| + virtual ~CronetURLRequestAdapter(); |
|
mmenke
2014/10/23 16:26:00
-virtual +override
mef
2014/10/24 03:31:43
Done.
|
| + |
| + // Sets the request_adapter method GET, POST etc |
|
mmenke
2014/10/23 16:26:01
request_adapter -> request? There is nothing here
mmenke
2014/10/23 16:26:01
nit: +.
mef
2014/10/24 03:31:43
Done.
mef
2014/10/24 03:31:44
Done.
|
| + void SetMethod(const std::string& method); |
| + |
| + // Adds a header to the request_adapter |
|
mmenke
2014/10/23 16:26:00
nit: +.
mmenke
2014/10/23 16:26:01
...to the request before it starts?
mef
2014/10/24 03:31:43
Done.
mef
2014/10/24 03:31:43
Done.
|
| + void AddRequestHeader(const std::string& name, const std::string& value); |
| + |
| + // Starts the request_adapter. |
|
mmenke
2014/10/23 16:26:00
->request?
mef
2014/10/24 03:31:44
Done.
|
| + void Start(); |
| + |
| + // Follow redirect. |
| + void FollowDeferredRedirect(); |
| + |
| + // Read more data. |
| + void ReadData(); |
| + |
| + // Cancels the request_adapter. |
|
mmenke
2014/10/23 16:26:01
CAncels the request? Though we may be able to get
mef
2014/10/24 03:31:43
Done.
|
| + void Cancel(); |
| + |
| + // Releases all resources for the request_adapter and deletes the object |
| + // itself. |
| + void Destroy(); |
| + |
| + // Returns the URL of the request_adapter. |
| + GURL url() const { return url_; } |
|
mmenke
2014/10/23 16:26:01
const GURL&
mef
2014/10/24 03:31:43
Done.
|
| + |
| + // Returns the HTTP status code. |
| + int http_status_code() const { return http_status_code_; }; |
| + |
| + // Get all response headers, as a HttpResponseHeaders object. |
| + net::HttpResponseHeaders* GetResponseHeaders() const; |
| + |
| + // Returns a pointer to the downloaded data. |
| + unsigned char* Data() const; |
| + |
| + // Get NPN or ALPN Negotiated Protocol (if any) from HttpResponseInfo. |
| + std::string GetNegotiatedProtocol() const; |
|
mmenke
2014/10/23 16:26:00
const std::string&
mef
2014/10/24 03:31:44
It doesn't work right now as we return empty strin
|
| + |
| + // 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 |
| + void OnReceivedRedirect(net::URLRequest* request, |
| + const net::RedirectInfo& redirect_info, |
| + bool* defer_redirect) override; |
| + |
| + void OnResponseStarted(net::URLRequest* request) override; |
| + |
| + void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
| + // Return true if currently running on network thread. |
| + bool IsOnNetworkThread() const; |
| + |
| + private: |
| + void StartOnNetworkThread(); |
| + void FollowDeferredRedirectOnNetworkThread(); |
| + void ReadDataOnNetworkThread(); |
| + void CancelOnNetworkThread(); |
| + // Check whether request was cancelled while |called_to_delegate_| and if so, |
| + // then perform actual cancellation and return true. |
| + bool WasCanceledWhileCalledToDelegate(); |
| + // Check status of the request_adapter, return true if |is_success()| is true, |
| + // otherwise report error and cancel request_adapter. |
| + bool CheckStatus(net::URLRequest* request); |
| + |
| + |
| + CronetURLRequestContextAdapter* context_; |
| + scoped_refptr<CronetURLRequestAdapterDelegate> delegate_; |
| + GURL url_; |
| + net::RequestPriority priority_; |
| + std::string method_; |
| + net::HttpRequestHeaders request_headers_; |
|
mmenke
2014/10/23 16:26:01
Should prefix the above 4 variables (With the poss
mef
2014/10/24 03:31:43
Done.
|
| + scoped_ptr<net::URLRequest> url_request_; |
| + scoped_refptr<net::IOBufferWithSize> read_buffer_; |
| + int http_status_code_; |
| + bool called_to_delegate_; |
| + bool cancel_soon_; |
|
xunjieli
2014/10/22 21:02:16
nit: should we initialize these booleans?
mef
2014/10/24 03:31:43
Yes, they are initialized in constructor.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(CronetURLRequestAdapter); |
| +}; |
| + |
| +} // namespace cronet |
| + |
| +#endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ |