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

Side by Side Diff: net/cronet/android/url_request_context_peer.cc

Issue 145213003: Initial upload of cronet for Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: NET_EXPORT RequestPriorityToString to avoid buildbot errors. Created 6 years, 9 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 #include "net/cronet/android/url_request_context_peer.h"
6
7 #include "net/cert/cert_verifier.h"
8 #include "net/http/http_auth_handler_factory.h"
9 #include "net/http/http_network_layer.h"
10 #include "net/http/http_server_properties_impl.h"
11 #include "net/proxy/proxy_config_service_fixed.h"
12 #include "net/proxy/proxy_service.h"
13 #include "net/ssl/ssl_config_service_defaults.h"
14 #include "net/url_request/static_http_user_agent_settings.h"
15 #include "net/url_request/url_request_context_storage.h"
16 #include "net/url_request/url_request_job_factory_impl.h"
mmenke 2014/02/27 23:06:02 net/base/net_errors.h.
mef 2014/03/03 19:15:13 Done.
17
18 class BasicNetworkDelegate : public net::NetworkDelegate {
mmenke 2014/02/27 23:06:02 Move into anonymous namespace?
mef 2014/03/03 19:15:13 Done.
19 public:
20 BasicNetworkDelegate() {}
21 virtual ~BasicNetworkDelegate() {}
22
23 private:
24 virtual int OnBeforeURLRequest(net::URLRequest* request,
mmenke 2014/02/27 23:06:02 Comment that all these are the net::NetworkDelegat
mef 2014/03/03 19:15:13 Done.
25 const net::CompletionCallback& callback,
26 GURL* new_url) OVERRIDE {
27 return net::OK;
28 }
29
30 virtual int OnBeforeSendHeaders(net::URLRequest* request,
31 const net::CompletionCallback& callback,
32 net::HttpRequestHeaders* headers) OVERRIDE {
33 return net::OK;
34 }
35
36 virtual void OnSendHeaders(net::URLRequest* request,
37 const net::HttpRequestHeaders& headers) OVERRIDE {}
38
39 virtual int OnHeadersReceived(
40 net::URLRequest* request,
41 const net::CompletionCallback& callback,
42 const net::HttpResponseHeaders* original_response_headers,
43 scoped_refptr<net::HttpResponseHeaders>* _response_headers) OVERRIDE {
44 return net::OK;
45 }
46
47 virtual void OnBeforeRedirect(net::URLRequest* request,
48 const GURL& new_location) OVERRIDE {}
49
50 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE {}
51
52 virtual void OnRawBytesRead(const net::URLRequest& request,
53 int bytes_read) OVERRIDE {}
54
55 virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE {}
56
57 virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE {}
58
59 virtual void OnPACScriptError(int line_number,
60 const base::string16& error) OVERRIDE {}
61
62 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired(
63 net::URLRequest* request,
64 const net::AuthChallengeInfo& auth_info,
65 const AuthCallback& callback,
66 net::AuthCredentials* credentials) OVERRIDE {
67 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
68 }
mmenke 2014/02/27 23:06:02 Hmm...All of the functions above this are the same
mef 2014/03/03 19:15:13 Sounds good.
69
70 virtual bool OnCanGetCookies(const net::URLRequest& request,
71 const net::CookieList& cookie_list) OVERRIDE {
72 return false;
73 }
74
75 virtual bool OnCanSetCookie(const net::URLRequest& request,
76 const std::string& cookie_line,
77 net::CookieOptions* options) OVERRIDE {
78 return false;
79 }
80
81 virtual bool OnCanAccessFile(const net::URLRequest& request,
82 const base::FilePath& path) const OVERRIDE {
83 return false;
84 }
85
86 virtual bool OnCanThrottleRequest(
87 const net::URLRequest& request) const OVERRIDE{
88 return false;
89 }
90
91 virtual int OnBeforeSocketStreamConnect(
92 net::SocketStream* stream,
93 const net::CompletionCallback& callback) OVERRIDE {
94 return net::OK;
95 }
96
97 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate);
98 };
99
100 class BasicURLRequestContext : public net::URLRequestContext {
mmenke 2014/02/27 23:06:02 Move into anonymous namespace?
mef 2014/03/03 19:15:13 Done.
101 public:
102 BasicURLRequestContext() : storage_(this) {}
103
104 net::URLRequestContextStorage* storage() { return &storage_; }
105
106 protected:
107 virtual ~BasicURLRequestContext() {}
108
109 private:
110 net::URLRequestContextStorage storage_;
mmenke 2014/02/27 23:06:02 nit: Add blank line.
mef 2014/03/03 19:15:13 Done.
111 DISALLOW_COPY_AND_ASSIGN(BasicURLRequestContext);
112 };
113
114 URLRequestContextPeer::URLRequestContextPeer(
115 URLRequestContextPeerDelegate* delegate, std::string user_agent,
116 int logging_level, const char* version) {
117 delegate_ = delegate;
118 user_agent_ = user_agent;
119 logging_level_ = logging_level;
120 version_ = version;
121 }
122
123 void URLRequestContextPeer::Initialize() {
124 network_thread_ = new base::Thread("network");
125 base::Thread::Options options;
126 options.message_loop_type = base::MessageLoop::TYPE_IO;
127 network_thread_->StartWithOptions(options);
128
129 GetNetworkTaskRunner()->PostTask(
130 FROM_HERE,
131 base::Bind(&URLRequestContextPeer::InitializeURLRequestContext, this));
132 }
133
134 void URLRequestContextPeer::InitializeURLRequestContext() {
135 BasicURLRequestContext* context = new BasicURLRequestContext;
136 net::URLRequestContextStorage* storage = context->storage();
137
138 net::NetworkDelegate* network_delegate = new BasicNetworkDelegate;
139 storage->set_network_delegate(network_delegate);
140
141 storage->set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL));
142
143 net::ProxyConfigService* proxy_config_service =
144 new net::ProxyConfigServiceFixed(net::ProxyConfig());
145 storage->set_proxy_service(net::ProxyService::CreateUsingSystemProxyResolver(
146 proxy_config_service,
147 4, // TODO(willchan): Find a better constant somewhere.
148 context->net_log()));
149 storage->set_ssl_config_service(new net::SSLConfigServiceDefaults);
150 storage->set_http_auth_handler_factory(
151 net::HttpAuthHandlerRegistryFactory::CreateDefault(
152 context->host_resolver()));
153 storage->set_transport_security_state(new net::TransportSecurityState());
154 storage->set_http_server_properties(
155 scoped_ptr<net::HttpServerProperties>(
156 new net::HttpServerPropertiesImpl()));
157 storage->set_cert_verifier(net::CertVerifier::CreateDefault());
158
159 net::HttpNetworkSession::Params network_session_params;
160 network_session_params.host_resolver = context->host_resolver();
161 network_session_params.cert_verifier = context->cert_verifier();
162 network_session_params.transport_security_state =
163 context->transport_security_state();
164 network_session_params.proxy_service = context->proxy_service();
165 network_session_params.ssl_config_service = context->ssl_config_service();
166 network_session_params.http_auth_handler_factory =
167 context->http_auth_handler_factory();
168 network_session_params.network_delegate = network_delegate;
169 network_session_params.http_server_properties =
170 context->http_server_properties();
171 network_session_params.net_log = context->net_log();
172
173 scoped_refptr<net::HttpNetworkSession> network_session(
174 new net::HttpNetworkSession(network_session_params));
175
176 net::HttpTransactionFactory* http_transaction_factory =
177 new net::HttpNetworkLayer(network_session.get());
178 storage->set_http_transaction_factory(http_transaction_factory);
179
180 net::URLRequestJobFactoryImpl* job_factory =
181 new net::URLRequestJobFactoryImpl;
182 storage->set_job_factory(job_factory);
183
184 context_.reset(context);
185
186 if (VLOG_IS_ON(2)) {
187 context_->set_net_log(new net::NetLog);
188 netlog_observer_.reset(new NetLogObserver(logging_level_));
189 context_->net_log()->AddThreadSafeObserver(netlog_observer_.get(),
190 net::NetLog::LOG_ALL_BUT_BYTES);
191 }
192
193 net::HttpStreamFactory::EnableNpnSpdy31();
194
195 delegate_->OnContextInitialized(this);
196 }
197
198 URLRequestContextPeer::~URLRequestContextPeer() {
199 }
200
201 const std::string &URLRequestContextPeer::GetUserAgent(const GURL &url) const {
202 return user_agent_;
203 }
204
205 int URLRequestContextPeer::logging_level() const {
206 return logging_level_;
207 }
208
209 const char* URLRequestContextPeer::version() const {
210 return version_;
211 }
212
213 net::URLRequestContext *URLRequestContextPeer::GetURLRequestContext() {
mmenke 2014/02/27 23:06:02 nit: net::URLRequestContext* URLRequestContextPee
mef 2014/03/03 19:15:13 Done.
214 if (!context_) {
215 LOG(ERROR) << "URLRequestContext is not set up";
216 }
217 return context_.get();
218 }
219
220 scoped_refptr<base::SingleThreadTaskRunner>
221 URLRequestContextPeer::GetNetworkTaskRunner() const {
222 return network_thread_->message_loop_proxy();
223 }
224
225 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
226 if (VLOG_IS_ON(2)) {
227 VLOG(2) << "Net log entry: type=" << entry.type()
228 << ", source=" << entry.source().type
229 << ", phase=" << entry.phase();
230 }
231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698