| 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 |
| 99 void CronetEnvironment::PostToNetworkThread( | 103 void CronetEnvironment::PostToNetworkThread( |
| 100 const tracked_objects::Location& from_here, | 104 const tracked_objects::Location& from_here, |
| 101 const base::Closure& task) { | 105 const base::Closure& task) { |
| 102 network_io_thread_->task_runner()->PostTask(from_here, task); | 106 network_io_thread_->task_runner()->PostTask(from_here, task); |
| 103 } | 107 } |
| 104 | 108 |
| 105 void CronetEnvironment::PostToFileUserBlockingThread( | 109 void CronetEnvironment::PostToFileUserBlockingThread( |
| 106 const tracked_objects::Location& from_here, | 110 const tracked_objects::Location& from_here, |
| 107 const base::Closure& task) { | 111 const base::Closure& task) { |
| 108 file_user_blocking_thread_->task_runner()->PostTask(from_here, task); | 112 file_user_blocking_thread_->task_runner()->PostTask(from_here, task); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 main_context_->set_http_server_properties(http_server_properties_.get()); | 290 main_context_->set_http_server_properties(http_server_properties_.get()); |
| 287 | 291 |
| 288 // TODO(rdsmith): Note that the ".release()" calls below are leaking | 292 // TODO(rdsmith): Note that the ".release()" calls below are leaking |
| 289 // the objects in question; this should be fixed by having an object | 293 // the objects in question; this should be fixed by having an object |
| 290 // corresponding to URLRequestContextStorage that actually owns those | 294 // corresponding to URLRequestContextStorage that actually owns those |
| 291 // objects. See http://crbug.com/523858. | 295 // objects. See http://crbug.com/523858. |
| 292 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver( | 296 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver( |
| 293 new net::MappedHostResolver( | 297 new net::MappedHostResolver( |
| 294 net::HostResolver::CreateDefaultResolver(nullptr))); | 298 net::HostResolver::CreateDefaultResolver(nullptr))); |
| 295 | 299 |
| 300 mapped_host_resolver->SetRulesFromString(host_resolver_rules_); |
| 296 main_context_->set_host_resolver(mapped_host_resolver.release()); | 301 main_context_->set_host_resolver(mapped_host_resolver.release()); |
| 297 | 302 |
| 298 if (!cert_verifier_) | 303 if (!cert_verifier_) |
| 299 cert_verifier_ = net::CertVerifier::CreateDefault(); | 304 cert_verifier_ = net::CertVerifier::CreateDefault(); |
| 300 main_context_->set_cert_verifier(cert_verifier_.get()); | 305 main_context_->set_cert_verifier(cert_verifier_.get()); |
| 301 | 306 |
| 302 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier = | 307 std::unique_ptr<net::MultiLogCTVerifier> ct_verifier = |
| 303 base::MakeUnique<net::MultiLogCTVerifier>(); | 308 base::MakeUnique<net::MultiLogCTVerifier>(); |
| 304 ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs()); | 309 ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs()); |
| 305 main_context_->set_cert_transparency_verifier(ct_verifier.release()); | 310 main_context_->set_cert_transparency_verifier(ct_verifier.release()); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 393 } |
| 389 | 394 |
| 390 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { | 395 std::vector<uint8_t> CronetEnvironment::GetHistogramDeltas() { |
| 391 base::StatisticsRecorder::Initialize(); | 396 base::StatisticsRecorder::Initialize(); |
| 392 std::vector<uint8_t> data; | 397 std::vector<uint8_t> data; |
| 393 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 398 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 394 return std::vector<uint8_t>(); | 399 return std::vector<uint8_t>(); |
| 395 return data; | 400 return data; |
| 396 } | 401 } |
| 397 | 402 |
| 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 | |
| 416 } // namespace cronet | 403 } // namespace cronet |
| OLD | NEW |