Use mojo to connect to BackgroundSyncManager object
Removes the BackgroundSyncProviderThreadProxy class, and the manual hopping from workers to the main thread. The proxy class was passing WebStrings across threads, which aren't thread-safe.
With mojo connections, it lets mojo handle the thread hopping more efficiently, and the mojo structs passed are thread-safe.
Tested using https://jakearchibald.github.io/isserviceworkerready/demos/sync/, as well as new browser tests.
BUG=527601
Committed: https://crrev.com/f993b733666c5c3664889be5c61b65f3f48b222d
Cr-Commit-Position: refs/heads/master@{#354963}
+R michaeln as he is interested in this bug https://codereview.chromium.org/1358063004/diff/40001/content/child/background_sync/background_sync_provider.cc File content/child/background_sync/background_sync_provider.cc (right): https://codereview.chromium.org/1358063004/diff/40001/content/child/background_sync/background_sync_provider.cc#newcode35 content/child/background_sync/background_sync_provider.cc:35: ...
5 years, 2 months ago
(2015-09-28 20:10:05 UTC)
#4
https://codereview.chromium.org/1358063004/diff/40001/content/child/background_sync/background_sync_provider.h File content/child/background_sync/background_sync_provider.h (right): https://codereview.chromium.org/1358063004/diff/40001/content/child/background_sync/background_sync_provider.h#newcode73 content/child/background_sync/background_sync_provider.h:73: void WillStopCurrentWorkerThread() override; I see how worker threads get ...
5 years, 2 months ago
(2015-09-28 20:12:51 UTC)
#5
thnx for cc'ing me https://codereview.chromium.org/1358063004/diff/40001/content/child/background_sync/background_sync_provider.h File content/child/background_sync/background_sync_provider.h (right): https://codereview.chromium.org/1358063004/diff/40001/content/child/background_sync/background_sync_provider.h#newcode73 content/child/background_sync/background_sync_provider.h:73: void WillStopCurrentWorkerThread() override; On 2015/09/28 ...
5 years, 2 months ago
(2015-10-02 00:13:08 UTC)
#6
thnx for cc'ing me
https://codereview.chromium.org/1358063004/diff/40001/content/child/backgroun...
File content/child/background_sync/background_sync_provider.h (right):
https://codereview.chromium.org/1358063004/diff/40001/content/child/backgroun...
content/child/background_sync/background_sync_provider.h:73: void
WillStopCurrentWorkerThread() override;
On 2015/09/28 20:12:51, jkarlin wrote:
> I see how worker threads get killed, thanks to this override. But how does the
> main thread's provider get killed?
For other threadspecific classes like this, the instance for the main thread can
be owned and deleted by the RenderThreadImpl (see IndexedDBDispatcher for
example). In newer classes we usually make a distinction between
GetThreadSpecificInstance() and GetOrCreateThreadSpecificInstance(). The
RenderThreadImpl dtor could test and conditionally delete the main threads
instance. I think we might intentionally leak some of these objects too???
chasej
On 2015/10/02 00:13:08, michaeln wrote: > thnx for cc'ing me > > https://codereview.chromium.org/1358063004/diff/40001/content/child/background_sync/background_sync_provider.h > File ...
5 years, 2 months ago
(2015-10-08 03:25:30 UTC)
#7
On 2015/10/02 00:13:08, michaeln wrote:
> thnx for cc'ing me
>
>
https://codereview.chromium.org/1358063004/diff/40001/content/child/backgroun...
> File content/child/background_sync/background_sync_provider.h (right):
>
>
https://codereview.chromium.org/1358063004/diff/40001/content/child/backgroun...
> content/child/background_sync/background_sync_provider.h:73: void
> WillStopCurrentWorkerThread() override;
> On 2015/09/28 20:12:51, jkarlin wrote:
> > I see how worker threads get killed, thanks to this override. But how does
the
> > main thread's provider get killed?
>
> For other threadspecific classes like this, the instance for the main thread
can
> be owned and deleted by the RenderThreadImpl (see IndexedDBDispatcher for
> example). In newer classes we usually make a distinction between
> GetThreadSpecificInstance() and GetOrCreateThreadSpecificInstance(). The
> RenderThreadImpl dtor could test and conditionally delete the main threads
> instance. I think we might intentionally leak some of these objects too???
I implemented a similar pattern to IndexedDBDispatcher, except in
BlinkPlatformImpl.
That class previously held the main thread instance for the provider anyway.
This is
probably best seen by looking at the diff between original code and latest
patch. Ignore
the intermediate patch (#4), as that was an attempt at a different approach,
which was
then removed.
jkarlin, michaeln please take another look. https://codereview.chromium.org/1358063004/diff/100001/content/child/background_sync/background_sync_provider.cc File content/child/background_sync/background_sync_provider.cc (right): https://codereview.chromium.org/1358063004/diff/100001/content/child/background_sync/background_sync_provider.cc#newcode41 content/child/background_sync/background_sync_provider.cc:41: LazyInstance<ThreadLocalPointer<BackgroundSyncProvider>>::Leaky On 2015/10/08 ...
5 years, 2 months ago
(2015-10-09 14:58:30 UTC)
#10
jkarlin, michaeln please take another look.
https://codereview.chromium.org/1358063004/diff/100001/content/child/backgrou...
File content/child/background_sync/background_sync_provider.cc (right):
https://codereview.chromium.org/1358063004/diff/100001/content/child/backgrou...
content/child/background_sync/background_sync_provider.cc:41:
LazyInstance<ThreadLocalPointer<BackgroundSyncProvider>>::Leaky
On 2015/10/08 15:43:14, jkarlin wrote:
> Why Leaky?
This was copied from the previous implementation of
BackgroundSyncProviderThreadProxy. I've removed it as it's not clear why it
would be needed now (or in the previous implementation). There's hundreds of
usages of LazyInstance<ThreadLocalPointer<>>, many with Leaky, many without.
Based on a random sampling, I couldn't tell why Leaky is used in some cases, but
not others.
https://codereview.chromium.org/1358063004/diff/100001/content/child/backgrou...
content/child/background_sync/background_sync_provider.cc:57: bool
on_main_thread = main_thread_task_runner &&
On 2015/10/08 15:43:14, jkarlin wrote:
> I don't see how main_thread_task_runner can be nullptr. Remove this check and
> DCHECK(main_thread_task_runner) at the start of the method instead.
Done. Also reworked the flag variables to more clearly capture the conditions.
jkarlin
lgtm but see comment https://codereview.chromium.org/1358063004/diff/100001/content/child/background_sync/background_sync_provider.cc File content/child/background_sync/background_sync_provider.cc (right): https://codereview.chromium.org/1358063004/diff/100001/content/child/background_sync/background_sync_provider.cc#newcode41 content/child/background_sync/background_sync_provider.cc:41: LazyInstance<ThreadLocalPointer<BackgroundSyncProvider>>::Leaky On 2015/10/09 14:58:29, chasej ...
5 years, 2 months ago
(2015-10-09 15:13:26 UTC)
#11
lgtm but see comment
https://codereview.chromium.org/1358063004/diff/100001/content/child/backgrou...
File content/child/background_sync/background_sync_provider.cc (right):
https://codereview.chromium.org/1358063004/diff/100001/content/child/backgrou...
content/child/background_sync/background_sync_provider.cc:41:
LazyInstance<ThreadLocalPointer<BackgroundSyncProvider>>::Leaky
On 2015/10/09 14:58:29, chasej wrote:
> On 2015/10/08 15:43:14, jkarlin wrote:
> > Why Leaky?
>
> This was copied from the previous implementation of
> BackgroundSyncProviderThreadProxy. I've removed it as it's not clear why it
> would be needed now (or in the previous implementation). There's hundreds of
> usages of LazyInstance<ThreadLocalPointer<>>, many with Leaky, many without.
> Based on a random sampling, I couldn't tell why Leaky is used in some cases,
but
> not others.
I found this: "NOTE: Both Singleton and base::LazyInstance provide "leaky"
traits to leak the global on shutdown. This is often advisable (except
potentially in library code where the code may be dynamically loaded into
another process's address space or when data needs to be flushed on process
shutdown) in order to not to slow down shutdown. There are valgrind suppressions
for these "leaky" traits." in
https://www.chromium.org/developers/coding-style/important-abstractions-and-d...
Looks like leaky is preferable.
chasej
On 2015/10/09 15:13:26, jkarlin wrote: > lgtm but see comment > > https://codereview.chromium.org/1358063004/diff/100001/content/child/background_sync/background_sync_provider.cc > File ...
5 years, 2 months ago
(2015-10-09 16:00:07 UTC)
#12
On 2015/10/09 15:13:26, jkarlin wrote:
> lgtm but see comment
>
>
https://codereview.chromium.org/1358063004/diff/100001/content/child/backgrou...
> File content/child/background_sync/background_sync_provider.cc (right):
>
>
https://codereview.chromium.org/1358063004/diff/100001/content/child/backgrou...
> content/child/background_sync/background_sync_provider.cc:41:
> LazyInstance<ThreadLocalPointer<BackgroundSyncProvider>>::Leaky
> On 2015/10/09 14:58:29, chasej wrote:
> > On 2015/10/08 15:43:14, jkarlin wrote:
> > > Why Leaky?
> >
> > This was copied from the previous implementation of
> > BackgroundSyncProviderThreadProxy. I've removed it as it's not clear why it
> > would be needed now (or in the previous implementation). There's hundreds
of
> > usages of LazyInstance<ThreadLocalPointer<>>, many with Leaky, many without.
> > Based on a random sampling, I couldn't tell why Leaky is used in some cases,
> but
> > not others.
>
> I found this: "NOTE: Both Singleton and base::LazyInstance provide "leaky"
> traits to leak the global on shutdown. This is often advisable (except
> potentially in library code where the code may be dynamically loaded into
> another process's address space or when data needs to be flushed on process
> shutdown) in order to not to slow down shutdown. There are valgrind
suppressions
> for these "leaky" traits." in
>
https://www.chromium.org/developers/coding-style/important-abstractions-and-d...
>
> Looks like leaky is preferable.
I've added back the Leaky traits.
michaeln, please take a look. I loosely followed the IndexedDBDispatcher example you provided for managing ...
5 years, 2 months ago
(2015-10-13 18:18:25 UTC)
#14
michaeln, please take a look. I loosely followed the IndexedDBDispatcher example
you provided for managing the main thread instance.
jochen, please take a look at content/child/blink_platform_impl.*
michaeln
lgtm 2
5 years, 2 months ago
(2015-10-14 01:24:35 UTC)
#15
davidben, please take a look at content/child/blink_platform_impl.*
5 years, 2 months ago
(2015-10-14 17:24:53 UTC)
#18
davidben, please take a look at content/child/blink_platform_impl.*
davidben
https://codereview.chromium.org/1358063004/diff/160001/content/child/blink_platform_impl.cc File content/child/blink_platform_impl.cc (right): https://codereview.chromium.org/1358063004/diff/160001/content/child/blink_platform_impl.cc#newcode461 content/child/blink_platform_impl.cc:461: main_thread_sync_provider_.reset( This is a scoped_ptr, but the method is ...
5 years, 2 months ago
(2015-10-14 21:52:16 UTC)
#19
davidben, please take another look. For jkarlin, michaeln, the approach for the main thread provider ...
5 years, 2 months ago
(2015-10-15 17:40:27 UTC)
#20
davidben, please take another look.
For jkarlin, michaeln, the approach for the main thread provider instance has
changed from what you reviewed.
https://codereview.chromium.org/1358063004/diff/160001/content/child/blink_pl...
File content/child/blink_platform_impl.cc (right):
https://codereview.chromium.org/1358063004/diff/160001/content/child/blink_pl...
content/child/blink_platform_impl.cc:461: main_thread_sync_provider_.reset(
On 2015/10/14 21:52:16, David Benjamin wrote:
> This is a scoped_ptr, but the method is GetOrCreateBlah. That seems wrong.
What
> if it was a 'Get' and you didn't create a new one? (I realize this is hanging
> off a singleton, but still.)
I see how this approach looks wrong/confusing. I've addressed it in my reply to
your other comment.
https://codereview.chromium.org/1358063004/diff/160001/content/child/blink_pl...
content/child/blink_platform_impl.cc:1217: main_thread_task_runner_.get());
On 2015/10/14 21:52:16, David Benjamin wrote:
> I'm not familiar with Mojo, but why GetOrCreateThreadSpecificInstance and not
> main_thread_sync_provider_? It doesn't look like the latter's even used.
The goal is to have a provider instance for each thread (main and workers), and
let mojo handle all the thread hopping. The creation/access to the provider goes
through GetOrCreate, as that is similar regardless of calling thread type.
However, destruction has to be handled differently for the main thread vs
workers. The main_thread_sync_provider_ was used only to ensure the instance for
the main thread was cleaned up.
There are a number of classes that use some variation of the
ThreadSpecificInstance approach. I've found another class (WebFileSystemImpl),
that uses a more explicit approach to solve this problem. I've copied that
approach, and instead added DeleteThreadSpecificInstance(), which allows removal
of the main_thread_sync_provider_. I think this is better because all
creation/deletion is encapsulated in BackgroundSyncProvider, and
BlinkPlatformImpl now uses symmetric methods for creation and deletion.
davidben
content/child/blink_platform_impl.* lgtm. I didn't look at the other files carefully since I wasn't asked to. ...
5 years, 2 months ago
(2015-10-15 18:16:17 UTC)
#21
content/child/blink_platform_impl.* lgtm. I didn't look at the other files
carefully since I wasn't asked to.
This approach for lifetimes seems honestly rather backwards to me (thread-local
storage is just another word for global variable) and BlinkPlatformImpl now
becomes even more global, but it seems that ship has sailed. This file is now
full of ThreadSpecificInstances for things.
jkarlin
lgtm though I preferred the approach from PS9.
5 years, 2 months ago
(2015-10-15 19:06:21 UTC)
#22
lgtm though I preferred the approach from PS9.
davidben
On 2015/10/15 19:06:21, jkarlin wrote: > lgtm though I preferred the approach from PS9. Perhaps ...
5 years, 2 months ago
(2015-10-15 19:11:39 UTC)
#23
On 2015/10/15 19:06:21, jkarlin wrote:
> lgtm though I preferred the approach from PS9.
Perhaps mimic BlinkPlatformImpl::permissionClient? So the main thread one is
just explicitly owned by BlinkPlatformImpl with no bells or whistles. Then if
IsMainThread doesn't check out, you can do something that mucks with
thread-locals and is annoyingly global and implicitly destroyed by being a
WorkerObserver and stuff.
jkarlin
On 2015/10/15 19:11:39, David Benjamin wrote: > On 2015/10/15 19:06:21, jkarlin wrote: > > lgtm ...
5 years, 2 months ago
(2015-10-15 20:36:07 UTC)
#24
On 2015/10/15 19:11:39, David Benjamin wrote:
> On 2015/10/15 19:06:21, jkarlin wrote:
> > lgtm though I preferred the approach from PS9.
>
> Perhaps mimic BlinkPlatformImpl::permissionClient? So the main thread one is
> just explicitly owned by BlinkPlatformImpl with no bells or whistles. Then if
> IsMainThread doesn't check out, you can do something that mucks with
> thread-locals and is annoyingly global and implicitly destroyed by being a
> WorkerObserver and stuff.
sgtm
chasej
On 2015/10/15 20:36:07, jkarlin wrote: > On 2015/10/15 19:11:39, David Benjamin wrote: > > On ...
5 years, 2 months ago
(2015-10-16 16:06:49 UTC)
#25
On 2015/10/15 20:36:07, jkarlin wrote:
> On 2015/10/15 19:11:39, David Benjamin wrote:
> > On 2015/10/15 19:06:21, jkarlin wrote:
> > > lgtm though I preferred the approach from PS9.
> >
> > Perhaps mimic BlinkPlatformImpl::permissionClient? So the main thread one is
> > just explicitly owned by BlinkPlatformImpl with no bells or whistles. Then
if
> > IsMainThread doesn't check out, you can do something that mucks with
> > thread-locals and is annoyingly global and implicitly destroyed by being a
> > WorkerObserver and stuff.
>
> sgtm
I've implemented the suggested approach to have BlinkPlatformImpl explicitly
own/use the main thread provider.
davidben, jkarlin, please review.
jkarlin
slgtm, thanks!
5 years, 2 months ago
(2015-10-16 16:10:09 UTC)
#26
slgtm, thanks!
jkarlin
I believe that David is out for a bit. I've reviewed the small changes that ...
5 years, 2 months ago
(2015-10-19 11:55:26 UTC)
#27
I believe that David is out for a bit. I've reviewed the small changes that
David recommended and he previously l-g-t-m'd. I'd say feel free to land.
chasej
The CQ bit was checked by chasej@chromium.org
5 years, 2 months ago
(2015-10-19 13:46:38 UTC)
#28
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1358063004/220001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1358063004/220001
5 years, 2 months ago
(2015-10-19 13:46:52 UTC)
#30
Try jobs failed on following builders: cast_shell_linux on tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/cast_shell_linux/builds/68208)
5 years, 2 months ago
(2015-10-19 14:11:44 UTC)
#32
jkarlin, michaeln, please take a look. A recent CL from jkarlin (1398633004) broke the browser ...
5 years, 2 months ago
(2015-10-19 21:04:33 UTC)
#34
jkarlin, michaeln, please take a look.
A recent CL from jkarlin (1398633004) broke the browser tests added in this CL.
I fixed IsSameOriginWindowProviderHost() to avoid crashing when checking
provider hosts (if any hosts had type SERVICE_WORKER_PROVIDER_FOR_CONTROLLER).
jkarlin
On 2015/10/19 21:04:33, chasej wrote: > jkarlin, michaeln, please take a look. > > A ...
5 years, 2 months ago
(2015-10-19 22:33:52 UTC)
#35
On 2015/10/19 21:04:33, chasej wrote:
> jkarlin, michaeln, please take a look.
>
> A recent CL from jkarlin (1398633004) broke the browser tests added in this
CL.
> I fixed IsSameOriginWindowProviderHost() to avoid crashing when checking
> provider hosts (if any hosts had type SERVICE_WORKER_PROVIDER_FOR_CONTROLLER).
Sorry about that! I have a CL up to fix it as well but will delete it since you
have it here.
SLGTM
michaeln
still lgtm w
5 years, 2 months ago
(2015-10-19 23:28:45 UTC)
#36
still lgtm w
chasej
The CQ bit was checked by chasej@chromium.org
5 years, 2 months ago
(2015-10-20 02:47:24 UTC)
#37
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1358063004/260001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1358063004/260001
5 years, 2 months ago
(2015-10-20 02:47:33 UTC)
#39
Issue 1358063004: Use mojo to connect to BackgroundSyncManager object
(Closed)
Created 5 years, 3 months ago by chasej
Modified 5 years, 2 months ago
Reviewers: jkarlin, michaeln
Base URL: https://chromium.googlesource.com/chromium/src.git@master
Comments: 18