QUIC - Persist MRU 200 server's srtt (smoothed_rtt) of ServerNetworkStats
[chromium-blink-merge.git] / gin / public / isolate_holder.h
blobb12734c4413c377ebcd6318b41fddd2b3ba721dd
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;
18 // To embed Gin, first initialize gin using IsolateHolder::Initialize and then
19 // create an instance of IsolateHolder to hold the v8::Isolate in which you
20 // will execute JavaScript. You might wish to subclass IsolateHolder if you
21 // want to tie more state to the lifetime of the isolate.
22 class GIN_EXPORT IsolateHolder {
23 public:
24 // Controls whether or not V8 should only accept strict mode scripts.
25 enum ScriptMode {
26 kNonStrictMode,
27 kStrictMode
30 IsolateHolder();
31 ~IsolateHolder();
33 // Should be invoked once before creating IsolateHolder instances to
34 // initialize V8 and Gin. In case V8_USE_EXTERNAL_STARTUP_DATA is defined,
35 // V8's initial snapshot should be loaded (by calling LoadV8Snapshot or
36 // LoadV8SnapshotFD) before calling Initialize.
37 static void Initialize(ScriptMode mode,
38 v8::ArrayBuffer::Allocator* allocator);
40 v8::Isolate* isolate() { return isolate_; }
42 // The implementations of Object.observe() and Promise enqueue v8 Microtasks
43 // that should be executed just before control is returned to the message
44 // loop. This method adds a MessageLoop TaskObserver which runs any pending
45 // Microtasks each time a Task is completed. This method should be called
46 // once, when a MessageLoop is created and it should be called on the
47 // MessageLoop's thread.
48 void AddRunMicrotasksObserver();
50 // This method should also only be called once, and on the MessageLoop's
51 // thread.
52 void RemoveRunMicrotasksObserver();
54 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
55 static bool LoadV8SnapshotFD(int natives_fd, int snapshot_fd);
56 static bool LoadV8Snapshot();
57 #endif // V8_USE_EXTERNAL_STARTUP_DATA
58 static void GetV8ExternalSnapshotData(const char** natives_data_out,
59 int* natives_size_out,
60 const char** snapshot_data_out,
61 int* snapshot_size_out);
63 private:
64 v8::Isolate* isolate_;
65 scoped_ptr<PerIsolateData> isolate_data_;
66 scoped_ptr<RunMicrotasksObserver> task_observer_;
68 DISALLOW_COPY_AND_ASSIGN(IsolateHolder);
71 } // namespace gin
73 #endif // GIN_PUBLIC_ISOLATE_HOLDER_H_