| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 base::AtExitManager* g_at_exit_ = nullptr; | 60 base::AtExitManager* g_at_exit_ = nullptr; |
| 61 net::NetworkChangeNotifier* g_network_change_notifier = nullptr; | 61 net::NetworkChangeNotifier* g_network_change_notifier = nullptr; |
| 62 // MessageLoop on the main thread. | 62 // MessageLoop on the main thread. |
| 63 base::MessageLoop* g_main_message_loop = nullptr; | 63 base::MessageLoop* g_main_message_loop = nullptr; |
| 64 | 64 |
| 65 } // namespace | 65 } // namespace |
| 66 | 66 |
| 67 namespace cronet { | 67 namespace cronet { |
| 68 | 68 |
| 69 bool CronetEnvironment::IsOnNetworkThread() { | |
| 70 return network_io_thread_->task_runner()->BelongsToCurrentThread(); | |
| 71 } | |
| 72 | |
| 73 void CronetEnvironment::PostToNetworkThread( | 69 void CronetEnvironment::PostToNetworkThread( |
| 74 const tracked_objects::Location& from_here, | 70 const tracked_objects::Location& from_here, |
| 75 const base::Closure& task) { | 71 const base::Closure& task) { |
| 76 network_io_thread_->task_runner()->PostTask(from_here, task); | 72 network_io_thread_->task_runner()->PostTask(from_here, task); |
| 77 } | 73 } |
| 78 | 74 |
| 79 void CronetEnvironment::PostToFileUserBlockingThread( | 75 void CronetEnvironment::PostToFileUserBlockingThread( |
| 80 const tracked_objects::Location& from_here, | 76 const tracked_objects::Location& from_here, |
| 81 const base::Closure& task) { | 77 const base::Closure& task) { |
| 82 file_user_blocking_thread_->task_runner()->PostTask(from_here, task); | 78 file_user_blocking_thread_->task_runner()->PostTask(from_here, task); |
| 83 } | 79 } |
| 84 | 80 |
| 85 net::URLRequestContext* CronetEnvironment::GetURLRequestContext() const { | 81 net::URLRequestContextGetter* CronetEnvironment::GetURLRequestContextGetter() { |
| 86 return main_context_.get(); | 82 return request_context_getter_.get(); |
| 87 } | 83 } |
| 88 | 84 |
| 89 // static | 85 // static |
| 90 void CronetEnvironment::Initialize() { | 86 void CronetEnvironment::Initialize() { |
| 91 // DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); | 87 // DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); |
| 92 // This method must be called once from the main thread. | 88 // This method must be called once from the main thread. |
| 93 if (!g_at_exit_) | 89 if (!g_at_exit_) |
| 94 g_at_exit_ = new base::AtExitManager; | 90 g_at_exit_ = new base::AtExitManager; |
| 95 | 91 |
| 96 url::Initialize(); | 92 url::Initialize(); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 if (!PathService::Get(base::DIR_HOME, &ssl_key_log_file)) | 211 if (!PathService::Get(base::DIR_HOME, &ssl_key_log_file)) |
| 216 return; | 212 return; |
| 217 net::SSLClientSocket::SetSSLKeyLogFile( | 213 net::SSLClientSocket::SetSSLKeyLogFile( |
| 218 ssl_key_log_file.Append(ssl_key_log_file_name_), | 214 ssl_key_log_file.Append(ssl_key_log_file_name_), |
| 219 file_thread_->task_runner()); | 215 file_thread_->task_runner()); |
| 220 } | 216 } |
| 221 | 217 |
| 222 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( | 218 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( |
| 223 network_io_thread_->task_runner(), nullptr); | 219 network_io_thread_->task_runner(), nullptr); |
| 224 | 220 |
| 221 // Create request_context_getter_ here so that it will be availble as soon |
| 222 // as this function returns. main_context_ won't actually be setup at that |
| 223 // point, but any usage should happen on the network thread and the |
| 224 // initialization callback will be run before any other posted task. |
| 225 main_context_.reset(new net::URLRequestContext); |
| 226 main_context_->DetachFromThread(); |
| 227 request_context_getter_ = new net::TrivialURLRequestContextGetter( |
| 228 main_context_.get(), network_io_thread_->task_runner()); |
| 229 |
| 225 #if defined(USE_NSS_CERTS) | 230 #if defined(USE_NSS_CERTS) |
| 226 net::SetURLRequestContextForNSSHttpIO(main_context_.get()); | 231 net::SetURLRequestContextForNSSHttpIO(main_context_.get()); |
| 227 #endif | 232 #endif |
| 228 base::subtle::MemoryBarrier(); | 233 base::subtle::MemoryBarrier(); |
| 229 PostToNetworkThread(FROM_HERE, | 234 PostToNetworkThread(FROM_HERE, |
| 230 base::Bind(&CronetEnvironment::InitializeOnNetworkThread, | 235 base::Bind(&CronetEnvironment::InitializeOnNetworkThread, |
| 231 base::Unretained(this))); | 236 base::Unretained(this))); |
| 232 } | 237 } |
| 233 | 238 |
| 234 CronetEnvironment::~CronetEnvironment() { | 239 CronetEnvironment::~CronetEnvironment() { |
| 235 // net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); | 240 // net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); |
| 236 #if defined(USE_NSS_CERTS) | 241 #if defined(USE_NSS_CERTS) |
| 237 net::SetURLRequestContextForNSSHttpIO(nullptr); | 242 net::SetURLRequestContextForNSSHttpIO(nullptr); |
| 238 #endif | 243 #endif |
| 239 } | 244 } |
| 240 | 245 |
| 241 void CronetEnvironment::InitializeOnNetworkThread() { | 246 void CronetEnvironment::InitializeOnNetworkThread() { |
| 242 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); | 247 DCHECK(network_io_thread_->task_runner()->BelongsToCurrentThread()); |
| 243 base::FeatureList::InitializeInstance(std::string(), std::string()); | 248 base::FeatureList::InitializeInstance(std::string(), std::string()); |
| 244 // TODO(mef): Use net:UrlRequestContextBuilder instead of manual build. | 249 // TODO(mef): Use net:UrlRequestContextBuilder instead of manual build. |
| 245 main_context_.reset(new net::URLRequestContext); | |
| 246 main_context_->set_net_log(net_log_.get()); | 250 main_context_->set_net_log(net_log_.get()); |
| 247 std::string user_agent(user_agent_product_name_ + | 251 std::string user_agent(user_agent_product_name_ + |
| 248 " (iOS); Cronet/" CRONET_VERSION); | 252 " (iOS); Cronet/" CRONET_VERSION); |
| 249 main_context_->set_http_user_agent_settings( | 253 main_context_->set_http_user_agent_settings( |
| 250 new net::StaticHttpUserAgentSettings("en", user_agent)); | 254 new net::StaticHttpUserAgentSettings("en", user_agent)); |
| 251 | 255 |
| 252 main_context_->set_ssl_config_service(new net::SSLConfigServiceDefaults); | 256 main_context_->set_ssl_config_service(new net::SSLConfigServiceDefaults); |
| 253 main_context_->set_transport_security_state( | 257 main_context_->set_transport_security_state( |
| 254 new net::TransportSecurityState()); | 258 new net::TransportSecurityState()); |
| 255 http_server_properties_.reset(new net::HttpServerPropertiesImpl()); | 259 http_server_properties_.reset(new net::HttpServerPropertiesImpl()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 const net::HttpUserAgentSettings* user_agent_settings = | 356 const net::HttpUserAgentSettings* user_agent_settings = |
| 353 main_context_->http_user_agent_settings(); | 357 main_context_->http_user_agent_settings(); |
| 354 if (!user_agent_settings) { | 358 if (!user_agent_settings) { |
| 355 return nullptr; | 359 return nullptr; |
| 356 } | 360 } |
| 357 | 361 |
| 358 return user_agent_settings->GetUserAgent(); | 362 return user_agent_settings->GetUserAgent(); |
| 359 } | 363 } |
| 360 | 364 |
| 361 } // namespace cronet | 365 } // namespace cronet |
| OLD | NEW |