OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 #include "chrome/browser/net/system_network_context_manager.h" |
| 6 |
| 7 #include "base/feature_list.h" |
| 8 #include "base/logging.h" |
| 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/network_service_instance.h" |
| 11 #include "content/public/common/content_features.h" |
| 12 #include "content/public/common/service_names.mojom.h" |
| 13 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
| 14 |
| 15 namespace { |
| 16 |
| 17 content::mojom::NetworkContextParamsPtr CreateNetworkContextParams() { |
| 18 // TODO(mmenke): Set up parameters here (No cache, in memory cookie store, |
| 19 // etc). |
| 20 return content::mojom::NetworkContextParams::New(); |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
| 25 base::LazyInstance<SystemNetworkContextManager>::Leaky |
| 26 g_system_network_context_manager = LAZY_INSTANCE_INITIALIZER; |
| 27 |
| 28 content::mojom::NetworkContext* SystemNetworkContextManager::Context() { |
| 29 return GetInstance()->GetContext(); |
| 30 } |
| 31 |
| 32 void SystemNetworkContextManager::SetUp( |
| 33 content::mojom::NetworkContextRequest* network_context_request, |
| 34 content::mojom::NetworkContextParamsPtr* network_context_params) { |
| 35 DCHECK(!GetInstance()->io_thread_network_context_); |
| 36 *network_context_request = |
| 37 mojo::MakeRequest(&GetInstance()->io_thread_network_context_); |
| 38 *network_context_params = CreateNetworkContextParams(); |
| 39 } |
| 40 |
| 41 SystemNetworkContextManager* SystemNetworkContextManager::GetInstance() { |
| 42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 43 return g_system_network_context_manager.Pointer(); |
| 44 } |
| 45 |
| 46 SystemNetworkContextManager::SystemNetworkContextManager() {} |
| 47 |
| 48 SystemNetworkContextManager::~SystemNetworkContextManager() {} |
| 49 |
| 50 content::mojom::NetworkContext* SystemNetworkContextManager::GetContext() { |
| 51 if (!base::FeatureList::IsEnabled(features::kNetworkService)) { |
| 52 // SetUp should already have been called. |
| 53 DCHECK(io_thread_network_context_); |
| 54 return io_thread_network_context_.get(); |
| 55 } |
| 56 |
| 57 if (!network_service_network_context_) { |
| 58 content::GetNetworkService()->CreateNetworkContext( |
| 59 MakeRequest(&network_service_network_context_), |
| 60 CreateNetworkContextParams()); |
| 61 } |
| 62 return network_service_network_context_.get(); |
| 63 } |
OLD | NEW |