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

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

Issue 2644583002: Add configuration functions for HTTP cache type to Obj-C and C++ (Closed)
Patch Set: make enum more obj-c-compatible Created 3 years, 10 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 | « components/cronet/ios/Cronet.h ('k') | components/cronet/ios/cronet_environment.h » ('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 15 matching lines...) Expand all
26 class CronetHttpProtocolHandlerDelegate; 26 class CronetHttpProtocolHandlerDelegate;
27 27
28 // Currently there is one and only one instance of CronetEnvironment, 28 // Currently there is one and only one instance of CronetEnvironment,
29 // which is leaked at the shutdown. We should consider allowing multiple 29 // which is leaked at the shutdown. We should consider allowing multiple
30 // instances if that makes sense in the future. 30 // instances if that makes sense in the future.
31 base::LazyInstance<std::unique_ptr<cronet::CronetEnvironment>>::Leaky 31 base::LazyInstance<std::unique_ptr<cronet::CronetEnvironment>>::Leaky
32 gChromeNet = LAZY_INSTANCE_INITIALIZER; 32 gChromeNet = LAZY_INSTANCE_INITIALIZER;
33 33
34 BOOL gHttp2Enabled = YES; 34 BOOL gHttp2Enabled = YES;
35 BOOL gQuicEnabled = NO; 35 BOOL gQuicEnabled = NO;
36 cronet::URLRequestContextConfig::HttpCacheType gHttpCache =
37 cronet::URLRequestContextConfig::HttpCacheType::DISK;
36 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints; 38 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints;
37 NSString* gUserAgent = nil; 39 NSString* gUserAgent = nil;
38 BOOL gUserAgentPartial = NO; 40 BOOL gUserAgentPartial = NO;
39 NSString* gSslKeyLogFileName = nil; 41 NSString* gSslKeyLogFileName = nil;
40 RequestFilterBlock gRequestFilterBlock = nil; 42 RequestFilterBlock gRequestFilterBlock = nil;
41 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate; 43 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate;
42 NSURLCache* gPreservedSharedURLCache = nil; 44 NSURLCache* gPreservedSharedURLCache = nil;
43 BOOL gEnableTestCertVerifierForTesting = FALSE; 45 BOOL gEnableTestCertVerifierForTesting = FALSE;
44 46
45 // CertVerifier, which allows any certificates for testing. 47 // CertVerifier, which allows any certificates for testing.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 [self checkNotStarted]; 154 [self checkNotStarted];
153 gUserAgent = userAgent; 155 gUserAgent = userAgent;
154 gUserAgentPartial = partial; 156 gUserAgentPartial = partial;
155 } 157 }
156 158
157 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName { 159 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName {
158 [self checkNotStarted]; 160 [self checkNotStarted];
159 gSslKeyLogFileName = sslKeyLogFileName; 161 gSslKeyLogFileName = sslKeyLogFileName;
160 } 162 }
161 163
164 + (void)setHttpCacheType:(CRNHttpCacheType)httpCacheType {
165 [self checkNotStarted];
166 switch (httpCacheType) {
167 case CRNHttpCacheTypeDisabled:
168 gHttpCache = cronet::URLRequestContextConfig::HttpCacheType::DISABLED;
169 break;
170 case CRNHttpCacheTypeDisk:
171 gHttpCache = cronet::URLRequestContextConfig::HttpCacheType::DISK;
172 break;
173 case CRNHttpCacheTypeMemory:
174 gHttpCache = cronet::URLRequestContextConfig::HttpCacheType::MEMORY;
175 break;
176 default:
177 DCHECK(NO) << "Invalid HTTP cache type: " << httpCacheType;
178 }
179 }
180
162 + (void)setRequestFilterBlock:(RequestFilterBlock)block { 181 + (void)setRequestFilterBlock:(RequestFilterBlock)block {
163 if (gHttpProtocolHandlerDelegate.get()) 182 if (gHttpProtocolHandlerDelegate.get())
164 gHttpProtocolHandlerDelegate.get()->SetRequestFilterBlock(block); 183 gHttpProtocolHandlerDelegate.get()->SetRequestFilterBlock(block);
165 else 184 else
166 gRequestFilterBlock = block; 185 gRequestFilterBlock = block;
167 } 186 }
168 187
169 + (void)startInternal { 188 + (void)startInternal {
170 cronet::CronetEnvironment::Initialize(); 189 cronet::CronetEnvironment::Initialize();
171 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); 190 std::string user_agent = base::SysNSStringToUTF8(gUserAgent);
172 gChromeNet.Get().reset( 191 gChromeNet.Get().reset(
173 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); 192 new cronet::CronetEnvironment(user_agent, gUserAgentPartial));
174 gChromeNet.Get()->set_accept_language( 193 gChromeNet.Get()->set_accept_language(
175 base::SysNSStringToUTF8([self getAcceptLanguages])); 194 base::SysNSStringToUTF8([self getAcceptLanguages]));
176 195
177 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled); 196 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled);
178 gChromeNet.Get()->set_quic_enabled(gQuicEnabled); 197 gChromeNet.Get()->set_quic_enabled(gQuicEnabled);
198 gChromeNet.Get()->set_http_cache(gHttpCache);
179 gChromeNet.Get()->set_ssl_key_log_file_name( 199 gChromeNet.Get()->set_ssl_key_log_file_name(
180 base::SysNSStringToUTF8(gSslKeyLogFileName)); 200 base::SysNSStringToUTF8(gSslKeyLogFileName));
181 for (const auto* quicHint : gQuicHints) { 201 for (const auto* quicHint : gQuicHints) {
182 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, 202 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port,
183 quicHint->alternate_port); 203 quicHint->alternate_port);
184 } 204 }
185 205
186 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()]; 206 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()];
187 gChromeNet.Get()->Start(); 207 gChromeNet.Get()->Start();
188 gHttpProtocolHandlerDelegate.reset(new CronetHttpProtocolHandlerDelegate( 208 gHttpProtocolHandlerDelegate.reset(new CronetHttpProtocolHandlerDelegate(
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 base::SysNSStringToUTF8(hostResolverRulesForTesting)); 310 base::SysNSStringToUTF8(hostResolverRulesForTesting));
291 } 311 }
292 312
293 // This is a non-public dummy method that prevents the linker from stripping out 313 // This is a non-public dummy method that prevents the linker from stripping out
294 // the otherwise non-referenced methods from 'bidirectional_stream.cc'. 314 // the otherwise non-referenced methods from 'bidirectional_stream.cc'.
295 + (void)preventStrippingCronetBidirectionalStream { 315 + (void)preventStrippingCronetBidirectionalStream {
296 bidirectional_stream_create(NULL, 0, 0); 316 bidirectional_stream_create(NULL, 0, 0);
297 } 317 }
298 318
299 @end 319 @end
OLDNEW
« no previous file with comments | « components/cronet/ios/Cronet.h ('k') | components/cronet/ios/cronet_environment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698