Roll src/third_party/skia a04c650:ac856c9
[chromium-blink-merge.git] / gin / per_isolate_data.h
blobef44f313a2769521447d7f32a3e37f6ab73bed6e
1 // Copyright 2013 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 GIN_PER_ISOLATE_DATA_H_
6 #define GIN_PER_ISOLATE_DATA_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "gin/gin_export.h"
14 #include "gin/public/v8_idle_task_runner.h"
15 #include "gin/public/wrapper_info.h"
16 #include "v8/include/v8.h"
18 namespace base {
19 class SingleThreadTaskRunner;
22 namespace gin {
24 class IndexedPropertyInterceptor;
25 class NamedPropertyInterceptor;
26 class WrappableBase;
28 // There is one instance of PerIsolateData per v8::Isolate managed by Gin. This
29 // class stores all the Gin-related data that varies per isolate.
30 class GIN_EXPORT PerIsolateData {
31 public:
32 PerIsolateData(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator);
33 ~PerIsolateData();
35 static PerIsolateData* From(v8::Isolate* isolate);
37 // Each isolate is associated with a collection of v8::ObjectTemplates and
38 // v8::FunctionTemplates. Typically these template objects are created
39 // lazily.
40 void SetObjectTemplate(WrapperInfo* info,
41 v8::Local<v8::ObjectTemplate> object_template);
42 void SetFunctionTemplate(WrapperInfo* info,
43 v8::Local<v8::FunctionTemplate> function_template);
45 // These are low-level functions for retrieving object or function templates
46 // stored in this object. Because these templates are often created lazily,
47 // most clients should call higher-level functions that know how to populate
48 // these templates if they haven't already been created.
49 v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info);
50 v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info);
52 // We maintain a map from Wrappable objects that derive from one of the
53 // interceptor interfaces to the interceptor interface pointers.
54 void SetIndexedPropertyInterceptor(WrappableBase* base,
55 IndexedPropertyInterceptor* interceptor);
56 void SetNamedPropertyInterceptor(WrappableBase* base,
57 NamedPropertyInterceptor* interceptor);
59 void ClearIndexedPropertyInterceptor(WrappableBase* base,
60 IndexedPropertyInterceptor* interceptor);
61 void ClearNamedPropertyInterceptor(WrappableBase* base,
62 NamedPropertyInterceptor* interceptor);
64 IndexedPropertyInterceptor* GetIndexedPropertyInterceptor(
65 WrappableBase* base);
66 NamedPropertyInterceptor* GetNamedPropertyInterceptor(WrappableBase* base);
68 void EnableIdleTasks(scoped_ptr<V8IdleTaskRunner> idle_task_runner);
70 v8::Isolate* isolate() { return isolate_; }
71 v8::ArrayBuffer::Allocator* allocator() { return allocator_; }
72 base::SingleThreadTaskRunner* task_runner() { return task_runner_.get(); }
73 V8IdleTaskRunner* idle_task_runner() {
74 return idle_task_runner_.get();
77 private:
78 typedef std::map<
79 WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap;
80 typedef std::map<
81 WrapperInfo*, v8::Eternal<v8::FunctionTemplate> > FunctionTemplateMap;
82 typedef std::map<WrappableBase*, IndexedPropertyInterceptor*>
83 IndexedPropertyInterceptorMap;
84 typedef std::map<WrappableBase*, NamedPropertyInterceptor*>
85 NamedPropertyInterceptorMap;
87 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is
88 // owned by the IsolateHolder, which also owns the PerIsolateData.
89 v8::Isolate* isolate_;
90 v8::ArrayBuffer::Allocator* allocator_;
91 ObjectTemplateMap object_templates_;
92 FunctionTemplateMap function_templates_;
93 IndexedPropertyInterceptorMap indexed_interceptors_;
94 NamedPropertyInterceptorMap named_interceptors_;
95 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
96 scoped_ptr<V8IdleTaskRunner> idle_task_runner_;
98 DISALLOW_COPY_AND_ASSIGN(PerIsolateData);
101 } // namespace gin
103 #endif // GIN_PER_ISOLATE_DATA_H_