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

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: Created 3 years, 11 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 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 HttpCacheType gHttpCache = HttpCacheType::DISK;
36 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints; 37 ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints;
37 NSString* gUserAgent = nil; 38 NSString* gUserAgent = nil;
38 BOOL gUserAgentPartial = NO; 39 BOOL gUserAgentPartial = NO;
39 NSString* gSslKeyLogFileName = nil; 40 NSString* gSslKeyLogFileName = nil;
40 RequestFilterBlock gRequestFilterBlock = nil; 41 RequestFilterBlock gRequestFilterBlock = nil;
41 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate; 42 std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate;
42 NSURLCache* gPreservedSharedURLCache = nil; 43 NSURLCache* gPreservedSharedURLCache = nil;
43 BOOL gEnableTestCertVerifierForTesting = FALSE; 44 BOOL gEnableTestCertVerifierForTesting = FALSE;
44 45
45 // CertVerifier, which allows any certificates for testing. 46 // CertVerifier, which allows any certificates for testing.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 [self checkNotStarted]; 153 [self checkNotStarted];
153 gUserAgent = userAgent; 154 gUserAgent = userAgent;
154 gUserAgentPartial = partial; 155 gUserAgentPartial = partial;
155 } 156 }
156 157
157 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName { 158 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName {
158 [self checkNotStarted]; 159 [self checkNotStarted];
159 gSslKeyLogFileName = sslKeyLogFileName; 160 gSslKeyLogFileName = sslKeyLogFileName;
160 } 161 }
161 162
163 + (void)setHttpCacheType:(HttpCacheType)httpCache {
164 [self checkNotStarted];
165 gHttpCache = httpCache;
mef 2017/01/18 22:39:51 I think this is a good place to map from ObjC to H
lilyhoughton 2017/01/19 16:17:15 Done; there may be a more robust way to map the Ob
166 }
167
162 + (void)setRequestFilterBlock:(RequestFilterBlock)block { 168 + (void)setRequestFilterBlock:(RequestFilterBlock)block {
163 if (gHttpProtocolHandlerDelegate.get()) 169 if (gHttpProtocolHandlerDelegate.get())
164 gHttpProtocolHandlerDelegate.get()->SetRequestFilterBlock(block); 170 gHttpProtocolHandlerDelegate.get()->SetRequestFilterBlock(block);
165 else 171 else
166 gRequestFilterBlock = block; 172 gRequestFilterBlock = block;
167 } 173 }
168 174
169 + (void)startInternal { 175 + (void)startInternal {
170 cronet::CronetEnvironment::Initialize(); 176 cronet::CronetEnvironment::Initialize();
171 std::string user_agent = base::SysNSStringToUTF8(gUserAgent); 177 std::string user_agent = base::SysNSStringToUTF8(gUserAgent);
172 gChromeNet.Get().reset( 178 gChromeNet.Get().reset(
173 new cronet::CronetEnvironment(user_agent, gUserAgentPartial)); 179 new cronet::CronetEnvironment(user_agent, gUserAgentPartial));
174 gChromeNet.Get()->set_accept_language( 180 gChromeNet.Get()->set_accept_language(
175 base::SysNSStringToUTF8([self getAcceptLanguages])); 181 base::SysNSStringToUTF8([self getAcceptLanguages]));
176 182
177 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled); 183 gChromeNet.Get()->set_http2_enabled(gHttp2Enabled);
178 gChromeNet.Get()->set_quic_enabled(gQuicEnabled); 184 gChromeNet.Get()->set_quic_enabled(gQuicEnabled);
185 gChromeNet.Get()->set_http_cache(gHttpCache);
179 gChromeNet.Get()->set_ssl_key_log_file_name( 186 gChromeNet.Get()->set_ssl_key_log_file_name(
180 base::SysNSStringToUTF8(gSslKeyLogFileName)); 187 base::SysNSStringToUTF8(gSslKeyLogFileName));
181 for (const auto* quicHint : gQuicHints) { 188 for (const auto* quicHint : gQuicHints) {
182 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port, 189 gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port,
183 quicHint->alternate_port); 190 quicHint->alternate_port);
184 } 191 }
185 192
186 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()]; 193 [self configureCronetEnvironmentForTesting:gChromeNet.Get().get()];
187 gChromeNet.Get()->Start(); 194 gChromeNet.Get()->Start();
188 gHttpProtocolHandlerDelegate.reset(new CronetHttpProtocolHandlerDelegate( 195 gHttpProtocolHandlerDelegate.reset(new CronetHttpProtocolHandlerDelegate(
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 base::SysNSStringToUTF8(hostResolverRulesForTesting)); 297 base::SysNSStringToUTF8(hostResolverRulesForTesting));
291 } 298 }
292 299
293 // This is a non-public dummy method that prevents the linker from stripping out 300 // This is a non-public dummy method that prevents the linker from stripping out
294 // the otherwise non-referenced methods from 'bidirectional_stream.cc'. 301 // the otherwise non-referenced methods from 'bidirectional_stream.cc'.
295 + (void)preventStrippingCronetBidirectionalStream { 302 + (void)preventStrippingCronetBidirectionalStream {
296 bidirectional_stream_create(NULL, 0, 0); 303 bidirectional_stream_create(NULL, 0, 0);
297 } 304 }
298 305
299 @end 306 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698