| 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 #import "components/cronet/ios/Cronet.h" | 5 #import "components/cronet/ios/Cronet.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 BOOL gHttp2Enabled = YES; | 35 BOOL gHttp2Enabled = YES; |
| 36 BOOL gQuicEnabled = NO; | 36 BOOL gQuicEnabled = NO; |
| 37 cronet::URLRequestContextConfig::HttpCacheType gHttpCache = | 37 cronet::URLRequestContextConfig::HttpCacheType gHttpCache = |
| 38 cronet::URLRequestContextConfig::HttpCacheType::DISK; | 38 cronet::URLRequestContextConfig::HttpCacheType::DISK; |
| 39 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints; | 39 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints; |
| 40 NSString* gUserAgent = nil; | 40 NSString* gUserAgent = nil; |
| 41 BOOL gUserAgentPartial = NO; | 41 BOOL gUserAgentPartial = NO; |
| 42 NSString* gSslKeyLogFileName = nil; | 42 NSString* gSslKeyLogFileName = nil; |
| 43 RequestFilterBlock gRequestFilterBlock = nil; | 43 RequestFilterBlock gRequestFilterBlock = nil; |
| 44 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate; | 44 base::LazyInstance<std::unique_ptr<CronetHttpProtocolHandlerDelegate>>::Leaky |
| 45 gHttpProtocolHandlerDelegate = LAZY_INSTANCE_INITIALIZER; |
| 45 NSURLCache* gPreservedSharedURLCache = nil; | 46 NSURLCache* gPreservedSharedURLCache = nil; |
| 46 BOOL gEnableTestCertVerifierForTesting = FALSE; | 47 BOOL gEnableTestCertVerifierForTesting = FALSE; |
| 47 NSString* gAcceptLanguages = nil; | 48 NSString* gAcceptLanguages = nil; |
| 48 | 49 |
| 49 // CertVerifier, which allows any certificates for testing. | 50 // CertVerifier, which allows any certificates for testing. |
| 50 class TestCertVerifier : public net::CertVerifier { | 51 class TestCertVerifier : public net::CertVerifier { |
| 51 int Verify(const RequestParams& params, | 52 int Verify(const RequestParams& params, |
| 52 net::CRLSet* crl_set, | 53 net::CRLSet* crl_set, |
| 53 net::CertVerifyResult* verify_result, | 54 net::CertVerifyResult* verify_result, |
| 54 const net::CompletionCallback& callback, | 55 const net::CompletionCallback& callback, |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 break; | 190 break; |
| 190 case CRNHttpCacheTypeMemory: | 191 case CRNHttpCacheTypeMemory: |
| 191 gHttpCache = cronet::URLRequestContextConfig::HttpCacheType::MEMORY; | 192 gHttpCache = cronet::URLRequestContextConfig::HttpCacheType::MEMORY; |
| 192 break; | 193 break; |
| 193 default: | 194 default: |
| 194 DCHECK(NO) << "Invalid HTTP cache type: " << httpCacheType; | 195 DCHECK(NO) << "Invalid HTTP cache type: " << httpCacheType; |
| 195 } | 196 } |
| 196 } | 197 } |
| 197 | 198 |
| 198 + (void)setRequestFilterBlock:(RequestFilterBlock)block { | 199 + (void)setRequestFilterBlock:(RequestFilterBlock)block { |
| 199 if (gHttpProtocolHandlerDelegate.get()) | 200 if (gHttpProtocolHandlerDelegate.Get().get()) |
| 200 gHttpProtocolHandlerDelegate.get()->SetRequestFilterBlock(block); | 201 gHttpProtocolHandlerDelegate.Get().get()->SetRequestFilterBlock(block); |
| 201 else | 202 else |
| 202 gRequestFilterBlock = block; | 203 gRequestFilterBlock = block; |
| 203 } | 204 } |
| 204 | 205 |
| 205 + (void)startInternal { | 206 + (void)startInternal { |
| 206 cronet::CronetEnvironment::Initialize(); | 207 cronet::CronetEnvironment::Initialize(); |
| 207 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); | 208 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); |
| 208 gChromeNet.Get().reset( | 209 gChromeNet.Get().reset( |
| 209 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); | 210 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); |
| 210 gChromeNet.Get()->set_accept_language( | 211 gChromeNet.Get()->set_accept_language( |
| 211 base::SysNSStringToUTF8(gAcceptLanguages ?: [self getAcceptLanguages])); | 212 base::SysNSStringToUTF8(gAcceptLanguages ?: [self getAcceptLanguages])); |
| 212 | 213 |
| 213 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled); | 214 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled); |
| 214 gChromeNet.Get()->set_quic_enabled(gQuicEnabled); | 215 gChromeNet.Get()->set_quic_enabled(gQuicEnabled); |
| 215 gChromeNet.Get()->set_http_cache(gHttpCache); | 216 gChromeNet.Get()->set_http_cache(gHttpCache); |
| 216 gChromeNet.Get()->set_ssl_key_log_file_name( | 217 gChromeNet.Get()->set_ssl_key_log_file_name( |
| 217 base::SysNSStringToUTF8(gSslKeyLogFileName)); | 218 base::SysNSStringToUTF8(gSslKeyLogFileName)); |
| 218 for (const auto* quicHint : gQuicHints) { | 219 for (const auto* quicHint : gQuicHints) { |
| 219 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, | 220 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, |
| 220 quicHint->alternate_port); | 221 quicHint->alternate_port); |
| 221 } | 222 } |
| 222 | 223 |
| 223 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()]; | 224 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()]; |
| 224 gChromeNet.Get()->Start(); | 225 gChromeNet.Get()->Start(); |
| 225 gHttpProtocolHandlerDelegate.reset(new CronetHttpProtocolHandlerDelegate( | 226 gHttpProtocolHandlerDelegate.Get().reset( |
| 226 gChromeNet.Get()->GetURLRequestContextGetter(), gRequestFilterBlock)); | 227 new CronetHttpProtocolHandlerDelegate( |
| 228 gChromeNet.Get()->GetURLRequestContextGetter(), gRequestFilterBlock)); |
| 227 net::HTTPProtocolHandlerDelegate::SetInstance( | 229 net::HTTPProtocolHandlerDelegate::SetInstance( |
| 228 gHttpProtocolHandlerDelegate.get()); | 230 gHttpProtocolHandlerDelegate.Get().get()); |
| 229 gRequestFilterBlock = nil; | 231 gRequestFilterBlock = nil; |
| 230 } | 232 } |
| 231 | 233 |
| 232 + (void)start { | 234 + (void)start { |
| 233 static dispatch_once_t onceToken; | 235 static dispatch_once_t onceToken; |
| 234 dispatch_once(&onceToken, ^{ | 236 dispatch_once(&onceToken, ^{ |
| 235 if (![NSThread isMainThread]) { | 237 if (![NSThread isMainThread]) { |
| 236 dispatch_sync(dispatch_get_main_queue(), ^(void) { | 238 dispatch_sync(dispatch_get_main_queue(), ^(void) { |
| 237 [self startInternal]; | 239 [self startInternal]; |
| 238 }); | 240 }); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 base::SysNSStringToUTF8(hostResolverRulesForTesting)); | 329 base::SysNSStringToUTF8(hostResolverRulesForTesting)); |
| 328 } | 330 } |
| 329 | 331 |
| 330 // This is a non-public dummy method that prevents the linker from stripping out | 332 // This is a non-public dummy method that prevents the linker from stripping out |
| 331 // the otherwise non-referenced methods from 'bidirectional_stream.cc'. | 333 // the otherwise non-referenced methods from 'bidirectional_stream.cc'. |
| 332 + (void)preventStrippingCronetBidirectionalStream { | 334 + (void)preventStrippingCronetBidirectionalStream { |
| 333 bidirectional_stream_create(NULL, 0, 0); | 335 bidirectional_stream_create(NULL, 0, 0); |
| 334 } | 336 } |
| 335 | 337 |
| 336 @end | 338 @end |
| OLD | NEW |