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

Unified Diff: components/cronet/ios/Cronet.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: Address comments, bundle libboringssl.a into libcronet.a 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
« no previous file with comments | « components/cronet/ios/Cronet.h ('k') | components/cronet/ios/cronet_bidirectional_stream.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/ios/Cronet.mm
diff --git a/components/cronet/ios/Cronet.mm b/components/cronet/ios/Cronet.mm
new file mode 100644
index 0000000000000000000000000000000000000000..50ee355247c263c95b401c974e03c51905004791
--- /dev/null
+++ b/components/cronet/ios/Cronet.mm
@@ -0,0 +1,123 @@
+// Copyright 2016 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.h"
+
+#include "base/lazy_instance.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
+#include "base/strings/sys_string_conversions.h"
+#include "components/cronet/ios/cronet_environment.h"
+#include "components/cronet/url_request_context_config.h"
+
+namespace {
+
+// Currently there is one and only one instance of CronetEnvironment,
+// which is leaked at the shutdown. We should consider allowing multiple
+// instances if that makes sense in the future.
+base::LazyInstance<scoped_ptr<cronet::CronetEnvironment>>::Leaky gChromeNet =
+ LAZY_INSTANCE_INITIALIZER;
+
+BOOL gHttp2Enabled = YES;
+BOOL gQuicEnabled = NO;
+ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints;
+NSString* gUserAgent = nil;
+NSString* gSslKeyLogFileName = nil;
+
+} // namespace
+
+@implementation Cronet
+
++ (void)checkNotStarted {
+ CHECK(gChromeNet == NULL) << "Cronet is already started.";
+}
+
++ (void)setHttp2Enabled:(BOOL)http2Enabled {
+ [self checkNotStarted];
+ gHttp2Enabled = http2Enabled;
+}
+
++ (void)setQuicEnabled:(BOOL)quicEnabled {
+ [self checkNotStarted];
+ gQuicEnabled = quicEnabled;
+}
+
++ (void)addQuicHint:(NSString*)host port:(int)port altPort:(int)altPort {
+ [self checkNotStarted];
+ gQuicHints.push_back(new cronet::URLRequestContextConfig::QuicHint(
+ base::SysNSStringToUTF8(host), port, altPort));
+}
+
++ (void)setPartialUserAgent:(NSString*)userAgent {
+ [self checkNotStarted];
+ gUserAgent = userAgent;
+}
+
++ (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName {
+ [self checkNotStarted];
+ gSslKeyLogFileName = sslKeyLogFileName;
+}
+
++ (void)startInternal {
+ cronet::CronetEnvironment::Initialize();
+ std::string partialUserAgent = base::SysNSStringToUTF8(gUserAgent);
+ gChromeNet.Get().reset(new cronet::CronetEnvironment(partialUserAgent));
+
+ gChromeNet.Get()->set_http2_enabled(gHttp2Enabled);
+ gChromeNet.Get()->set_quic_enabled(gQuicEnabled);
+ gChromeNet.Get()->set_ssl_key_log_file_name(
+ base::SysNSStringToUTF8(gSslKeyLogFileName));
+ for (const auto& quicHint : gQuicHints) {
+ gChromeNet.Get()->AddQuicHint(quicHint->host, quicHint->port,
+ quicHint->alternate_port);
+ }
+ gChromeNet.Get()->Start();
+}
+
++ (void)start {
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ if (![NSThread isMainThread]) {
+ dispatch_sync(dispatch_get_main_queue(), ^(void) {
+ [self startInternal];
+ });
+ } else {
+ [self startInternal];
+ }
+ });
+}
+
++ (void)startNetLogToFile:(NSString*)fileName logBytes:(BOOL)logBytes {
+ if (gChromeNet.Get().get() && [fileName length]) {
+ gChromeNet.Get()->StartNetLog([fileName UTF8String], logBytes);
+ }
+}
+
++ (void)stopNetLog {
+ if (gChromeNet.Get().get()) {
+ gChromeNet.Get()->StopNetLog();
+ }
+}
+
++ (NSString*)getUserAgent {
+ if (!gChromeNet.Get().get()) {
+ return nil;
+ }
+
+ return [NSString stringWithCString:gChromeNet.Get()->user_agent().c_str()
+ encoding:[NSString defaultCStringEncoding]];
+}
+
++ (cronet_engine*)getGlobalEngine {
+ DCHECK(gChromeNet.Get().get());
+ if (gChromeNet.Get().get()) {
+ static cronet_engine engine;
+ engine.obj = gChromeNet.Get().get();
+ return &engine;
+ }
+ return nil;
+}
+
+@end
« no previous file with comments | « components/cronet/ios/Cronet.h ('k') | components/cronet/ios/cronet_bidirectional_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698