Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "components/cronet/ios/Cronet.h" | |
|
xunjieli
2016/04/08 17:46:15
newbie question: Why is this file is named as Cron
mef
2016/04/08 20:40:43
In my integration prototype I've noticed that all
| |
| 6 | |
| 7 #include <vector> | |
|
xunjieli
2016/04/08 17:46:15
not needed?
mef
2016/04/08 20:40:43
Done.
| |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/scoped_vector.h" | |
| 11 #include "base/strings/sys_string_conversions.h" | |
| 12 #include "components/cronet/ios/cronet_environment.h" | |
| 13 #include "components/cronet/url_request_context_config.h" | |
| 14 | |
| 15 static cronet::CronetEnvironment* gChromeNet = NULL; | |
|
xunjieli
2016/04/08 17:46:15
Can we add a comment here to say why we have a glo
mef
2016/04/08 20:40:43
Added comment.
xunjieli
2016/04/11 13:42:05
See: http://dev.chromium.org/developers/coding-sty
mef
2016/04/13 11:24:49
Done.
| |
| 16 | |
| 17 static BOOL gHttp2Enabled = YES; | |
| 18 static BOOL gQuicEnabled = NO; | |
| 19 static ScopedVector<cronet::URLRequestContextConfig::QuicHint> gQuicHints; | |
| 20 static NSString* gUserAgent = nil; | |
| 21 static NSString* gSslKeyLogFileName = nil; | |
| 22 | |
| 23 namespace { | |
| 24 void CheckNotStarted() { | |
| 25 CHECK(gChromeNet == NULL) << "Cronet is already started."; | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 @implementation Cronet | |
| 31 | |
| 32 + (void)setHttp2Enabled:(BOOL)http2Enabled { | |
| 33 CheckNotStarted(); | |
| 34 gHttp2Enabled = http2Enabled; | |
| 35 } | |
| 36 | |
| 37 + (void)setQuicEnabled:(BOOL)quicEnabled { | |
| 38 CheckNotStarted(); | |
| 39 gQuicEnabled = quicEnabled; | |
| 40 } | |
| 41 | |
| 42 + (void)addQuicHint:(NSString*)host port:(int)port altPort:(int)altPort { | |
| 43 CheckNotStarted(); | |
| 44 gQuicHints.push_back(new cronet::URLRequestContextConfig::QuicHint( | |
| 45 base::SysNSStringToUTF8(host), port, altPort)); | |
| 46 } | |
| 47 | |
| 48 + (void)setPartialUserAgent:(NSString*)userAgent { | |
| 49 CheckNotStarted(); | |
| 50 gUserAgent = userAgent; | |
| 51 } | |
| 52 | |
| 53 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName { | |
| 54 CheckNotStarted(); | |
| 55 gSslKeyLogFileName = sslKeyLogFileName; | |
| 56 } | |
| 57 | |
| 58 + (void)installInternal { | |
| 59 cronet::CronetEnvironment::Initialize(); | |
| 60 std::string partial_user_agent = base::SysNSStringToUTF8(gUserAgent); | |
| 61 gChromeNet = new cronet::CronetEnvironment(partial_user_agent); | |
| 62 | |
| 63 gChromeNet->set_http2_enabled(gHttp2Enabled); | |
| 64 gChromeNet->set_quic_enabled(gQuicEnabled); | |
| 65 gChromeNet->set_ssl_key_log_file_name( | |
| 66 base::SysNSStringToUTF8(gSslKeyLogFileName)); | |
| 67 for (auto quicHint : gQuicHints) { | |
| 68 gChromeNet->AddQuicHint(quicHint->host, quicHint->port, | |
| 69 quicHint->alternate_port); | |
| 70 } | |
| 71 gChromeNet->Install(); | |
| 72 } | |
| 73 | |
| 74 + (void)start { | |
| 75 static dispatch_once_t onceToken; | |
| 76 dispatch_once(&onceToken, ^{ | |
| 77 [self installInternal]; | |
| 78 }); | |
| 79 } | |
| 80 | |
| 81 + (void)startNetLogToFile:(NSString*)fileName logBytes:(BOOL)logBytes { | |
| 82 if (gChromeNet && [fileName length]) { | |
| 83 gChromeNet->StartNetLog([fileName UTF8String], logBytes); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 + (void)stopNetLog { | |
| 88 if (gChromeNet) { | |
| 89 gChromeNet->StopNetLog(); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 + (NSString*)getUserAgent { | |
| 94 if (!gChromeNet) { | |
| 95 return nil; | |
| 96 } | |
| 97 | |
| 98 std::string user_agent = gChromeNet->user_agent(); | |
| 99 return [NSString stringWithCString:user_agent.c_str() | |
| 100 encoding:[NSString defaultCStringEncoding]]; | |
| 101 } | |
| 102 | |
| 103 + (cronet_engine*)getGlobalEngine { | |
| 104 DCHECK(gChromeNet); | |
| 105 if (gChromeNet) { | |
| 106 static cronet_engine engine; | |
| 107 engine.obj = gChromeNet; | |
| 108 return &engine; | |
| 109 } | |
| 110 return nil; | |
| 111 } | |
| 112 | |
| 113 @end | |
| OLD | NEW |