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

Side by Side Diff: webkit/glue/plugins/pepper_resource_tracker.cc

Issue 5685002: Make it possible to write simple unit tests for the pepper implementation. Th... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/glue/plugins/pepper_resource_tracker.h" 5 #include "webkit/glue/plugins/pepper_resource_tracker.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <set> 8 #include <set>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "ppapi/c/pp_resource.h" 12 #include "ppapi/c/pp_resource.h"
13 #include "webkit/glue/plugins/pepper_resource.h" 13 #include "webkit/glue/plugins/pepper_resource.h"
14 14
15 namespace pepper { 15 namespace pepper {
16 16
17 scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const { 17 scoped_refptr<Resource> ResourceTracker::GetResource(PP_Resource res) const {
18 ResourceMap::const_iterator result = live_resources_.find(res); 18 ResourceMap::const_iterator result = live_resources_.find(res);
19 if (result == live_resources_.end()) { 19 if (result == live_resources_.end()) {
20 return scoped_refptr<Resource>(); 20 return scoped_refptr<Resource>();
21 } 21 }
22 return result->second.first; 22 return result->second.first;
23 } 23 }
24 24
25 // static
26 ResourceTracker* ResourceTracker::singleton_override_ = NULL;
27
25 ResourceTracker::ResourceTracker() 28 ResourceTracker::ResourceTracker()
26 : last_id_(0) { 29 : last_id_(0) {
27 } 30 }
28 31
29 ResourceTracker::~ResourceTracker() { 32 ResourceTracker::~ResourceTracker() {
30 } 33 }
31 34
32 // static 35 // static
33 ResourceTracker* ResourceTracker::Get() { 36 ResourceTracker* ResourceTracker::Get() {
37 if (singleton_override_)
38 return singleton_override_;
34 return Singleton<ResourceTracker>::get(); 39 return Singleton<ResourceTracker>::get();
35 } 40 }
36 41
37 PP_Resource ResourceTracker::AddResource(Resource* resource) { 42 PP_Resource ResourceTracker::AddResource(Resource* resource) {
38 // If the plugin manages to create 4B resources... 43 // If the plugin manages to create 4B resources...
39 if (last_id_ == std::numeric_limits<PP_Resource>::max()) { 44 if (last_id_ == std::numeric_limits<PP_Resource>::max()) {
40 return 0; 45 return 0;
41 } 46 }
42 // Add the resource with plugin use-count 1. 47 // Add the resource with plugin use-count 1.
43 ++last_id_; 48 ++last_id_;
(...skipping 22 matching lines...) Expand all
66 live_resources_.erase(i); 71 live_resources_.erase(i);
67 } 72 }
68 return true; 73 return true;
69 } else { 74 } else {
70 return false; 75 return false;
71 } 76 }
72 } 77 }
73 78
74 void ResourceTracker::ForceDeletePluginResourceRefs(PP_Resource res) { 79 void ResourceTracker::ForceDeletePluginResourceRefs(PP_Resource res) {
75 ResourceMap::iterator i = live_resources_.find(res); 80 ResourceMap::iterator i = live_resources_.find(res);
76 if (i != live_resources_.end()) 81 if (i == live_resources_.end())
77 return; // Nothing to do. 82 return; // Nothing to do.
78 83
79 i->second.second = 0; 84 i->second.second = 0;
80 i->second.first->StoppedTracking(); 85 i->second.first->StoppedTracking();
81 live_resources_.erase(i); 86 live_resources_.erase(i);
82 } 87 }
83 88
84 uint32 ResourceTracker::GetLiveObjectsForModule(PluginModule* module) const { 89 uint32 ResourceTracker::GetLiveObjectsForModule(PluginModule* module) const {
85 // Since this is for testing only, we'll just go through all of them and 90 // Since this is for testing only, we'll just go through all of them and
86 // count. 91 // count.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 module_map_.erase(found); 167 module_map_.erase(found);
163 } 168 }
164 169
165 PluginModule* ResourceTracker::GetModule(PP_Module module) { 170 PluginModule* ResourceTracker::GetModule(PP_Module module) {
166 ModuleMap::iterator found = module_map_.find(module); 171 ModuleMap::iterator found = module_map_.find(module);
167 if (found == module_map_.end()) 172 if (found == module_map_.end())
168 return NULL; 173 return NULL;
169 return found->second; 174 return found->second;
170 } 175 }
171 176
177 // static
178 void ResourceTracker::SetSingletonOverride(ResourceTracker* tracker) {
179 DCHECK(!singleton_override_);
180 singleton_override_ = tracker;
181 }
182
183 // static
184 void ResourceTracker::ClearSingletonOverride() {
185 DCHECK(singleton_override_);
186 singleton_override_ = NULL;
187 }
188
172 } // namespace pepper 189 } // namespace pepper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698