summaryrefslogtreecommitdiffstats
path: root/gin/context_holder.h
blob: d43e1933fa896a581eeec1d39b804b768878e88e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GIN_CONTEXT_HOLDER_H_
#define GIN_CONTEXT_HOLDER_H_

#include <list>

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "v8/include/v8.h"

namespace gin {

class PerContextData;

class ContextHolder {
 public:
  explicit ContextHolder(v8::Isolate* isolate);
  ~ContextHolder();

  v8::Isolate* isolate() const { return isolate_; }

  v8::Handle<v8::Context> context() const {
    return v8::Local<v8::Context>::New(isolate_, context_);
  }

  void SetContext(v8::Handle<v8::Context> context);

 private:
  v8::Isolate* isolate_;
  v8::Persistent<v8::Context> context_;
  scoped_ptr<PerContextData> data_;

  DISALLOW_COPY_AND_ASSIGN(ContextHolder);
};

}  // namespace gin

#endif  // GIN_CONTEXT_HOLDER_H_