OLD | NEW |
(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 <Foundation/Foundation.h> |
| 6 |
| 7 // A block, that takes a request, and returns YES if the request should |
| 8 // be handled. |
| 9 typedef BOOL(^RequestFilterBlock)(NSURLRequest *request); |
| 10 |
| 11 |
| 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 |
| 17 // gathering. |
| 18 typedef void(^ClearCacheCallback)(int errorCode); |
| 19 |
| 20 // Interface for installing CrNet. |
| 21 @interface CrNet : NSObject |
| 22 |
| 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; |
| 26 |
| 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; |
| 30 |
| 31 // Set the alternate protocol threshold. Servers announce alternate protocols |
| 32 // with a probability value; any alternate protocol whose probability value is |
| 33 // greater than this value will be used, so |alternateProtocolThreshold| == 0 |
| 34 // implies any announced alternate protocol will be used, and |
| 35 // |alternateProtocolThreshold| == 1 implies no alternate protocol will ever be |
| 36 // used. Note that individual alternate protocols must also be individually |
| 37 // enabled to be considered; currently the only alternate protocol is QUIC (SPDY |
| 38 // is not controlled by this mechanism). |
| 39 // |
| 40 // For example, imagine your service has two frontends a.service.com and |
| 41 // b.service.com, and you would like to divide your users into three classes: |
| 42 // Users who use QUIC for both a and b |
| 43 // Users who use QUIC for a but not b |
| 44 // Users who use QUIC for neither a nor b |
| 45 // You can achieve that effect with: |
| 46 // a.service.com advertises QUIC with p=0.67 |
| 47 // b.service.com advertises QUIC with p=0.33 |
| 48 // alternateProtocolThreshold set to a uniform random number in [0,1] |
| 49 // Now equal proportions of users will fall into the three experimental groups. |
| 50 // |
| 51 // The default for this value is 1.0, i.e. all alternate protocols disabled. |
| 52 + (void)setAlternateProtocolThreshold:(double)alternateProtocolThreshold; |
| 53 |
| 54 // |userAgent| is expected to be of the form Product/Version. |
| 55 // Example: Foo/3.0.0.0 |
| 56 // |
| 57 // This method only has any effect before |install| is called. |
| 58 + (void)setPartialUserAgent:(NSString *)userAgent; |
| 59 |
| 60 // Set the block used to determine whether or not CrNet should handle the |
| 61 // request. If this is not set, CrNet will handle all requests. |
| 62 // Must not be called while requests are in progress. This method can be called |
| 63 // either before or after |install|. |
| 64 + (void)setRequestFilterBlock:(RequestFilterBlock)block; |
| 65 |
| 66 // Installs CrNet. Once installed, CrNet intercepts and handles all |
| 67 // NSURLConnection and NSURLRequests issued by the app, including UIWebView page |
| 68 // loads. |
| 69 + (void)install; |
| 70 |
| 71 // Installs CrNet into an NSURLSession, passed in by the caller. Note that this |
| 72 // NSURLSession will share settings with the sharedSession, which the |install| |
| 73 // method installs CrNet into. This method must be called after |install|. |
| 74 + (void)installIntoSessionConfiguration:(NSURLSessionConfiguration*)config; |
| 75 |
| 76 // Installs CrNet. This function is a deprecated shortcut for: |
| 77 // [CrNet setPartialUserAgent:userAgent]; |
| 78 // [CrNet install]; |
| 79 // See the documentation for |setPartialUserAgent| for details about the |
| 80 // |userAgent| argument. |
| 81 + (void)installWithPartialUserAgent:(NSString *)userAgent |
| 82 __attribute__((deprecated)); |
| 83 |
| 84 // Installs CrNet. This function is a deprecated shortcut for: |
| 85 // [CrNet setPartialUserAgent:userAgent]; |
| 86 // [CrNet install]; |
| 87 // The |enableDataReductionProxy| argument is ignored since data reduction proxy |
| 88 // support is currently missing from CrNet. See |setPartialUserAgent| for |
| 89 // details about the |userAgent| argument. |
| 90 + (void)installWithPartialUserAgent:(NSString *)userAgent |
| 91 enableDataReductionProxy:(BOOL)enableDataReductionProxy |
| 92 __attribute__((deprecated)); |
| 93 |
| 94 // Installs CrNet. This function is a deprecated shortcut for: |
| 95 // [CrNet setPartialUserAgent:userAgent]; |
| 96 // [CrNet setRequestFilterBlock:block]; |
| 97 // [CrNet install]; |
| 98 // See |setPartialUserAgent| and |setRequestFilterBlock| for details about the |
| 99 // |userAgent| and |requestFilterBlock| arguments respectively. |
| 100 + (void)installWithPartialUserAgent:(NSString *)userAgent |
| 101 withRequestFilterBlock:(RequestFilterBlock)requestFilterBlock |
| 102 __attribute__((deprecated)); |
| 103 |
| 104 // Starts net-internals logging to a file named |fileName| in the application |
| 105 // temporary directory. |fileName| must not be empty. Log level is determined |
| 106 // by |logBytes| - if YES then LOG_ALL otherwise LOG_ALL_BUT_BYTES. If the file |
| 107 // exists it is truncated before starting. If actively logging the call is |
| 108 // ignored. |
| 109 + (void)startNetLogToFile:(NSString *)fileName logBytes:(BOOL)logBytes; |
| 110 |
| 111 // Stop net-internals logging and flush file to disk. If a logging session is |
| 112 // not in progress this call is ignored. |
| 113 + (void)stopNetLog; |
| 114 |
| 115 // Closes all current SPDY sessions. Do not do this unless you know what |
| 116 // you're doing. |
| 117 // TODO(alokm): This is a hack. Remove it later. |
| 118 + (void)closeAllSpdySessions; |
| 119 |
| 120 // "Uninstalls" CrNet. This means that CrNet will stop intercepting requests. |
| 121 // However, it won't tear down all of the CrNet environment. |
| 122 + (void)uninstall; |
| 123 |
| 124 // Returns the full user-agent that the stack uses. |
| 125 // This is the exact string servers will see. |
| 126 + (NSString *)userAgent; |
| 127 |
| 128 // Clears CrNet's http cache. The supplied callback, if not nil, is run on an |
| 129 // unspecified thread. |
| 130 + (void)clearCacheWithCompletionCallback:(ClearCacheCallback)completionBlock; |
| 131 |
| 132 @end |
OLD | NEW |