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

Side by Side Diff: webkit/plugins/ppapi/host_var_tracker.cc

Issue 12378050: PPAPI: Remove threading options; it's always on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PDFResource unit test Created 7 years, 8 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
« no previous file with comments | « webkit/plugins/ppapi/host_globals.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/plugins/ppapi/host_var_tracker.h" 5 #include "webkit/plugins/ppapi/host_var_tracker.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ppapi/c/pp_var.h" 8 #include "ppapi/c/pp_var.h"
9 #include "webkit/plugins/ppapi/host_array_buffer_var.h" 9 #include "webkit/plugins/ppapi/host_array_buffer_var.h"
10 #include "webkit/plugins/ppapi/npobject_var.h" 10 #include "webkit/plugins/ppapi/npobject_var.h"
11 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 11 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
12 12
13 using ppapi::ArrayBufferVar; 13 using ppapi::ArrayBufferVar;
14 using ppapi::NPObjectVar; 14 using ppapi::NPObjectVar;
15 15
16 namespace webkit { 16 namespace webkit {
17 namespace ppapi { 17 namespace ppapi {
18 18
19 HostVarTracker::HostVarTracker() : last_shared_memory_map_id_(0) { 19 HostVarTracker::HostVarTracker()
20 : VarTracker(SINGLE_THREADED),
21 last_shared_memory_map_id_(0) {
20 } 22 }
21 23
22 HostVarTracker::~HostVarTracker() { 24 HostVarTracker::~HostVarTracker() {
23 } 25 }
24 26
25 ArrayBufferVar* HostVarTracker::CreateArrayBuffer(uint32 size_in_bytes) { 27 ArrayBufferVar* HostVarTracker::CreateArrayBuffer(uint32 size_in_bytes) {
26 return new HostArrayBufferVar(size_in_bytes); 28 return new HostArrayBufferVar(size_in_bytes);
27 } 29 }
28 30
29 ArrayBufferVar* HostVarTracker::CreateShmArrayBuffer( 31 ArrayBufferVar* HostVarTracker::CreateShmArrayBuffer(
30 uint32 size_in_bytes, 32 uint32 size_in_bytes,
31 base::SharedMemoryHandle handle) { 33 base::SharedMemoryHandle handle) {
32 return new HostArrayBufferVar(size_in_bytes, handle); 34 return new HostArrayBufferVar(size_in_bytes, handle);
33 } 35 }
34 36
35 void HostVarTracker::AddNPObjectVar(NPObjectVar* object_var) { 37 void HostVarTracker::AddNPObjectVar(NPObjectVar* object_var) {
36 DCHECK(CalledOnValidThread()); 38 CheckThreadingPreconditions();
37 39
38 InstanceMap::iterator found_instance = instance_map_.find( 40 InstanceMap::iterator found_instance = instance_map_.find(
39 object_var->pp_instance()); 41 object_var->pp_instance());
40 if (found_instance == instance_map_.end()) { 42 if (found_instance == instance_map_.end()) {
41 // Lazily create the instance map. 43 // Lazily create the instance map.
42 DCHECK(object_var->pp_instance() != 0); 44 DCHECK(object_var->pp_instance() != 0);
43 found_instance = instance_map_.insert(std::make_pair( 45 found_instance = instance_map_.insert(std::make_pair(
44 object_var->pp_instance(), 46 object_var->pp_instance(),
45 linked_ptr<NPObjectToNPObjectVarMap>(new NPObjectToNPObjectVarMap))). 47 linked_ptr<NPObjectToNPObjectVarMap>(new NPObjectToNPObjectVarMap))).
46 first; 48 first;
47 } 49 }
48 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); 50 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get();
49 51
50 DCHECK(np_object_map->find(object_var->np_object()) == 52 DCHECK(np_object_map->find(object_var->np_object()) ==
51 np_object_map->end()) << "NPObjectVar already in map"; 53 np_object_map->end()) << "NPObjectVar already in map";
52 np_object_map->insert(std::make_pair(object_var->np_object(), object_var)); 54 np_object_map->insert(std::make_pair(object_var->np_object(), object_var));
53 } 55 }
54 56
55 void HostVarTracker::RemoveNPObjectVar(NPObjectVar* object_var) { 57 void HostVarTracker::RemoveNPObjectVar(NPObjectVar* object_var) {
56 DCHECK(CalledOnValidThread()); 58 CheckThreadingPreconditions();
57 59
58 InstanceMap::iterator found_instance = instance_map_.find( 60 InstanceMap::iterator found_instance = instance_map_.find(
59 object_var->pp_instance()); 61 object_var->pp_instance());
60 if (found_instance == instance_map_.end()) { 62 if (found_instance == instance_map_.end()) {
61 NOTREACHED() << "NPObjectVar has invalid instance."; 63 NOTREACHED() << "NPObjectVar has invalid instance.";
62 return; 64 return;
63 } 65 }
64 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); 66 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get();
65 67
66 NPObjectToNPObjectVarMap::iterator found_object = 68 NPObjectToNPObjectVarMap::iterator found_object =
67 np_object_map->find(object_var->np_object()); 69 np_object_map->find(object_var->np_object());
68 if (found_object == np_object_map->end()) { 70 if (found_object == np_object_map->end()) {
69 NOTREACHED() << "NPObjectVar not registered."; 71 NOTREACHED() << "NPObjectVar not registered.";
70 return; 72 return;
71 } 73 }
72 if (found_object->second != object_var) { 74 if (found_object->second != object_var) {
73 NOTREACHED() << "NPObjectVar doesn't match."; 75 NOTREACHED() << "NPObjectVar doesn't match.";
74 return; 76 return;
75 } 77 }
76 np_object_map->erase(found_object); 78 np_object_map->erase(found_object);
77 } 79 }
78 80
79 NPObjectVar* HostVarTracker::NPObjectVarForNPObject(PP_Instance instance, 81 NPObjectVar* HostVarTracker::NPObjectVarForNPObject(PP_Instance instance,
80 NPObject* np_object) { 82 NPObject* np_object) {
81 DCHECK(CalledOnValidThread()); 83 CheckThreadingPreconditions();
82 84
83 InstanceMap::iterator found_instance = instance_map_.find(instance); 85 InstanceMap::iterator found_instance = instance_map_.find(instance);
84 if (found_instance == instance_map_.end()) 86 if (found_instance == instance_map_.end())
85 return NULL; // No such instance. 87 return NULL; // No such instance.
86 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); 88 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get();
87 89
88 NPObjectToNPObjectVarMap::iterator found_object = 90 NPObjectToNPObjectVarMap::iterator found_object =
89 np_object_map->find(np_object); 91 np_object_map->find(np_object);
90 if (found_object == np_object_map->end()) 92 if (found_object == np_object_map->end())
91 return NULL; // No such object. 93 return NULL; // No such object.
92 return found_object->second; 94 return found_object->second;
93 } 95 }
94 96
95 int HostVarTracker::GetLiveNPObjectVarsForInstance(PP_Instance instance) const { 97 int HostVarTracker::GetLiveNPObjectVarsForInstance(PP_Instance instance) const {
96 DCHECK(CalledOnValidThread()); 98 CheckThreadingPreconditions();
97 99
98 InstanceMap::const_iterator found = instance_map_.find(instance); 100 InstanceMap::const_iterator found = instance_map_.find(instance);
99 if (found == instance_map_.end()) 101 if (found == instance_map_.end())
100 return 0; 102 return 0;
101 return static_cast<int>(found->second->size()); 103 return static_cast<int>(found->second->size());
102 } 104 }
103 105
104 void HostVarTracker::DidDeleteInstance(PP_Instance instance) { 106 void HostVarTracker::DidDeleteInstance(PP_Instance instance) {
105 DCHECK(CalledOnValidThread()); 107 CheckThreadingPreconditions();
106 108
107 InstanceMap::iterator found_instance = instance_map_.find(instance); 109 InstanceMap::iterator found_instance = instance_map_.find(instance);
108 if (found_instance == instance_map_.end()) 110 if (found_instance == instance_map_.end())
109 return; // Nothing to do. 111 return; // Nothing to do.
110 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get(); 112 NPObjectToNPObjectVarMap* np_object_map = found_instance->second.get();
111 113
112 // Force delete all var references. ForceReleaseNPObject() will cause 114 // Force delete all var references. ForceReleaseNPObject() will cause
113 // this object, and potentially others it references, to be removed from 115 // this object, and potentially others it references, to be removed from
114 // |np_object_map|. 116 // |np_object_map|.
115 while (!np_object_map->empty()) { 117 while (!np_object_map->empty()) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 return false; 164 return false;
163 165
164 *handle = it->second.handle; 166 *handle = it->second.handle;
165 *size_in_bytes = it->second.size_in_bytes; 167 *size_in_bytes = it->second.size_in_bytes;
166 shared_memory_map_.erase(it); 168 shared_memory_map_.erase(it);
167 return true; 169 return true;
168 } 170 }
169 171
170 } // namespace ppapi 172 } // namespace ppapi
171 } // namespace webkit 173 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/host_globals.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698