forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook up ProfileIOData's URLRequestContext to a NetworkService.
This CL adds ProfileNetworkContextService, a BrowserContext KeyedService, that wraps ProfileIOData's URLRequestContext in a NetworkContext (Which ProfileIOData hooks up to IOThread's in-process NetworkService), and provides NetworkContext configuration parameters for it as well. When the network service is disabled, the new service provides direct access to the net NetworkContext. When the network service is enabled, the new service configures and provides acess to the StoragePartition's NetworkContext instance instead (Though it still sets up a NetworkContext for ProfileIOData's URLRequestContext as well). Bug=715695 Review-Url: https://codereview.chromium.org/2976323002 Cr-Commit-Position: refs/heads/master@{#488893}
- Loading branch information
mmenke
authored and
Commit Bot
committed
Jul 23, 2017
1 parent
d475282
commit 0d1d09c
Showing
25 changed files
with
439 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/net/profile_network_context_service.h" | ||
|
||
#include "base/feature_list.h" | ||
#include "base/logging.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "content/public/browser/browser_context.h" | ||
#include "content/public/browser/browser_thread.h" | ||
#include "content/public/browser/network_service_instance.h" | ||
#include "content/public/browser/storage_partition.h" | ||
#include "content/public/common/content_features.h" | ||
#include "content/public/common/service_names.mojom.h" | ||
#include "mojo/public/cpp/bindings/associated_interface_ptr.h" | ||
|
||
namespace { | ||
|
||
content::mojom::NetworkContextParamsPtr CreateMainNetworkContextParams() { | ||
// TODO(mmenke): Set up parameters here. | ||
return content::mojom::NetworkContextParams::New(); | ||
} | ||
|
||
} // namespace | ||
|
||
ProfileNetworkContextService::ProfileNetworkContextService(Profile* profile) | ||
: profile_(profile) {} | ||
|
||
ProfileNetworkContextService::~ProfileNetworkContextService() {} | ||
|
||
void ProfileNetworkContextService::SetUpProfileIODataMainContext( | ||
content::mojom::NetworkContextRequest* network_context_request, | ||
content::mojom::NetworkContextParamsPtr* network_context_params) { | ||
DCHECK(!profile_io_data_main_network_context_); | ||
*network_context_request = | ||
mojo::MakeRequest(&profile_io_data_main_network_context_); | ||
if (!base::FeatureList::IsEnabled(features::kNetworkService)) { | ||
*network_context_params = CreateMainNetworkContextParams(); | ||
} else { | ||
// Just use default if network service is enabled, to avoid the legacy | ||
// in-process URLRequestContext from fighting with the NetworkService over | ||
// ownership of on-disk files. | ||
*network_context_params = content::mojom::NetworkContextParams::New(); | ||
} | ||
} | ||
|
||
content::mojom::NetworkContext* ProfileNetworkContextService::MainContext() { | ||
// ProfileIOData must be initialized before this call. | ||
DCHECK(profile_io_data_main_network_context_); | ||
if (!base::FeatureList::IsEnabled(features::kNetworkService)) | ||
return profile_io_data_main_network_context_.get(); | ||
|
||
return content::BrowserContext::GetDefaultStoragePartition(profile_) | ||
->GetNetworkContext(); | ||
} | ||
|
||
content::mojom::NetworkContextPtr | ||
ProfileNetworkContextService::CreateMainNetworkContext() { | ||
DCHECK(base::FeatureList::IsEnabled(features::kNetworkService)); | ||
|
||
content::mojom::NetworkContextPtr network_context; | ||
content::GetNetworkService()->CreateNetworkContext( | ||
MakeRequest(&network_context), CreateMainNetworkContextParams()); | ||
return network_context; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_NET_PROFILE_NETWORK_CONTEXT_SERVICE_H_ | ||
#define CHROME_BROWSER_NET_PROFILE_NETWORK_CONTEXT_SERVICE_H_ | ||
|
||
#include "base/macros.h" | ||
#include "components/keyed_service/core/keyed_service.h" | ||
#include "content/public/common/network_service.mojom.h" | ||
|
||
class Profile; | ||
|
||
// KeyedService that initializes and provides access to the NetworkContexts for | ||
// a Profile. This will eventually replace ProfileIOData. | ||
class ProfileNetworkContextService : public KeyedService { | ||
public: | ||
explicit ProfileNetworkContextService(Profile* profile); | ||
~ProfileNetworkContextService() override; | ||
|
||
// Initializes |*network_context_params| to set up the ProfileIOData's | ||
// main URLRequestContext and |*network_context_request| to be one end of a | ||
// Mojo pipe to be bound to the NetworkContext for that URLRequestContext. | ||
// The caller will need to send these parameters to the IOThread's in-process | ||
// NetworkService. This class retains the NetworkContext at the other end of | ||
// the |*network_context_request| pipe for later vending. | ||
// | ||
// If the network service is disabled, MainContext() will return that end of | ||
// the pipe. In this case, all requests associated with this profile will use | ||
// the associated URLRequestContext (either through MainContext() or | ||
// directly). | ||
// | ||
// If the network service is enabled, MainContext() will instead return a | ||
// network context vended by the network service's NetworkService (Instead of | ||
// the IOThread's in-process one). In this case, the ProfileIOData's | ||
// URLRequest context will be configured not to use on-disk storage (so as not | ||
// to conflict with the network service vended context), and will only be used | ||
// for legacy requests that use it directly. | ||
// | ||
// Must be called before anything uses the NetworkContext vended by this | ||
// class. | ||
void SetUpProfileIODataMainContext( | ||
content::mojom::NetworkContextRequest* network_context_request, | ||
content::mojom::NetworkContextParamsPtr* network_context_params); | ||
|
||
// Returns the main NetworkContext for the BrowserContext. If the network | ||
// service is disabled, this will be the | ||
// ProfileIOData NetworkContext set up above. Otherwise, it will be a | ||
// NetworkContext vended from the network service. | ||
content::mojom::NetworkContext* MainContext(); | ||
|
||
// Creates the main NetworkContext for the BrowserContext, using the network | ||
// service. May only be called when the network service is enabled. Must only | ||
// be called once for a profile, from the ChromeContentBrowserClient. | ||
content::mojom::NetworkContextPtr CreateMainNetworkContext(); | ||
|
||
private: | ||
Profile* const profile_; | ||
|
||
// This is a NetworkContext that wraps ProfileIOData's main URLRequestContext. | ||
// Always initialized in SetUpProfileIODataMainContext, but it's only returned | ||
// by Context() when the network service is disabled. | ||
content::mojom::NetworkContextPtr profile_io_data_main_network_context_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ProfileNetworkContextService); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_NET_PROFILE_NETWORK_CONTEXT_SERVICE_H_ |
40 changes: 40 additions & 0 deletions
40
chrome/browser/net/profile_network_context_service_factory.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/net/profile_network_context_service_factory.h" | ||
|
||
#include "chrome/browser/net/profile_network_context_service.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/keyed_service/content/browser_context_dependency_manager.h" | ||
|
||
ProfileNetworkContextService* | ||
ProfileNetworkContextServiceFactory::GetForContext( | ||
content::BrowserContext* browser_context) { | ||
return static_cast<ProfileNetworkContextService*>( | ||
GetInstance()->GetServiceForBrowserContext(browser_context, true)); | ||
} | ||
|
||
ProfileNetworkContextServiceFactory* | ||
ProfileNetworkContextServiceFactory::GetInstance() { | ||
return base::Singleton<ProfileNetworkContextServiceFactory>::get(); | ||
} | ||
|
||
ProfileNetworkContextServiceFactory::ProfileNetworkContextServiceFactory() | ||
: BrowserContextKeyedServiceFactory( | ||
"ProfileNetworkContextService", | ||
BrowserContextDependencyManager::GetInstance()) {} | ||
|
||
ProfileNetworkContextServiceFactory::~ProfileNetworkContextServiceFactory() {} | ||
|
||
KeyedService* ProfileNetworkContextServiceFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* profile) const { | ||
return new ProfileNetworkContextService(Profile::FromBrowserContext(profile)); | ||
} | ||
|
||
content::BrowserContext* | ||
ProfileNetworkContextServiceFactory::GetBrowserContextToUse( | ||
content::BrowserContext* context) const { | ||
// Create separate service for incognito profiles. | ||
return context; | ||
} |
Oops, something went wrong.