OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/renderer/gc_callback.h" | 5 #include "extensions/renderer/gc_callback.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "extensions/renderer/script_context.h" | 9 #include "extensions/renderer/script_context.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 // DO NOT add any more work to this method. The only acceptable place to add | 34 // DO NOT add any more work to this method. The only acceptable place to add |
35 // code is RunCallback. | 35 // code is RunCallback. |
36 GCCallback* self = data.GetParameter(); | 36 GCCallback* self = data.GetParameter(); |
37 self->object_.Reset(); | 37 self->object_.Reset(); |
38 base::MessageLoop::current()->PostTask( | 38 base::MessageLoop::current()->PostTask( |
39 FROM_HERE, base::Bind(&GCCallback::RunCallback, | 39 FROM_HERE, base::Bind(&GCCallback::RunCallback, |
40 self->weak_ptr_factory_.GetWeakPtr())); | 40 self->weak_ptr_factory_.GetWeakPtr())); |
41 } | 41 } |
42 | 42 |
43 void GCCallback::RunCallback() { | 43 void GCCallback::RunCallback() { |
| 44 fallback_.Reset(); |
44 v8::Isolate* isolate = context_->isolate(); | 45 v8::Isolate* isolate = context_->isolate(); |
45 v8::HandleScope handle_scope(isolate); | 46 v8::HandleScope handle_scope(isolate); |
46 context_->CallFunction(v8::Local<v8::Function>::New(isolate, callback_)); | 47 context_->CallFunction(v8::Local<v8::Function>::New(isolate, callback_)); |
47 delete this; | 48 delete this; |
48 } | 49 } |
49 | 50 |
50 void GCCallback::OnContextInvalidated() { | 51 void GCCallback::OnContextInvalidated() { |
51 fallback_.Run(); | 52 if (!fallback_.is_null()) { |
52 delete this; | 53 fallback_.Run(); |
| 54 delete this; |
| 55 } |
53 } | 56 } |
54 | 57 |
55 } // namespace extensions | 58 } // namespace extensions |
OLD | NEW |