| 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 19 matching lines...) Expand all Loading... |
| 30 // which is leaked at the shutdown. We should consider allowing multiple | 30 // which is leaked at the shutdown. We should consider allowing multiple |
| 31 // instances if that makes sense in the future. | 31 // instances if that makes sense in the future. |
| 32 base::LazyInstance<std::unique_ptr<cronet::CronetEnvironment>>::Leaky | 32 base::LazyInstance<std::unique_ptr<cronet::CronetEnvironment>>::Leaky |
| 33 gChromeNet = LAZY_INSTANCE_INITIALIZER; | 33 gChromeNet = LAZY_INSTANCE_INITIALIZER; |
| 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* gExperimentalOptions = @"{}"; | |
| 41 NSString* gUserAgent = nil; | 40 NSString* gUserAgent = nil; |
| 42 BOOL gUserAgentPartial = NO; | 41 BOOL gUserAgentPartial = NO; |
| 43 NSString* gSslKeyLogFileName = nil; | 42 NSString* gSslKeyLogFileName = nil; |
| 44 RequestFilterBlock gRequestFilterBlock = nil; | 43 RequestFilterBlock gRequestFilterBlock = nil; |
| 45 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate; | 44 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate; |
| 46 NSURLCache* gPreservedSharedURLCache = nil; | 45 NSURLCache* gPreservedSharedURLCache = nil; |
| 47 BOOL gEnableTestCertVerifierForTesting = FALSE; | 46 BOOL gEnableTestCertVerifierForTesting = FALSE; |
| 48 NSString* gAcceptLanguages = nil; | 47 NSString* gAcceptLanguages = nil; |
| 49 | 48 |
| 50 // CertVerifier, which allows any certificates for testing. | 49 // CertVerifier, which allows any certificates for testing. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 [self checkNotStarted]; | 160 [self checkNotStarted]; |
| 162 gQuicEnabled = quicEnabled; | 161 gQuicEnabled = quicEnabled; |
| 163 } | 162 } |
| 164 | 163 |
| 165 + (void)addQuicHint:(NSString*)host port:(int)port altPort:(int)altPort { | 164 + (void)addQuicHint:(NSString*)host port:(int)port altPort:(int)altPort { |
| 166 [self checkNotStarted]; | 165 [self checkNotStarted]; |
| 167 gQuicHints.push_back(new cronet::URLRequestContextConfig::QuicHint( | 166 gQuicHints.push_back(new cronet::URLRequestContextConfig::QuicHint( |
| 168 base::SysNSStringToUTF8(host), port, altPort)); | 167 base::SysNSStringToUTF8(host), port, altPort)); |
| 169 } | 168 } |
| 170 | 169 |
| 171 + (void)setExperimentalOptions:(NSString*)experimentalOptions { | |
| 172 [self checkNotStarted]; | |
| 173 gExperimentalOptions = experimentalOptions; | |
| 174 } | |
| 175 | |
| 176 + (void)setUserAgent:(NSString*)userAgent partial:(BOOL)partial { | 170 + (void)setUserAgent:(NSString*)userAgent partial:(BOOL)partial { |
| 177 [self checkNotStarted]; | 171 [self checkNotStarted]; |
| 178 gUserAgent = userAgent; | 172 gUserAgent = userAgent; |
| 179 gUserAgentPartial = partial; | 173 gUserAgentPartial = partial; |
| 180 } | 174 } |
| 181 | 175 |
| 182 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName { | 176 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName { |
| 183 [self checkNotStarted]; | 177 [self checkNotStarted]; |
| 184 gSslKeyLogFileName = [self getNetLogPathForFile:sslKeyLogFileName]; | 178 gSslKeyLogFileName = sslKeyLogFileName; |
| 185 } | 179 } |
| 186 | 180 |
| 187 + (void)setHttpCacheType:(CRNHttpCacheType)httpCacheType { | 181 + (void)setHttpCacheType:(CRNHttpCacheType)httpCacheType { |
| 188 [self checkNotStarted]; | 182 [self checkNotStarted]; |
| 189 switch (httpCacheType) { | 183 switch (httpCacheType) { |
| 190 case CRNHttpCacheTypeDisabled: | 184 case CRNHttpCacheTypeDisabled: |
| 191 gHttpCache = cronet::URLRequestContextConfig::HttpCacheType::DISABLED; | 185 gHttpCache = cronet::URLRequestContextConfig::HttpCacheType::DISABLED; |
| 192 break; | 186 break; |
| 193 case CRNHttpCacheTypeDisk: | 187 case CRNHttpCacheTypeDisk: |
| 194 gHttpCache = cronet::URLRequestContextConfig::HttpCacheType::DISK; | 188 gHttpCache = cronet::URLRequestContextConfig::HttpCacheType::DISK; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 211 + (void)startInternal { | 205 + (void)startInternal { |
| 212 cronet::CronetEnvironment::Initialize(); | 206 cronet::CronetEnvironment::Initialize(); |
| 213 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); | 207 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); |
| 214 gChromeNet.Get().reset( | 208 gChromeNet.Get().reset( |
| 215 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); | 209 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); |
| 216 gChromeNet.Get()->set_accept_language( | 210 gChromeNet.Get()->set_accept_language( |
| 217 base::SysNSStringToUTF8(gAcceptLanguages ?: [self getAcceptLanguages])); | 211 base::SysNSStringToUTF8(gAcceptLanguages ?: [self getAcceptLanguages])); |
| 218 | 212 |
| 219 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled); | 213 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled); |
| 220 gChromeNet.Get()->set_quic_enabled(gQuicEnabled); | 214 gChromeNet.Get()->set_quic_enabled(gQuicEnabled); |
| 221 gChromeNet.Get()->set_experimental_options( | |
| 222 base::SysNSStringToUTF8(gExperimentalOptions)); | |
| 223 gChromeNet.Get()->set_http_cache(gHttpCache); | 215 gChromeNet.Get()->set_http_cache(gHttpCache); |
| 224 gChromeNet.Get()->set_ssl_key_log_file_name( | 216 gChromeNet.Get()->set_ssl_key_log_file_name( |
| 225 base::SysNSStringToUTF8(gSslKeyLogFileName)); | 217 base::SysNSStringToUTF8(gSslKeyLogFileName)); |
| 226 for (const auto* quicHint : gQuicHints) { | 218 for (const auto* quicHint : gQuicHints) { |
| 227 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, | 219 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, |
| 228 quicHint->alternate_port); | 220 quicHint->alternate_port); |
| 229 } | 221 } |
| 230 | 222 |
| 231 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()]; | 223 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()]; |
| 232 gChromeNet.Get()->Start(); | 224 gChromeNet.Get()->Start(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 base::SysNSStringToUTF8(hostResolverRulesForTesting)); | 327 base::SysNSStringToUTF8(hostResolverRulesForTesting)); |
| 336 } | 328 } |
| 337 | 329 |
| 338 // This is a non-public dummy method that prevents the linker from stripping out | 330 // This is a non-public dummy method that prevents the linker from stripping out |
| 339 // the otherwise non-referenced methods from 'bidirectional_stream.cc'. | 331 // the otherwise non-referenced methods from 'bidirectional_stream.cc'. |
| 340 + (void)preventStrippingCronetBidirectionalStream { | 332 + (void)preventStrippingCronetBidirectionalStream { |
| 341 bidirectional_stream_create(NULL, 0, 0); | 333 bidirectional_stream_create(NULL, 0, 0); |
| 342 } | 334 } |
| 343 | 335 |
| 344 @end | 336 @end |
| OLD | NEW |