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

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

Issue 453053002: Rename url_request_[context_]peer.* into url_request_[context_]adapter.* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix java formatting Created 6 years, 4 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 "components/cronet/android/url_request_context_peer.h"
6
7 #include "base/bind.h"
8 #include "base/file_util.h"
9 #include "base/single_thread_task_runner.h"
10 #include "components/cronet/url_request_context_config.h"
11 #include "net/base/net_errors.h"
12 #include "net/base/net_log_logger.h"
13 #include "net/cert/cert_verifier.h"
14 #include "net/http/http_auth_handler_factory.h"
15 #include "net/http/http_network_layer.h"
16 #include "net/http/http_server_properties_impl.h"
17 #include "net/proxy/proxy_config_service_fixed.h"
18 #include "net/proxy/proxy_service.h"
19 #include "net/ssl/ssl_config_service_defaults.h"
20 #include "net/url_request/static_http_user_agent_settings.h"
21 #include "net/url_request/url_request_context_builder.h"
22 #include "net/url_request/url_request_context_storage.h"
23 #include "net/url_request/url_request_job_factory_impl.h"
24
25 namespace {
26
27 class BasicNetworkDelegate : public net::NetworkDelegate {
28 public:
29 BasicNetworkDelegate() {}
30 virtual ~BasicNetworkDelegate() {}
31
32 private:
33 // net::NetworkDelegate implementation.
34 virtual int OnBeforeURLRequest(net::URLRequest* request,
35 const net::CompletionCallback& callback,
36 GURL* new_url) OVERRIDE {
37 return net::OK;
38 }
39
40 virtual int OnBeforeSendHeaders(net::URLRequest* request,
41 const net::CompletionCallback& callback,
42 net::HttpRequestHeaders* headers) OVERRIDE {
43 return net::OK;
44 }
45
46 virtual void OnSendHeaders(net::URLRequest* request,
47 const net::HttpRequestHeaders& headers) OVERRIDE {}
48
49 virtual int OnHeadersReceived(
50 net::URLRequest* request,
51 const net::CompletionCallback& callback,
52 const net::HttpResponseHeaders* original_response_headers,
53 scoped_refptr<net::HttpResponseHeaders>* _response_headers,
54 GURL* allowed_unsafe_redirect_url) OVERRIDE {
55 return net::OK;
56 }
57
58 virtual void OnBeforeRedirect(net::URLRequest* request,
59 const GURL& new_location) OVERRIDE {}
60
61 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE {}
62
63 virtual void OnRawBytesRead(const net::URLRequest& request,
64 int bytes_read) OVERRIDE {}
65
66 virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE {}
67
68 virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE {}
69
70 virtual void OnPACScriptError(int line_number,
71 const base::string16& error) OVERRIDE {}
72
73 virtual NetworkDelegate::AuthRequiredResponse OnAuthRequired(
74 net::URLRequest* request,
75 const net::AuthChallengeInfo& auth_info,
76 const AuthCallback& callback,
77 net::AuthCredentials* credentials) OVERRIDE {
78 return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
79 }
80
81 virtual bool OnCanGetCookies(const net::URLRequest& request,
82 const net::CookieList& cookie_list) OVERRIDE {
83 return false;
84 }
85
86 virtual bool OnCanSetCookie(const net::URLRequest& request,
87 const std::string& cookie_line,
88 net::CookieOptions* options) OVERRIDE {
89 return false;
90 }
91
92 virtual bool OnCanAccessFile(const net::URLRequest& request,
93 const base::FilePath& path) const OVERRIDE {
94 return false;
95 }
96
97 virtual bool OnCanThrottleRequest(const net::URLRequest& request)
98 const OVERRIDE {
99 return false;
100 }
101
102 virtual int OnBeforeSocketStreamConnect(
103 net::SocketStream* stream,
104 const net::CompletionCallback& callback) OVERRIDE {
105 return net::OK;
106 }
107
108 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate);
109 };
110
111 } // namespace
112
113 namespace cronet {
114
115 URLRequestContextPeer::URLRequestContextPeer(
116 URLRequestContextPeerDelegate* delegate,
117 std::string user_agent) {
118 delegate_ = delegate;
119 user_agent_ = user_agent;
120 }
121
122 void URLRequestContextPeer::Initialize(
123 scoped_ptr<URLRequestContextConfig> config) {
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,
132 this,
133 Passed(&config)));
134 }
135
136 void URLRequestContextPeer::InitializeURLRequestContext(
137 scoped_ptr<URLRequestContextConfig> config) {
138 // TODO(mmenke): Add method to have the builder enable SPDY.
139 net::URLRequestContextBuilder context_builder;
140 context_builder.set_network_delegate(new BasicNetworkDelegate());
141 context_builder.set_proxy_config_service(
142 new net::ProxyConfigServiceFixed(net::ProxyConfig()));
143 config->ConfigureURLRequestContextBuilder(&context_builder);
144
145 context_.reset(context_builder.Build());
146
147 if (VLOG_IS_ON(2)) {
148 net_log_observer_.reset(new NetLogObserver());
149 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(),
150 net::NetLog::LOG_ALL_BUT_BYTES);
151 }
152
153 delegate_->OnContextInitialized(this);
154 }
155
156 URLRequestContextPeer::~URLRequestContextPeer() {
157 if (net_log_observer_) {
158 context_->net_log()->RemoveThreadSafeObserver(net_log_observer_.get());
159 net_log_observer_.reset();
160 }
161 StopNetLog();
162 // TODO(mef): Ensure that |network_thread_| is destroyed properly.
163 }
164
165 const std::string& URLRequestContextPeer::GetUserAgent(const GURL& url) const {
166 return user_agent_;
167 }
168
169 net::URLRequestContext* URLRequestContextPeer::GetURLRequestContext() {
170 if (!context_) {
171 LOG(ERROR) << "URLRequestContext is not set up";
172 }
173 return context_.get();
174 }
175
176 scoped_refptr<base::SingleThreadTaskRunner>
177 URLRequestContextPeer::GetNetworkTaskRunner() const {
178 return network_thread_->message_loop_proxy();
179 }
180
181 void URLRequestContextPeer::StartNetLogToFile(const std::string& file_name) {
182 // Do nothing if already logging to a file.
183 if (net_log_logger_)
184 return;
185
186 base::FilePath file_path(file_name);
187 FILE* file = base::OpenFile(file_path, "w");
188 if (!file)
189 return;
190
191 scoped_ptr<base::Value> constants(net::NetLogLogger::GetConstants());
192 net_log_logger_.reset(new net::NetLogLogger(file, *constants));
193 net_log_logger_->StartObserving(context_->net_log());
194 }
195
196 void URLRequestContextPeer::StopNetLog() {
197 if (net_log_logger_) {
198 net_log_logger_->StopObserving();
199 net_log_logger_.reset();
200 }
201 }
202
203 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) {
204 VLOG(2) << "Net log entry: type=" << entry.type()
205 << ", source=" << entry.source().type
206 << ", phase=" << entry.phase();
207 }
208
209 } // namespace cronet
OLDNEW
« no previous file with comments | « components/cronet/android/url_request_context_peer.h ('k') | components/cronet/android/url_request_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698