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

Side by Side Diff: ios/crnet/crnet_consumer/crnet_consumer_app_delegate.mm

Issue 1125293004: ios: add CrNet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 "crnet_consumer_app_delegate.h"
6
7 #import "CrNet.h"
8 #include "base/format_macros.h"
9 #import "crnet_consumer_view_controller.h"
10
11 @implementation CrNetConsumerAppDelegate {
12 NSUInteger _counter;
13 }
14
15 @synthesize window;
16 @synthesize viewController;
17
18 // Returns a file name to save net internals logging. This method suffixes
19 // the ivar |_counter| to the file name so a new name can be obtained by
20 // modifying that.
21 - (NSString *)currentNetLogFileName {
22 return [NSString
23 stringWithFormat:@"crnet-consumer-net-log%" PRIuNS ".json", _counter];
24 }
25
26 - (BOOL)application:(UIApplication *)application
27 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
28 [CrNet setPartialUserAgent:@"Dummy/1.0"];
29 [CrNet setQuicEnabled:YES];
30 // Always use QUIC if able.
31 [CrNet setAlternateProtocolThreshold:0.0];
32 [CrNet install];
33 [CrNet startNetLogToFile:[self currentNetLogFileName] logBytes:NO];
34
35 NSURLSessionConfiguration* config =
36 [NSURLSessionConfiguration ephemeralSessionConfiguration];
37 [CrNet installIntoSessionConfiguration:config];
38
39 // Just for fun, don't route apple.com requests through CrNet.
stuartmorgan 2015/05/19 17:39:36 Let's use a domain we control. How about chromium.
Elly Fong-Jones 2015/05/20 22:02:26 Done.
40 //
41 // |applePrefix| is declared outside the scope of the request block so that
42 // the block references something outside of its own scope, and cannot be
43 // declared as a global block. This makes sure the block is
44 // an __NSStackBlock__, and verifies the fix for http://crbug.com/436175 .
45 NSString *applePrefix = @"www.apple.com";
46 [CrNet setRequestFilterBlock:^BOOL (NSURLRequest *request) {
47 BOOL isAppleSite = [[[request URL] host] hasPrefix:applePrefix];
48 return !isAppleSite;
49 }];
50
51 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
52 self.viewController =
53 [[CrNetConsumerViewController alloc] initWithNibName:nil bundle:nil];
54 self.window.rootViewController = self.viewController;
55 [self.window makeKeyAndVisible];
56
57 return YES;
58 }
59
60 - (void)applicationDidEnterBackground:(UIApplication *)application {
61 [CrNet stopNetLog];
62 [CrNet clearCacheWithCompletionCallback:^(int error) {
63 NSLog(@"Cache cleared: %d\n", error);
64 }];
65 }
66
67 - (void)applicationWillEnterForeground:(UIApplication *)application {
68 _counter++;
69 [CrNet startNetLogToFile:[self currentNetLogFileName] logBytes:NO];
70 }
71
72 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698