Chromium Code Reviews| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 + (NSString*)getAcceptLanguages { | 141 + (NSString*)getAcceptLanguages { |
| 142 return [self | 142 return [self |
| 143 getAcceptLanguagesFromPreferredLanguages:[NSLocale preferredLanguages]]; | 143 getAcceptLanguagesFromPreferredLanguages:[NSLocale preferredLanguages]]; |
| 144 } | 144 } |
| 145 | 145 |
| 146 + (void)setAcceptLanguages:(NSString*)acceptLanguages { | 146 + (void)setAcceptLanguages:(NSString*)acceptLanguages { |
| 147 [self checkNotStarted]; | 147 [self checkNotStarted]; |
| 148 gAcceptLanguages = acceptLanguages; | 148 gAcceptLanguages = acceptLanguages; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // TODO(lilyhoughton) this should either be removed, or made more sophisticated | |
| 151 + (void)checkNotStarted { | 152 + (void)checkNotStarted { |
| 152 CHECK(gChromeNet == NULL) << "Cronet is already started."; | 153 // CHECK(gChromeNet == NULL) << "Cronet is already started."; |
| 153 } | 154 } |
| 154 | 155 |
| 155 + (void)setHttp2Enabled:(BOOL)http2Enabled { | 156 + (void)setHttp2Enabled:(BOOL)http2Enabled { |
| 156 [self checkNotStarted]; | 157 [self checkNotStarted]; |
| 157 gHttp2Enabled = http2Enabled; | 158 gHttp2Enabled = http2Enabled; |
| 158 } | 159 } |
| 159 | 160 |
| 160 + (void)setQuicEnabled:(BOOL)quicEnabled { | 161 + (void)setQuicEnabled:(BOOL)quicEnabled { |
| 161 [self checkNotStarted]; | 162 [self checkNotStarted]; |
| 162 gQuicEnabled = quicEnabled; | 163 gQuicEnabled = quicEnabled; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 } | 197 } |
| 197 } | 198 } |
| 198 | 199 |
| 199 + (void)setRequestFilterBlock:(RequestFilterBlock)block { | 200 + (void)setRequestFilterBlock:(RequestFilterBlock)block { |
| 200 if (gHttpProtocolHandlerDelegate.Get().get()) | 201 if (gHttpProtocolHandlerDelegate.Get().get()) |
| 201 gHttpProtocolHandlerDelegate.Get().get()->SetRequestFilterBlock(block); | 202 gHttpProtocolHandlerDelegate.Get().get()->SetRequestFilterBlock(block); |
| 202 else | 203 else |
| 203 gRequestFilterBlock = block; | 204 gRequestFilterBlock = block; |
| 204 } | 205 } |
| 205 | 206 |
| 207 + (void)initializeCronet { | |
| 208 cronet::CronetEnvironment::Initialize(); | |
| 209 } | |
| 210 | |
| 206 + (void)startInternal { | 211 + (void)startInternal { |
| 207 cronet::CronetEnvironment::Initialize(); | |
| 208 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); | 212 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); |
| 213 | |
| 209 gChromeNet.Get().reset( | 214 gChromeNet.Get().reset( |
| 210 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); | 215 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); |
| 216 | |
| 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); |
| 216 gChromeNet.Get()->set_http_cache(gHttpCache); | 222 gChromeNet.Get()->set_http_cache(gHttpCache); |
| 217 gChromeNet.Get()->set_ssl_key_log_file_name( | 223 gChromeNet.Get()->set_ssl_key_log_file_name( |
| 218 base::SysNSStringToUTF8(gSslKeyLogFileName)); | 224 base::SysNSStringToUTF8(gSslKeyLogFileName)); |
| 219 for (const auto* quicHint : gQuicHints) { | 225 for (const auto* quicHint : gQuicHints) { |
| 220 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, | 226 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, |
| 221 quicHint->alternate_port); | 227 quicHint->alternate_port); |
| 222 } | 228 } |
| 223 | 229 |
| 224 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()]; | 230 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()]; |
| 225 gChromeNet.Get()->Start(); | 231 gChromeNet.Get()->Start(); |
| 226 gHttpProtocolHandlerDelegate.Get().reset( | 232 gHttpProtocolHandlerDelegate.Get().reset( |
| 227 new CronetHttpProtocolHandlerDelegate( | 233 new CronetHttpProtocolHandlerDelegate( |
| 228 gChromeNet.Get()->GetURLRequestContextGetter(), gRequestFilterBlock)); | 234 gChromeNet.Get()->GetURLRequestContextGetter(), gRequestFilterBlock)); |
| 229 net::HTTPProtocolHandlerDelegate::SetInstance( | 235 net::HTTPProtocolHandlerDelegate::SetInstance( |
| 230 gHttpProtocolHandlerDelegate.Get().get()); | 236 gHttpProtocolHandlerDelegate.Get().get()); |
| 231 gRequestFilterBlock = nil; | 237 gRequestFilterBlock = nil; |
| 232 } | 238 } |
| 233 | 239 |
| 234 + (void)start { | 240 + (void)start { |
| 235 static dispatch_once_t onceToken; | 241 static dispatch_once_t onceToken; |
| 236 dispatch_once(&onceToken, ^{ | 242 dispatch_once(&onceToken, ^{ |
| 237 if (![NSThread isMainThread]) { | 243 if (![NSThread isMainThread]) { |
| 238 dispatch_sync(dispatch_get_main_queue(), ^(void) { | 244 dispatch_sync(dispatch_get_main_queue(), ^(void) { |
| 239 [self startInternal]; | 245 [self initializeCronet]; |
|
mef
2017/04/25 17:55:10
maybe call cronet::CronetEnvironment::Initialize()
lilyhoughton
2017/04/26 18:31:53
Good call. Done.
| |
| 240 }); | 246 }); |
| 241 } else { | 247 } else { |
| 242 [self startInternal]; | 248 [self initializeCronet]; |
| 243 } | 249 } |
| 244 }); | 250 }); |
| 251 | |
| 252 [self startInternal]; | |
|
mef
2017/04/25 17:55:10
This now will happen current thread instead of mai
lilyhoughton
2017/04/26 18:31:53
Acknowledged.
| |
| 245 } | 253 } |
| 246 | 254 |
| 247 + (void)registerHttpProtocolHandler { | 255 + (void)registerHttpProtocolHandler { |
| 248 if (gPreservedSharedURLCache == nil) { | 256 if (gPreservedSharedURLCache == nil) { |
| 249 gPreservedSharedURLCache = [NSURLCache sharedURLCache]; | 257 gPreservedSharedURLCache = [NSURLCache sharedURLCache]; |
| 250 } | 258 } |
| 251 // Disable the default cache. | 259 // Disable the default cache. |
| 252 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; | 260 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; |
| 253 // Register the chrome http protocol handler to replace the default one. | 261 // Register the chrome http protocol handler to replace the default one. |
| 254 BOOL success = | 262 BOOL success = |
| (...skipping 74 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 |