| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 main_context_->set_http_server_properties(http_server_properties_.get()); | 286 main_context_->set_http_server_properties(http_server_properties_.get()); |
| 291 | 287 |
| 292 // TODO(rdsmith): Note that the ".release()" calls below are leaking | 288 // TODO(rdsmith): Note that the ".release()" calls below are leaking |
| 293 // the objects in question; this should be fixed by having an object | 289 // the objects in question; this should be fixed by having an object |
| 294 // corresponding to URLRequestContextStorage that actually owns those | 290 // corresponding to URLRequestContextStorage that actually owns those |
| 295 // objects. See http://crbug.com/523858. | 291 // objects. See http://crbug.com/523858. |
| 296 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver( | 292 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver( |
| 297 new net::MappedHostResolver( | 293 new net::MappedHostResolver( |
| 298 net::HostResolver::CreateDefaultResolver(nullptr))); | 294 net::HostResolver::CreateDefaultResolver(nullptr))); |
| 299 | 295 |
| 300 mapped_host_resolver->SetRulesFromString(host_resolver_rules_); | |
| 301 main_context_->set_host_resolver(mapped_host_resolver.release()); | 296 main_context_->set_host_resolver(mapped_host_resolver.release()); |
| 302 | 297 |
| 303 if (!cert_verifier_) | 298 if (!cert_verifier_) |
| 304 cert_verifier_ = net::CertVerifier::CreateDefault(); | 299 cert_verifier_ = net::CertVerifier::CreateDefault(); |
| 305 main_context_->set_cert_verifier(cert_verifier_.get()); | 300 main_context_->set_cert_verifier(cert_verifier_.get()); |
| 306 | 301 |
| 307 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier = | 302 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier = |
| 308 base::MakeUnique<net::MultiLogCTVerifier>(); | 303 base::MakeUnique<net::MultiLogCTVerifier>(); |
| 309 ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs()); | 304 ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs()); |
| 310 main_context_->set_cert_transparency_verifier(ct_verifier.release()); | 305 main_context_->set_cert_transparency_verifier(ct_verifier.release()); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 } | 388 } |
| 394 | 389 |
| 395 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { | 390 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { |
| 396 base::StatisticsRecorder::Initialize(); | 391 base::StatisticsRecorder::Initialize(); |
| 397 std::vector<uint8_t> data; | 392 std::vector<uint8_t> data; |
| 398 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 393 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 399 return std::vector<uint8_t>(); | 394 return std::vector<uint8_t>(); |
| 400 return data; | 395 return data; |
| 401 } | 396 } |
| 402 | 397 |
| 398 void CronetEnvironment::SetHostResolverRules(const std::string& rules) { |
| 399 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 400 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 401 PostToNetworkThread( |
| 402 FROM_HERE, |
| 403 base::Bind(&CronetEnvironment::SetHostResolverRulesOnNetworkThread, |
| 404 base::Unretained(this), rules, &event)); |
| 405 event.Wait(); |
| 406 } |
| 407 |
| 408 void CronetEnvironment::SetHostResolverRulesOnNetworkThread( |
| 409 const std::string& rules, |
| 410 base::WaitableEvent* event) { |
| 411 static_cast<net::MappedHostResolver*>(main_context_->host_resolver()) |
| 412 ->SetRulesFromString(rules); |
| 413 event->Signal(); |
| 414 } |
| 415 |
| 403 } // namespace cronet | 416 } // namespace cronet |
| OLD | NEW |