| 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; |
| 19 static RequestFilterBlock g_request_filter_block = nil; | 20 static RequestFilterBlock g_request_filter_block = nil; |
| 20 | 21 |
| 21 @implementation CrNet | 22 @implementation CrNet |
| 22 | 23 |
| 23 + (void)setSpdyEnabled:(BOOL)spdyEnabled { | 24 + (void)setSpdyEnabled:(BOOL)spdyEnabled { |
| 24 g_spdy_enabled = spdyEnabled; | 25 g_spdy_enabled = spdyEnabled; |
| 25 } | 26 } |
| 26 | 27 |
| 27 + (void)setQuicEnabled:(BOOL)quicEnabled { | 28 + (void)setQuicEnabled:(BOOL)quicEnabled { |
| 28 g_quic_enabled = quicEnabled; | 29 g_quic_enabled = quicEnabled; |
| 29 } | 30 } |
| 30 | 31 |
| 31 + (void)setSDCHEnabled:(BOOL)sdchEnabled | 32 + (void)setSDCHEnabled:(BOOL)sdchEnabled |
| 32 withPrefStore:(NSString*)filename { | 33 withPrefStore:(NSString*)filename { |
| 33 g_sdch_enabled = sdchEnabled; | 34 g_sdch_enabled = sdchEnabled; |
| 34 g_sdch_pref_store_filename = filename; | 35 g_sdch_pref_store_filename = filename; |
| 35 } | 36 } |
| 36 | 37 |
| 37 + (void)setPartialUserAgent:(NSString *)userAgent { | 38 + (void)setPartialUserAgent:(NSString *)userAgent { |
| 38 g_user_agent = userAgent; | 39 g_user_agent = userAgent; |
| 39 } | 40 } |
| 40 | 41 |
| 42 + (void)setAlternateProtocolThreshold:(double)alternateProtocolThreshold { |
| 43 g_alternate_protocol_threshold = alternateProtocolThreshold; |
| 44 } |
| 45 |
| 41 + (void)installInternal { | 46 + (void)installInternal { |
| 42 CrNetEnvironment::Initialize(); | 47 CrNetEnvironment::Initialize(); |
| 43 std::string partial_user_agent = base::SysNSStringToUTF8(g_user_agent); | 48 std::string partial_user_agent = base::SysNSStringToUTF8(g_user_agent); |
| 44 g_chrome_net = new CrNetEnvironment(partial_user_agent); | 49 g_chrome_net = new CrNetEnvironment(partial_user_agent); |
| 45 | 50 |
| 46 g_chrome_net->set_spdy_enabled(g_spdy_enabled); | 51 g_chrome_net->set_spdy_enabled(g_spdy_enabled); |
| 47 g_chrome_net->set_quic_enabled(g_quic_enabled); | 52 g_chrome_net->set_quic_enabled(g_quic_enabled); |
| 48 g_chrome_net->set_sdch_enabled(g_sdch_enabled); | 53 g_chrome_net->set_sdch_enabled(g_sdch_enabled); |
| 49 if (g_sdch_pref_store_filename) { | 54 if (g_sdch_pref_store_filename) { |
| 50 std::string filename = base::SysNSStringToUTF8(g_sdch_pref_store_filename); | 55 std::string filename = base::SysNSStringToUTF8(g_sdch_pref_store_filename); |
| 51 g_chrome_net->set_sdch_pref_store_filename(filename); | 56 g_chrome_net->set_sdch_pref_store_filename(filename); |
| 52 } | 57 } |
| 58 g_chrome_net->set_alternate_protocol_threshold( |
| 59 g_alternate_protocol_threshold); |
| 53 | 60 |
| 54 g_chrome_net->Install(); | 61 g_chrome_net->Install(); |
| 55 g_chrome_net->SetHTTPProtocolHandlerRegistered(true); | 62 g_chrome_net->SetHTTPProtocolHandlerRegistered(true); |
| 56 g_chrome_net->SetRequestFilterBlock(g_request_filter_block); | 63 g_chrome_net->SetRequestFilterBlock(g_request_filter_block); |
| 57 } | 64 } |
| 58 | 65 |
| 59 + (void)install { | 66 + (void)install { |
| 60 static dispatch_once_t onceToken; | 67 static dispatch_once_t onceToken; |
| 61 dispatch_once(&onceToken, ^{ | 68 dispatch_once(&onceToken, ^{ |
| 62 [self installInternal]; | 69 [self installInternal]; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 136 } |
| 130 } | 137 } |
| 131 | 138 |
| 132 + (void)clearCacheWithCompletionCallback:(ClearCacheCallback)clearCacheCallback
{ | 139 + (void)clearCacheWithCompletionCallback:(ClearCacheCallback)clearCacheCallback
{ |
| 133 if (g_chrome_net) { | 140 if (g_chrome_net) { |
| 134 g_chrome_net->ClearCache(clearCacheCallback); | 141 g_chrome_net->ClearCache(clearCacheCallback); |
| 135 } | 142 } |
| 136 } | 143 } |
| 137 | 144 |
| 138 @end | 145 @end |
| OLD | NEW |