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

Side by Side Diff: net/cronet/android/url_request_peer.h

Issue 145213003: Initial upload of cronet for Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added cronet_package target to copy cronet.jar and stripped libcronet.so Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_CRONET_ANDROID_URL_REQUEST_PEER_H_
6 #define NET_CRONET_ANDROID_URL_REQUEST_PEER_H_
7
8 #include "net/base/upload_data_stream.h"
9 #include "net/cronet/android/url_request_context_peer.h"
10 #include "net/http/http_request_headers.h"
11 #include "net/url_request/url_request.h"
12
13 // An adapter from the JNI |UrlRequest| object and the Chromium |URLRequest|
14 // object.
15 class URLRequestPeer : public net::URLRequest::Delegate {
16 public:
17 /*
18 * The delegate which is called when the request finishes.
19 */
20 class URLRequestPeerDelegate
21 : public base::RefCountedThreadSafe<URLRequestPeerDelegate> {
22 public:
23 virtual void OnResponseStarted(URLRequestPeer* request) = 0;
24 virtual void OnBytesRead(URLRequestPeer* request) = 0;
25 virtual void OnRequestFinished(URLRequestPeer* request) = 0;
26 virtual ~URLRequestPeerDelegate() {}
27 };
28
29 URLRequestPeer(URLRequestContextPeer* context,
30 URLRequestPeerDelegate* delegate, GURL url,
31 net::RequestPriority priority);
32 virtual ~URLRequestPeer();
33
34 // Sets the request method GET, POST etc
35 void SetMethod(const std::string& method);
36
37 // Adds a header to the request
38 void AddHeader(const std::string& name, const std::string& value);
39
40 // Sets the contents of the POST request
41 void SetPostContent(const char* bytes, int bytes_len);
42
43 // Starts the request.
44 void Start();
45
46 // Cancels the request.
47 void Cancel();
48
49 // Releases all resources for the request and deletes the object itself.
50 void Destroy();
51
52 // Returns the URL of the request.
53 GURL url() const;
54
55 // Returns the error code after the request is complete.
56 // Negative codes indicate system errors.
57 int error_code() const;
58
59 // Returns the HTTP status code.
60 int http_status_code() const;
61
62 // Returns the value of the content-length response header.
63 int64 content_length() const;
64
65 // Returns the value of the content-type response header.
66 std::string content_type() const;
67
68 // Returns the overall number of bytes read.
69 size_t BytesRead() const;
70
71 // Returns a pointer to the downloaded data.
72 unsigned char* Data() const;
73
74 virtual void OnResponseStarted(net::URLRequest* request);
75
76 virtual void OnReadCompleted(net::URLRequest* request, int bytes_read);
77
78 private:
79 typedef Delegate inherited;
80
81 URLRequestContextPeer* context_;
82 scoped_refptr<URLRequestPeerDelegate> delegate_;
83 GURL url_;
84 net::RequestPriority priority_;
85 std::string method_;
86 net::HttpRequestHeaders headers_;
87 net::URLRequest* url_request_;
88 scoped_ptr<net::UploadDataStream> upload_data_stream_;
89 scoped_refptr<net::GrowableIOBuffer> read_buffer_;
90 int bytes_read_;
91 int total_bytes_read_;
92 int error_code_;
93 int http_status_code_;
94 std::string content_type_;
95 bool canceled_;
96 int64 expected_size_;
97
98 static void OnInitiateConnectionWrapper(URLRequestPeer* self);
99 static void OnCancelRequestWrapper(URLRequestPeer* self);
100 static void OnDestroyRequest(URLRequestPeer* self);
101
102 void OnInitiateConnection();
103 void OnCancelRequest();
104 void OnRequestSucceeded();
105 void OnRequestFailed();
106 void OnRequestCompleted();
107 void OnRequestCanceled();
108 void OnBytesRead(int bytes_read);
109
110 void Read();
111
112 DISALLOW_EVIL_CONSTRUCTORS(URLRequestPeer);
113 };
114
115 #endif // NET_CRONET_ANDROID_URL_REQUEST_PEER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698