blob: 624dfc77ba07a001e79e4cfe7eec2a2811c73c74 [file] [log] [blame]
kalman04755302015-09-14 18:52:111// 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.
4
5#ifndef EXTENSIONS_RENDERER_WORKER_SCRIPT_CONTEXT_SET_H_
6#define EXTENSIONS_RENDERER_WORKER_SCRIPT_CONTEXT_SET_H_
7
dchengf6f80662016-04-20 20:26:048#include <memory>
leon.hanb4d9ea92017-01-24 04:28:329#include <vector>
dchengf6f80662016-04-20 20:26:0410
kalman04755302015-09-14 18:52:1111#include "base/macros.h"
kalman04755302015-09-14 18:52:1112#include "base/threading/thread_local.h"
13#include "content/public/child/worker_thread.h"
14#include "url/gurl.h"
15#include "v8/include/v8.h"
16
17namespace extensions {
18
19class ScriptContext;
20
21// A set of ScriptContexts owned by worker threads. Thread safe.
22class WorkerScriptContextSet : public content::WorkerThread::Observer {
23 public:
24 WorkerScriptContextSet();
25
26 ~WorkerScriptContextSet() override;
27
28 // Inserts |context| into the set. Contexts are stored in TLS.
dchengf6f80662016-04-20 20:26:0429 void Insert(std::unique_ptr<ScriptContext> context);
kalman04755302015-09-14 18:52:1130
31 // Removes the ScriptContext associated with |v8_context| which was added for
32 // |url| (used for sanity checking).
33 void Remove(v8::Local<v8::Context> v8_context, const GURL& url);
34
35 private:
36 // WorkerThread::Observer:
37 void WillStopCurrentWorkerThread() override;
38
39 // Implement thread safety by storing each ScriptContext in TLS.
leon.hanb4d9ea92017-01-24 04:28:3240 base::ThreadLocalPointer<std::vector<std::unique_ptr<ScriptContext>>>
41 contexts_tls_;
kalman04755302015-09-14 18:52:1142
43 DISALLOW_COPY_AND_ASSIGN(WorkerScriptContextSet);
44};
45
46} // namespace extensions
47
48#endif // EXTENSIONS_RENDERER_WORKER_SCRIPT_CONTEXT_SET_H_