-
Notifications
You must be signed in to change notification settings - Fork 965
Moves backup results function to service workers #8493
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
Conversation
38d4977
to
e257f91
Compare
const GURL& script_url); | ||
|
||
private: | ||
base::ThreadLocalPointer<std::vector<std::unique_ptr<BraveSearchJSHandler>>> |
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 is this a thread local?
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.
can we add a comment explaining that WillEvaluateServiceWorkerOnWorkerThread
and WillDestroyServiceWorkerContextOnWorkerThread
are called from the worker thread so this makes accessing the list thread safe?
int64_t service_worker_version_id, | ||
const GURL& service_worker_scope, | ||
const GURL& script_url) { | ||
brave_search::BraveSearchSWHolder::GetInstance() |
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 isn't this class just owned by BraveContentRendererClient?
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.
changed it to be a member
void PopulateBinderMap(ServiceWorkerHost* host, mojo::BinderMap* map) { | ||
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId()); | ||
PopulateServiceWorkerBinders(host, map); | ||
+ PopulateServiceWorkerBindersBrave(host, map); |
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 not an extensible patch, it should BRAVE_POPULATE_BINDER_MAP
|
||
class BraveSearchJSHandler; | ||
|
||
class BraveSearchSWHolder { |
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 name is a bit confusing to me, maybe BraveSearchServiceWorkerHandler? Using JS
is ok because that's used more commonly than Javascript, but SW
is not immediately obvious and in general abbreviations should be avoided unless it's to follow existing naming conventions, but in this case the convention is to use ServiceWorker
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 will rename it in a follow up with tests
@@ -1,29 +1,27 @@ | |||
# common includes which can help minimize patches for | |||
# src/third_party/blink/renderer/core/BUILD.gn | |||
brave_blink_renderer_core_visibility = [ | |||
"//brave/third_party/blink/renderer/*" | |||
"//brave/third_party/blink/renderer/*", | |||
"//brave/components/brave_search/renderer:renderer", |
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 is this being added to blink visibility? Is this maybe leftover from previous patching?
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.
redid the mojo and removed it from here
@@ -6,7 +6,7 @@ | |||
#include "brave/renderer/brave_content_renderer_client.h" | |||
|
|||
#include "base/feature_list.h" | |||
#include "brave/components/brave_search/renderer/brave_search_render_frame_observer.h" | |||
#include "brave/components/brave_search/renderer/brave_search_sw_holder.h" |
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.
missing a dep for this in brave_chrome_renderer_public_deps
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.
brave_chrome_renderer_public_deps = [
"//brave/components/brave_search/renderer",
if (observer) | ||
observer->RunScriptsAtDocumentStart(); | ||
|
||
ChromeContentRendererClient::RunScriptsAtDocumentStart(render_frame); | ||
} | ||
|
||
void BraveContentRendererClient::WillEvaluateServiceWorkerOnWorkerThread( | ||
blink::WebServiceWorkerContextProxy* context_proxy, |
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.
missing includes for this and GURL which are both forward decls in the header
v8::Local<v8::Context> context) { | ||
v8::Isolate* isolate = blink::MainThreadIsolate(); | ||
v8::Local<v8::Context> BraveSearchJSHandler::Context() { | ||
return v8::Local<v8::Context>::New(isolate_, *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.
this could potentially be null if it is called before AddJavaScriptObject
. You can pass the v8::Context into the BraveSearchJSHandler
constructor because you have it in WillEvaluateServiceWorkerOnWorkerThread
v8::Local<v8::Object> javascript_object, | ||
const std::string& name, | ||
const base::RepeatingCallback<Sig>& callback) { | ||
v8::Local<v8::Context> context = isolate->GetCurrentContext(); | ||
v8::Local<v8::Context> context = isolate_->GetCurrentContext(); |
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.
you already have the context in context_
return; | ||
|
||
std::unique_ptr<BraveSearchJSHandler> js_handler(new BraveSearchJSHandler()); | ||
js_handler->AddJavaScriptObject(v8_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.
just pass the v8_context into the BraveSearchJSHandler
as mentioned above
v8::HandleScope handle_scope(isolate); | ||
v8::Local<v8::Context> context = context_old->Get(isolate); | ||
v8::HandleScope handle_scope(isolate_); | ||
v8::Local<v8::Context> context = context_->Get(isolate_); | ||
v8::Context::Scope context_scope(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.
I think you also want v8::MicrotasksScope microtasks(isolate(), v8::MicrotasksScope::kDoNotRunMicrotasks);
here.
// Brave-specific: allows the embedder to modify the referrer string | ||
// according to user preferences. | ||
#define BRAVE_CONTENT_BROWSER_CLIENT_H \ | ||
virtual void MaybeHideReferrer( \ | ||
BrowserContext* browser_context, const GURL& request_url, \ | ||
const GURL& document_url, blink::mojom::ReferrerPtr* referrer) {} \ | ||
virtual std::string GetEffectiveUserAgent(BrowserContext* browser_context, \ | ||
const GURL& url); | ||
const GURL& url); \ | ||
virtual void RegisterBrowserInterfaceBindersForHost( \ |
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 isn't needed anymore
const std::string& response); | ||
|
||
content::RenderFrame* render_frame_; | ||
blink::ThreadSafeBrowserInterfaceBrokerProxy* broker_; |
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.
// not owned
@@ -46,6 +47,8 @@ void BraveContentRendererClient::RenderThreadStarted() { | |||
|
|||
brave_observer_ = std::make_unique<BraveRenderThreadObserver>(); | |||
content::RenderThread::Get()->AddObserver(brave_observer_.get()); | |||
brave_search_sw_holder_.InitBrowserInterfaceBrokerProxy( |
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 guess I was thinking this would be a unique_ptr and you would initialize it here with browser_interface_broker_
, but this is ok too. I would, however, change the name because Init
has special meaning for mojo interface so maybe just set_browser_interface_broker
?
int64_t service_worker_version_id, | ||
const GURL& service_worker_scope, | ||
const GURL& script_url) { | ||
if (!service_worker_scope.is_valid() || |
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.
we should also DCHECK broker_
here if we're not initializing this object with it
@@ -1,29 +1,25 @@ | |||
# common includes which can help minimize patches for |
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.
you can probably just drop these changes? Also fine if you leave them I guess, but you don't have to fix the lint errors if you don't touch it :)
Moves backup results function to service workers
Resolves brave/brave-browser#15217
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
,npm run lint
,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan: