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