1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_RENDERER_WORKER_SCRIPT_CONTEXT_SET_H_
6 #define EXTENSIONS_RENDERER_WORKER_SCRIPT_CONTEXT_SET_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h"
11 #include "base/threading/thread_local.h"
12 #include "content/public/child/worker_thread.h"
14 #include "v8/include/v8.h"
16 namespace extensions
{
20 // A set of ScriptContexts owned by worker threads. Thread safe.
21 class WorkerScriptContextSet
: public content::WorkerThread::Observer
{
23 WorkerScriptContextSet();
25 ~WorkerScriptContextSet() override
;
27 // Inserts |context| into the set. Contexts are stored in TLS.
28 void Insert(scoped_ptr
<ScriptContext
> context
);
30 // Removes the ScriptContext associated with |v8_context| which was added for
31 // |url| (used for sanity checking).
32 void Remove(v8::Local
<v8::Context
> v8_context
, const GURL
& url
);
35 // WorkerThread::Observer:
36 void WillStopCurrentWorkerThread() override
;
38 // Implement thread safety by storing each ScriptContext in TLS.
39 base::ThreadLocalPointer
<ScopedVector
<ScriptContext
>> contexts_tls_
;
41 DISALLOW_COPY_AND_ASSIGN(WorkerScriptContextSet
);
44 } // namespace extensions
46 #endif // EXTENSIONS_RENDERER_WORKER_SCRIPT_CONTEXT_SET_H_