Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / renderer / gc_callback.h
blob072c191ced9c5df0c3c6017a029ba8346f9ea9e6
1 // Copyright 2015 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 EXTENSIONS_RENDERER_GC_CALLBACK_H_
6 #define EXTENSIONS_RENDERER_GC_CALLBACK_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h"
14 #include "v8/include/v8.h"
16 namespace extensions {
18 class ScriptContext;
20 // Runs |callback| when v8 garbage collects |object|, or |fallback| if
21 // |context| is invalidated first. Exactly one of |callback| or |fallback| will
22 // be called, after which it deletes itself.
23 class GCCallback {
24 public:
25 GCCallback(ScriptContext* context,
26 const v8::Local<v8::Object>& object,
27 const v8::Local<v8::Function>& callback,
28 const base::Closure& fallback);
29 ~GCCallback();
31 private:
32 static void OnObjectGC(const v8::WeakCallbackInfo<GCCallback>& data);
33 void RunCallback();
34 void OnContextInvalidated();
36 // The context which owns |object_|.
37 ScriptContext* context_;
39 // The object this GCCallback is bound to.
40 v8::Global<v8::Object> object_;
42 // The function to run when |object_| is garbage collected.
43 v8::Global<v8::Function> callback_;
45 // The function to run if |context_| is invalidated before we have a chance
46 // to execute |callback_|.
47 base::Closure fallback_;
49 base::WeakPtrFactory<GCCallback> weak_ptr_factory_;
51 DISALLOW_COPY_AND_ASSIGN(GCCallback);
54 } // namespace extensions
56 #endif // EXTENSIONS_RENDERER_GC_CALLBACK_H_