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

Side by Side Diff: content/utility/utility_service_factory.cc

Issue 2837813004: Sync the browser test host resolver with the network process before a test runs. (Closed)
Patch Set: review comments Created 3 years, 8 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
« no previous file with comments | « content/utility/utility_service_factory.h ('k') | net/dns/mock_host_resolver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/utility/utility_service_factory.h" 5 #include "content/utility/utility_service_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "content/child/child_process.h" 9 #include "content/child/child_process.h"
10 #include "content/network/network_service.h" 10 #include "content/network/network_service.h"
(...skipping 16 matching lines...) Expand all
27 27
28 namespace { 28 namespace {
29 29
30 std::unique_ptr<service_manager::Service> CreateDataDecoderService() { 30 std::unique_ptr<service_manager::Service> CreateDataDecoderService() {
31 content::UtilityThread::Get()->EnsureBlinkInitialized(); 31 content::UtilityThread::Get()->EnsureBlinkInitialized();
32 return data_decoder::DataDecoderService::Create(); 32 return data_decoder::DataDecoderService::Create();
33 } 33 }
34 34
35 } // namespace 35 } // namespace
36 36
37 UtilityServiceFactory::UtilityServiceFactory() {} 37 UtilityServiceFactory::UtilityServiceFactory()
38 : network_registry_(base::MakeUnique<service_manager::BinderRegistry>()) {}
38 39
39 UtilityServiceFactory::~UtilityServiceFactory() {} 40 UtilityServiceFactory::~UtilityServiceFactory() {}
40 41
41 void UtilityServiceFactory::RegisterServices(ServiceMap* services) { 42 void UtilityServiceFactory::RegisterServices(ServiceMap* services) {
42 GetContentClient()->utility()->RegisterServices(services); 43 GetContentClient()->utility()->RegisterServices(services);
43 44
44 #if defined(ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS) 45 #if defined(ENABLE_MOJO_MEDIA_IN_UTILITY_PROCESS)
45 ServiceInfo info; 46 ServiceInfo info;
46 info.factory = base::Bind(&media::CreateMediaService); 47 info.factory = base::Bind(&media::CreateMediaService);
47 services->insert(std::make_pair("media", info)); 48 services->insert(std::make_pair("media", info));
48 #endif 49 #endif
49 ServiceInfo shape_detection_info; 50 ServiceInfo shape_detection_info;
50 shape_detection_info.factory = 51 shape_detection_info.factory =
51 base::Bind(&shape_detection::ShapeDetectionService::Create); 52 base::Bind(&shape_detection::ShapeDetectionService::Create);
52 services->insert(std::make_pair(shape_detection::mojom::kServiceName, 53 services->insert(std::make_pair(shape_detection::mojom::kServiceName,
53 shape_detection_info)); 54 shape_detection_info));
54 55
55 ServiceInfo data_decoder_info; 56 ServiceInfo data_decoder_info;
56 data_decoder_info.factory = base::Bind(&CreateDataDecoderService); 57 data_decoder_info.factory = base::Bind(&CreateDataDecoderService);
57 services->insert( 58 services->insert(
58 std::make_pair(data_decoder::mojom::kServiceName, data_decoder_info)); 59 std::make_pair(data_decoder::mojom::kServiceName, data_decoder_info));
59 60
60 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 61 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
61 switches::kEnableNetworkService)) { 62 switches::kEnableNetworkService)) {
63 GetContentClient()->utility()->RegisterNetworkBinders(
64 network_registry_.get());
62 ServiceInfo network_info; 65 ServiceInfo network_info;
63 network_info.factory = base::Bind(&NetworkService::CreateNetworkService); 66 network_info.factory = base::Bind(
67 &UtilityServiceFactory::CreateNetworkService, base::Unretained(this));
64 network_info.task_runner = ChildProcess::current()->io_task_runner(); 68 network_info.task_runner = ChildProcess::current()->io_task_runner();
65 services->insert( 69 services->insert(
66 std::make_pair(content::mojom::kNetworkServiceName, network_info)); 70 std::make_pair(content::mojom::kNetworkServiceName, network_info));
67 } 71 }
68 } 72 }
69 73
70 void UtilityServiceFactory::OnServiceQuit() { 74 void UtilityServiceFactory::OnServiceQuit() {
71 UtilityThread::Get()->ReleaseProcessIfNeeded(); 75 UtilityThread::Get()->ReleaseProcessIfNeeded();
72 } 76 }
73 77
74 void UtilityServiceFactory::OnLoadFailed() { 78 void UtilityServiceFactory::OnLoadFailed() {
75 UtilityThreadImpl* utility_thread = 79 UtilityThreadImpl* utility_thread =
76 static_cast<UtilityThreadImpl*>(UtilityThread::Get()); 80 static_cast<UtilityThreadImpl*>(UtilityThread::Get());
77 utility_thread->Shutdown(); 81 utility_thread->Shutdown();
78 utility_thread->ReleaseProcessIfNeeded(); 82 utility_thread->ReleaseProcessIfNeeded();
79 } 83 }
80 84
85 std::unique_ptr<service_manager::Service>
86 UtilityServiceFactory::CreateNetworkService() {
87 return base::MakeUnique<NetworkService>(std::move(network_registry_));
88 }
89
81 } // namespace content 90 } // namespace content
OLDNEW
« no previous file with comments | « content/utility/utility_service_factory.h ('k') | net/dns/mock_host_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698