Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: gin/unsafe_persistent.h

Issue 172263002: Move WebAXObjectProxy and AccessibleController from CppBoundClass to gin::Wrappable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bug fix: Clear the callbacks when reset or destroyed Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef CHROME_RENDERER_EXTENSIONS_UNSAFE_PERSISTENT_H_ 5 #ifndef GIN_UNSAFE_PERSISTENT_H_
jochen (gone - plz use gerrit) 2014/02/24 11:21:52 instead of putting this into gin/, i'd put it into
hajimehoshi 2014/02/25 04:27:47 Done. (I put this into the namespace 'content', bu
6 #define CHROME_RENDERER_EXTENSIONS_UNSAFE_PERSISTENT_H_ 6 #define GIN_UNSAFE_PERSISTENT_H_
7 7
8 #include "v8/include/v8.h" 8 #include "v8/include/v8.h"
9 9
10 namespace extensions { 10 namespace gin {
11 11
12 // An unsafe way to pass Persistent handles around. Do not use unless you know 12 // An unsafe way to pass Persistent handles around. Do not use unless you know
13 // what you're doing. UnsafePersistent is only safe to use when we know that the 13 // what you're doing. UnsafePersistent is only safe to use when we know that the
14 // memory pointed by it is not going away: 1) When GC cannot happen while the 14 // memory pointed by it is not going away: 1) When GC cannot happen while the
15 // UnsafePersistent is alive or 2) when there is a strong Persistent keeping the 15 // UnsafePersistent is alive or 2) when there is a strong Persistent keeping the
16 // memory alive while the UnsafePersistent is alive. 16 // memory alive while the UnsafePersistent is alive.
17 template<typename T> class UnsafePersistent { 17 template<typename T> class UnsafePersistent {
18 public: 18 public:
19 UnsafePersistent() : value_(0) { } 19 UnsafePersistent() : value_(0) { }
20 20
21 explicit UnsafePersistent(v8::Persistent<T>* handle) { 21 explicit UnsafePersistent(v8::Persistent<T>* handle) {
22 value_ = handle->ClearAndLeak(); 22 value_ = handle->ClearAndLeak();
23 } 23 }
24 24
25 UnsafePersistent(v8::Isolate* isolate, const v8::Handle<T>& handle) { 25 UnsafePersistent(v8::Isolate* isolate, const v8::Handle<T>& handle) {
26 v8::Persistent<T> persistent(isolate, handle); 26 v8::Persistent<T> persistent(isolate, handle);
27 value_ = persistent.ClearAndLeak(); 27 value_ = persistent.ClearAndLeak();
28 } 28 }
29 29
30 T* Value() const {
31 return value_;
32 }
33
34 T* operator ->() const {
35 return value_;
36 }
37
30 // Usage of this function requires 38 // Usage of this function requires
31 // V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR to be defined 39 // V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR to be defined
32 void dispose() { 40 void Dispose() {
33 v8::Persistent<T> handle(value_); 41 v8::Persistent<T> handle(value_);
34 handle.Reset(); 42 handle.Reset();
35 value_ = 0; 43 value_ = 0;
36 } 44 }
37 45
38 // Usage of this function requires 46 // Usage of this function requires
39 // V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR to be defined 47 // V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR to be defined
40 v8::Local<T> newLocal(v8::Isolate* isolate) { 48 v8::Local<T> NewLocal(v8::Isolate* isolate) {
41 return v8::Local<T>::New(isolate, v8::Local<T>(value_)); 49 return v8::Local<T>::New(isolate, v8::Local<T>(value_));
42 } 50 }
43 51
44 private: 52 private:
45 T* value_; 53 T* value_;
46 }; 54 };
47 55
48 } // namespace extensions 56 } // namespace gin
49 57
50 #endif // CHROME_RENDERER_EXTENSIONS_UNSAFE_PERSISTENT_H_ 58 #endif // GIN_UNSAFE_PERSISTENT_H_
OLDNEW
« content/shell/renderer/test_runner/accessibility_controller.cc ('K') | « gin/gin.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698