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

Side by Side Diff: ios/crnet/CrNet.mm

Issue 1125293004: ios: add CrNet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix last nits Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « ios/crnet/CrNet.h ('k') | ios/crnet/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/crnet/CrNet.h"
6
7 #include "base/logging.h"
8 #import "ios/net/crn_http_protocol_handler.h"
9 #import "ios/crnet/crnet_environment.h"
10
11 static CrNetEnvironment* g_chrome_net = NULL;
12
13 static BOOL g_spdy_enabled = YES;
14 static BOOL g_quic_enabled = NO;
15 static NSString *g_user_agent = nil;
16 static double g_alternate_protocol_threshold = 1.0;
17 static RequestFilterBlock g_request_filter_block = nil;
18
19 @implementation CrNet
20
21 + (void)setSpdyEnabled:(BOOL)spdyEnabled {
22 g_spdy_enabled = spdyEnabled;
23 }
24
25 + (void)setQuicEnabled:(BOOL)quicEnabled {
26 g_quic_enabled = quicEnabled;
27 }
28
29 + (void)setPartialUserAgent:(NSString *)userAgent {
30 g_user_agent = userAgent;
31 }
32
33 + (void)setAlternateProtocolThreshold:(double)alternateProtocolThreshold {
34 g_alternate_protocol_threshold = alternateProtocolThreshold;
35 }
36
37 + (void)installInternal {
38 CrNetEnvironment::Initialize();
39 std::string partial_user_agent =
40 [g_user_agent cStringUsingEncoding:NSASCIIStringEncoding];
41 g_chrome_net = new CrNetEnvironment(partial_user_agent);
42
43 g_chrome_net->set_spdy_enabled(g_spdy_enabled);
44 g_chrome_net->set_quic_enabled(g_quic_enabled);
45 g_chrome_net->set_alternate_protocol_threshold(
46 g_alternate_protocol_threshold);
47
48 g_chrome_net->Install();
49 g_chrome_net->SetHTTPProtocolHandlerRegistered(true);
50 g_chrome_net->SetRequestFilterBlock(g_request_filter_block);
51 }
52
53 + (void)install {
54 static dispatch_once_t onceToken;
55 dispatch_once(&onceToken, ^{
56 [self installInternal];
57 });
58 }
59
60 + (void)installIntoSessionConfiguration:(NSURLSessionConfiguration*)config {
61 g_chrome_net->InstallIntoSessionConfiguration(config);
62 }
63
64 + (void)installWithPartialUserAgent:(NSString *)partialUserAgent {
65 [self setPartialUserAgent:partialUserAgent];
66 [self install];
67 }
68
69 + (void)installWithPartialUserAgent:(NSString *)partialUserAgent
70 enableDataReductionProxy:(BOOL)enableDataReductionProxy {
71 LOG(ERROR) << "enableDataReductionProxy is no longer respected. The "
72 << "functionality has been removed from CrNet.";
73
74 [self setPartialUserAgent:partialUserAgent];
75 [self install];
76 }
77
78 + (void)installWithPartialUserAgent:(NSString *)partialUserAgent
79 withRequestFilterBlock:(RequestFilterBlock)requestFilterBlock {
80 [self setPartialUserAgent:partialUserAgent];
81 [self setRequestFilterBlock:requestFilterBlock];
82 [self install];
83 }
84
85 + (void)setRequestFilterBlock:(RequestFilterBlock)block {
86 if (g_chrome_net)
87 g_chrome_net->SetRequestFilterBlock(block);
88 else
89 g_request_filter_block = block;
90 }
91
92 + (void)uninstall {
93 if (g_chrome_net) {
94 g_chrome_net->SetHTTPProtocolHandlerRegistered(false);
95 }
96 }
97
98 + (void)startNetLogToFile:(NSString *)fileName logBytes:(BOOL)logBytes {
99 if (g_chrome_net && [fileName length]) {
100 g_chrome_net->StartNetLog([fileName UTF8String], logBytes);
101 }
102 }
103
104 + (void)stopNetLog {
105 if (g_chrome_net) {
106 return g_chrome_net->StopNetLog();
107 }
108 }
109
110 + (NSString *)userAgent {
111 if (!g_chrome_net) {
112 return nil;
113 }
114
115 std::string user_agent = g_chrome_net->user_agent();
116 return [NSString stringWithCString:user_agent.c_str()
117 encoding:[NSString defaultCStringEncoding]];
118 }
119
120 + (void)closeAllSpdySessions {
121 if (g_chrome_net) {
122 return g_chrome_net->CloseAllSpdySessions();
123 }
124 }
125
126 + (void)clearCacheWithCompletionCallback:(ClearCacheCallback)clearCacheCallback {
127 if (g_chrome_net) {
128 g_chrome_net->ClearCache(clearCacheCallback);
129 }
130 }
131
132 @end
OLDNEW
« no previous file with comments | « ios/crnet/CrNet.h ('k') | ios/crnet/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698