OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/var.h" | 5 #include "ppapi/shared_impl/var.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 | 92 |
93 void Var::AssignVarID(int32 id) { | 93 void Var::AssignVarID(int32 id) { |
94 DCHECK(!var_id_); // Must not have already been generated. | 94 DCHECK(!var_id_); // Must not have already been generated. |
95 var_id_ = id; | 95 var_id_ = id; |
96 } | 96 } |
97 | 97 |
98 // StringVar ------------------------------------------------------------------- | 98 // StringVar ------------------------------------------------------------------- |
99 | 99 |
100 StringVar::StringVar(const std::string& str) | 100 StringVar::StringVar(const std::string& str) |
101 : value_(str) { | 101 : value_(str) { |
102 GetOrCreateVarID(); | |
102 } | 103 } |
103 | 104 |
104 StringVar::StringVar(const char* str, uint32 len) | 105 StringVar::StringVar(const char* str, uint32 len) |
105 : value_(str, len) { | 106 : value_(str, len) { |
107 GetOrCreateVarID(); | |
dmichael (off chromium)
2011/12/12 18:28:50
I think we shouldn't have this ref-count here. If
| |
106 } | 108 } |
107 | 109 |
108 StringVar::~StringVar() { | 110 StringVar::~StringVar() { |
111 VarTracker* tracker = PpapiGlobals::Get()->GetVarTracker(); | |
112 tracker->ReleaseVar(GetExistingVarID()); | |
109 } | 113 } |
110 | 114 |
111 StringVar* StringVar::AsStringVar() { | 115 StringVar* StringVar::AsStringVar() { |
112 return this; | 116 return this; |
113 } | 117 } |
114 | 118 |
115 PP_Var StringVar::GetPPVar() { | 119 PP_Var StringVar::GetPPVar() { |
116 int32 id = GetOrCreateVarID(); | 120 int32 id = GetExistingVarID(); |
117 if (!id) | 121 if (!id) |
118 return PP_MakeNull(); | 122 return PP_MakeNull(); |
119 | 123 |
120 PP_Var result; | 124 PP_Var result; |
121 result.type = PP_VARTYPE_STRING; | 125 result.type = PP_VARTYPE_STRING; |
122 result.padding = 0; | 126 result.padding = 0; |
123 result.value.as_id = id; | 127 result.value.as_id = id; |
124 return result; | 128 return result; |
125 } | 129 } |
126 | 130 |
(...skipping 19 matching lines...) Expand all Loading... | |
146 if (var.type != PP_VARTYPE_STRING) | 150 if (var.type != PP_VARTYPE_STRING) |
147 return NULL; | 151 return NULL; |
148 scoped_refptr<Var> var_object( | 152 scoped_refptr<Var> var_object( |
149 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); | 153 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); |
150 if (!var_object) | 154 if (!var_object) |
151 return NULL; | 155 return NULL; |
152 return var_object->AsStringVar(); | 156 return var_object->AsStringVar(); |
153 } | 157 } |
154 | 158 |
155 } // namespace ppapi | 159 } // namespace ppapi |
156 | |
OLD | NEW |