| 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 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
| 10 #include "ppapi/c/pp_var.h" | 10 #include "ppapi/c/pp_var.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 const int kRefsToAdd = 20; | 23 const int kRefsToAdd = 20; |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 namespace ppapi { | 26 namespace ppapi { |
| 27 namespace proxy { | 27 namespace proxy { |
| 28 | 28 |
| 29 class PPB_VarTest : public PluginProxyTest { | 29 class PPB_VarTest : public PluginProxyTest { |
| 30 public: | 30 public: |
| 31 PPB_VarTest() | 31 PPB_VarTest() |
| 32 : test_strings_(kNumStrings), vars_(kNumStrings), | 32 : test_strings_(kNumStrings), vars_(kNumStrings), |
| 33 ppb_var_(ppapi::PPB_Var_Shared::GetVarInterface()) { | 33 ppb_var_(ppapi::PPB_Var_Shared::GetVarInterface1_1()) { |
| 34 // Set the value of test_strings_[i] to "i". | 34 // Set the value of test_strings_[i] to "i". |
| 35 for (size_t i = 0; i < kNumStrings; ++i) | 35 for (size_t i = 0; i < kNumStrings; ++i) |
| 36 test_strings_[i] = base::IntToString(i); | 36 test_strings_[i] = base::IntToString(i); |
| 37 } | 37 } |
| 38 protected: | 38 protected: |
| 39 std::vector<std::string> test_strings_; | 39 std::vector<std::string> test_strings_; |
| 40 std::vector<PP_Var> vars_; | 40 std::vector<PP_Var> vars_; |
| 41 const PPB_Var* ppb_var_; | 41 const PPB_Var* ppb_var_; |
| 42 }; | 42 }; |
| 43 | 43 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // For each |strings_in[i]|, we will set |vars[i]| using that value. Then we | 95 // For each |strings_in[i]|, we will set |vars[i]| using that value. Then we |
| 96 // read the var back out to |strings_out[i]|. | 96 // read the var back out to |strings_out[i]|. |
| 97 CreateVarThreadDelegate(PP_Module pp_module, const std::string* strings_in, | 97 CreateVarThreadDelegate(PP_Module pp_module, const std::string* strings_in, |
| 98 PP_Var* vars_out, std::string* strings_out, | 98 PP_Var* vars_out, std::string* strings_out, |
| 99 size_t size) | 99 size_t size) |
| 100 : pp_module_(pp_module), strings_in_(strings_in), vars_out_(vars_out), | 100 : pp_module_(pp_module), strings_in_(strings_in), vars_out_(vars_out), |
| 101 strings_out_(strings_out), size_(size) { | 101 strings_out_(strings_out), size_(size) { |
| 102 } | 102 } |
| 103 virtual ~CreateVarThreadDelegate() {} | 103 virtual ~CreateVarThreadDelegate() {} |
| 104 virtual void ThreadMain() { | 104 virtual void ThreadMain() { |
| 105 const PPB_Var* ppb_var = ppapi::PPB_Var_Shared::GetVarInterface(); | 105 const PPB_Var* ppb_var = ppapi::PPB_Var_Shared::GetVarInterface1_1(); |
| 106 for (size_t i = 0; i < size_; ++i) { | 106 for (size_t i = 0; i < size_; ++i) { |
| 107 vars_out_[i] = ppb_var->VarFromUtf8(strings_in_[i].c_str(), | 107 vars_out_[i] = ppb_var->VarFromUtf8(strings_in_[i].c_str(), |
| 108 strings_in_[i].length()); | 108 strings_in_[i].length()); |
| 109 strings_out_[i] = VarToString(vars_out_[i], ppb_var); | 109 strings_out_[i] = VarToString(vars_out_[i], ppb_var); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 private: | 112 private: |
| 113 PP_Module pp_module_; | 113 PP_Module pp_module_; |
| 114 const std::string* strings_in_; | 114 const std::string* strings_in_; |
| 115 PP_Var* vars_out_; | 115 PP_Var* vars_out_; |
| 116 std::string* strings_out_; | 116 std::string* strings_out_; |
| 117 size_t size_; | 117 size_t size_; |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 // A thread that will increment and decrement the reference count of every var | 120 // A thread that will increment and decrement the reference count of every var |
| 121 // multiple times. | 121 // multiple times. |
| 122 class ChangeRefVarThreadDelegate : public base::PlatformThread::Delegate { | 122 class ChangeRefVarThreadDelegate : public base::PlatformThread::Delegate { |
| 123 public: | 123 public: |
| 124 ChangeRefVarThreadDelegate(const std::vector<PP_Var>& vars) : vars_(vars) { | 124 ChangeRefVarThreadDelegate(const std::vector<PP_Var>& vars) : vars_(vars) { |
| 125 } | 125 } |
| 126 virtual ~ChangeRefVarThreadDelegate() {} | 126 virtual ~ChangeRefVarThreadDelegate() {} |
| 127 virtual void ThreadMain() { | 127 virtual void ThreadMain() { |
| 128 const PPB_Var* ppb_var = ppapi::PPB_Var_Shared::GetVarInterface(); | 128 const PPB_Var* ppb_var = ppapi::PPB_Var_Shared::GetVarInterface1_1(); |
| 129 // Increment and decrement the reference count for each var kRefsToAdd | 129 // Increment and decrement the reference count for each var kRefsToAdd |
| 130 // times. Note that we always AddRef once before doing the matching Release, | 130 // times. Note that we always AddRef once before doing the matching Release, |
| 131 // to ensure that we never accidentally release the last reference. | 131 // to ensure that we never accidentally release the last reference. |
| 132 for (int ref = 0; ref < kRefsToAdd; ++ref) { | 132 for (int ref = 0; ref < kRefsToAdd; ++ref) { |
| 133 for (size_t i = 0; i < kNumStrings; ++i) { | 133 for (size_t i = 0; i < kNumStrings; ++i) { |
| 134 ppb_var->AddRef(vars_[i]); | 134 ppb_var->AddRef(vars_[i]); |
| 135 ppb_var->Release(vars_[i]); | 135 ppb_var->Release(vars_[i]); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 // Now add 1 ref to each Var. The net result is that all Vars will have a | 138 // Now add 1 ref to each Var. The net result is that all Vars will have a |
| 139 // ref-count of (kNumThreads + 1) after this. That will allow us to have all | 139 // ref-count of (kNumThreads + 1) after this. That will allow us to have all |
| 140 // threads release all vars later. | 140 // threads release all vars later. |
| 141 for (size_t i = 0; i < kNumStrings; ++i) { | 141 for (size_t i = 0; i < kNumStrings; ++i) { |
| 142 ppb_var->AddRef(vars_[i]); | 142 ppb_var->AddRef(vars_[i]); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 private: | 145 private: |
| 146 std::vector<PP_Var> vars_; | 146 std::vector<PP_Var> vars_; |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 // A thread that will decrement the reference count of every var once. | 149 // A thread that will decrement the reference count of every var once. |
| 150 class RemoveRefVarThreadDelegate : public base::PlatformThread::Delegate { | 150 class RemoveRefVarThreadDelegate : public base::PlatformThread::Delegate { |
| 151 public: | 151 public: |
| 152 RemoveRefVarThreadDelegate(const std::vector<PP_Var>& vars) : vars_(vars) { | 152 RemoveRefVarThreadDelegate(const std::vector<PP_Var>& vars) : vars_(vars) { |
| 153 } | 153 } |
| 154 virtual ~RemoveRefVarThreadDelegate() {} | 154 virtual ~RemoveRefVarThreadDelegate() {} |
| 155 virtual void ThreadMain() { | 155 virtual void ThreadMain() { |
| 156 const PPB_Var* ppb_var = ppapi::PPB_Var_Shared::GetVarInterface(); | 156 const PPB_Var* ppb_var = ppapi::PPB_Var_Shared::GetVarInterface1_1(); |
| 157 for (size_t i = 0; i < kNumStrings; ++i) { | 157 for (size_t i = 0; i < kNumStrings; ++i) { |
| 158 ppb_var->Release(vars_[i]); | 158 ppb_var->Release(vars_[i]); |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 private: | 161 private: |
| 162 std::vector<PP_Var> vars_; | 162 std::vector<PP_Var> vars_; |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 } // namespace | 165 } // namespace |
| 166 | 166 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 for (size_t i = 0; i < kNumStrings; ++i) { | 236 for (size_t i = 0; i < kNumStrings; ++i) { |
| 237 uint32_t len = 10; | 237 uint32_t len = 10; |
| 238 const char* utf8 = ppb_var_->VarToUtf8(vars_[i], &len); | 238 const char* utf8 = ppb_var_->VarToUtf8(vars_[i], &len); |
| 239 EXPECT_EQ(NULL, utf8); | 239 EXPECT_EQ(NULL, utf8); |
| 240 EXPECT_EQ(0u, len); | 240 EXPECT_EQ(0u, len); |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 } // namespace proxy | 244 } // namespace proxy |
| 245 } // namespace ppapi | 245 } // namespace ppapi |
| 246 | |
| OLD | NEW |