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

Side by Side Diff: content/renderer/pepper/host_var_tracker.cc

Issue 1113783002: Use Local instead of Handle in src/content/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
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 "content/renderer/pepper/host_var_tracker.h" 5 #include "content/renderer/pepper/host_var_tracker.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/renderer/pepper/host_array_buffer_var.h" 8 #include "content/renderer/pepper/host_array_buffer_var.h"
9 #include "content/renderer/pepper/host_globals.h" 9 #include "content/renderer/pepper/host_globals.h"
10 #include "content/renderer/pepper/host_resource_var.h" 10 #include "content/renderer/pepper/host_resource_var.h"
11 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 11 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
12 #include "content/renderer/pepper/v8object_var.h" 12 #include "content/renderer/pepper/v8object_var.h"
13 #include "ppapi/c/pp_var.h" 13 #include "ppapi/c/pp_var.h"
14 14
15 using ppapi::ArrayBufferVar; 15 using ppapi::ArrayBufferVar;
16 using ppapi::V8ObjectVar; 16 using ppapi::V8ObjectVar;
17 17
18 namespace content { 18 namespace content {
19 19
20 HostVarTracker::V8ObjectVarKey::V8ObjectVarKey(V8ObjectVar* object_var) 20 HostVarTracker::V8ObjectVarKey::V8ObjectVarKey(V8ObjectVar* object_var)
21 : instance(object_var->instance()->pp_instance()) { 21 : instance(object_var->instance()->pp_instance()) {
22 v8::Local<v8::Object> object = object_var->GetHandle(); 22 v8::Local<v8::Object> object = object_var->GetHandle();
23 hash = object.IsEmpty() ? 0 : object->GetIdentityHash(); 23 hash = object.IsEmpty() ? 0 : object->GetIdentityHash();
24 } 24 }
25 25
26 HostVarTracker::V8ObjectVarKey::V8ObjectVarKey(PP_Instance instance, 26 HostVarTracker::V8ObjectVarKey::V8ObjectVarKey(PP_Instance instance,
27 v8::Handle<v8::Object> object) 27 v8::Local<v8::Object> object)
28 : instance(instance), 28 : instance(instance),
29 hash(object.IsEmpty() ? 0 : object->GetIdentityHash()) {} 29 hash(object.IsEmpty() ? 0 : object->GetIdentityHash()) {}
30 30
31 HostVarTracker::V8ObjectVarKey::~V8ObjectVarKey() {} 31 HostVarTracker::V8ObjectVarKey::~V8ObjectVarKey() {}
32 32
33 bool HostVarTracker::V8ObjectVarKey::operator<( 33 bool HostVarTracker::V8ObjectVarKey::operator<(
34 const V8ObjectVarKey& other) const { 34 const V8ObjectVarKey& other) const {
35 if (instance == other.instance) 35 if (instance == other.instance)
36 return hash < other.hash; 36 return hash < other.hash;
37 return instance < other.instance; 37 return instance < other.instance;
(...skipping 25 matching lines...) Expand all
63 void HostVarTracker::RemoveV8ObjectVar(V8ObjectVar* object_var) { 63 void HostVarTracker::RemoveV8ObjectVar(V8ObjectVar* object_var) {
64 CheckThreadingPreconditions(); 64 CheckThreadingPreconditions();
65 v8::HandleScope handle_scope(object_var->instance()->GetIsolate()); 65 v8::HandleScope handle_scope(object_var->instance()->GetIsolate());
66 ObjectMap::iterator it = GetForV8Object( 66 ObjectMap::iterator it = GetForV8Object(
67 object_var->instance()->pp_instance(), object_var->GetHandle()); 67 object_var->instance()->pp_instance(), object_var->GetHandle());
68 DCHECK(it != object_map_.end()); 68 DCHECK(it != object_map_.end());
69 object_map_.erase(it); 69 object_map_.erase(it);
70 } 70 }
71 71
72 PP_Var HostVarTracker::V8ObjectVarForV8Object(PP_Instance instance, 72 PP_Var HostVarTracker::V8ObjectVarForV8Object(PP_Instance instance,
73 v8::Handle<v8::Object> object) { 73 v8::Local<v8::Object> object) {
74 CheckThreadingPreconditions(); 74 CheckThreadingPreconditions();
75 ObjectMap::const_iterator it = GetForV8Object(instance, object); 75 ObjectMap::const_iterator it = GetForV8Object(instance, object);
76 if (it == object_map_.end()) 76 if (it == object_map_.end())
77 return (new V8ObjectVar(instance, object))->GetPPVar(); 77 return (new V8ObjectVar(instance, object))->GetPPVar();
78 return it->second->GetPPVar(); 78 return it->second->GetPPVar();
79 } 79 }
80 80
81 int HostVarTracker::GetLiveV8ObjectVarsForTest(PP_Instance instance) { 81 int HostVarTracker::GetLiveV8ObjectVarsForTest(PP_Instance instance) {
82 CheckThreadingPreconditions(); 82 CheckThreadingPreconditions();
83 int count = 0; 83 int count = 0;
84 // Use a key with an empty handle to find the v8 object var in the map with 84 // Use a key with an empty handle to find the v8 object var in the map with
85 // the given instance and the lowest hash. 85 // the given instance and the lowest hash.
86 V8ObjectVarKey key(instance, v8::Handle<v8::Object>()); 86 V8ObjectVarKey key(instance, v8::Local<v8::Object>());
87 ObjectMap::const_iterator it = object_map_.lower_bound(key); 87 ObjectMap::const_iterator it = object_map_.lower_bound(key);
88 while (it != object_map_.end() && it->first.instance == instance) { 88 while (it != object_map_.end() && it->first.instance == instance) {
89 ++count; 89 ++count;
90 ++it; 90 ++it;
91 } 91 }
92 return count; 92 return count;
93 } 93 }
94 94
95 PP_Var HostVarTracker::MakeResourcePPVarFromMessage( 95 PP_Var HostVarTracker::MakeResourcePPVarFromMessage(
96 PP_Instance instance, 96 PP_Instance instance,
(...skipping 15 matching lines...) Expand all
112 112
113 PepperPluginInstanceImpl* instance = 113 PepperPluginInstanceImpl* instance =
114 HostGlobals::Get()->GetInstance(pp_instance); 114 HostGlobals::Get()->GetInstance(pp_instance);
115 v8::HandleScope handle_scope(instance->GetIsolate()); 115 v8::HandleScope handle_scope(instance->GetIsolate());
116 // Force delete all var references. ForceReleaseV8Object() will cause 116 // Force delete all var references. ForceReleaseV8Object() will cause
117 // this object, and potentially others it references, to be removed from 117 // this object, and potentially others it references, to be removed from
118 // |live_vars_|. 118 // |live_vars_|.
119 119
120 // Use a key with an empty handle to find the v8 object var in the map with 120 // Use a key with an empty handle to find the v8 object var in the map with
121 // the given instance and the lowest hash. 121 // the given instance and the lowest hash.
122 V8ObjectVarKey key(pp_instance, v8::Handle<v8::Object>()); 122 V8ObjectVarKey key(pp_instance, v8::Local<v8::Object>());
123 ObjectMap::iterator it = object_map_.lower_bound(key); 123 ObjectMap::iterator it = object_map_.lower_bound(key);
124 while (it != object_map_.end() && it->first.instance == pp_instance) { 124 while (it != object_map_.end() && it->first.instance == pp_instance) {
125 ForceReleaseV8Object(it->second); 125 ForceReleaseV8Object(it->second);
126 object_map_.erase(it++); 126 object_map_.erase(it++);
127 } 127 }
128 } 128 }
129 129
130 void HostVarTracker::ForceReleaseV8Object(ppapi::V8ObjectVar* object_var) { 130 void HostVarTracker::ForceReleaseV8Object(ppapi::V8ObjectVar* object_var) {
131 object_var->InstanceDeleted(); 131 object_var->InstanceDeleted();
132 VarMap::iterator iter = live_vars_.find(object_var->GetExistingVarID()); 132 VarMap::iterator iter = live_vars_.find(object_var->GetExistingVarID());
133 if (iter == live_vars_.end()) { 133 if (iter == live_vars_.end()) {
134 NOTREACHED(); 134 NOTREACHED();
135 return; 135 return;
136 } 136 }
137 iter->second.ref_count = 0; 137 iter->second.ref_count = 0;
138 DCHECK(iter->second.track_with_no_reference_count == 0); 138 DCHECK(iter->second.track_with_no_reference_count == 0);
139 DeleteObjectInfoIfNecessary(iter); 139 DeleteObjectInfoIfNecessary(iter);
140 } 140 }
141 141
142 HostVarTracker::ObjectMap::iterator HostVarTracker::GetForV8Object( 142 HostVarTracker::ObjectMap::iterator HostVarTracker::GetForV8Object(
143 PP_Instance instance, 143 PP_Instance instance,
144 v8::Handle<v8::Object> object) { 144 v8::Local<v8::Object> object) {
145 std::pair<ObjectMap::iterator, ObjectMap::iterator> range = 145 std::pair<ObjectMap::iterator, ObjectMap::iterator> range =
146 object_map_.equal_range(V8ObjectVarKey(instance, object)); 146 object_map_.equal_range(V8ObjectVarKey(instance, object));
147 147
148 for (ObjectMap::iterator it = range.first; it != range.second; ++it) { 148 for (ObjectMap::iterator it = range.first; it != range.second; ++it) {
149 if (object == it->second->GetHandle()) 149 if (object == it->second->GetHandle())
150 return it; 150 return it;
151 } 151 }
152 return object_map_.end(); 152 return object_map_.end();
153 } 153 }
154 154
(...skipping 25 matching lines...) Expand all
180 if (it->second.instance != instance) 180 if (it->second.instance != instance)
181 return false; 181 return false;
182 182
183 *handle = it->second.handle; 183 *handle = it->second.handle;
184 *size_in_bytes = it->second.size_in_bytes; 184 *size_in_bytes = it->second.size_in_bytes;
185 shared_memory_map_.erase(it); 185 shared_memory_map_.erase(it);
186 return true; 186 return true;
187 } 187 }
188 188
189 } // namespace content 189 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/host_var_tracker.h ('k') | content/renderer/pepper/host_var_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698