Commit 9cbcf63d authored by Min Qin's avatar Min Qin Committed by Commit Bot

Add a helper method to retrieve network service from a service manager Connector

If services are launched without full browser process, they need to retrieve
the network service from the service manager connector they have.
This CL adds a helper method to allow that to work.

BUG=695115

Change-Id: I362b814b03d60d9645523664a7243555bac6f053
Reviewed-on: https://chromium-review.googlesource.com/1188776Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586094}
parent cd9e2a56
...@@ -46,16 +46,24 @@ void BindNetworkChangeManagerRequest( ...@@ -46,16 +46,24 @@ void BindNetworkChangeManagerRequest(
} // namespace } // namespace
network::mojom::NetworkService* GetNetworkService() { network::mojom::NetworkService* GetNetworkService() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); service_manager::Connector* connector =
base::FeatureList::IsEnabled(network::features::kNetworkService)
? ServiceManagerConnection::GetForProcess()->GetConnector()
: nullptr;
return GetNetworkServiceFromConnector(connector);
}
CONTENT_EXPORT network::mojom::NetworkService* GetNetworkServiceFromConnector(
service_manager::Connector* connector) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!g_network_service_ptr) if (!g_network_service_ptr)
g_network_service_ptr = new network::mojom::NetworkServicePtr; g_network_service_ptr = new network::mojom::NetworkServicePtr;
static NetworkServiceClient* g_client; static NetworkServiceClient* g_client;
if (!g_network_service_ptr->is_bound() || if (!g_network_service_ptr->is_bound() ||
g_network_service_ptr->encountered_error()) { g_network_service_ptr->encountered_error()) {
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) { if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( connector->BindInterface(mojom::kNetworkServiceName,
mojom::kNetworkServiceName, g_network_service_ptr); g_network_service_ptr);
} else { } else {
DCHECK(!g_network_service_ptr->is_bound()); DCHECK(!g_network_service_ptr->is_bound());
BrowserThread::PostTask( BrowserThread::PostTask(
......
...@@ -15,6 +15,10 @@ class NetworkService; ...@@ -15,6 +15,10 @@ class NetworkService;
} }
} // namespace network } // namespace network
namespace service_manager {
class Connector;
} // namespace service_manager
namespace content { namespace content {
// Returns a pointer to the NetworkService, creating / re-creating it as needed. // Returns a pointer to the NetworkService, creating / re-creating it as needed.
...@@ -25,6 +29,14 @@ namespace content { ...@@ -25,6 +29,14 @@ namespace content {
// This method can only be called on the UI thread. // This method can only be called on the UI thread.
CONTENT_EXPORT network::mojom::NetworkService* GetNetworkService(); CONTENT_EXPORT network::mojom::NetworkService* GetNetworkService();
// Similar to GetNetworkService(), but will create the NetworkService from a
// service manager connector if needed. If network service is disabled,
// |connector| will be ignored and this method is identical to
// GetNetworkService().
// This method can only be called on the UI thread.
CONTENT_EXPORT network::mojom::NetworkService* GetNetworkServiceFromConnector(
service_manager::Connector* connector);
// When network service is disabled, returns the in-process NetworkService // When network service is disabled, returns the in-process NetworkService
// pointer which is used to ease transition to network service. // pointer which is used to ease transition to network service.
// Must only be called on the IO thread. Must not be called if the network // Must only be called on the IO thread. Must not be called if the network
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment