| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ios/chrome/app/startup/network_stack_setup.h" | 5 #include "ios/chrome/app/startup/network_stack_setup.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ios/chrome/browser/application_context.h" | 8 #include "ios/chrome/browser/application_context.h" |
| 9 #include "ios/chrome/browser/chrome_url_constants.h" | 9 #include "ios/chrome/browser/chrome_url_constants.h" |
| 10 #import "ios/net/empty_nsurlcache.h" | 10 #import "ios/net/empty_nsurlcache.h" |
| 11 #include "ios/web/net/request_tracker_factory_impl.h" | 11 #include "ios/web/net/request_tracker_factory_impl.h" |
| 12 #include "ios/web/net/web_http_protocol_handler_delegate.h" | |
| 13 | 12 |
| 14 @implementation NetworkStackSetup | 13 @implementation NetworkStackSetup |
| 15 | 14 |
| 16 + (void)setUpChromeNetworkStack: | 15 + (std::unique_ptr<web::RequestTrackerFactoryImpl>)setUpChromeNetworkStack { |
| 17 (std::unique_ptr<web::RequestTrackerFactoryImpl>*) | |
| 18 requestTrackerFactory | |
| 19 httpProtocolHandlerDelegate: | |
| 20 (std::unique_ptr<web::WebHTTPProtocolHandlerDelegate>*) | |
| 21 httpProtocolHandlerDelegate { | |
| 22 // Disable the default cache. | 16 // Disable the default cache. |
| 23 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; | 17 [NSURLCache setSharedURLCache:[EmptyNSURLCache emptyNSURLCache]]; |
| 24 | 18 |
| 25 // Configuration for the HTTP protocol handler. | 19 auto requestTrackerFactory = |
| 26 // TODO(crbug.com/585700): Remove this code. | |
| 27 *httpProtocolHandlerDelegate = | |
| 28 base::MakeUnique<web::WebHTTPProtocolHandlerDelegate>( | |
| 29 GetApplicationContext()->GetSystemURLRequestContext()); | |
| 30 net::HTTPProtocolHandlerDelegate::SetInstance( | |
| 31 httpProtocolHandlerDelegate->get()); | |
| 32 | |
| 33 // Register the chrome http protocol handler to replace the default one. | |
| 34 // TODO(crbug.com/665036): Move the network stack initialization to the web | |
| 35 // layer. | |
| 36 BOOL success = [NSURLProtocol registerClass:[CRNHTTPProtocolHandler class]]; | |
| 37 DCHECK(success); | |
| 38 *requestTrackerFactory = | |
| 39 base::MakeUnique<web::RequestTrackerFactoryImpl>(kChromeUIScheme); | 20 base::MakeUnique<web::RequestTrackerFactoryImpl>(kChromeUIScheme); |
| 40 net::RequestTracker::SetRequestTrackerFactory(requestTrackerFactory->get()); | 21 net::RequestTracker::SetRequestTrackerFactory(requestTrackerFactory.get()); |
| 41 | 22 return requestTrackerFactory; |
| 42 DCHECK(success); | |
| 43 } | 23 } |
| 44 | 24 |
| 45 @end | 25 @end |
| OLD | NEW |