Chromium Code Reviews| Index: components/cronet/ios/cronet_engine.mm |
| diff --git a/components/cronet/ios/cronet_engine.mm b/components/cronet/ios/cronet_engine.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a1c572ec0b54e0b2f30168938f1db61c7891715e |
| --- /dev/null |
| +++ b/components/cronet/ios/cronet_engine.mm |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "components/cronet/ios/cronet_engine.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/strings/sys_string_conversions.h" |
| +#import "components/cronet/ios/cronet_environment.h" |
| + |
| +static cronet::CronetEnvironment* g_chrome_net = NULL; |
| + |
| +static BOOL g_http2_enabled = YES; |
|
kapishnikov
2016/04/06 17:33:25
The convention is to use mixed case to delimit wor
mef
2016/04/08 15:13:01
Done. I'd do instance variables in another CL.
|
| +static BOOL g_quic_enabled = NO; |
| +static NSString* g_user_agent = nil; |
| +static NSString* g_ssl_key_log_file_name = nil; |
| + |
| +@implementation CronetEngine |
| + |
| ++ (void)setHttp2Enabled:(BOOL)http2Enabled { |
|
kapishnikov
2016/04/06 17:33:25
We could add the verification that the method is n
mef
2016/04/08 15:13:01
Done.
|
| + g_http2_enabled = http2Enabled; |
| +} |
| + |
| ++ (void)setQuicEnabled:(BOOL)quicEnabled { |
| + g_quic_enabled = quicEnabled; |
| +} |
| + |
| ++ (void)setPartialUserAgent:(NSString*)userAgent { |
| + g_user_agent = userAgent; |
| +} |
| + |
| ++ (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName { |
| + g_ssl_key_log_file_name = sslKeyLogFileName; |
| +} |
| + |
| ++ (void)installInternal { |
| + cronet::CronetEnvironment::Initialize(); |
| + std::string partial_user_agent = base::SysNSStringToUTF8(g_user_agent); |
| + g_chrome_net = new cronet::CronetEnvironment(partial_user_agent); |
| + |
| + g_chrome_net->set_http2_enabled(g_http2_enabled); |
| + g_chrome_net->set_quic_enabled(g_quic_enabled); |
| + g_chrome_net->set_ssl_key_log_file_name( |
| + base::SysNSStringToUTF8(g_ssl_key_log_file_name)); |
| + g_chrome_net->Install(); |
| +} |
| + |
| ++ (void)install { |
| + static dispatch_once_t onceToken; |
| + dispatch_once(&onceToken, ^{ |
| + [self installInternal]; |
| + }); |
| +} |
| + |
| ++ (void)startNetLogToFile:(NSString*)fileName logBytes:(BOOL)logBytes { |
| + if (g_chrome_net && [fileName length]) { |
|
kapishnikov
2016/04/06 17:33:25
It would be great to log full path to the netlog f
mef
2016/04/08 15:13:01
Full path is logged in CronetEnvironment::StartNet
|
| + g_chrome_net->StartNetLog([fileName UTF8String], logBytes); |
| + } |
| +} |
| + |
| ++ (void)stopNetLog { |
| + if (g_chrome_net) { |
| + return g_chrome_net->StopNetLog(); |
|
kapishnikov
2016/04/06 17:33:25
The method return type is void. Does this line gen
mef
2016/04/08 15:13:01
Done.
|
| + } |
| +} |
| + |
| ++ (NSString*)userAgent { |
| + if (!g_chrome_net) { |
| + return nil; |
| + } |
| + |
| + std::string user_agent = g_chrome_net->user_agent(); |
| + return [NSString stringWithCString:user_agent.c_str() |
| + encoding:[NSString defaultCStringEncoding]]; |
| +} |
| + |
| ++ (cronet_engine*)getGlobalEngine { |
| + DCHECK(g_chrome_net); |
| + if (g_chrome_net) { |
| + static cronet_engine engine; |
| + engine.obj = g_chrome_net; |
| + return &engine; |
| + } |
| + return nil; |
| +} |
| + |
| +@end |