| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "components/cronet/ios/cronet_engine.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" |
| 9 #import "components/cronet/ios/cronet_environment.h" |
| 10 |
| 11 static cronet::CronetEnvironment* g_chrome_net = NULL; |
| 12 |
| 13 static BOOL g_http2_enabled = YES; |
| 14 static BOOL g_quic_enabled = NO; |
| 15 static NSString* g_user_agent = nil; |
| 16 static NSString* g_ssl_key_log_file_name = nil; |
| 17 |
| 18 @implementation CronetEngine |
| 19 |
| 20 + (void)setHttp2Enabled:(BOOL)http2Enabled { |
| 21 g_http2_enabled = http2Enabled; |
| 22 } |
| 23 |
| 24 + (void)setQuicEnabled:(BOOL)quicEnabled { |
| 25 g_quic_enabled = quicEnabled; |
| 26 } |
| 27 |
| 28 + (void)setPartialUserAgent:(NSString*)userAgent { |
| 29 g_user_agent = userAgent; |
| 30 } |
| 31 |
| 32 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName { |
| 33 g_ssl_key_log_file_name = sslKeyLogFileName; |
| 34 } |
| 35 |
| 36 + (void)installInternal { |
| 37 cronet::CronetEnvironment::Initialize(); |
| 38 std::string partial_user_agent = base::SysNSStringToUTF8(g_user_agent); |
| 39 g_chrome_net = new cronet::CronetEnvironment(partial_user_agent); |
| 40 |
| 41 g_chrome_net->set_http2_enabled(g_http2_enabled); |
| 42 g_chrome_net->set_quic_enabled(g_quic_enabled); |
| 43 g_chrome_net->set_ssl_key_log_file_name( |
| 44 base::SysNSStringToUTF8(g_ssl_key_log_file_name)); |
| 45 g_chrome_net->Install(); |
| 46 } |
| 47 |
| 48 + (void)install { |
| 49 static dispatch_once_t onceToken; |
| 50 dispatch_once(&onceToken, ^{ |
| 51 [self installInternal]; |
| 52 }); |
| 53 } |
| 54 |
| 55 + (void)startNetLogToFile:(NSString*)fileName logBytes:(BOOL)logBytes { |
| 56 if (g_chrome_net && [fileName length]) { |
| 57 g_chrome_net->StartNetLog([fileName UTF8String], logBytes); |
| 58 } |
| 59 } |
| 60 |
| 61 + (void)stopNetLog { |
| 62 if (g_chrome_net) { |
| 63 return g_chrome_net->StopNetLog(); |
| 64 } |
| 65 } |
| 66 |
| 67 + (NSString*)userAgent { |
| 68 if (!g_chrome_net) { |
| 69 return nil; |
| 70 } |
| 71 |
| 72 std::string user_agent = g_chrome_net->user_agent(); |
| 73 return [NSString stringWithCString:user_agent.c_str() |
| 74 encoding:[NSString defaultCStringEncoding]]; |
| 75 } |
| 76 |
| 77 + (cronet_engine*)getGlobalEngine { |
| 78 DCHECK(g_chrome_net); |
| 79 if (g_chrome_net) { |
| 80 static cronet_engine engine; |
| 81 engine.obj = g_chrome_net; |
| 82 return &engine; |
| 83 } |
| 84 return nil; |
| 85 } |
| 86 |
| 87 @end |
| OLD | NEW |