Skip to content

Commit

Permalink
Remove ContentBrowserClient::CreateRequestContext & CreateRequestCont…
Browse files Browse the repository at this point in the history
…extForStoragePartition.

The various implementations just delegate to the BrowserContext to create the request context, so these should just be on BrowserContext directly. The main motivator is to remove BrowserContext::GetRequestContext, which depends on this change since in tests the default ContentBrowserClient doesn't know which BrowserContext implementation is used.

GetRequestContext duplicates BrowserContext::GetDefaultStoragePartition(browser_context)->GetURLRequestContext().

BUG=159193
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1862203005

Cr-Commit-Position: refs/heads/master@{#385855}
  • Loading branch information
jam authored and Commit bot committed Apr 7, 2016
1 parent 6060a04 commit 547f267
Show file tree
Hide file tree
Showing 50 changed files with 307 additions and 479 deletions.
48 changes: 24 additions & 24 deletions android_webview/browser/aw_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,30 +269,6 @@ void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) {
visitedlink_master_->AddURLs(urls);
}

net::URLRequestContextGetter* AwBrowserContext::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
// This function cannot actually create the request context because
// there is a reentrant dependency on GetResourceContext() via
// content::StoragePartitionImplMap::Create(). This is not fixable
// until http://crbug.com/159193. Until then, assert that the context
// has already been allocated and just handle setting the protocol_handlers.
DCHECK(url_request_context_getter_.get());
url_request_context_getter_->SetHandlersAndInterceptors(
protocol_handlers, std::move(request_interceptors));
return url_request_context_getter_.get();
}

net::URLRequestContextGetter*
AwBrowserContext::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
NOTREACHED();
return NULL;
}

AwQuotaManagerBridge* AwBrowserContext::GetQuotaManagerBridge() {
if (!quota_manager_bridge_.get()) {
quota_manager_bridge_ = native_factory_->CreateAwQuotaManagerBridge(this);
Expand Down Expand Up @@ -439,6 +415,30 @@ AwBrowserContext::GetBackgroundSyncController() {
return nullptr;
}

net::URLRequestContextGetter* AwBrowserContext::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
// This function cannot actually create the request context because
// there is a reentrant dependency on GetResourceContext() via
// content::StoragePartitionImplMap::Create(). This is not fixable
// until http://crbug.com/159193. Until then, assert that the context
// has already been allocated and just handle setting the protocol_handlers.
DCHECK(url_request_context_getter_.get());
url_request_context_getter_->SetHandlersAndInterceptors(
protocol_handlers, std::move(request_interceptors));
return url_request_context_getter_.get();
}

net::URLRequestContextGetter*
AwBrowserContext::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
NOTREACHED();
return NULL;
}

policy::URLBlacklistManager* AwBrowserContext::GetURLBlacklistManager() {
// Should not be called until the end of PreMainMessageLoopRun, where
// blacklist_manager_ is initialized.
Expand Down
17 changes: 8 additions & 9 deletions android_webview/browser/aw_browser_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,6 @@ class AwBrowserContext : public content::BrowserContext,
// These methods map to Add methods in visitedlink::VisitedLinkMaster.
void AddVisitedURLs(const std::vector<GURL>& urls);

net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors);
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors);

AwQuotaManagerBridge* GetQuotaManagerBridge();
AwFormDatabaseService* GetFormDatabaseService();
data_reduction_proxy::DataReductionProxySettings*
Expand Down Expand Up @@ -126,6 +117,14 @@ class AwBrowserContext : public content::BrowserContext,
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::PermissionManager* GetPermissionManager() override;
content::BackgroundSyncController* GetBackgroundSyncController() override;
net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;

// visitedlink::VisitedLinkDelegate implementation.
void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override;
Expand Down
24 changes: 0 additions & 24 deletions android_webview/browser/aw_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,30 +232,6 @@ void AwContentBrowserClient::RenderProcessWillLaunch(
host->AddFilter(new AwPrintingMessageFilter(host->GetID()));
}

net::URLRequestContextGetter* AwContentBrowserClient::CreateRequestContext(
content::BrowserContext* browser_context,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
DCHECK_EQ(browser_context_.get(), browser_context);
return browser_context_->CreateRequestContext(
protocol_handlers, std::move(request_interceptors));
}

net::URLRequestContextGetter*
AwContentBrowserClient::CreateRequestContextForStoragePartition(
content::BrowserContext* browser_context,
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
DCHECK_EQ(browser_context_.get(), browser_context);
// TODO(mkosiba,kinuko): request_interceptors should be hooked up in the
// downstream. (crbug.com/350286)
return browser_context_->CreateRequestContextForStoragePartition(
partition_path, in_memory, protocol_handlers,
std::move(request_interceptors));
}

bool AwContentBrowserClient::IsHandledURL(const GURL& url) {
if (!url.is_valid()) {
// We handle error cases.
Expand Down
10 changes: 0 additions & 10 deletions android_webview/browser/aw_content_browser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ class AwContentBrowserClient : public content::ContentBrowserClient {
content::WebContentsViewDelegate* GetWebContentsViewDelegate(
content::WebContents* web_contents) override;
void RenderProcessWillLaunch(content::RenderProcessHost* host) override;
net::URLRequestContextGetter* CreateRequestContext(
content::BrowserContext* browser_context,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
content::BrowserContext* browser_context,
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
bool IsHandledURL(const GURL& url) override;
std::string GetCanonicalEncodingNameByAliasName(
const std::string& alias_name) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/files/file_path.h"
#include "base/macros.h"
#include "components/prefs/pref_member.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_job_factory.h"
Expand Down
15 changes: 0 additions & 15 deletions ash/shell/content/client/shell_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "ash/shell/content/client/shell_browser_main_parts.h"
#include "base/command_line.h"
#include "content/shell/browser/shell_browser_context.h"
#include "third_party/skia/include/core/SkBitmap.h"

namespace ash {
Expand All @@ -25,19 +24,5 @@ content::BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts(
return shell_browser_main_parts_;
}

net::URLRequestContextGetter* ShellContentBrowserClient::CreateRequestContext(
content::BrowserContext* content_browser_context,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
content::ShellBrowserContext* shell_context =
static_cast<content::ShellBrowserContext*>(content_browser_context);
return shell_context->CreateRequestContext(protocol_handlers,
std::move(request_interceptors));
}

content::ShellBrowserContext* ShellContentBrowserClient::browser_context() {
return shell_browser_main_parts_->browser_context();
}

} // namespace examples
} // namespace views
6 changes: 0 additions & 6 deletions ash/shell/content/client/shell_content_browser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ class ShellContentBrowserClient : public content::ContentBrowserClient {
// Overridden from content::ContentBrowserClient:
content::BrowserMainParts* CreateBrowserMainParts(
const content::MainFunctionParams& parameters) override;
net::URLRequestContextGetter* CreateRequestContext(
content::BrowserContext* browser_context,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;

content::ShellBrowserContext* browser_context();

private:
ShellBrowserMainParts* shell_browser_main_parts_;
Expand Down
12 changes: 0 additions & 12 deletions blimp/engine/app/blimp_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "blimp/engine/app/blimp_content_browser_client.h"
#include "blimp/engine/app/blimp_browser_main_parts.h"
#include "blimp/engine/app/settings_manager.h"
#include "blimp/engine/common/blimp_browser_context.h"
#include "blimp/engine/mojo/blob_channel_service.h"
#include "content/public/common/service_registry.h"

Expand All @@ -23,17 +22,6 @@ content::BrowserMainParts* BlimpContentBrowserClient::CreateBrowserMainParts(
return blimp_browser_main_parts_;
}

net::URLRequestContextGetter* BlimpContentBrowserClient::CreateRequestContext(
content::BrowserContext* content_browser_context,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
BlimpBrowserContext* blimp_context =
static_cast<BlimpBrowserContext*>(content_browser_context);
return blimp_context->CreateRequestContext(protocol_handlers,
std::move(request_interceptors))
.get();
}

void BlimpContentBrowserClient::OverrideWebkitPrefs(
content::RenderViewHost* render_view_host,
content::WebPreferences* prefs) {
Expand Down
4 changes: 0 additions & 4 deletions blimp/engine/app/blimp_content_browser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ class BlimpContentBrowserClient : public content::ContentBrowserClient {
// content::ContentBrowserClient implementation.
content::BrowserMainParts* CreateBrowserMainParts(
const content::MainFunctionParams& parameters) override;
net::URLRequestContextGetter* CreateRequestContext(
content::BrowserContext* browser_context,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
void OverrideWebkitPrefs(content::RenderViewHost* render_view_host,
content::WebPreferences* prefs) override;
void RegisterRenderProcessMojoServices(
Expand Down
1 change: 1 addition & 0 deletions blimp/engine/app/blimp_url_request_context_getter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/files/file_path.h"
#include "base/macros.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
#include "net/url_request/url_request_context_getter.h"

Expand Down
42 changes: 25 additions & 17 deletions blimp/engine/common/blimp_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,6 @@ net::URLRequestContextGetter* BlimpBrowserContext::GetRequestContext() {
return GetDefaultStoragePartition(this)->GetURLRequestContext();
}

const scoped_refptr<BlimpURLRequestContextGetter>&
BlimpBrowserContext::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
DCHECK(!resource_context_->url_request_context_getter());
// net_log_ is owned by BrowserMainParts.
resource_context_->set_url_request_context_getter(
new BlimpURLRequestContextGetter(
ignore_certificate_errors_, GetPath(),
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::IO),
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::FILE),
protocol_handlers, std::move(request_interceptors), net_log_));
return resource_context_->url_request_context_getter();
}

net::URLRequestContextGetter* BlimpBrowserContext::GetMediaRequestContext() {
return GetRequestContext();
}
Expand Down Expand Up @@ -166,5 +149,30 @@ BlimpBrowserContext::GetBackgroundSyncController() {
return nullptr;
}

net::URLRequestContextGetter* BlimpBrowserContext::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
DCHECK(!resource_context_->url_request_context_getter());
// net_log_ is owned by BrowserMainParts.
resource_context_->set_url_request_context_getter(
new BlimpURLRequestContextGetter(
ignore_certificate_errors_, GetPath(),
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::IO),
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::FILE),
protocol_handlers, std::move(request_interceptors), net_log_));
return resource_context_->url_request_context_getter().get();
}

net::URLRequestContextGetter*
BlimpBrowserContext::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
return nullptr;
}

} // namespace engine
} // namespace blimp
12 changes: 7 additions & 5 deletions blimp/engine/common/blimp_browser_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ class BlimpBrowserContext : public content::BrowserContext {
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::PermissionManager* GetPermissionManager() override;
content::BackgroundSyncController* GetBackgroundSyncController() override;

// The content of |protocol_handlers| is swapped into the returned instance.
// Caller should take a reference to the returned instance via scoped_refptr.
const scoped_refptr<BlimpURLRequestContextGetter>& CreateRequestContext(
net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors);
content::URLRequestInterceptorScopedVector request_interceptors) override;

private:
// Performs initialization of the BlimpBrowserContext while IO is still
Expand Down
23 changes: 0 additions & 23 deletions chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1087,29 +1087,6 @@ bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) const {
return webui::LogWebUIUrl(web_ui_url);
}

net::URLRequestContextGetter*
ChromeContentBrowserClient::CreateRequestContext(
content::BrowserContext* browser_context,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
Profile* profile = Profile::FromBrowserContext(browser_context);
return profile->CreateRequestContext(protocol_handlers,
std::move(request_interceptors));
}

net::URLRequestContextGetter*
ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
content::BrowserContext* browser_context,
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
Profile* profile = Profile::FromBrowserContext(browser_context);
return profile->CreateRequestContextForStoragePartition(
partition_path, in_memory, protocol_handlers,
std::move(request_interceptors));
}

bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
return ProfileIOData::IsHandledURL(url);
}
Expand Down
10 changes: 0 additions & 10 deletions chrome/browser/chrome_content_browser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,6 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
void GetAdditionalWebUIHostsToIgnoreParititionCheck(
std::vector<std::string>* hosts) override;
bool LogWebUIUrl(const GURL& web_ui_url) const override;
net::URLRequestContextGetter* CreateRequestContext(
content::BrowserContext* browser_context,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
content::BrowserContext* browser_context,
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
bool IsHandledURL(const GURL& url) override;
bool CanCommitURL(content::RenderProcessHost* process_host,
const GURL& url) override;
Expand Down
23 changes: 0 additions & 23 deletions chrome/browser/profiles/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,29 +223,6 @@ class Profile : public content::BrowserContext {
// the user started chrome.
virtual base::Time GetStartTime() const = 0;

// Creates the main net::URLRequestContextGetter that will be returned by
// GetRequestContext(). Should only be called once per ContentBrowserClient
// object. This function is exposed because of the circular dependency where
// GetStoragePartition() is used to retrieve the request context, but creation
// still has to happen in the Profile so the StoragePartition calls
// ContextBrowserClient to call this function.
// TODO(ajwong): Remove once http://crbug.com/159193 is resolved.
virtual net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) = 0;

// Creates the net::URLRequestContextGetter for a StoragePartition. Should
// only be called once per partition_path per ContentBrowserClient object.
// This function is exposed because the request context is retrieved from the
// StoragePartition, but creation still has to happen in the Profile so the
// StoragePartition calls ContextBrowserClient to call this function.
// TODO(ajwong): Remove once http://crbug.com/159193 is resolved.
virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) = 0;

// Returns the last directory that was chosen for uploading or opening a file.
virtual base::FilePath last_selected_directory() = 0;
virtual void set_last_selected_directory(const base::FilePath& path) = 0;
Expand Down
Loading

0 comments on commit 547f267

Please sign in to comment.