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 PPAPI_SHARED_IMPL_VAR_H_ | 5 #ifndef PPAPI_SHARED_IMPL_VAR_H_ |
6 #define PPAPI_SHARED_IMPL_VAR_H_ | 6 #define PPAPI_SHARED_IMPL_VAR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "ppapi/c/pp_var.h" | 12 #include "ppapi/c/pp_var.h" |
13 #include "ppapi/shared_impl/ppapi_shared_export.h" | 13 #include "ppapi/shared_impl/ppapi_shared_export.h" |
14 | 14 |
15 namespace ppapi { | 15 namespace ppapi { |
16 | 16 |
17 class NPObjectVar; | 17 class NPObjectVar; |
18 class ProxyObjectVar; | 18 class ProxyObjectVar; |
19 class StringVar; | 19 class StringVar; |
20 class VarTracker; | |
21 | 20 |
22 // Var ------------------------------------------------------------------------- | 21 // Var ------------------------------------------------------------------------- |
23 | 22 |
24 // Represents a non-POD var. | 23 // Represents a non-POD var. |
25 class PPAPI_SHARED_EXPORT Var : public base::RefCounted<Var> { | 24 class PPAPI_SHARED_EXPORT Var : public base::RefCounted<Var> { |
26 public: | 25 public: |
27 virtual ~Var(); | 26 virtual ~Var(); |
28 | 27 |
29 // Returns a string representing the given var for logging purposes. | 28 // Returns a string representing the given var for logging purposes. |
30 static std::string PPVarToLogString(PP_Var var); | 29 static std::string PPVarToLogString(PP_Var var); |
(...skipping 11 matching lines...) Expand all Loading... |
42 | 41 |
43 // Returns the ID corresponing to the string or object if it exists already, | 42 // Returns the ID corresponing to the string or object if it exists already, |
44 // or 0 if an ID hasn't been generated for this object (the plugin is holding | 43 // or 0 if an ID hasn't been generated for this object (the plugin is holding |
45 // no refs). | 44 // no refs). |
46 // | 45 // |
47 // Contrast to GetOrCreateVarID which creates the ID and a ref on behalf of | 46 // Contrast to GetOrCreateVarID which creates the ID and a ref on behalf of |
48 // the plugin. | 47 // the plugin. |
49 int32 GetExistingVarID() const; | 48 int32 GetExistingVarID() const; |
50 | 49 |
51 protected: | 50 protected: |
52 friend class VarTracker; | |
53 | |
54 Var(); | 51 Var(); |
55 | 52 |
56 // Returns the unique ID associated with this string or object, creating it | 53 // Returns the unique ID associated with this string or object, creating it |
57 // if necessary. The return value will be 0 if the string or object is | 54 // if necessary. The return value will be 0 if the string or object is |
58 // invalid. | 55 // invalid. |
59 // | 56 // |
60 // This function will take a reference to the var that will be passed to the | 57 // This function will take a reference to the var that will be passed to the |
61 // caller. | 58 // caller. |
62 int32 GetOrCreateVarID(); | 59 int32 GetOrCreateVarID(); |
63 | 60 |
64 // Sets the internal object ID. This assumes that the ID hasn't been set | 61 // Sets the internal object ID. This assumes that the ID hasn't been set |
65 // before. This is used in cases where the ID is generated externally. | 62 // before. This is used in cases where the ID is generated externally. |
66 void AssignVarID(int32 id); | 63 void AssignVarID(int32 id); |
67 | 64 |
68 // Reset the assigned object ID. | |
69 void ResetVarID() { AssignVarID(0); }; | |
70 | |
71 private: | 65 private: |
72 // This will be 0 if no ID has been assigned (this happens lazily). | 66 // This will be 0 if no ID has been assigned (this happens lazily). |
73 int32 var_id_; | 67 int32 var_id_; |
74 | 68 |
75 DISALLOW_COPY_AND_ASSIGN(Var); | 69 DISALLOW_COPY_AND_ASSIGN(Var); |
76 }; | 70 }; |
77 | 71 |
78 // StringVar ------------------------------------------------------------------- | 72 // StringVar ------------------------------------------------------------------- |
79 | 73 |
80 // Represents a string-based Var. | 74 // Represents a string-based Var. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 109 |
116 private: | 110 private: |
117 std::string value_; | 111 std::string value_; |
118 | 112 |
119 DISALLOW_COPY_AND_ASSIGN(StringVar); | 113 DISALLOW_COPY_AND_ASSIGN(StringVar); |
120 }; | 114 }; |
121 | 115 |
122 } // namespace ppapi | 116 } // namespace ppapi |
123 | 117 |
124 #endif // PPAPI_SHARED_IMPL_VAR_H_ | 118 #endif // PPAPI_SHARED_IMPL_VAR_H_ |
OLD | NEW |