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 "ios/crnet/crnet_environment.h" | 5 #include "ios/crnet/crnet_environment.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 146 |
147 // static | 147 // static |
148 void CrNetEnvironment::Initialize() { | 148 void CrNetEnvironment::Initialize() { |
149 DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); | 149 DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); |
150 if (!g_at_exit_) | 150 if (!g_at_exit_) |
151 g_at_exit_ = new base::AtExitManager; | 151 g_at_exit_ = new base::AtExitManager; |
152 | 152 |
153 CHECK(base::i18n::InitializeICU()); | 153 CHECK(base::i18n::InitializeICU()); |
154 url::Initialize(); | 154 url::Initialize(); |
155 base::CommandLine::Init(0, nullptr); | 155 base::CommandLine::Init(0, nullptr); |
| 156 |
| 157 #if defined(USE_NSS_VERIFIER) |
156 // This needs to happen on the main thread. NSPR's initialization sets up its | 158 // This needs to happen on the main thread. NSPR's initialization sets up its |
157 // memory allocator; if this is not done before other threads are created, | 159 // memory allocator; if this is not done before other threads are created, |
158 // this initialization can race to cause accidental free/allocation | 160 // this initialization can race to cause accidental free/allocation |
159 // mismatches. | 161 // mismatches. |
160 crypto::EnsureNSPRInit(); | 162 crypto::EnsureNSPRInit(); |
| 163 #endif |
| 164 |
161 // Without doing this, StatisticsRecorder::FactoryGet() leaks one histogram | 165 // Without doing this, StatisticsRecorder::FactoryGet() leaks one histogram |
162 // per call after the first for a given name. | 166 // per call after the first for a given name. |
163 base::StatisticsRecorder::Initialize(); | 167 base::StatisticsRecorder::Initialize(); |
164 | 168 |
165 // Create a message loop on the UI thread. | 169 // Create a message loop on the UI thread. |
166 base::MessageLoop* main_message_loop = | 170 base::MessageLoop* main_message_loop = |
167 new base::MessageLoop(base::MessageLoop::TYPE_UI); | 171 new base::MessageLoop(base::MessageLoop::TYPE_UI); |
168 #pragma unused(main_message_loop) | 172 #pragma unused(main_message_loop) |
169 base::MessageLoopForUI::current()->Attach(); | 173 base::MessageLoopForUI::current()->Attach(); |
170 } | 174 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 new base::Thread("Chrome File User Blocking Thread")); | 285 new base::Thread("Chrome File User Blocking Thread")); |
282 file_user_blocking_thread_->StartWithOptions( | 286 file_user_blocking_thread_->StartWithOptions( |
283 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 287 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
284 | 288 |
285 // The network change notifier must be initialized so that registered | 289 // The network change notifier must be initialized so that registered |
286 // delegates will receive callbacks. | 290 // delegates will receive callbacks. |
287 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 291 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
288 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( | 292 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( |
289 network_io_thread_->task_runner(), nullptr); | 293 network_io_thread_->task_runner(), nullptr); |
290 | 294 |
| 295 #if defined(USE_NSS_VERIFIER) |
291 net::SetURLRequestContextForNSSHttpIO(main_context_.get()); | 296 net::SetURLRequestContextForNSSHttpIO(main_context_.get()); |
| 297 #endif |
292 main_context_getter_ = new CrNetURLRequestContextGetter( | 298 main_context_getter_ = new CrNetURLRequestContextGetter( |
293 main_context_.get(), network_io_thread_->task_runner()); | 299 main_context_.get(), network_io_thread_->task_runner()); |
294 base::subtle::MemoryBarrier(); | 300 base::subtle::MemoryBarrier(); |
295 PostToNetworkThread(FROM_HERE, | 301 PostToNetworkThread(FROM_HERE, |
296 base::Bind(&CrNetEnvironment::InitializeOnNetworkThread, | 302 base::Bind(&CrNetEnvironment::InitializeOnNetworkThread, |
297 base::Unretained(this))); | 303 base::Unretained(this))); |
298 | 304 |
299 SetRequestFilterBlock(nil); | 305 SetRequestFilterBlock(nil); |
300 } | 306 } |
301 | 307 |
302 void CrNetEnvironment::InstallIntoSessionConfiguration( | 308 void CrNetEnvironment::InstallIntoSessionConfiguration( |
303 NSURLSessionConfiguration* config) { | 309 NSURLSessionConfiguration* config) { |
304 config.protocolClasses = @[ [CRNPauseableHTTPProtocolHandler class] ]; | 310 config.protocolClasses = @[ [CRNPauseableHTTPProtocolHandler class] ]; |
305 } | 311 } |
306 | 312 |
307 CrNetEnvironment::~CrNetEnvironment() { | 313 CrNetEnvironment::~CrNetEnvironment() { |
308 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); | 314 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); |
| 315 #if defined(USE_NSS_VERIFIER) |
309 net::SetURLRequestContextForNSSHttpIO(nullptr); | 316 net::SetURLRequestContextForNSSHttpIO(nullptr); |
| 317 #endif |
310 } | 318 } |
311 | 319 |
312 net::URLRequestContextGetter* CrNetEnvironment::GetMainContextGetter() { | 320 net::URLRequestContextGetter* CrNetEnvironment::GetMainContextGetter() { |
313 return main_context_getter_.get(); | 321 return main_context_getter_.get(); |
314 } | 322 } |
315 | 323 |
316 void CrNetEnvironment::SetHTTPProtocolHandlerRegistered(bool registered) { | 324 void CrNetEnvironment::SetHTTPProtocolHandlerRegistered(bool registered) { |
317 if (registered) { | 325 if (registered) { |
318 // Disable the default cache. | 326 // Disable the default cache. |
319 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; | 327 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 | 501 |
494 return user_agent_settings->GetUserAgent(); | 502 return user_agent_settings->GetUserAgent(); |
495 } | 503 } |
496 | 504 |
497 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { | 505 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { |
498 PostToNetworkThread( | 506 PostToNetworkThread( |
499 FROM_HERE, | 507 FROM_HERE, |
500 base::Bind(&net::ClearHttpCache, main_context_getter_, | 508 base::Bind(&net::ClearHttpCache, main_context_getter_, |
501 network_io_thread_->task_runner(), base::BindBlock(callback))); | 509 network_io_thread_->task_runner(), base::BindBlock(callback))); |
502 } | 510 } |
OLD | NEW |