| Index: net/cronet/android/url_request_peer.h
|
| diff --git a/net/cronet/android/url_request_peer.h b/net/cronet/android/url_request_peer.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3dc5722884b3a6930912f36ab2c5307c9af826a9
|
| --- /dev/null
|
| +++ b/net/cronet/android/url_request_peer.h
|
| @@ -0,0 +1,115 @@
|
| +// 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 NET_CRONET_ANDROID_URL_REQUEST_PEER_H_
|
| +#define NET_CRONET_ANDROID_URL_REQUEST_PEER_H_
|
| +
|
| +#include "net/base/upload_data_stream.h"
|
| +#include "net/cronet/android/url_request_context_peer.h"
|
| +#include "net/http/http_request_headers.h"
|
| +#include "net/url_request/url_request.h"
|
| +
|
| +// An adapter from the JNI |UrlRequest| object and the Chromium |URLRequest|
|
| +// object.
|
| +class URLRequestPeer : public net::URLRequest::Delegate {
|
| + public:
|
| + /*
|
| + * The delegate which is called when the request finishes.
|
| + */
|
| + class URLRequestPeerDelegate
|
| + : public base::RefCountedThreadSafe<URLRequestPeerDelegate> {
|
| + public:
|
| + virtual void OnResponseStarted(URLRequestPeer* request) = 0;
|
| + virtual void OnBytesRead(URLRequestPeer* request) = 0;
|
| + virtual void OnRequestFinished(URLRequestPeer* request) = 0;
|
| + virtual ~URLRequestPeerDelegate() {}
|
| + };
|
| +
|
| + URLRequestPeer(URLRequestContextPeer* context,
|
| + URLRequestPeerDelegate* delegate, GURL url,
|
| + net::RequestPriority priority);
|
| + virtual ~URLRequestPeer();
|
| +
|
| + // Sets the request method GET, POST etc
|
| + void SetMethod(const std::string& method);
|
| +
|
| + // Adds a header to the request
|
| + void AddHeader(const std::string& name, const std::string& value);
|
| +
|
| + // Sets the contents of the POST request
|
| + void SetPostContent(const char* bytes, int bytes_len);
|
| +
|
| + // Starts the request.
|
| + void Start();
|
| +
|
| + // 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;
|
| +
|
| + // Returns the error code after the request is complete.
|
| + // Negative codes indicate system errors.
|
| + int error_code() const;
|
| +
|
| + // Returns the HTTP status code.
|
| + int http_status_code() const;
|
| +
|
| + // Returns the value of the content-length response header.
|
| + int64 content_length() const;
|
| +
|
| + // Returns the value of the content-type response header.
|
| + std::string content_type() const;
|
| +
|
| + // Returns the overall number of bytes read.
|
| + size_t BytesRead() const;
|
| +
|
| + // Returns a pointer to the downloaded data.
|
| + unsigned char* Data() const;
|
| +
|
| + virtual void OnResponseStarted(net::URLRequest* request);
|
| +
|
| + virtual void OnReadCompleted(net::URLRequest* request, int bytes_read);
|
| +
|
| + private:
|
| + typedef Delegate inherited;
|
| +
|
| + URLRequestContextPeer* context_;
|
| + scoped_refptr<URLRequestPeerDelegate> delegate_;
|
| + GURL url_;
|
| + net::RequestPriority priority_;
|
| + std::string method_;
|
| + net::HttpRequestHeaders headers_;
|
| + net::URLRequest* url_request_;
|
| + scoped_ptr<net::UploadDataStream> upload_data_stream_;
|
| + scoped_refptr<net::GrowableIOBuffer> read_buffer_;
|
| + int bytes_read_;
|
| + int total_bytes_read_;
|
| + int error_code_;
|
| + int http_status_code_;
|
| + std::string content_type_;
|
| + bool canceled_;
|
| + int64 expected_size_;
|
| +
|
| + static void OnInitiateConnectionWrapper(URLRequestPeer* self);
|
| + static void OnCancelRequestWrapper(URLRequestPeer* self);
|
| + static void OnDestroyRequest(URLRequestPeer* self);
|
| +
|
| + void OnInitiateConnection();
|
| + void OnCancelRequest();
|
| + void OnRequestSucceeded();
|
| + void OnRequestFailed();
|
| + void OnRequestCompleted();
|
| + void OnRequestCanceled();
|
| + void OnBytesRead(int bytes_read);
|
| +
|
| + void Read();
|
| +
|
| + DISALLOW_EVIL_CONSTRUCTORS(URLRequestPeer);
|
| +};
|
| +
|
| +#endif // NET_CRONET_ANDROID_URL_REQUEST_PEER_H_
|
|
|