OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/shared_impl/scoped_pp_var.h" | 5 #include "ppapi/shared_impl/scoped_pp_var.h" |
6 | 6 |
7 #include "ppapi/shared_impl/ppapi_globals.h" | 7 #include "ppapi/shared_impl/ppapi_globals.h" |
8 #include "ppapi/shared_impl/var_tracker.h" | 8 #include "ppapi/shared_impl/var_tracker.h" |
9 | 9 |
10 namespace ppapi { | 10 namespace ppapi { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 void CallAddRef(const PP_Var& v) { | 14 void CallAddRef(const PP_Var& v) { |
15 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(v); | 15 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(v); |
16 } | 16 } |
17 | 17 |
18 void CallRelease(const PP_Var& v) { | 18 void CallRelease(const PP_Var& v) { |
19 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(v); | 19 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(v); |
20 } | 20 } |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 ScopedPPVar::ScopedPPVar() : var_(PP_MakeUndefined()) { | 24 ScopedPPVar::ScopedPPVar() : var_(PP_MakeUndefined()) {} |
25 } | |
26 | 25 |
27 ScopedPPVar::ScopedPPVar(const PP_Var& v) : var_(v) { | 26 ScopedPPVar::ScopedPPVar(const PP_Var& v) : var_(v) { CallAddRef(var_); } |
| 27 |
| 28 ScopedPPVar::ScopedPPVar(const PassRef&, const PP_Var& v) : var_(v) {} |
| 29 |
| 30 ScopedPPVar::ScopedPPVar(const ScopedPPVar& other) : var_(other.var_) { |
28 CallAddRef(var_); | 31 CallAddRef(var_); |
29 } | 32 } |
30 | 33 |
31 ScopedPPVar::ScopedPPVar(const PassRef&, const PP_Var& v) : var_(v) { | 34 ScopedPPVar::~ScopedPPVar() { CallRelease(var_); } |
32 } | |
33 | |
34 ScopedPPVar::ScopedPPVar(const ScopedPPVar& other) | |
35 : var_(other.var_) { | |
36 CallAddRef(var_); | |
37 } | |
38 | |
39 ScopedPPVar::~ScopedPPVar() { | |
40 CallRelease(var_); | |
41 } | |
42 | 35 |
43 ScopedPPVar& ScopedPPVar::operator=(const PP_Var& v) { | 36 ScopedPPVar& ScopedPPVar::operator=(const PP_Var& v) { |
44 CallAddRef(v); | 37 CallAddRef(v); |
45 CallRelease(var_); | 38 CallRelease(var_); |
46 var_ = v; | 39 var_ = v; |
47 return *this; | 40 return *this; |
48 } | 41 } |
49 | 42 |
50 PP_Var ScopedPPVar::Release() { | 43 PP_Var ScopedPPVar::Release() { |
51 PP_Var result = var_; | 44 PP_Var result = var_; |
52 var_ = PP_MakeUndefined(); | 45 var_ = PP_MakeUndefined(); |
53 return result; | 46 return result; |
54 } | 47 } |
55 | 48 |
56 } // namespace ppapi | 49 } // namespace ppapi |
OLD | NEW |