| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/cronet/android/url_request_context_adapter.h" | 5 #include "components/cronet/android/url_request_context_adapter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "components/cronet/url_request_context_config.h" | 10 #include "components/cronet/url_request_context_config.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 171 } |
| 172 | 172 |
| 173 net::HostPortPair quic_hint_host_port_pair(quic_hint.host, | 173 net::HostPortPair quic_hint_host_port_pair(quic_hint.host, |
| 174 quic_hint.port); | 174 quic_hint.port); |
| 175 context_->http_server_properties()->SetAlternateProtocol( | 175 context_->http_server_properties()->SetAlternateProtocol( |
| 176 quic_hint_host_port_pair, | 176 quic_hint_host_port_pair, |
| 177 static_cast<uint16>(quic_hint.alternate_port), | 177 static_cast<uint16>(quic_hint.alternate_port), |
| 178 net::AlternateProtocol::QUIC, | 178 net::AlternateProtocol::QUIC, |
| 179 1.0f); | 179 1.0f); |
| 180 } | 180 } |
| 181 is_context_initialized_ = true; |
| 182 while (!tasks_.empty()) { |
| 183 tasks_.front().Run(); |
| 184 tasks_.pop(); |
| 185 } |
| 181 } | 186 } |
| 182 | 187 |
| 183 if (VLOG_IS_ON(2)) { | 188 if (VLOG_IS_ON(2)) { |
| 184 net_log_observer_.reset(new NetLogObserver()); | 189 net_log_observer_.reset(new NetLogObserver()); |
| 185 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), | 190 context_->net_log()->AddThreadSafeObserver(net_log_observer_.get(), |
| 186 net::NetLog::LOG_ALL_BUT_BYTES); | 191 net::NetLog::LOG_ALL_BUT_BYTES); |
| 187 } | 192 } |
| 188 | 193 |
| 189 delegate_->OnContextInitialized(this); | 194 delegate_->OnContextInitialized(this); |
| 190 } | 195 } |
| 191 | 196 |
| 197 // Runs a task that might depend on the context being initialized. |
| 198 // This method can be called on any thread. |
| 199 void URLRequestContextAdapter::RunTask( |
| 200 const RunAfterContextInitTask& callback) { |
| 201 GetNetworkTaskRunner()->PostTask( |
| 202 FROM_HERE, |
| 203 base::Bind( |
| 204 &URLRequestContextAdapter::RunTaskOnNetworkThread, this, callback)); |
| 205 } |
| 206 |
| 207 // This method should only be run on the network thread. |
| 208 void URLRequestContextAdapter::RunTaskOnNetworkThread( |
| 209 const RunAfterContextInitTask& callback) { |
| 210 if (is_context_initialized_) { |
| 211 callback.Run(); |
| 212 return; |
| 213 } |
| 214 tasks_.push(callback); |
| 215 } |
| 216 |
| 192 URLRequestContextAdapter::~URLRequestContextAdapter() { | 217 URLRequestContextAdapter::~URLRequestContextAdapter() { |
| 193 if (net_log_observer_) { | 218 if (net_log_observer_) { |
| 194 context_->net_log()->RemoveThreadSafeObserver(net_log_observer_.get()); | 219 context_->net_log()->RemoveThreadSafeObserver(net_log_observer_.get()); |
| 195 net_log_observer_.reset(); | 220 net_log_observer_.reset(); |
| 196 } | 221 } |
| 197 StopNetLog(); | 222 StopNetLog(); |
| 198 // TODO(mef): Ensure that |network_thread_| is destroyed properly. | 223 // TODO(mef): Ensure that |network_thread_| is destroyed properly. |
| 199 } | 224 } |
| 200 | 225 |
| 201 const std::string& URLRequestContextAdapter::GetUserAgent( | 226 const std::string& URLRequestContextAdapter::GetUserAgent( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 net_log_logger_.reset(); | 261 net_log_logger_.reset(); |
| 237 } | 262 } |
| 238 } | 263 } |
| 239 | 264 |
| 240 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | 265 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { |
| 241 VLOG(2) << "Net log entry: type=" << entry.type() | 266 VLOG(2) << "Net log entry: type=" << entry.type() |
| 242 << ", source=" << entry.source().type << ", phase=" << entry.phase(); | 267 << ", source=" << entry.source().type << ", phase=" << entry.phase(); |
| 243 } | 268 } |
| 244 | 269 |
| 245 } // namespace cronet | 270 } // namespace cronet |
| OLD | NEW |