Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: components/cronet/ios/Cronet.mm

Issue 2836063005: [cronet] Add mechanism for restarting CronetEnvironment (Closed)
Patch Set: per #21 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.Get()) << "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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
206 + (void)startInternal { 207 + (void)startInternal {
207 cronet::CronetEnvironment::Initialize();
208 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); 208 std::string user_agent = base::SysNSStringToUTF8(gUserAgent);
209
209 gChromeNet.Get().reset( 210 gChromeNet.Get().reset(
210 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); 211 new cronet::CronetEnvironment(user_agent, gUserAgentPartial));
212
211 gChromeNet.Get()->set_accept_language( 213 gChromeNet.Get()->set_accept_language(
212 base::SysNSStringToUTF8(gAcceptLanguages ?: [self getAcceptLanguages])); 214 base::SysNSStringToUTF8(gAcceptLanguages ?: [self getAcceptLanguages]));
213 215
214 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled); 216 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled);
215 gChromeNet.Get()->set_quic_enabled(gQuicEnabled); 217 gChromeNet.Get()->set_quic_enabled(gQuicEnabled);
216 gChromeNet.Get()->set_http_cache(gHttpCache); 218 gChromeNet.Get()->set_http_cache(gHttpCache);
217 gChromeNet.Get()->set_ssl_key_log_file_name( 219 gChromeNet.Get()->set_ssl_key_log_file_name(
218 base::SysNSStringToUTF8(gSslKeyLogFileName)); 220 base::SysNSStringToUTF8(gSslKeyLogFileName));
219 for (const auto* quicHint : gQuicHints) { 221 for (const auto* quicHint : gQuicHints) {
220 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, 222 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port,
221 quicHint->alternate_port); 223 quicHint->alternate_port);
222 } 224 }
223 225
224 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()]; 226 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()];
225 gChromeNet.Get()->Start(); 227 gChromeNet.Get()->Start();
226 gHttpProtocolHandlerDelegate.Get().reset( 228 gHttpProtocolHandlerDelegate.Get().reset(
227 new CronetHttpProtocolHandlerDelegate( 229 new CronetHttpProtocolHandlerDelegate(
228 gChromeNet.Get()->GetURLRequestContextGetter(), gRequestFilterBlock)); 230 gChromeNet.Get()->GetURLRequestContextGetter(), gRequestFilterBlock));
229 net::HTTPProtocolHandlerDelegate::SetInstance( 231 net::HTTPProtocolHandlerDelegate::SetInstance(
230 gHttpProtocolHandlerDelegate.Get().get()); 232 gHttpProtocolHandlerDelegate.Get().get());
231 gRequestFilterBlock = nil; 233 gRequestFilterBlock = nil;
232 } 234 }
233 235
234 + (void)start { 236 + (void)start {
235 static dispatch_once_t onceToken; 237 static dispatch_once_t onceToken;
236 dispatch_once(&onceToken, ^{ 238 dispatch_once(&onceToken, ^{
237 if (![NSThread isMainThread]) { 239 if (![NSThread isMainThread]) {
238 dispatch_sync(dispatch_get_main_queue(), ^(void) { 240 dispatch_sync(dispatch_get_main_queue(), ^(void) {
239 [self startInternal]; 241 cronet::CronetEnvironment::Initialize();
240 }); 242 });
241 } else { 243 } else {
242 [self startInternal]; 244 cronet::CronetEnvironment::Initialize();
243 } 245 }
244 }); 246 });
247
248 [self startInternal];
249 }
250
251 + (void)shutdownForTesting {
252 gChromeNet.Get().reset();
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
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
OLDNEW
« no previous file with comments | « no previous file | components/cronet/ios/cronet_environment.mm » ('j') | components/cronet/ios/test/cronet_http_test.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698