Index: ios/chrome/app/startup/network_stack_setup.mm |
diff --git a/ios/chrome/app/startup/network_stack_setup.mm b/ios/chrome/app/startup/network_stack_setup.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..533edeea8e2378ebed09fde6ef1de161c70c8e41 |
--- /dev/null |
+++ b/ios/chrome/app/startup/network_stack_setup.mm |
@@ -0,0 +1,45 @@ |
+// Copyright 2016 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. |
+ |
+#include "ios/chrome/app/startup/network_stack_setup.h" |
+ |
+#include "base/memory/ptr_util.h" |
+#include "ios/chrome/browser/application_context.h" |
+#include "ios/chrome/browser/chrome_url_constants.h" |
+#import "ios/net/empty_nsurlcache.h" |
+#include "ios/web/net/request_tracker_factory_impl.h" |
+#include "ios/web/net/web_http_protocol_handler_delegate.h" |
+ |
+@implementation NetworkStackSetup |
+ |
++ (void)setUpChromeNetworkStack: |
+ (std::unique_ptr<web::RequestTrackerFactoryImpl>*) |
+ requestTrackerFactory |
+ httpProtocolHandlerDelegate: |
+ (std::unique_ptr<web::WebHTTPProtocolHandlerDelegate>*) |
+ httpProtocolHandlerDelegate { |
+ // Disable the default cache. |
+ [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; |
+ |
+ // Configuration for the HTTP protocol handler. |
+ // TODO(crbug.com/585700): Remove this code. |
+ *httpProtocolHandlerDelegate = |
+ base::MakeUnique<web::WebHTTPProtocolHandlerDelegate>( |
+ GetApplicationContext()->GetSystemURLRequestContext()); |
+ net::HTTPProtocolHandlerDelegate::SetInstance( |
+ httpProtocolHandlerDelegate->get()); |
+ |
+ // Register the chrome http protocol handler to replace the default one. |
+ // TODO(crbug.com/665036): Move the network stack initialization to the web |
+ // layer. |
+ BOOL success = [NSURLProtocol registerClass:[CRNHTTPProtocolHandler class]]; |
+ DCHECK(success); |
+ *requestTrackerFactory = |
+ base::MakeUnique<web::RequestTrackerFactoryImpl>(kChromeUIScheme); |
+ net::RequestTracker::SetRequestTrackerFactory(requestTrackerFactory->get()); |
+ |
+ DCHECK(success); |
+} |
+ |
+@end |