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..91ac3d6acc1d35e1b8150cf158a5d2ee0ccb8dbe |
--- /dev/null |
+++ b/components/cronet/android/cronet_url_request_adapter.h |
@@ -0,0 +1,140 @@ |
+// 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" |
+ |
+namespace base { |
+class SingleThreadTaskRunner; |
xunjieli
2014/10/17 00:31:34
nit: new line before ending a namespace.
mef
2014/10/17 20:19:42
Done. Although it looks funny. Should there be a n
xunjieli
2014/10/17 20:32:22
http://google-styleguide.googlecode.com/svn/trunk/
mmenke
2014/10/17 20:38:12
This falls under the keep with prevailing style ru
|
+} // namespace base |
+ |
+namespace net { |
+class GrowableIOBuffer; |
+class HttpResponseHeaders; |
+class UploadDataStream; |
+} // namespace net |
+ |
+namespace cronet { |
+ |
+class CronetURLRequestContextAdapter; |
+ |
+// An adapter from the JNI |UrlRequest| object and the Chromium |URLRequest| |
xunjieli
2014/10/17 00:31:34
nit: s/and/to ?
mef
2014/10/17 20:19:42
Done.
|
+// object. |
+class CronetURLRequestAdapter : public net::URLRequest::Delegate { |
+ public: |
+ // The delegate which is called when the request finishes. |
+ class CronetURLRequestAdapterDelegate |
+ : public base::RefCountedThreadSafe<CronetURLRequestAdapterDelegate> { |
+ public: |
+ virtual void OnRedirect(CronetURLRequestAdapter* request, |
xunjieli
2014/10/17 00:31:34
nit: I find using a longer name might improve the
mef
2014/10/17 20:19:42
Done.
|
+ 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<CronetURLRequestAdapterDelegate>; |
+ virtual ~CronetURLRequestAdapterDelegate() {} |
+ }; |
+ |
+ 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); |
+ |
+ // Adds a header to the request |
+ void AddRequestHeader(const std::string& name, const std::string& value); |
+ |
+ // Starts the request. |
+ void Start(); |
+ |
+ // Follow redirect. |
+ void FollowDeferredRedirect(); |
+ |
+ // Read more data. |
+ void ReadData(); |
+ |
+ // Cancels the request. |
+ void Cancel(); |
+ |
+ // Releases all resources for the request and deletes the object itself. |
+ void Destroy(); |
+ |
+ // Returns the URL of the request. |
+ GURL url() const { return url_; } |
+ |
+ // 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; |
+ |
+ // 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 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 request_headers_; |
+ scoped_ptr<net::URLRequest> url_request_; |
+ scoped_refptr<net::IOBufferWithSize> read_buffer_; |
+ int http_status_code_; |
+ bool canceled_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CronetURLRequestAdapter); |
+}; |
+ |
+} // namespace cronet |
+ |
+#endif // COMPONENTS_CRONET_ANDROID_CRONET_URL_REQUEST_ADAPTER_H_ |