diff options
author | kalman <kalman@chromium.org> | 2015-09-02 11:38:56 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-02 18:40:17 +0000 |
commit | 27acdc49c530aead33a2f8cc273c01cc206822c7 (patch) | |
tree | 05d6648e941c4ed2588395f711b259fe68ecda06 /extensions/renderer | |
parent | b26f03db16a4752572e136d3c531234bfa45eb63 (diff) | |
download | chromium_src-27acdc49c530aead33a2f8cc273c01cc206822c7.zip chromium_src-27acdc49c530aead33a2f8cc273c01cc206822c7.tar.gz chromium_src-27acdc49c530aead33a2f8cc273c01cc206822c7.tar.bz2 |
Revert of Pass the v8::Context through the willDestroyServiceWorkerContextOnWorkerThread event. (patchset #3 id:60001 of https://codereview.chromium.org/1318643002/ )
Reason for revert:
Canary is frequently crashing, likely due to threading issues with this patch.
Original issue's description:
> Pass the v8::Context through the willDestroyServiceWorkerContextOnWorkerThread event.
>
> Currently it only passes a URL, and this isn't enough to uniquely identify the worker.
> Update extension's dispatcher.cc to use the context.
>
> BUG=501569, 525965
> R=kinuko@chromium.org, thestig@chromium.org
>
> Committed: https://crrev.com/4a0bb926cb1d83fab27b6ad866c04ba481f66268
> Cr-Commit-Position: refs/heads/master@{#346424}
TBR=thestig@chromium.org,kinuko@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=501569, 525965
Review URL: https://codereview.chromium.org/1319603003
Cr-Commit-Position: refs/heads/master@{#346978}
Diffstat (limited to 'extensions/renderer')
-rw-r--r-- | extensions/renderer/dispatcher.cc | 67 | ||||
-rw-r--r-- | extensions/renderer/dispatcher.h | 4 |
2 files changed, 14 insertions, 57 deletions
diff --git a/extensions/renderer/dispatcher.cc b/extensions/renderer/dispatcher.cc index 1203e6f..34324e2 100644 --- a/extensions/renderer/dispatcher.cc +++ b/extensions/renderer/dispatcher.cc @@ -197,41 +197,21 @@ class ServiceWorkerScriptContextSet { ServiceWorkerScriptContextSet() {} ~ServiceWorkerScriptContextSet() {} - void Insert(scoped_ptr<ScriptContext> context) { + void Insert(const GURL& url, scoped_ptr<ScriptContext> context) { base::AutoLock lock(lock_); - CHECK(FindScriptContext(context->v8_context()) == contexts_.end()); - contexts_.push_back(context.Pass()); + CHECK(script_contexts_.find(url) == script_contexts_.end()); + script_contexts_.set(url, context.Pass()); } - void Remove(v8::Local<v8::Context> v8_context) { + void Remove(const GURL& url) { base::AutoLock lock(lock_); - ScriptContextList::iterator context_it = FindScriptContext(v8_context); - // TODO(kalman): It would be good to CHECK(context_it != contexts_.end()) - // here, but service workers can be started before the extension has been - // installed. See the length comment explaining why this happens, and - // how to solve it, in DidInitializeServiceWorkerContextOnWorkerThread. - // This does need to be fixed eventually, but for now, at least don't crash. - if (context_it == contexts_.end()) - return; - (*context_it)->Invalidate(); - contexts_.erase(context_it); + scoped_ptr<ScriptContext> context = script_contexts_.take_and_erase(url); + CHECK(context); + context->Invalidate(); } private: - using ScriptContextList = ScopedVector<ScriptContext>; - - // Returns an iterator to the ScriptContext associated with |v8_context|, or - // contexts_.end() if not found. - ScriptContextList::iterator FindScriptContext( - v8::Local<v8::Context> v8_context) { - for (auto it = contexts_.begin(); it != contexts_.end(); ++it) { - if ((*it)->v8_context() == v8_context) - return it; - } - return contexts_.end(); - } - - ScriptContextList contexts_; + base::ScopedPtrMap<GURL, scoped_ptr<ScriptContext>> script_contexts_; mutable base::Lock lock_; @@ -403,35 +383,15 @@ void Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( const Extension* extension = RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(url); - if (!extension) { - // TODO(kalman): This is no good. Instead we need to either: - // - // - Hold onto the v8::Context and create the ScriptContext and install - // our bindings when this extension is loaded. - // - Deal with there being an extension ID (url.host()) but no - // extension associated with it, then document that getBackgroundClient - // may fail if the extension hasn't loaded yet. - // - // The former is safer, but is unfriendly to caching (e.g. session restore). - // It seems to contradict the service worker idiom. - // - // The latter is friendly to caching, but running extension code without an - // installed extension makes me nervous, and means that we won't be able to - // expose arbitrary (i.e. capability-checked) extension APIs to service - // workers. We will probably need to relax some assertions - we just need - // to find them. - // - // Perhaps this could be solved with our own event on the service worker - // saying that an extension is ready, and documenting that extension APIs - // won't work before that event has fired? + if (!extension) return; - } ScriptContext* context = new ScriptContext( v8_context, nullptr, extension, Feature::SERVICE_WORKER_CONTEXT, extension, Feature::SERVICE_WORKER_CONTEXT); - g_service_worker_script_context_set.Get().Insert(make_scoped_ptr(context)); + g_service_worker_script_context_set.Get().Insert(url, + make_scoped_ptr(context)); v8::Isolate* isolate = context->isolate(); @@ -478,10 +438,9 @@ void Dispatcher::WillReleaseScriptContext( // static void Dispatcher::WillDestroyServiceWorkerContextOnWorkerThread( - v8::Local<v8::Context> v8_context, const GURL& url) { - if (url.SchemeIs(kExtensionScheme)) - g_service_worker_script_context_set.Get().Remove(v8_context); + if (RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(url)) + g_service_worker_script_context_set.Get().Remove(url); } void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { diff --git a/extensions/renderer/dispatcher.h b/extensions/renderer/dispatcher.h index fb1714d..428efd7 100644 --- a/extensions/renderer/dispatcher.h +++ b/extensions/renderer/dispatcher.h @@ -102,9 +102,7 @@ class Dispatcher : public content::RenderProcessObserver, int world_id); // Runs on a different thread and should not use any member variables. - static void WillDestroyServiceWorkerContextOnWorkerThread( - v8::Local<v8::Context> v8_context, - const GURL& url); + static void WillDestroyServiceWorkerContextOnWorkerThread(const GURL& url); void DidCreateDocumentElement(blink::WebLocalFrame* frame); |