Skip to content

Commit

Permalink
Add a helper method to retrieve network service from a service manage…
Browse files Browse the repository at this point in the history
…r 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/1188776
Reviewed-by: John Abd-El-Malek <[email protected]>
Commit-Queue: Min Qin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#586094}
  • Loading branch information
Min Qin authored and Commit Bot committed Aug 25, 2018
1 parent cd9e2a5 commit 9cbcf63
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
14 changes: 11 additions & 3 deletions content/browser/network_service_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,24 @@ void BindNetworkChangeManagerRequest(
} // namespace

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)
g_network_service_ptr = new network::mojom::NetworkServicePtr;
static NetworkServiceClient* g_client;
if (!g_network_service_ptr->is_bound() ||
g_network_service_ptr->encountered_error()) {
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface(
mojom::kNetworkServiceName, g_network_service_ptr);
connector->BindInterface(mojom::kNetworkServiceName,
g_network_service_ptr);
} else {
DCHECK(!g_network_service_ptr->is_bound());
BrowserThread::PostTask(
Expand Down
12 changes: 12 additions & 0 deletions content/public/browser/network_service_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class NetworkService;
}
} // namespace network

namespace service_manager {
class Connector;
} // namespace service_manager

namespace content {

// Returns a pointer to the NetworkService, creating / re-creating it as needed.
Expand All @@ -25,6 +29,14 @@ namespace content {
// This method can only be called on the UI thread.
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
// 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
Expand Down

0 comments on commit 9cbcf63

Please sign in to comment.