Revert "Temporarily add a CHECK() in the PushMessagingDispatcher."
[chromium-blink-merge.git] / gin / per_isolate_data.h
blob175161cebc211b04440187c567352f47bfeb136d
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 "gin/gin_export.h"
13 #include "gin/public/wrapper_info.h"
14 #include "v8/include/v8.h"
16 namespace base {
17 class SingleThreadTaskRunner;
20 namespace gin {
22 class IndexedPropertyInterceptor;
23 class NamedPropertyInterceptor;
24 class WrappableBase;
26 // There is one instance of PerIsolateData per v8::Isolate managed by Gin. This
27 // class stores all the Gin-related data that varies per isolate.
28 class GIN_EXPORT PerIsolateData {
29 public:
30 PerIsolateData(v8::Isolate* isolate, v8::ArrayBuffer::Allocator* allocator);
31 ~PerIsolateData();
33 static PerIsolateData* From(v8::Isolate* isolate);
35 // Each isolate is associated with a collection of v8::ObjectTemplates and
36 // v8::FunctionTemplates. Typically these template objects are created
37 // lazily.
38 void SetObjectTemplate(WrapperInfo* info,
39 v8::Local<v8::ObjectTemplate> object_template);
40 void SetFunctionTemplate(WrapperInfo* info,
41 v8::Local<v8::FunctionTemplate> function_template);
43 // These are low-level functions for retrieving object or function templates
44 // stored in this object. Because these templates are often created lazily,
45 // most clients should call higher-level functions that know how to populate
46 // these templates if they haven't already been created.
47 v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info);
48 v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info);
50 // We maintain a map from Wrappable objects that derive from one of the
51 // interceptor interfaces to the interceptor interface pointers.
52 void SetIndexedPropertyInterceptor(WrappableBase* base,
53 IndexedPropertyInterceptor* interceptor);
54 void SetNamedPropertyInterceptor(WrappableBase* base,
55 NamedPropertyInterceptor* interceptor);
57 void ClearIndexedPropertyInterceptor(WrappableBase* base,
58 IndexedPropertyInterceptor* interceptor);
59 void ClearNamedPropertyInterceptor(WrappableBase* base,
60 NamedPropertyInterceptor* interceptor);
62 IndexedPropertyInterceptor* GetIndexedPropertyInterceptor(
63 WrappableBase* base);
64 NamedPropertyInterceptor* GetNamedPropertyInterceptor(WrappableBase* base);
66 v8::Isolate* isolate() { return isolate_; }
67 v8::ArrayBuffer::Allocator* allocator() { return allocator_; }
68 base::SingleThreadTaskRunner* task_runner() { return task_runner_.get(); }
70 private:
71 typedef std::map<
72 WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap;
73 typedef std::map<
74 WrapperInfo*, v8::Eternal<v8::FunctionTemplate> > FunctionTemplateMap;
75 typedef std::map<WrappableBase*, IndexedPropertyInterceptor*>
76 IndexedPropertyInterceptorMap;
77 typedef std::map<WrappableBase*, NamedPropertyInterceptor*>
78 NamedPropertyInterceptorMap;
80 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is
81 // owned by the IsolateHolder, which also owns the PerIsolateData.
82 v8::Isolate* isolate_;
83 v8::ArrayBuffer::Allocator* allocator_;
84 ObjectTemplateMap object_templates_;
85 FunctionTemplateMap function_templates_;
86 IndexedPropertyInterceptorMap indexed_interceptors_;
87 NamedPropertyInterceptorMap named_interceptors_;
88 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
90 DISALLOW_COPY_AND_ASSIGN(PerIsolateData);
93 } // namespace gin
95 #endif // GIN_PER_ISOLATE_DATA_H_