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 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/atomicops.h" | 12 #include "base/atomicops.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/files/scoped_file.h" | 16 #include "base/files/scoped_file.h" |
17 #include "base/i18n/icu_util.h" | 17 #include "base/i18n/icu_util.h" |
18 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
19 #include "base/mac/bind_objc_block.h" | 19 #include "base/mac/bind_objc_block.h" |
20 #include "base/mac/foundation_util.h" | 20 #include "base/mac/foundation_util.h" |
21 #include "base/mac/scoped_block.h" | 21 #include "base/mac/scoped_block.h" |
22 #include "base/macros.h" | 22 #include "base/macros.h" |
23 #include "base/memory/ptr_util.h" | 23 #include "base/memory/ptr_util.h" |
24 #include "base/metrics/statistics_recorder.h" | 24 #include "base/metrics/statistics_recorder.h" |
25 #include "base/path_service.h" | 25 #include "base/path_service.h" |
26 #include "base/threading/worker_pool.h" | 26 #include "base/threading/worker_pool.h" |
27 #include "components/prefs/json_pref_store.h" | 27 #include "components/prefs/json_pref_store.h" |
28 #include "components/prefs/pref_filter.h" | 28 #include "components/prefs/pref_filter.h" |
29 #include "crypto/nss_util.h" | |
30 #include "ios/crnet/sdch_owner_pref_storage.h" | 29 #include "ios/crnet/sdch_owner_pref_storage.h" |
31 #include "ios/net/cookies/cookie_store_ios.h" | 30 #include "ios/net/cookies/cookie_store_ios.h" |
32 #include "ios/net/crn_http_protocol_handler.h" | 31 #include "ios/net/crn_http_protocol_handler.h" |
33 #include "ios/net/empty_nsurlcache.h" | 32 #include "ios/net/empty_nsurlcache.h" |
34 #include "ios/net/http_cache_helper.h" | 33 #include "ios/net/http_cache_helper.h" |
35 #include "ios/net/request_tracker.h" | 34 #include "ios/net/request_tracker.h" |
36 #include "ios/web/public/user_agent.h" | 35 #include "ios/web/public/user_agent.h" |
37 #include "net/base/net_errors.h" | 36 #include "net/base/net_errors.h" |
38 #include "net/base/network_change_notifier.h" | 37 #include "net/base/network_change_notifier.h" |
39 #include "net/base/sdch_manager.h" | 38 #include "net/base/sdch_manager.h" |
40 #include "net/cert/cert_verifier.h" | 39 #include "net/cert/cert_verifier.h" |
41 #include "net/cert_net/nss_ocsp.h" | |
42 #include "net/cookies/cookie_store.h" | 40 #include "net/cookies/cookie_store.h" |
43 #include "net/http/http_auth_handler_factory.h" | 41 #include "net/http/http_auth_handler_factory.h" |
44 #include "net/http/http_cache.h" | 42 #include "net/http/http_cache.h" |
45 #include "net/http/http_server_properties_impl.h" | 43 #include "net/http/http_server_properties_impl.h" |
46 #include "net/http/http_stream_factory.h" | 44 #include "net/http/http_stream_factory.h" |
47 #include "net/http/http_util.h" | 45 #include "net/http/http_util.h" |
48 #include "net/log/net_log.h" | 46 #include "net/log/net_log.h" |
49 #include "net/log/write_to_file_net_log_observer.h" | 47 #include "net/log/write_to_file_net_log_observer.h" |
50 #include "net/proxy/proxy_service.h" | 48 #include "net/proxy/proxy_service.h" |
51 #include "net/sdch/sdch_owner.h" | 49 #include "net/sdch/sdch_owner.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // static | 145 // static |
148 void CrNetEnvironment::Initialize() { | 146 void CrNetEnvironment::Initialize() { |
149 DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); | 147 DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); |
150 if (!g_at_exit_) | 148 if (!g_at_exit_) |
151 g_at_exit_ = new base::AtExitManager; | 149 g_at_exit_ = new base::AtExitManager; |
152 | 150 |
153 CHECK(base::i18n::InitializeICU()); | 151 CHECK(base::i18n::InitializeICU()); |
154 url::Initialize(); | 152 url::Initialize(); |
155 base::CommandLine::Init(0, nullptr); | 153 base::CommandLine::Init(0, nullptr); |
156 | 154 |
157 #if defined(USE_NSS_VERIFIER) | |
158 // This needs to happen on the main thread. NSPR's initialization sets up its | |
159 // memory allocator; if this is not done before other threads are created, | |
160 // this initialization can race to cause accidental free/allocation | |
161 // mismatches. | |
162 crypto::EnsureNSPRInit(); | |
163 #endif | |
164 | |
165 // Without doing this, StatisticsRecorder::FactoryGet() leaks one histogram | 155 // Without doing this, StatisticsRecorder::FactoryGet() leaks one histogram |
166 // per call after the first for a given name. | 156 // per call after the first for a given name. |
167 base::StatisticsRecorder::Initialize(); | 157 base::StatisticsRecorder::Initialize(); |
168 | 158 |
169 // Create a message loop on the UI thread. | 159 // Create a message loop on the UI thread. |
170 base::MessageLoop* main_message_loop = | 160 base::MessageLoop* main_message_loop = |
171 new base::MessageLoop(base::MessageLoop::TYPE_UI); | 161 new base::MessageLoop(base::MessageLoop::TYPE_UI); |
172 #pragma unused(main_message_loop) | 162 #pragma unused(main_message_loop) |
173 base::MessageLoopForUI::current()->Attach(); | 163 base::MessageLoopForUI::current()->Attach(); |
174 } | 164 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 new base::Thread("Chrome File User Blocking Thread")); | 275 new base::Thread("Chrome File User Blocking Thread")); |
286 file_user_blocking_thread_->StartWithOptions( | 276 file_user_blocking_thread_->StartWithOptions( |
287 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 277 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
288 | 278 |
289 // The network change notifier must be initialized so that registered | 279 // The network change notifier must be initialized so that registered |
290 // delegates will receive callbacks. | 280 // delegates will receive callbacks. |
291 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 281 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
292 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( | 282 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( |
293 network_io_thread_->task_runner(), nullptr); | 283 network_io_thread_->task_runner(), nullptr); |
294 | 284 |
295 #if defined(USE_NSS_VERIFIER) | |
296 net::SetURLRequestContextForNSSHttpIO(main_context_.get()); | |
297 #endif | |
298 main_context_getter_ = new CrNetURLRequestContextGetter( | 285 main_context_getter_ = new CrNetURLRequestContextGetter( |
299 main_context_.get(), network_io_thread_->task_runner()); | 286 main_context_.get(), network_io_thread_->task_runner()); |
300 base::subtle::MemoryBarrier(); | 287 base::subtle::MemoryBarrier(); |
301 PostToNetworkThread(FROM_HERE, | 288 PostToNetworkThread(FROM_HERE, |
302 base::Bind(&CrNetEnvironment::InitializeOnNetworkThread, | 289 base::Bind(&CrNetEnvironment::InitializeOnNetworkThread, |
303 base::Unretained(this))); | 290 base::Unretained(this))); |
304 | 291 |
305 SetRequestFilterBlock(nil); | 292 SetRequestFilterBlock(nil); |
306 } | 293 } |
307 | 294 |
308 void CrNetEnvironment::InstallIntoSessionConfiguration( | 295 void CrNetEnvironment::InstallIntoSessionConfiguration( |
309 NSURLSessionConfiguration* config) { | 296 NSURLSessionConfiguration* config) { |
310 config.protocolClasses = @[ [CRNPauseableHTTPProtocolHandler class] ]; | 297 config.protocolClasses = @[ [CRNPauseableHTTPProtocolHandler class] ]; |
311 } | 298 } |
312 | 299 |
313 CrNetEnvironment::~CrNetEnvironment() { | 300 CrNetEnvironment::~CrNetEnvironment() { |
314 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); | 301 net::HTTPProtocolHandlerDelegate::SetInstance(nullptr); |
315 #if defined(USE_NSS_VERIFIER) | |
316 net::SetURLRequestContextForNSSHttpIO(nullptr); | |
317 #endif | |
318 } | 302 } |
319 | 303 |
320 net::URLRequestContextGetter* CrNetEnvironment::GetMainContextGetter() { | 304 net::URLRequestContextGetter* CrNetEnvironment::GetMainContextGetter() { |
321 return main_context_getter_.get(); | 305 return main_context_getter_.get(); |
322 } | 306 } |
323 | 307 |
324 void CrNetEnvironment::SetHTTPProtocolHandlerRegistered(bool registered) { | 308 void CrNetEnvironment::SetHTTPProtocolHandlerRegistered(bool registered) { |
325 if (registered) { | 309 if (registered) { |
326 // Disable the default cache. | 310 // Disable the default cache. |
327 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; | 311 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 474 |
491 return user_agent_settings->GetUserAgent(); | 475 return user_agent_settings->GetUserAgent(); |
492 } | 476 } |
493 | 477 |
494 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { | 478 void CrNetEnvironment::ClearCache(ClearCacheCallback callback) { |
495 PostToNetworkThread( | 479 PostToNetworkThread( |
496 FROM_HERE, | 480 FROM_HERE, |
497 base::Bind(&net::ClearHttpCache, main_context_getter_, | 481 base::Bind(&net::ClearHttpCache, main_context_getter_, |
498 network_io_thread_->task_runner(), base::BindBlock(callback))); | 482 network_io_thread_->task_runner(), base::BindBlock(callback))); |
499 } | 483 } |
OLD | NEW |