New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: create request context from network context #14656
Conversation
50c448e
to
2ce9271
Compare
This PR is ready for review, there are some minor cleanups that will follow up separately. Its easier to review if looked at individual commits, after this change all network code now live under one place in |
7d04f1f
to
440296b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only a few commits in, but here's what i got so far
content::BrowserContext::GetDefaultStoragePartition(browser_context_) | ||
->GetCookieManagerForBrowserProcess(); | ||
if (!cookie_manager) | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a noisier error? What does a null return from GetCookieManagerForBrowserProcess indicate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cookie manager should be initialized whenever a network context is initialized, if there is none then there should be no reason to observe cookie changes in this context. But I can't think of situations where this can happen though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it should be a CHECK
then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated it to a CHECK
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | ||
|
||
binding_.Close(); | ||
StartListening(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the cookie service goes down, will this result in us spinning very quickly trying to reconnect to a service that isn't coming back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the situation needs to be handled, but its not a service yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand—what isn't a service yet?
atom/browser/atom_browser_context.cc
Outdated
return WrapRefCounted(browser_context_map_[key].get()); | ||
auto* browser_context = browser_context_map_[key].get(); | ||
if (browser_context) | ||
return browser_context; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to WrapRefCounted
any more?
@@ -76,6 +74,7 @@ network::mojom::NetworkContextParamsPtr CreateDefaultNetworkContextParams( | |||
network_context_params->accept_language = | |||
net::HttpUtil::GenerateAcceptLanguageHeader( | |||
brightray::BrowserClient::Get()->GetApplicationLocale()); | |||
network_context_params->allow_gssapi_library_load = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this new functionality that we weren't previously enabling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope this has been a default parameter on the HttpAuthHandlerFactory
creation and gets enabled indirectly with the old interface, I am just explicitly specifying for this interface.
job_factory->SetProtocolHandler(url::kAboutScheme, | ||
std::make_unique<AboutProtocolHandler>()); | ||
job_factory->SetProtocolHandler(url::kDataScheme, | ||
std::unique_ptr<net::DataProtocolHandler>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why handle these protocols here rather than allowing the network context to handle them (presuming that's what enable_data_url_support = true
does)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because of the protocol module we provide https://github.com/electron/electron/blob/master/docs/api/protocol.md, to intercept some of the standard schemes with atom/browser/net/atom_url_request_job_factory
we need to establish these handlers explicitly so that they can replaced dynamically.
#if !BUILDFLAG(DISABLE_FTP_SUPPORT) | ||
auto* host_resolver = url_request_context->host_resolver(); | ||
job_factory->SetProtocolHandler( | ||
url::kFtpScheme, net::FtpProtocolHandler::Create(host_resolver)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the host_resolver
guaranteed to have a longer lifetime than the job_factory
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a rough check of the code and everything seems to be fine.
atom/browser/api/atom_api_net_log.cc
Outdated
} | ||
|
||
void NetLog::StopLogging(mate::Arguments* args) { | ||
base::OnceClosure callback; | ||
args->GetNext(&callback); | ||
args->GetNext(&stop_callback_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this gets called twice quickly, then only one of the callbacks will get called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's by design with the OnceClosure but I agree it could be problematic if used wrongly.
Maybe a DCHECK(stop_callback_.is_null());
at the front of the func?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have updated to queue up the callbacks when the logging is not stopped 5fa25ad
spec/api-session-spec.js
Outdated
}) | ||
server.listen(0, '127.0.0.1', () => { | ||
const config = { pacScript: `http://127.0.0.1:${server.address().port}` } | ||
session.defaultSession.setProxy(config, () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need to reset this back to the default config after the test? (or better, use a fresh session?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use a custom session.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM.
atom/browser/api/atom_api_net_log.cc
Outdated
} | ||
|
||
void NetLog::StopLogging(mate::Arguments* args) { | ||
base::OnceClosure callback; | ||
args->GetNext(&callback); | ||
args->GetNext(&stop_callback_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's by design with the OnceClosure but I agree it could be problematic if used wrongly.
Maybe a DCHECK(stop_callback_.is_null());
at the front of the func?
atom/browser/api/atom_api_net_log.h
Outdated
@@ -22,15 +27,20 @@ class NetLog : public mate::Wrappable<NetLog> { | |||
|
|||
void StartLogging(mate::Arguments* args); | |||
bool IsCurrentlyLogging(); | |||
base::FilePath::StringType GetCurrentlyLoggingPath(); | |||
std::string GetCurrentlyLoggingPath(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) this could be a const method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
atom/browser/api/atom_api_net_log.cc
Outdated
net_log_->StopDynamicLogging(std::move(callback)); | ||
const auto* current_log_state = | ||
state.FindKeyOfType("state", base::Value::Type::STRING); | ||
if (current_log_state && current_log_state->GetString() == "STOPPING_LOG") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor, DRY) this sequence is similar to the IsCurrentlyLogging
impl. Might be better to have a std::string GetLoggingState() const
that does this and returns the GetString() so that both places can use that code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
atom/browser/atom_browser_client.cc
Outdated
network::mojom::NetworkContextPtr AtomBrowserClient::CreateNetworkContext( | ||
content::BrowserContext* browser_context, | ||
bool in_memory, | ||
const base::FilePath& relative_partition_path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor) As per style guide, I think in_memory and relative_partition_path should be commented out as unused, e.g.
content::BrowserContext* browser_context,
bool /*in_memory*/,
const base::FilePath& /*relative_partition_path*/) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is only required when the parameter names are omitted which is not in this case ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this comment -- if the name is omitted, then by definition the name can't be commented out? 😃
Unused variables which are obvious from context can have their names omitted entirely, e.g. class Foo { Foo(Foo&&); };
but those not obvious from context should have a name commented out, e.g. void Circle::Rotate(double /*radians*/) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm seems like I misread the style guide, will update them. Thanks!
// for the global requests, like the cert fetchers below and | ||
// geolocation requests. | ||
// 3) There is also ongoing work in upstream which will eventually allow | ||
// localizing these global fetchers to their own URLRequestContexts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
the breadcrumbs & rationale are appreciated
440296b
to
d27352d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 !
"includes": [28750], | ||
}, | ||
+ "electron/electron_resources.grd": { | ||
+ "includes": [31750], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the fact that the number should be greater than 31000, no special reason for this number, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup that is the only reason.
|
||
net_log_->StopDynamicLogging(std::move(callback)); | ||
if (stop_callback_queue_.empty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't matter right now, because we're not doing much here; but ☝️ should be checked inside the if
block 👇 in the stop logging case or it can be removed.
protocol_interceptors_.clear(); | ||
} | ||
top_job_factory_->Chain(std::move(inner_job_factory)); | ||
main_request_context_->set_job_factory(top_job_factory_.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ownership is transferred here. How will the lifetimes work for top_job_factory_
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not transferred, URLRequestContext
only has weak references to its members, any reason to think the ownership was transferred here ?
atom/browser/api/atom_api_net_log.cc
Outdated
return current_log_path->GetString(); | ||
} | ||
|
||
return std::string(); | ||
} | ||
|
||
void NetLog::StopLogging(mate::Arguments* args) { | ||
base::OnceClosure callback; | ||
args->GetNext(&callback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if the callback
not provided case is taken care of here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its actually checked on the js side atom/browser/lib/net-log.js
, could have moved that code here but its better to do that check on js side avoiding an extra js<->c++ type conversion
std::unique_ptr<content::ZoomLevelDelegate> | ||
AtomBrowserContext::CreateZoomLevelDelegate( | ||
const base::FilePath& partition_path) { | ||
if (!IsOffTheRecord()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my understanding, what does this if condition mean, and why do we need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsOffTheRecord
is the incognito mode in Electron, we don't persist any of the user preferences to file system when the app exits. Users will get this mode when they create a temporary partition for a session.
d27352d
to
915cd4a
Compare
915cd4a
to
cd58f06
Compare
No Release Notes |
* [ci skip] refactor: create request context from network context * [ci skip] refactor: subscribe to mojo cookiemanager for cookie changes * [ci skip] refactor: manage the lifetime of custom URLRequestJobFactory * refactor: use OOP mojo proxy resolver * revert: add support for kIgnoreCertificateErrorsSPKIList * build: provide service manifest overlays for content services * chore: gn format * fix: log-net-log switch not working as expected * spec: verify proxy settings are respected from pac script with session.setProxy * chore: use chrome constants where possible * fix: initialize request context for global cert fetcher * refactor: fix destruction of request context getters * spec: use custom session for proxy tests * fix: queue up additional stop callbacks while net log is being stopped * fix: Add CHECK for cookie manager retrieval * chore: add helper to retrieve logging state for net log module * fix: ui::ResourceBundle::GetRawDataResourceForScale => GetRawDataResource * style: comment unused parameters * build: move //components/certificate_transparency deps from //brightray * chore: update gritsettings_resource_ids patch * chore: update api for chromium 68 * fix: net log instance is now a property of session
Hey guys! Thanks again. |
@tallev266 3.1.0-beta.x has this fix and also 4.x release line. |
@deepak1556 - Thanks! I guess we'll wait for the RC then |
@deepak1556 #14411 is fixed in 3.1? |
already in v3.1.0-beta.2 or in next release? |
Description of Change
Create request context using the network service apis, the service is disabled and will simply be created on the io thread in the browser process. So there should be no change in behavior of these apis. This change is a prerequisite to use the mojo proxy resolver and cookie change notifiers.
Fixes #14441
Fixes #13829
Fixes corrupted net log generation in 3.x and above
Checklist
npm test
passesRelease Notes
Notes: no-notes