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

Unified Diff: components/cronet/ios/cronet_engine.mm

Issue 1858483002: Cronet for iOS with C API for GRPC support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@small
Patch Set: Make it syncable Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
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;
+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 {
+ 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]) {
+ g_chrome_net->StartNetLog([fileName UTF8String], logBytes);
+ }
+}
+
++ (void)stopNetLog {
+ if (g_chrome_net) {
+ return g_chrome_net->StopNetLog();
+ }
+}
+
++ (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

Powered by Google App Engine
This is Rietveld 408576698