| 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 BOOL gHttp2Enabled = YES; | 34 BOOL gHttp2Enabled = YES; |
| 35 BOOL gQuicEnabled = NO; | 35 BOOL gQuicEnabled = NO; |
| 36 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints; | 36 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints; |
| 37 NSString* gUserAgent = nil; | 37 NSString* gUserAgent = nil; |
| 38 BOOL gUserAgentPartial = NO; | 38 BOOL gUserAgentPartial = NO; |
| 39 NSString* gSslKeyLogFileName = nil; | 39 NSString* gSslKeyLogFileName = nil; |
| 40 RequestFilterBlock gRequestFilterBlock = nil; | 40 RequestFilterBlock gRequestFilterBlock = nil; |
| 41 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate; | 41 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate; |
| 42 NSURLCache* gPreservedSharedURLCache = nil; | 42 NSURLCache* gPreservedSharedURLCache = nil; |
| 43 BOOL gEnableTestCertVerifierForTesting = FALSE; | 43 BOOL gEnableTestCertVerifierForTesting = FALSE; |
| 44 NSString* gHostResolverRulesForTesting = @""; | |
| 45 | 44 |
| 46 // CertVerifier, which allows any certificates for testing. | 45 // CertVerifier, which allows any certificates for testing. |
| 47 class TestCertVerifier : public net::CertVerifier { | 46 class TestCertVerifier : public net::CertVerifier { |
| 48 int Verify(const RequestParams& params, | 47 int Verify(const RequestParams& params, |
| 49 net::CRLSet* crl_set, | 48 net::CRLSet* crl_set, |
| 50 net::CertVerifyResult* verify_result, | 49 net::CertVerifyResult* verify_result, |
| 51 const net::CompletionCallback& callback, | 50 const net::CompletionCallback& callback, |
| 52 std::unique_ptr<Request>* out_req, | 51 std::unique_ptr<Request>* out_req, |
| 53 const net::NetLogWithSource& net_log) override { | 52 const net::NetLogWithSource& net_log) override { |
| 54 net::Error result = net::OK; | 53 net::Error result = net::OK; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 base::mac::ScopedBlock<RequestFilterBlock> filter_; | 98 base::mac::ScopedBlock<RequestFilterBlock> filter_; |
| 100 base::Lock lock_; | 99 base::Lock lock_; |
| 101 }; | 100 }; |
| 102 | 101 |
| 103 } // namespace | 102 } // namespace |
| 104 | 103 |
| 105 @implementation Cronet | 104 @implementation Cronet |
| 106 | 105 |
| 107 + (void)configureCronetEnvironmentForTesting: | 106 + (void)configureCronetEnvironmentForTesting: |
| 108 (cronet::CronetEnvironment*)cronetEnvironment { | 107 (cronet::CronetEnvironment*)cronetEnvironment { |
| 109 cronetEnvironment->set_host_resolver_rules( | |
| 110 [gHostResolverRulesForTesting UTF8String]); | |
| 111 if (gEnableTestCertVerifierForTesting) { | 108 if (gEnableTestCertVerifierForTesting) { |
| 112 std::unique_ptr<TestCertVerifier> test_cert_verifier = | 109 std::unique_ptr<TestCertVerifier> test_cert_verifier = |
| 113 base::MakeUnique<TestCertVerifier>(); | 110 base::MakeUnique<TestCertVerifier>(); |
| 114 cronetEnvironment->set_cert_verifier(std::move(test_cert_verifier)); | 111 cronetEnvironment->set_cert_verifier(std::move(test_cert_verifier)); |
| 115 } | 112 } |
| 116 } | 113 } |
| 117 | 114 |
| 118 + (NSString*)getAcceptLanguages { | 115 + (NSString*)getAcceptLanguages { |
| 119 // Use the framework bundle to search for resources. | 116 // Use the framework bundle to search for resources. |
| 120 NSBundle* frameworkBundle = [NSBundle bundleForClass:self]; | 117 NSBundle* frameworkBundle = [NSBundle bundleForClass:self]; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 244 |
| 248 + (NSString*)getUserAgent { | 245 + (NSString*)getUserAgent { |
| 249 if (!gChromeNet.Get().get()) { | 246 if (!gChromeNet.Get().get()) { |
| 250 return nil; | 247 return nil; |
| 251 } | 248 } |
| 252 | 249 |
| 253 return [NSString stringWithCString:gChromeNet.Get()->user_agent().c_str() | 250 return [NSString stringWithCString:gChromeNet.Get()->user_agent().c_str() |
| 254 encoding:[NSString defaultCStringEncoding]]; | 251 encoding:[NSString defaultCStringEncoding]]; |
| 255 } | 252 } |
| 256 | 253 |
| 257 + (cronet_engine*)getGlobalEngine { | 254 + (stream_engine*)getGlobalEngine { |
| 258 DCHECK(gChromeNet.Get().get()); | 255 DCHECK(gChromeNet.Get().get()); |
| 259 if (gChromeNet.Get().get()) { | 256 if (gChromeNet.Get().get()) { |
| 260 static cronet_engine engine; | 257 static stream_engine engine; |
| 261 engine.obj = gChromeNet.Get().get(); | 258 engine.obj = gChromeNet.Get()->GetURLRequestContextGetter(); |
| 262 return &engine; | 259 return &engine; |
| 263 } | 260 } |
| 264 return nil; | 261 return nil; |
| 265 } | 262 } |
| 266 | 263 |
| 267 + (NSData*)getGlobalMetricsDeltas { | 264 + (NSData*)getGlobalMetricsDeltas { |
| 268 if (!gChromeNet.Get().get()) { | 265 if (!gChromeNet.Get().get()) { |
| 269 return nil; | 266 return nil; |
| 270 } | 267 } |
| 271 std::vector<uint8_t> deltas(gChromeNet.Get()->GetHistogramDeltas()); | 268 std::vector<uint8_t> deltas(gChromeNet.Get()->GetHistogramDeltas()); |
| 272 return [NSData dataWithBytes:deltas.data() length:deltas.size()]; | 269 return [NSData dataWithBytes:deltas.data() length:deltas.size()]; |
| 273 } | 270 } |
| 274 | 271 |
| 275 + (void)enableTestCertVerifierForTesting { | 272 + (void)enableTestCertVerifierForTesting { |
| 276 gEnableTestCertVerifierForTesting = YES; | 273 gEnableTestCertVerifierForTesting = YES; |
| 277 } | 274 } |
| 278 | 275 |
| 279 + (void)setHostResolverRulesForTesting:(NSString*)hostResolverRulesForTesting { | 276 + (void)setHostResolverRulesForTesting:(NSString*)hostResolverRulesForTesting { |
| 280 gHostResolverRulesForTesting = hostResolverRulesForTesting; | 277 DCHECK(gChromeNet.Get().get()); |
| 278 gChromeNet.Get()->SetHostResolverRules( |
| 279 base::SysNSStringToUTF8(hostResolverRulesForTesting)); |
| 281 } | 280 } |
| 282 | 281 |
| 283 // This is a non-public dummy method that prevents the linker from stripping out | 282 // This is a non-public dummy method that prevents the linker from stripping out |
| 284 // the otherwise non-referenced methods from 'cronet_bidirectional_stream.cc'. | 283 // the otherwise non-referenced methods from 'bidirectional_stream.cc'. |
| 285 + (void)preventStrippingCronetBidirectionalStream { | 284 + (void)preventStrippingCronetBidirectionalStream { |
| 286 cronet_bidirectional_stream_create(NULL, 0, 0); | 285 bidirectional_stream_create(NULL, 0, 0); |
| 287 } | 286 } |
| 288 | 287 |
| 289 @end | 288 @end |
| OLD | NEW |