Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ios/cronet_environment.h" | 5 #include "components/cronet/ios/cronet_environment.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 | 89 |
| 90 cronet::CronetEnvironment* environment_; | 90 cronet::CronetEnvironment* environment_; |
| 91 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 91 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 92 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextGetter); | 92 DISALLOW_COPY_AND_ASSIGN(CronetURLRequestContextGetter); |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 } // namespace | 95 } // namespace |
| 96 | 96 |
| 97 namespace cronet { | 97 namespace cronet { |
| 98 | 98 |
| 99 bool CronetEnvironment::IsOnNetworkThread() { | |
| 100 return network_io_thread_->task_runner()->BelongsToCurrentThread(); | |
| 101 } | |
| 102 | |
| 103 void CronetEnvironment::PostToNetworkThread( | 99 void CronetEnvironment::PostToNetworkThread( |
| 104 const tracked_objects::Location& from_here, | 100 const tracked_objects::Location& from_here, |
| 105 const base::Closure& task) { | 101 const base::Closure& task) { |
| 106 network_io_thread_->task_runner()->PostTask(from_here, task); | 102 network_io_thread_->task_runner()->PostTask(from_here, task); |
| 107 } | 103 } |
| 108 | 104 |
| 109 void CronetEnvironment::PostToFileUserBlockingThread( | 105 void CronetEnvironment::PostToFileUserBlockingThread( |
| 110 const tracked_objects::Location& from_here, | 106 const tracked_objects::Location& from_here, |
| 111 const base::Closure& task) { | 107 const base::Closure& task) { |
| 112 file_user_blocking_thread_->task_runner()->PostTask(from_here, task); | 108 file_user_blocking_thread_->task_runner()->PostTask(from_here, task); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 int port, | 214 int port, |
| 219 int alternate_port) { | 215 int alternate_port) { |
| 220 DCHECK(port == alternate_port); | 216 DCHECK(port == alternate_port); |
| 221 quic_hints_.push_back(net::HostPortPair(host, port)); | 217 quic_hints_.push_back(net::HostPortPair(host, port)); |
| 222 } | 218 } |
| 223 | 219 |
| 224 CronetEnvironment::CronetEnvironment(const std::string& user_agent, | 220 CronetEnvironment::CronetEnvironment(const std::string& user_agent, |
| 225 bool user_agent_partial) | 221 bool user_agent_partial) |
| 226 : http2_enabled_(false), | 222 : http2_enabled_(false), |
| 227 quic_enabled_(false), | 223 quic_enabled_(false), |
| 224 event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 225 base::WaitableEvent::InitialState::NOT_SIGNALED), | |
| 228 user_agent_(user_agent), | 226 user_agent_(user_agent), |
| 229 user_agent_partial_(user_agent_partial), | 227 user_agent_partial_(user_agent_partial), |
| 230 net_log_(new net::NetLog) {} | 228 net_log_(new net::NetLog) {} |
| 231 | 229 |
| 232 void CronetEnvironment::Start() { | 230 void CronetEnvironment::Start() { |
| 233 // Threads setup. | 231 // Threads setup. |
| 234 network_cache_thread_.reset(new base::Thread("Chrome Network Cache Thread")); | 232 network_cache_thread_.reset(new base::Thread("Chrome Network Cache Thread")); |
| 235 network_cache_thread_->StartWithOptions( | 233 network_cache_thread_->StartWithOptions( |
| 236 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 234 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 237 network_io_thread_.reset(new base::Thread("Chrome Network IO Thread")); | 235 network_io_thread_.reset(new base::Thread("Chrome Network IO Thread")); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 main_context_->set_http_server_properties(http_server_properties_.get()); | 288 main_context_->set_http_server_properties(http_server_properties_.get()); |
| 291 | 289 |
| 292 // TODO(rdsmith): Note that the ".release()" calls below are leaking | 290 // TODO(rdsmith): Note that the ".release()" calls below are leaking |
| 293 // the objects in question; this should be fixed by having an object | 291 // the objects in question; this should be fixed by having an object |
| 294 // corresponding to URLRequestContextStorage that actually owns those | 292 // corresponding to URLRequestContextStorage that actually owns those |
| 295 // objects. See http://crbug.com/523858. | 293 // objects. See http://crbug.com/523858. |
| 296 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver( | 294 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver( |
| 297 new net::MappedHostResolver( | 295 new net::MappedHostResolver( |
| 298 net::HostResolver::CreateDefaultResolver(nullptr))); | 296 net::HostResolver::CreateDefaultResolver(nullptr))); |
| 299 | 297 |
| 300 mapped_host_resolver->SetRulesFromString(host_resolver_rules_); | |
| 301 main_context_->set_host_resolver(mapped_host_resolver.release()); | 298 main_context_->set_host_resolver(mapped_host_resolver.release()); |
| 302 | 299 |
| 303 if (!cert_verifier_) | 300 if (!cert_verifier_) |
| 304 cert_verifier_ = net::CertVerifier::CreateDefault(); | 301 cert_verifier_ = net::CertVerifier::CreateDefault(); |
| 305 main_context_->set_cert_verifier(cert_verifier_.get()); | 302 main_context_->set_cert_verifier(cert_verifier_.get()); |
| 306 | 303 |
| 307 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier = | 304 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier = |
| 308 base::MakeUnique<net::MultiLogCTVerifier>(); | 305 base::MakeUnique<net::MultiLogCTVerifier>(); |
| 309 ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs()); | 306 ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs()); |
| 310 main_context_->set_cert_transparency_verifier(ct_verifier.release()); | 307 main_context_->set_cert_transparency_verifier(ct_verifier.release()); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 } | 390 } |
| 394 | 391 |
| 395 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { | 392 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { |
| 396 base::StatisticsRecorder::Initialize(); | 393 base::StatisticsRecorder::Initialize(); |
| 397 std::vector<uint8_t> data; | 394 std::vector<uint8_t> data; |
| 398 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 395 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 399 return std::vector<uint8_t>(); | 396 return std::vector<uint8_t>(); |
| 400 return data; | 397 return data; |
| 401 } | 398 } |
| 402 | 399 |
| 400 void CronetEnvironment::SetHostResolverRules(const std::string& rules) { | |
| 401 PostToNetworkThread( | |
| 402 FROM_HERE, base::Bind(&CronetEnvironment::SetHostResolverRulesInternal, | |
| 403 base::Unretained(this), rules)); | |
| 404 event_.Wait(); | |
|
mef
2016/11/07 18:15:20
Can event be allocated on the stack and passed as
Garrett Casto
2016/11/07 18:37:26
Done.
| |
| 405 } | |
| 406 | |
| 407 void CronetEnvironment::SetHostResolverRulesInternal(const std::string& rules) { | |
| 408 static_cast<net::MappedHostResolver*>(main_context_->host_resolver()) | |
| 409 ->SetRulesFromString(rules); | |
| 410 event_.Signal(); | |
| 411 } | |
| 412 | |
| 403 } // namespace cronet | 413 } // namespace cronet |
| OLD | NEW |