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.
5 #import <Foundation/Foundation.h>
7 // A block, that takes a request, and returns YES if the request should
9 typedef BOOL(^RequestFilterBlock
)(NSURLRequest
*request
);
12 // A callback, called when the clearCache message has completed. The |errorCode|
13 // is a network stack error code indicating whether the clear request succeeded
14 // or not. Even if the request failed, the cache may have been cleared anyway,
15 // or it may not have; it is not useful to retry a failing cache-clear attempt.
16 // The only real use of |errorCode| is for error reporting and statistics
18 typedef void(^ClearCacheCallback
)(int errorCode
);
20 // Interface for installing CrNet.
21 @interface CrNet
: NSObject
23 // Sets whether SPDY should be supported by CrNet. This method only has any
24 // effect before |install| is called.
25 + (void)setSpdyEnabled
:(BOOL
)spdyEnabled
;
27 // Sets whether QUIC should be supported by CrNet. This method only has any
28 // effect before |install| is called.
29 + (void)setQuicEnabled
:(BOOL
)quicEnabled
;
31 // Sets whether SDCH should be supported by CrNet. This method only has any
32 // effect before |install| is called. The |filename| argument is used to specify
33 // which file should be used for SDCH persistence metadata. If |filename| is
34 // nil, persistence is not enabled. The default is for SDCH to be disabled.
35 + (void)setSDCHEnabled
:(BOOL
)sdchEnabled
36 withPrefStore
:(NSString
*)filename
;
38 // Set the alternate protocol threshold. Servers announce alternate protocols
39 // with a probability value; any alternate protocol whose probability value is
40 // greater than this value will be used, so |alternateProtocolThreshold| == 0
41 // implies any announced alternate protocol will be used, and
42 // |alternateProtocolThreshold| == 1 implies no alternate protocol will ever be
43 // used. Note that individual alternate protocols must also be individually
44 // enabled to be considered; currently the only alternate protocol is QUIC (SPDY
45 // is not controlled by this mechanism).
47 // For example, imagine your service has two frontends a.service.com and
48 // b.service.com, and you would like to divide your users into three classes:
49 // Users who use QUIC for both a and b
50 // Users who use QUIC for a but not b
51 // Users who use QUIC for neither a nor b
52 // You can achieve that effect with:
53 // a.service.com advertises QUIC with p=0.67
54 // b.service.com advertises QUIC with p=0.33
55 // alternateProtocolThreshold set to a uniform random number in [0,1]
56 // Now equal proportions of users will fall into the three experimental groups.
58 // The default for this value is 1.0, i.e. all alternate protocols disabled.
59 + (void)setAlternateProtocolThreshold
:(double)alternateProtocolThreshold
;
61 // |userAgent| is expected to be of the form Product/Version.
62 // Example: Foo/3.0.0.0
64 // This method only has any effect before |install| is called.
65 + (void)setPartialUserAgent
:(NSString
*)userAgent
;
67 // Set the block used to determine whether or not CrNet should handle the
68 // request. If this is not set, CrNet will handle all requests.
69 // Must not be called while requests are in progress. This method can be called
70 // either before or after |install|.
71 + (void)setRequestFilterBlock
:(RequestFilterBlock
)block
;
73 // Installs CrNet. Once installed, CrNet intercepts and handles all
74 // NSURLConnection and NSURLRequests issued by the app, including UIWebView page
78 // Installs CrNet into an NSURLSession, passed in by the caller. Note that this
79 // NSURLSession will share settings with the sharedSession, which the |install|
80 // method installs CrNet into. This method must be called after |install|.
81 + (void)installIntoSessionConfiguration
:(NSURLSessionConfiguration
*)config
;
83 // Installs CrNet. This function is a deprecated shortcut for:
84 // [CrNet setPartialUserAgent:userAgent];
86 // See the documentation for |setPartialUserAgent| for details about the
87 // |userAgent| argument.
88 + (void)installWithPartialUserAgent
:(NSString
*)userAgent
89 __attribute__((deprecated
));
91 // Installs CrNet. This function is a deprecated shortcut for:
92 // [CrNet setPartialUserAgent:userAgent];
94 // The |enableDataReductionProxy| argument is ignored since data reduction proxy
95 // support is currently missing from CrNet. See |setPartialUserAgent| for
96 // details about the |userAgent| argument.
97 + (void)installWithPartialUserAgent
:(NSString
*)userAgent
98 enableDataReductionProxy
:(BOOL
)enableDataReductionProxy
99 __attribute__((deprecated
));
101 // Installs CrNet. This function is a deprecated shortcut for:
102 // [CrNet setPartialUserAgent:userAgent];
103 // [CrNet setRequestFilterBlock:block];
105 // See |setPartialUserAgent| and |setRequestFilterBlock| for details about the
106 // |userAgent| and |requestFilterBlock| arguments respectively.
107 + (void)installWithPartialUserAgent
:(NSString
*)userAgent
108 withRequestFilterBlock
:(RequestFilterBlock
)requestFilterBlock
109 __attribute__((deprecated
));
111 // Starts net-internals logging to a file named |fileName| in the application
112 // temporary directory. |fileName| must not be empty. Log level is determined
113 // by |logBytes| - if YES then LOG_ALL otherwise LOG_ALL_BUT_BYTES. If the file
114 // exists it is truncated before starting. If actively logging the call is
116 + (void)startNetLogToFile
:(NSString
*)fileName logBytes
:(BOOL
)logBytes
;
118 // Stop net-internals logging and flush file to disk. If a logging session is
119 // not in progress this call is ignored.
122 // Closes all current SPDY sessions. Do not do this unless you know what
124 // TODO(alokm): This is a hack. Remove it later.
125 + (void)closeAllSpdySessions
;
127 // "Uninstalls" CrNet. This means that CrNet will stop intercepting requests.
128 // However, it won't tear down all of the CrNet environment.
131 // Returns the full user-agent that the stack uses.
132 // This is the exact string servers will see.
133 + (NSString
*)userAgent
;
135 // Clears CrNet's http cache. The supplied callback, if not nil, is run on an
136 // unspecified thread.
137 + (void)clearCacheWithCompletionCallback
:(ClearCacheCallback
)completionBlock
;