| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/crnet/CrNet.h" | 5 #import "ios/crnet/CrNet.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #import "ios/net/crn_http_protocol_handler.h" | 9 #import "ios/net/crn_http_protocol_handler.h" |
| 10 #import "ios/crnet/crnet_environment.h" | 10 #import "ios/crnet/crnet_environment.h" |
| 11 | 11 |
| 12 static CrNetEnvironment* g_chrome_net = NULL; | 12 static CrNetEnvironment* g_chrome_net = NULL; |
| 13 | 13 |
| 14 static BOOL g_spdy_enabled = YES; | 14 static BOOL g_spdy_enabled = YES; |
| 15 static BOOL g_quic_enabled = NO; | 15 static BOOL g_quic_enabled = NO; |
| 16 static BOOL g_sdch_enabled = NO; | 16 static BOOL g_sdch_enabled = NO; |
| 17 static NSString* g_user_agent = nil; | 17 static NSString* g_user_agent = nil; |
| 18 static NSString* g_sdch_pref_store_filename = nil; | 18 static NSString* g_sdch_pref_store_filename = nil; |
| 19 static double g_alternate_protocol_threshold = 1.0; | |
| 20 static RequestFilterBlock g_request_filter_block = nil; | 19 static RequestFilterBlock g_request_filter_block = nil; |
| 21 | 20 |
| 22 @implementation CrNet | 21 @implementation CrNet |
| 23 | 22 |
| 24 + (void)setSpdyEnabled:(BOOL)spdyEnabled { | 23 + (void)setSpdyEnabled:(BOOL)spdyEnabled { |
| 25 g_spdy_enabled = spdyEnabled; | 24 g_spdy_enabled = spdyEnabled; |
| 26 } | 25 } |
| 27 | 26 |
| 28 + (void)setQuicEnabled:(BOOL)quicEnabled { | 27 + (void)setQuicEnabled:(BOOL)quicEnabled { |
| 29 g_quic_enabled = quicEnabled; | 28 g_quic_enabled = quicEnabled; |
| 30 } | 29 } |
| 31 | 30 |
| 32 + (void)setSDCHEnabled:(BOOL)sdchEnabled | 31 + (void)setSDCHEnabled:(BOOL)sdchEnabled |
| 33 withPrefStore:(NSString*)filename { | 32 withPrefStore:(NSString*)filename { |
| 34 g_sdch_enabled = sdchEnabled; | 33 g_sdch_enabled = sdchEnabled; |
| 35 g_sdch_pref_store_filename = filename; | 34 g_sdch_pref_store_filename = filename; |
| 36 } | 35 } |
| 37 | 36 |
| 38 + (void)setPartialUserAgent:(NSString *)userAgent { | 37 + (void)setPartialUserAgent:(NSString *)userAgent { |
| 39 g_user_agent = userAgent; | 38 g_user_agent = userAgent; |
| 40 } | 39 } |
| 41 | 40 |
| 42 + (void)setAlternateProtocolThreshold:(double)alternateProtocolThreshold { | |
| 43 g_alternate_protocol_threshold = alternateProtocolThreshold; | |
| 44 } | |
| 45 | |
| 46 + (void)installInternal { | 41 + (void)installInternal { |
| 47 CrNetEnvironment::Initialize(); | 42 CrNetEnvironment::Initialize(); |
| 48 std::string partial_user_agent = base::SysNSStringToUTF8(g_user_agent); | 43 std::string partial_user_agent = base::SysNSStringToUTF8(g_user_agent); |
| 49 g_chrome_net = new CrNetEnvironment(partial_user_agent); | 44 g_chrome_net = new CrNetEnvironment(partial_user_agent); |
| 50 | 45 |
| 51 g_chrome_net->set_spdy_enabled(g_spdy_enabled); | 46 g_chrome_net->set_spdy_enabled(g_spdy_enabled); |
| 52 g_chrome_net->set_quic_enabled(g_quic_enabled); | 47 g_chrome_net->set_quic_enabled(g_quic_enabled); |
| 53 g_chrome_net->set_sdch_enabled(g_sdch_enabled); | 48 g_chrome_net->set_sdch_enabled(g_sdch_enabled); |
| 54 if (g_sdch_pref_store_filename) { | 49 if (g_sdch_pref_store_filename) { |
| 55 std::string filename = base::SysNSStringToUTF8(g_sdch_pref_store_filename); | 50 std::string filename = base::SysNSStringToUTF8(g_sdch_pref_store_filename); |
| 56 g_chrome_net->set_sdch_pref_store_filename(filename); | 51 g_chrome_net->set_sdch_pref_store_filename(filename); |
| 57 } | 52 } |
| 58 g_chrome_net->set_alternate_protocol_threshold( | |
| 59 g_alternate_protocol_threshold); | |
| 60 | 53 |
| 61 g_chrome_net->Install(); | 54 g_chrome_net->Install(); |
| 62 g_chrome_net->SetHTTPProtocolHandlerRegistered(true); | 55 g_chrome_net->SetHTTPProtocolHandlerRegistered(true); |
| 63 g_chrome_net->SetRequestFilterBlock(g_request_filter_block); | 56 g_chrome_net->SetRequestFilterBlock(g_request_filter_block); |
| 64 } | 57 } |
| 65 | 58 |
| 66 + (void)install { | 59 + (void)install { |
| 67 static dispatch_once_t onceToken; | 60 static dispatch_once_t onceToken; |
| 68 dispatch_once(&onceToken, ^{ | 61 dispatch_once(&onceToken, ^{ |
| 69 [self installInternal]; | 62 [self installInternal]; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 129 } |
| 137 } | 130 } |
| 138 | 131 |
| 139 + (void)clearCacheWithCompletionCallback:(ClearCacheCallback)clearCacheCallback
{ | 132 + (void)clearCacheWithCompletionCallback:(ClearCacheCallback)clearCacheCallback
{ |
| 140 if (g_chrome_net) { | 133 if (g_chrome_net) { |
| 141 g_chrome_net->ClearCache(clearCacheCallback); | 134 g_chrome_net->ClearCache(clearCacheCallback); |
| 142 } | 135 } |
| 143 } | 136 } |
| 144 | 137 |
| 145 @end | 138 @end |
| OLD | NEW |