Home | History | Annotate | Download | only in public
      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.
      4 
      5 #ifndef GIN_PUBLIC_ISOLATE_HOLDER_H_
      6 #define GIN_PUBLIC_ISOLATE_HOLDER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "gin/gin_export.h"
     11 
     12 namespace v8 {
     13 class Isolate;
     14 }
     15 
     16 namespace gin {
     17 
     18 class PerIsolateData;
     19 
     20 // To embed Gin, first create an instance of IsolateHolder to hold the
     21 // v8::Isolate in which you will execute JavaScript. You might wish to subclass
     22 // IsolateHolder if you want to tie more state to the lifetime of the
     23 //
     24 // You can use gin in two modes: either gin manages V8, or the gin-embedder
     25 // manages gin. If gin manages V8, use the IsolateHolder constructor without
     26 // parameters, otherwise, the gin-embedder needs to create v8::Isolates and
     27 // pass them to IsolateHolder.
     28 //
     29 // It is not possible to mix the two.
     30 class GIN_EXPORT IsolateHolder {
     31  public:
     32   IsolateHolder();
     33   explicit IsolateHolder(v8::Isolate* isolate);
     34 
     35   ~IsolateHolder();
     36 
     37   v8::Isolate* isolate() { return isolate_; }
     38 
     39  private:
     40   void Init();
     41 
     42   bool isolate_owner_;
     43   v8::Isolate* isolate_;
     44   scoped_ptr<PerIsolateData> isolate_data_;
     45 
     46   DISALLOW_COPY_AND_ASSIGN(IsolateHolder);
     47 };
     48 
     49 }  // namespace gin
     50 
     51 #endif  // GIN_PUBLIC_ISOLATE_HOLDER_H_
     52