Reduce binary size impact of synthetic delays
[chromium-blink-merge.git] / gin / public / context_holder.h
blobf8f0c4727a5f6a66703f88d162f52833b0a28eed
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_PUBLIC_CONTEXT_HOLDER_H_
6 #define GIN_PUBLIC_CONTEXT_HOLDER_H_
8 #include <list>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "gin/gin_export.h"
13 #include "v8/include/v8.h"
15 namespace gin {
17 // Gin embedder that store embedder data in v8::Contexts must do so in a
18 // single field with the index kPerContextDataStartIndex + GinEmbedder-enum.
19 // The field at kDebugIdIndex is treated specially by V8 and is reserved for
20 // a V8 debugger implementation (not used by gin).
21 enum ContextEmbedderDataFields {
22 kDebugIdIndex = 0,
23 kPerContextDataStartIndex,
26 class PerContextData;
28 // ContextHolder is a generic class for holding a v8::Context. Rather than
29 // using ContextHolder directly, most code should use a subclass of
30 // ContextHolder, such as Runner.
31 class GIN_EXPORT ContextHolder {
32 public:
33 explicit ContextHolder(v8::Isolate* isolate);
34 ~ContextHolder();
36 v8::Isolate* isolate() const { return isolate_; }
38 v8::Handle<v8::Context> context() const {
39 return v8::Local<v8::Context>::New(isolate_, context_);
42 void SetContext(v8::Handle<v8::Context> context);
44 private:
45 v8::Isolate* isolate_;
46 v8::UniquePersistent<v8::Context> context_;
47 scoped_ptr<PerContextData> data_;
49 DISALLOW_COPY_AND_ASSIGN(ContextHolder);
52 } // namespace gin
54 #endif // GIN_PUBLIC_CONTEXT_HOLDER_H_