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 #ifndef NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PROXY_VAR_CACHE_H_ | 5 #ifndef NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PROXY_VAR_CACHE_H_ |
6 #define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PROXY_VAR_CACHE_H_ | 6 #define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PROXY_VAR_CACHE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <vector> |
9 | 10 |
10 #include "native_client/src/include/nacl_memory.h" | 11 #include "native_client/src/include/nacl_memory.h" |
11 #include "native_client/src/shared/ppapi_proxy/proxy_var.h" | 12 #include "native_client/src/shared/ppapi_proxy/proxy_var.h" |
12 #include "ppapi/c/pp_var.h" | 13 #include "ppapi/c/pp_var.h" |
13 | 14 |
14 namespace ppapi_proxy { | 15 namespace ppapi_proxy { |
15 | 16 |
16 // This class manages the proxy-local cache of ProxyVars. The base factory | 17 // This class manages the proxy-local cache of ProxyVars. The base factory |
17 // method generates a unique id that gets used as the PP_Var's id, this id is | 18 // method generates a unique id that gets used as the PP_Var's id, this id is |
18 // associated with the variant's content. The factory also inserts the new | 19 // associated with the variant's content. The factory also inserts the new |
(...skipping 22 matching lines...) Expand all Loading... |
41 | 42 |
42 // Release the cached object associated with |id|. If the reference count | 43 // Release the cached object associated with |id|. If the reference count |
43 // of the object falls to 0, it gets removed from the cache. This only | 44 // of the object falls to 0, it gets removed from the cache. This only |
44 // operates on vars that are cached (that is, IsCachedType() returns |true|). | 45 // operates on vars that are cached (that is, IsCachedType() returns |true|). |
45 // Any other var type is ignored, and this function does nothing. | 46 // Any other var type is ignored, and this function does nothing. |
46 void ReleaseProxyVar(const PP_Var& var); | 47 void ReleaseProxyVar(const PP_Var& var); |
47 | 48 |
48 // Find the object in the cache associated with |pp_var|. | 49 // Find the object in the cache associated with |pp_var|. |
49 SharedProxyVar SharedProxyVarForVar(PP_Var pp_var) const; | 50 SharedProxyVar SharedProxyVarForVar(PP_Var pp_var) const; |
50 | 51 |
| 52 // Return all live Vars in the tracker. Reference counts are incremented. |
| 53 std::vector<PP_Var> GetLiveVars(); |
| 54 |
51 private: | 55 private: |
52 // Return whether or not a var type is cached. | 56 // Return whether or not a var type is cached. |
53 // Note to implementers: be sure to add to this function when adding new | 57 // Note to implementers: be sure to add to this function when adding new |
54 // cached types. | 58 // cached types. |
55 // TODO(dspringer): When all the complex var types are handled, this | 59 // TODO(dspringer): When all the complex var types are handled, this |
56 // test can turn into something like var.type >= PP_VARTYPE_STRING. | 60 // test can turn into something like var.type >= PP_VARTYPE_STRING. |
57 bool IsCachedType(const PP_Var& var) { | 61 bool IsCachedType(const PP_Var& var) { |
58 return var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT; | 62 return var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT; |
59 } | 63 } |
60 | 64 |
61 // The cache of these objects. The value is a shared pointer so that | 65 // The cache of these objects. The value is a shared pointer so that |
62 // instances of subclasses can be inserted. | 66 // instances of subclasses can be inserted. |
63 typedef std::map<int64_t, SharedProxyVar> ProxyVarDictionary; | 67 typedef std::map<int64_t, SharedProxyVar> ProxyVarDictionary; |
64 ProxyVarDictionary proxy_var_cache_; | 68 ProxyVarDictionary proxy_var_cache_; |
65 | 69 |
66 static ProxyVarCache* cache_singleton; | 70 static ProxyVarCache* cache_singleton; |
67 | 71 |
68 ProxyVarCache() {} | 72 ProxyVarCache() {} |
69 }; | 73 }; |
70 | 74 |
71 } // namespace ppapi_proxy | 75 } // namespace ppapi_proxy |
72 | 76 |
73 #endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PROXY_VAR_CACHE_H_ | 77 #endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PROXY_VAR_CACHE_H_ |
OLD | NEW |