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

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

Issue 2836063005: [cronet] Add mechanism for restarting CronetEnvironment (Closed)
Patch Set: sync 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
« no previous file with comments | « no previous file | components/cronet/ios/cronet_environment.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 + (NSString*)getAcceptLanguages { 142 + (NSString*)getAcceptLanguages {
143 return [self 143 return [self
144 getAcceptLanguagesFromPreferredLanguages:[NSLocale preferredLanguages]]; 144 getAcceptLanguagesFromPreferredLanguages:[NSLocale preferredLanguages]];
145 } 145 }
146 146
147 + (void)setAcceptLanguages:(NSString*)acceptLanguages { 147 + (void)setAcceptLanguages:(NSString*)acceptLanguages {
148 [self checkNotStarted]; 148 [self checkNotStarted];
149 gAcceptLanguages = acceptLanguages; 149 gAcceptLanguages = acceptLanguages;
150 } 150 }
151 151
152 // TODO(lilyhoughton) this should either be removed, or made more sophisticated
152 + (void)checkNotStarted { 153 + (void)checkNotStarted {
153 CHECK(gChromeNet == NULL) << "Cronet is already started."; 154 CHECK(!gChromeNet.Get()) << "Cronet is already started.";
154 } 155 }
155 156
156 + (void)setHttp2Enabled:(BOOL)http2Enabled { 157 + (void)setHttp2Enabled:(BOOL)http2Enabled {
157 [self checkNotStarted]; 158 [self checkNotStarted];
158 gHttp2Enabled = http2Enabled; 159 gHttp2Enabled = http2Enabled;
159 } 160 }
160 161
161 + (void)setQuicEnabled:(BOOL)quicEnabled { 162 + (void)setQuicEnabled:(BOOL)quicEnabled {
162 [self checkNotStarted]; 163 [self checkNotStarted];
163 gQuicEnabled = quicEnabled; 164 gQuicEnabled = quicEnabled;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 204 }
204 205
205 + (void)setRequestFilterBlock:(RequestFilterBlock)block { 206 + (void)setRequestFilterBlock:(RequestFilterBlock)block {
206 if (gHttpProtocolHandlerDelegate.Get().get()) 207 if (gHttpProtocolHandlerDelegate.Get().get())
207 gHttpProtocolHandlerDelegate.Get().get()->SetRequestFilterBlock(block); 208 gHttpProtocolHandlerDelegate.Get().get()->SetRequestFilterBlock(block);
208 else 209 else
209 gRequestFilterBlock = block; 210 gRequestFilterBlock = block;
210 } 211 }
211 212
212 + (void)startInternal { 213 + (void)startInternal {
213 cronet::CronetEnvironment::Initialize();
214 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); 214 std::string user_agent = base::SysNSStringToUTF8(gUserAgent);
215
215 gChromeNet.Get().reset( 216 gChromeNet.Get().reset(
216 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); 217 new cronet::CronetEnvironment(user_agent, gUserAgentPartial));
218
217 gChromeNet.Get()->set_accept_language( 219 gChromeNet.Get()->set_accept_language(
218 base::SysNSStringToUTF8(gAcceptLanguages ?: [self getAcceptLanguages])); 220 base::SysNSStringToUTF8(gAcceptLanguages ?: [self getAcceptLanguages]));
219 221
220 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled); 222 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled);
221 gChromeNet.Get()->set_quic_enabled(gQuicEnabled); 223 gChromeNet.Get()->set_quic_enabled(gQuicEnabled);
222 gChromeNet.Get()->set_experimental_options( 224 gChromeNet.Get()->set_experimental_options(
223 base::SysNSStringToUTF8(gExperimentalOptions)); 225 base::SysNSStringToUTF8(gExperimentalOptions));
224 gChromeNet.Get()->set_http_cache(gHttpCache); 226 gChromeNet.Get()->set_http_cache(gHttpCache);
225 gChromeNet.Get()->set_ssl_key_log_file_name( 227 gChromeNet.Get()->set_ssl_key_log_file_name(
226 base::SysNSStringToUTF8(gSslKeyLogFileName)); 228 base::SysNSStringToUTF8(gSslKeyLogFileName));
(...skipping 10 matching lines...) Expand all
237 net::HTTPProtocolHandlerDelegate::SetInstance( 239 net::HTTPProtocolHandlerDelegate::SetInstance(
238 gHttpProtocolHandlerDelegate.Get().get()); 240 gHttpProtocolHandlerDelegate.Get().get());
239 gRequestFilterBlock = nil; 241 gRequestFilterBlock = nil;
240 } 242 }
241 243
242 + (void)start { 244 + (void)start {
243 static dispatch_once_t onceToken; 245 static dispatch_once_t onceToken;
244 dispatch_once(&onceToken, ^{ 246 dispatch_once(&onceToken, ^{
245 if (![NSThread isMainThread]) { 247 if (![NSThread isMainThread]) {
246 dispatch_sync(dispatch_get_main_queue(), ^(void) { 248 dispatch_sync(dispatch_get_main_queue(), ^(void) {
247 [self startInternal]; 249 cronet::CronetEnvironment::Initialize();
248 }); 250 });
249 } else { 251 } else {
250 [self startInternal]; 252 cronet::CronetEnvironment::Initialize();
251 } 253 }
252 }); 254 });
255
256 [self startInternal];
257 }
258
259 + (void)shutdownForTesting {
260 gChromeNet.Get().reset();
253 } 261 }
254 262
255 + (void)registerHttpProtocolHandler { 263 + (void)registerHttpProtocolHandler {
256 if (gPreservedSharedURLCache == nil) { 264 if (gPreservedSharedURLCache == nil) {
257 gPreservedSharedURLCache = [NSURLCache sharedURLCache]; 265 gPreservedSharedURLCache = [NSURLCache sharedURLCache];
258 } 266 }
259 // Disable the default cache. 267 // Disable the default cache.
260 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; 268 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]];
261 // Register the chrome http protocol handler to replace the default one. 269 // Register the chrome http protocol handler to replace the default one.
262 BOOL success = 270 BOOL success =
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 base::SysNSStringToUTF8(hostResolverRulesForTesting)); 345 base::SysNSStringToUTF8(hostResolverRulesForTesting));
338 } 346 }
339 347
340 // This is a non-public dummy method that prevents the linker from stripping out 348 // This is a non-public dummy method that prevents the linker from stripping out
341 // the otherwise non-referenced methods from 'bidirectional_stream.cc'. 349 // the otherwise non-referenced methods from 'bidirectional_stream.cc'.
342 + (void)preventStrippingCronetBidirectionalStream { 350 + (void)preventStrippingCronetBidirectionalStream {
343 bidirectional_stream_create(NULL, 0, 0); 351 bidirectional_stream_create(NULL, 0, 0);
344 } 352 }
345 353
346 @end 354 @end
OLDNEW
« no previous file with comments | « no previous file | components/cronet/ios/cronet_environment.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698