| 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 18 matching lines...) Expand all Loading... |
| 29 // which is leaked at the shutdown. We should consider allowing multiple | 29 // which is leaked at the shutdown. We should consider allowing multiple |
| 30 // instances if that makes sense in the future. | 30 // instances if that makes sense in the future. |
| 31 base::LazyInstance<std::unique_ptr<cronet::CronetEnvironment>>::Leaky | 31 base::LazyInstance<std::unique_ptr<cronet::CronetEnvironment>>::Leaky |
| 32 gChromeNet = LAZY_INSTANCE_INITIALIZER; | 32 gChromeNet = LAZY_INSTANCE_INITIALIZER; |
| 33 | 33 |
| 34 BOOL gHttp2Enabled = YES; | 34 BOOL gHttp2Enabled = YES; |
| 35 BOOL gQuicEnabled = NO; | 35 BOOL gQuicEnabled = NO; |
| 36 cronet::URLRequestContextConfig::HttpCacheType gHttpCache = | 36 cronet::URLRequestContextConfig::HttpCacheType gHttpCache = |
| 37 cronet::URLRequestContextConfig::HttpCacheType::DISK; | 37 cronet::URLRequestContextConfig::HttpCacheType::DISK; |
| 38 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints; | 38 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints; |
| 39 NSString* gExperimentalOptions = @"{}"; |
| 39 NSString* gUserAgent = nil; | 40 NSString* gUserAgent = nil; |
| 40 BOOL gUserAgentPartial = NO; | 41 BOOL gUserAgentPartial = NO; |
| 41 NSString* gSslKeyLogFileName = nil; | 42 NSString* gSslKeyLogFileName = nil; |
| 42 RequestFilterBlock gRequestFilterBlock = nil; | 43 RequestFilterBlock gRequestFilterBlock = nil; |
| 43 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate; | 44 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate; |
| 44 NSURLCache* gPreservedSharedURLCache = nil; | 45 NSURLCache* gPreservedSharedURLCache = nil; |
| 45 BOOL gEnableTestCertVerifierForTesting = FALSE; | 46 BOOL gEnableTestCertVerifierForTesting = FALSE; |
| 46 | 47 |
| 47 // CertVerifier, which allows any certificates for testing. | 48 // CertVerifier, which allows any certificates for testing. |
| 48 class TestCertVerifier : public net::CertVerifier { | 49 class TestCertVerifier : public net::CertVerifier { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 [self checkNotStarted]; | 146 [self checkNotStarted]; |
| 146 gQuicEnabled = quicEnabled; | 147 gQuicEnabled = quicEnabled; |
| 147 } | 148 } |
| 148 | 149 |
| 149 + (void)addQuicHint:(NSString*)host port:(int)port altPort:(int)altPort { | 150 + (void)addQuicHint:(NSString*)host port:(int)port altPort:(int)altPort { |
| 150 [self checkNotStarted]; | 151 [self checkNotStarted]; |
| 151 gQuicHints.push_back(new cronet::URLRequestContextConfig::QuicHint( | 152 gQuicHints.push_back(new cronet::URLRequestContextConfig::QuicHint( |
| 152 base::SysNSStringToUTF8(host), port, altPort)); | 153 base::SysNSStringToUTF8(host), port, altPort)); |
| 153 } | 154 } |
| 154 | 155 |
| 156 + (void)setExperimentalOptions:(NSString*)experimentalOptions { |
| 157 [self checkNotStarted]; |
| 158 gExperimentalOptions = experimentalOptions; |
| 159 } |
| 160 |
| 155 + (void)setUserAgent:(NSString*)userAgent partial:(BOOL)partial { | 161 + (void)setUserAgent:(NSString*)userAgent partial:(BOOL)partial { |
| 156 [self checkNotStarted]; | 162 [self checkNotStarted]; |
| 157 gUserAgent = userAgent; | 163 gUserAgent = userAgent; |
| 158 gUserAgentPartial = partial; | 164 gUserAgentPartial = partial; |
| 159 } | 165 } |
| 160 | 166 |
| 161 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName { | 167 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName { |
| 162 [self checkNotStarted]; | 168 [self checkNotStarted]; |
| 163 gSslKeyLogFileName = sslKeyLogFileName; | 169 gSslKeyLogFileName = sslKeyLogFileName; |
| 164 } | 170 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 190 + (void)startInternal { | 196 + (void)startInternal { |
| 191 cronet::CronetEnvironment::Initialize(); | 197 cronet::CronetEnvironment::Initialize(); |
| 192 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); | 198 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); |
| 193 gChromeNet.Get().reset( | 199 gChromeNet.Get().reset( |
| 194 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); | 200 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); |
| 195 gChromeNet.Get()->set_accept_language( | 201 gChromeNet.Get()->set_accept_language( |
| 196 base::SysNSStringToUTF8([self getAcceptLanguages])); | 202 base::SysNSStringToUTF8([self getAcceptLanguages])); |
| 197 | 203 |
| 198 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled); | 204 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled); |
| 199 gChromeNet.Get()->set_quic_enabled(gQuicEnabled); | 205 gChromeNet.Get()->set_quic_enabled(gQuicEnabled); |
| 206 gChromeNet.Get()->set_experimental_options( |
| 207 base::SysNSStringToUTF8(gExperimentalOptions)); |
| 200 gChromeNet.Get()->set_http_cache(gHttpCache); | 208 gChromeNet.Get()->set_http_cache(gHttpCache); |
| 201 gChromeNet.Get()->set_ssl_key_log_file_name( | 209 gChromeNet.Get()->set_ssl_key_log_file_name( |
| 202 base::SysNSStringToUTF8(gSslKeyLogFileName)); | 210 base::SysNSStringToUTF8(gSslKeyLogFileName)); |
| 203 for (const auto* quicHint : gQuicHints) { | 211 for (const auto* quicHint : gQuicHints) { |
| 204 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, | 212 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, |
| 205 quicHint->alternate_port); | 213 quicHint->alternate_port); |
| 206 } | 214 } |
| 207 | 215 |
| 208 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()]; | 216 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()]; |
| 209 gChromeNet.Get()->Start(); | 217 gChromeNet.Get()->Start(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 base::SysNSStringToUTF8(hostResolverRulesForTesting)); | 320 base::SysNSStringToUTF8(hostResolverRulesForTesting)); |
| 313 } | 321 } |
| 314 | 322 |
| 315 // This is a non-public dummy method that prevents the linker from stripping out | 323 // This is a non-public dummy method that prevents the linker from stripping out |
| 316 // the otherwise non-referenced methods from 'bidirectional_stream.cc'. | 324 // the otherwise non-referenced methods from 'bidirectional_stream.cc'. |
| 317 + (void)preventStrippingCronetBidirectionalStream { | 325 + (void)preventStrippingCronetBidirectionalStream { |
| 318 bidirectional_stream_create(NULL, 0, 0); | 326 bidirectional_stream_create(NULL, 0, 0); |
| 319 } | 327 } |
| 320 | 328 |
| 321 @end | 329 @end |
| OLD | NEW |