cc: Adding BeginFrameTracker object and removing Now() from LTHI.
[chromium-blink-merge.git] / gin / public / isolate_holder.h
blob111fde870f79af3979ab494317ef7c102f8b9126
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_ISOLATE_HOLDER_H_
6 #define GIN_PUBLIC_ISOLATE_HOLDER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "gin/gin_export.h"
11 #include "v8/include/v8.h"
13 namespace gin {
15 class PerIsolateData;
16 class RunMicrotasksObserver;
17 class V8IsolateMemoryDumpProvider;
19 // To embed Gin, first initialize gin using IsolateHolder::Initialize and then
20 // create an instance of IsolateHolder to hold the v8::Isolate in which you
21 // will execute JavaScript. You might wish to subclass IsolateHolder if you
22 // want to tie more state to the lifetime of the isolate.
23 class GIN_EXPORT IsolateHolder {
24 public:
25 // Controls whether or not V8 should only accept strict mode scripts.
26 enum ScriptMode {
27 kNonStrictMode,
28 kStrictMode
31 // Stores whether the client uses v8::Locker to access the isolate.
32 enum AccessMode {
33 kSingleThread,
34 kUseLocker
37 IsolateHolder();
38 explicit IsolateHolder(AccessMode access_mode);
39 ~IsolateHolder();
41 // Should be invoked once before creating IsolateHolder instances to
42 // initialize V8 and Gin. In case V8_USE_EXTERNAL_STARTUP_DATA is
43 // defined, V8's initial snapshot should be loaded (by calling
44 // V8Initializer::LoadV8SnapshotFromFD or
45 // V8Initializer::LoadV8Snapshot) before calling this method.
46 static void Initialize(ScriptMode mode,
47 v8::ArrayBuffer::Allocator* allocator);
49 v8::Isolate* isolate() { return isolate_; }
51 // The implementations of Object.observe() and Promise enqueue v8 Microtasks
52 // that should be executed just before control is returned to the message
53 // loop. This method adds a MessageLoop TaskObserver which runs any pending
54 // Microtasks each time a Task is completed. This method should be called
55 // once, when a MessageLoop is created and it should be called on the
56 // MessageLoop's thread.
57 void AddRunMicrotasksObserver();
59 // This method should also only be called once, and on the MessageLoop's
60 // thread.
61 void RemoveRunMicrotasksObserver();
63 // This method returns if v8::Locker is needed to access isolate.
64 AccessMode access_mode() const { return access_mode_; }
66 private:
67 v8::Isolate* isolate_;
68 scoped_ptr<PerIsolateData> isolate_data_;
69 scoped_ptr<RunMicrotasksObserver> task_observer_;
70 scoped_ptr<V8IsolateMemoryDumpProvider> isolate_memory_dump_provider_;
71 AccessMode access_mode_;
73 DISALLOW_COPY_AND_ASSIGN(IsolateHolder);
76 } // namespace gin
78 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_