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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ios/crnet/crnet_consumer/crnet_consumer_app_delegate.mm
diff --git a/ios/crnet/crnet_consumer/crnet_consumer_app_delegate.mm b/ios/crnet/crnet_consumer/crnet_consumer_app_delegate.mm
new file mode 100644
index 0000000000000000000000000000000000000000..869232890622a155691fe7c61e454dc99edcf71b
--- /dev/null
+++ b/ios/crnet/crnet_consumer/crnet_consumer_app_delegate.mm
@@ -0,0 +1,72 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "crnet_consumer_app_delegate.h"
+
+#import "CrNet.h"
+#include "base/format_macros.h"
+#import "crnet_consumer_view_controller.h"
+
+@implementation CrNetConsumerAppDelegate {
+ NSUInteger _counter;
+}
+
+@synthesize window;
+@synthesize viewController;
+
+// Returns a file name to save net internals logging. This method suffixes
+// the ivar |_counter| to the file name so a new name can be obtained by
+// modifying that.
+- (NSString *)currentNetLogFileName {
+ return [NSString
+ stringWithFormat:@"crnet-consumer-net-log%" PRIuNS ".json", _counter];
+}
+
+- (BOOL)application:(UIApplication *)application
+ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+ [CrNet setPartialUserAgent:@"Dummy/1.0"];
+ [CrNet setQuicEnabled:YES];
+ // Always use QUIC if able.
+ [CrNet setAlternateProtocolThreshold:0.0];
+ [CrNet install];
+ [CrNet startNetLogToFile:[self currentNetLogFileName] logBytes:NO];
+
+ NSURLSessionConfiguration* config =
+ [NSURLSessionConfiguration ephemeralSessionConfiguration];
+ [CrNet installIntoSessionConfiguration:config];
+
+ // 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.
+ //
+ // |applePrefix| is declared outside the scope of the request block so that
+ // the block references something outside of its own scope, and cannot be
+ // declared as a global block. This makes sure the block is
+ // an __NSStackBlock__, and verifies the fix for http://crbug.com/436175 .
+ NSString *applePrefix = @"www.apple.com";
+ [CrNet setRequestFilterBlock:^BOOL (NSURLRequest *request) {
+ BOOL isAppleSite = [[[request URL] host] hasPrefix:applePrefix];
+ return !isAppleSite;
+ }];
+
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ self.viewController =
+ [[CrNetConsumerViewController alloc] initWithNibName:nil bundle:nil];
+ self.window.rootViewController = self.viewController;
+ [self.window makeKeyAndVisible];
+
+ return YES;
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+ [CrNet stopNetLog];
+ [CrNet clearCacheWithCompletionCallback:^(int error) {
+ NSLog(@"Cache cleared: %d\n", error);
+ }];
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application {
+ _counter++;
+ [CrNet startNetLogToFile:[self currentNetLogFileName] logBytes:NO];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698