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