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

Side by Side Diff: ppapi/shared_impl/resource_tracker.h

Issue 1864293002: Convert //ppapi to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more nullptr Created 4 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
« no previous file with comments | « ppapi/shared_impl/proxy_lock.h ('k') | ppapi/shared_impl/resource_tracker.cc » ('j') | 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 #ifndef PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_ 5 #ifndef PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_
6 #define PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_ 6 #define PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory>
10 #include <set> 11 #include <set>
11 12
12 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
17 #include "base/threading/thread_checker_impl.h" 17 #include "base/threading/thread_checker_impl.h"
18 #include "ppapi/c/pp_instance.h" 18 #include "ppapi/c/pp_instance.h"
19 #include "ppapi/c/pp_resource.h" 19 #include "ppapi/c/pp_resource.h"
20 #include "ppapi/shared_impl/ppapi_shared_export.h" 20 #include "ppapi/shared_impl/ppapi_shared_export.h"
21 21
22 namespace ppapi { 22 namespace ppapi {
23 23
24 class Resource; 24 class Resource;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 bool CanOperateOnResource(PP_Resource res); 99 bool CanOperateOnResource(PP_Resource res);
100 100
101 typedef std::set<PP_Resource> ResourceSet; 101 typedef std::set<PP_Resource> ResourceSet;
102 102
103 struct InstanceData { 103 struct InstanceData {
104 // Lists all resources associated with the given instance as non-owning 104 // Lists all resources associated with the given instance as non-owning
105 // pointers. This allows us to notify those resources that the instance is 105 // pointers. This allows us to notify those resources that the instance is
106 // going away (otherwise, they may crash if they outlive the instance). 106 // going away (otherwise, they may crash if they outlive the instance).
107 ResourceSet resources; 107 ResourceSet resources;
108 }; 108 };
109 typedef base::hash_map<PP_Instance, scoped_ptr<InstanceData>> InstanceMap; 109 typedef base::hash_map<PP_Instance, std::unique_ptr<InstanceData>>
110 InstanceMap;
110 111
111 InstanceMap instance_map_; 112 InstanceMap instance_map_;
112 113
113 // For each PP_Resource, keep the object pointer and a plugin use count. 114 // For each PP_Resource, keep the object pointer and a plugin use count.
114 // This use count is different then Resource object's RefCount, and is 115 // This use count is different then Resource object's RefCount, and is
115 // manipulated using this AddRefResource/UnrefResource. When the plugin use 116 // manipulated using this AddRefResource/UnrefResource. When the plugin use
116 // count is positive, we keep an extra ref on the Resource on 117 // count is positive, we keep an extra ref on the Resource on
117 // behalf of the plugin. When it drops to 0, we free that ref, keeping 118 // behalf of the plugin. When it drops to 0, we free that ref, keeping
118 // the resource in the list. 119 // the resource in the list.
119 // 120 //
120 // A resource will be in this list as long as the object is alive. 121 // A resource will be in this list as long as the object is alive.
121 typedef std::pair<Resource*, int> ResourceAndRefCount; 122 typedef std::pair<Resource*, int> ResourceAndRefCount;
122 typedef base::hash_map<PP_Resource, ResourceAndRefCount> ResourceMap; 123 typedef base::hash_map<PP_Resource, ResourceAndRefCount> ResourceMap;
123 ResourceMap live_resources_; 124 ResourceMap live_resources_;
124 125
125 int32_t last_resource_value_; 126 int32_t last_resource_value_;
126 127
127 // On the host side, we want to check that we are only called on the main 128 // On the host side, we want to check that we are only called on the main
128 // thread. This is to protect us from accidentally using the tracker from 129 // thread. This is to protect us from accidentally using the tracker from
129 // other threads (especially the IO thread). On the plugin side, the tracker 130 // other threads (especially the IO thread). On the plugin side, the tracker
130 // is protected by the proxy lock and is thread-safe, so this will be NULL. 131 // is protected by the proxy lock and is thread-safe, so this will be NULL.
131 scoped_ptr<base::ThreadChecker> thread_checker_; 132 std::unique_ptr<base::ThreadChecker> thread_checker_;
132 133
133 base::WeakPtrFactory<ResourceTracker> weak_ptr_factory_; 134 base::WeakPtrFactory<ResourceTracker> weak_ptr_factory_;
134 135
135 DISALLOW_COPY_AND_ASSIGN(ResourceTracker); 136 DISALLOW_COPY_AND_ASSIGN(ResourceTracker);
136 }; 137 };
137 138
138 } // namespace ppapi 139 } // namespace ppapi
139 140
140 #endif // PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_ 141 #endif // PPAPI_SHARED_IMPL_RESOURCE_TRACKER_H_
OLDNEW
« no previous file with comments | « ppapi/shared_impl/proxy_lock.h ('k') | ppapi/shared_impl/resource_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698