Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1013)

Issue 1771283002: service worker: Observe when resource context is shutting down (Closed)

Created:
4 years, 9 months ago by falken
Modified:
4 years, 9 months ago
Reviewers:
kinuko, michaeln, mmenke, horo
CC:
chromium-reviews, jsbell+serviceworker_chromium.org, wjmaclean, tzik, serviceworker-reviews, jam, kinuko+serviceworker, nhiroki, darin-cc_chromium.org, horo+watch_chromium.org, kinuko+watch, blink-worker-reviews_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

service worker: Observe when resource context is shutting down Make SWContextWrapper use OnContextShuttingDown, so it can clear its ResourceContext on the IO thread then. Before it would wait until StoragePartition destruction calls Shutdown() which then posts a task on the IO thread, which can be too late (see bug). BUG=587621 Committed: https://crrev.com/a8bee310d105d8167d39a9d4d496ba49c823576d Cr-Commit-Position: refs/heads/master@{#380349}

Patch Set 1 #

Total comments: 6

Patch Set 2 : rebase #

Patch Set 3 : name change #

Patch Set 4 : fix unittests #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+40 lines, -11 lines) Patch
M content/browser/service_worker/service_worker_context_wrapper.h View 1 2 3 7 chunks +14 lines, -3 lines 0 comments Download
M content/browser/service_worker/service_worker_context_wrapper.cc View 1 2 3 2 chunks +23 lines, -6 lines 2 comments Download
M content/browser/storage_partition_impl_map.cc View 1 2 1 chunk +3 lines, -2 lines 0 comments Download

Messages

Total messages: 24 (6 generated)
falken
https://codereview.chromium.org/1771283002/diff/1/content/browser/service_worker/service_worker_context_wrapper.cc File content/browser/service_worker/service_worker_context_wrapper.cc (right): https://codereview.chromium.org/1771283002/diff/1/content/browser/service_worker/service_worker_context_wrapper.cc#newcode143 content/browser/service_worker/service_worker_context_wrapper.cc:143: DCHECK_CURRENTLY_ON(BrowserThread::IO); mmenke: URLRequestContextGetterObserver documentation says "network thread" but it ...
4 years, 9 months ago (2016-03-08 09:59:11 UTC) #2
michaeln
https://codereview.chromium.org/1771283002/diff/1/content/browser/service_worker/service_worker_context_wrapper.cc File content/browser/service_worker/service_worker_context_wrapper.cc (right): https://codereview.chromium.org/1771283002/diff/1/content/browser/service_worker/service_worker_context_wrapper.cc#newcode133 content/browser/service_worker/service_worker_context_wrapper.cc:133: void ServiceWorkerContextWrapper::InitializeOnIO( naming nit driveby: since there already are ...
4 years, 9 months ago (2016-03-08 22:04:27 UTC) #3
mmenke
This fix LGTM. Long term, I'd really like to see a careful thinking of StoragePartition ...
4 years, 9 months ago (2016-03-09 18:33:43 UTC) #4
falken
Thanks all. +kinuko for content/browser/storage_partition_impl_map.cc https://codereview.chromium.org/1771283002/diff/1/content/browser/service_worker/service_worker_context_wrapper.cc File content/browser/service_worker/service_worker_context_wrapper.cc (right): https://codereview.chromium.org/1771283002/diff/1/content/browser/service_worker/service_worker_context_wrapper.cc#newcode133 content/browser/service_worker/service_worker_context_wrapper.cc:133: void ServiceWorkerContextWrapper::InitializeOnIO( On 2016/03/08 ...
4 years, 9 months ago (2016-03-10 01:25:35 UTC) #6
kinuko
lgtm
4 years, 9 months ago (2016-03-10 03:11:56 UTC) #7
falken
Oh those try job failures were real. Added an if check since URLResourceContextGetter is null ...
4 years, 9 months ago (2016-03-10 03:43:29 UTC) #8
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1771283002/60001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1771283002/60001
4 years, 9 months ago (2016-03-10 03:44:09 UTC) #11
commit-bot: I haz the power
Committed patchset #4 (id:60001)
4 years, 9 months ago (2016-03-10 05:46:56 UTC) #12
commit-bot: I haz the power
Patchset 4 (id:??) landed as https://crrev.com/a8bee310d105d8167d39a9d4d496ba49c823576d Cr-Commit-Position: refs/heads/master@{#380349}
4 years, 9 months ago (2016-03-10 05:48:43 UTC) #14
horo
lgtm
4 years, 9 months ago (2016-03-10 06:50:36 UTC) #15
michaeln
sorry for the late comment https://codereview.chromium.org/1771283002/diff/60001/content/browser/service_worker/service_worker_context_wrapper.cc File content/browser/service_worker/service_worker_context_wrapper.cc (right): https://codereview.chromium.org/1771283002/diff/60001/content/browser/service_worker/service_worker_context_wrapper.cc#newcode146 content/browser/service_worker/service_worker_context_wrapper.cc:146: request_context_getter_->RemoveObserver(this); You mentioned this ...
4 years, 9 months ago (2016-03-10 21:15:53 UTC) #17
mmenke
https://codereview.chromium.org/1771283002/diff/60001/content/browser/service_worker/service_worker_context_wrapper.cc File content/browser/service_worker/service_worker_context_wrapper.cc (right): https://codereview.chromium.org/1771283002/diff/60001/content/browser/service_worker/service_worker_context_wrapper.cc#newcode146 content/browser/service_worker/service_worker_context_wrapper.cc:146: request_context_getter_->RemoveObserver(this); On 2016/03/10 21:15:53, michaeln wrote: > You mentioned ...
4 years, 9 months ago (2016-03-10 21:20:51 UTC) #18
michaeln
> > You mentioned this isn't called on ContentShell. > > > > I think ...
4 years, 9 months ago (2016-03-10 22:21:46 UTC) #19
mmenke
On 2016/03/10 22:21:46, michaeln wrote: > > > You mentioned this isn't called on ContentShell. ...
4 years, 9 months ago (2016-03-10 22:33:08 UTC) #20
mmenke
On 2016/03/10 21:20:51, mmenke wrote: > https://codereview.chromium.org/1771283002/diff/60001/content/browser/service_worker/service_worker_context_wrapper.cc > File content/browser/service_worker/service_worker_context_wrapper.cc (right): > > https://codereview.chromium.org/1771283002/diff/60001/content/browser/service_worker/service_worker_context_wrapper.cc#newcode146 > ...
4 years, 9 months ago (2016-03-10 22:37:58 UTC) #21
michaeln
> Perhaps being a bit strong here...If there were motivated by URLFetchers, I > wouldn't ...
4 years, 9 months ago (2016-03-10 23:04:41 UTC) #22
mmenke
On 2016/03/10 23:04:41, michaeln wrote: > > Perhaps being a bit strong here...If there were ...
4 years, 9 months ago (2016-03-10 23:30:06 UTC) #23
falken
4 years, 9 months ago (2016-03-11 03:43:18 UTC) #24
Message was sent while issue was closed.
On 2016/03/10 23:30:06, mmenke wrote:
> On 2016/03/10 23:04:41, michaeln wrote:
> > > Perhaps being a bit strong here...If there were motivated by URLFetchers,
I
> > > wouldn't be too concerned about going in this direction.  In this
particular
> > > case, I don't think this is really what we want to be relying on, long
term.
> > 
> > Last word on this... didn't intend to stir up anything...
> > 
> > Forgot what classes we're talking about in particular and look at what this
CL
> > is depending on as coded. Depending on that is folly. I'm saying change that
> > ever so slightly to not crash if OnBWentByeBye() doesn't happen (as falken
> > suggested is the case in at least some cases in at least one of our many
build
> > targets). Ymmv.
> > 
> > class A {
> >   ~A() {
> >     // Lets just assume OnBWentByeBye was called by complex far removed
code.
> >   }
> > 
> >   void setB(B* b) {
> >     b_ = b;
> >     b_ ->Observe(this);
> >   }
> > 
> >   void OnBWentByeBye() {
> >     b_ ->RemoveObserver(this)
> >     b_ = null;
> >   }
> > };
> > 
> > class B {
> >   Observe(...);
> >   RemoveObserver(...);
> > };
> 
> The thing is....Very little depends on the URLRequestContextGetter, almost
> everything depends on the Profile, the ProfileIOData, or the RequestContext.
> 
> So it's more like:
> 
> class A {
>   void setB(B* b) {
>     b_ = b;
>     b_->c()->Observe(this);
>   }
> 
>   void OnClassCWentByeBye() {
>     b_->c()->RemoveObserver(this)
>     b_ = null;
>   }
> }

Thanks all. I need to change the patch a little anyway. The membots are
complaining of a leak on unit_tests
<https://bugs.chromium.org/p/chromium/issues/detail?id=593913>. It looks like
request_context_getter_ must be released in the IO thread in ShutdownOnIO. I
guess relying on it being destroyed in the dtor is too late.

I think calling RemoveObserver in ShutdownOnIO as Michael suggests is also good
(or needed?) for cleanup. Although the class dependencies may be incorrect, it's
the current reality this class has to deal with, and it's just a small amount of
code.

Powered by Google App Engine
This is Rietveld 408576698