Index: talk/app/webrtc/test/androidtestinitializer.cc |
diff --git a/talk/app/webrtc/fakemetricsobserver.cc b/talk/app/webrtc/test/androidtestinitializer.cc |
similarity index 50% |
copy from talk/app/webrtc/fakemetricsobserver.cc |
copy to talk/app/webrtc/test/androidtestinitializer.cc |
index 4a100a079e58f163466b5eed97c1c91209f10adc..883c2d81782d80f4dedccdb04d4e5ac9ee48ad67 100644 |
--- a/talk/app/webrtc/fakemetricsobserver.cc |
+++ b/talk/app/webrtc/test/androidtestinitializer.cc |
@@ -25,55 +25,50 @@ |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
-#include "talk/app/webrtc/fakemetricsobserver.h" |
+#include "talk/app/webrtc/test/androidtestinitializer.h" |
+ |
+#include <pthread.h> |
+ |
+// Note: this dependency is dangerous since it reaches into Chromium's base. |
+// There's a risk of e.g. macro clashes. This file may only be used in tests. |
+// Since we use Chromes build system for creating the gtest binary, this should |
+// be fine. |
+#include "base/android/context_utils.h" |
+#include "base/android/jni_android.h" |
+ |
+#include "talk/app/webrtc/java/jni/classreferenceholder.h" |
+#include "talk/app/webrtc/java/jni/jni_helpers.h" |
#include "webrtc/base/checks.h" |
+#include "webrtc/base/ssladapter.h" |
+#include "webrtc/voice_engine/include/voe_base.h" |
namespace webrtc { |
-FakeMetricsObserver::FakeMetricsObserver() { |
- Reset(); |
-} |
+namespace { |
-void FakeMetricsObserver::Reset() { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
- counters_.clear(); |
- memset(histogram_samples_, 0, sizeof(histogram_samples_)); |
-} |
+static pthread_once_t g_initialize_once = PTHREAD_ONCE_INIT; |
-void FakeMetricsObserver::IncrementEnumCounter( |
- PeerConnectionEnumCounterType type, |
- int counter, |
- int counter_max) { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
- if (counters_.size() <= static_cast<size_t>(type)) { |
- counters_.resize(type + 1); |
- } |
- auto& counters = counters_[type]; |
- ++counters[counter]; |
-} |
+// There can only be one JNI_OnLoad in each binary. So since this is a GTEST |
+// C++ runner binary, we want to initialize the same global objects we normally |
+// do if this had been a Java binary. |
+void EnsureInitializedOnce() { |
+ RTC_CHECK(::base::android::IsVMInitialized()); |
+ JNIEnv* jni = ::base::android::AttachCurrentThread(); |
+ JavaVM* jvm = NULL; |
+ RTC_CHECK_EQ(0, jni->GetJavaVM(&jvm)); |
+ jobject context = ::base::android::GetApplicationContext(); |
-void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, |
- int value) { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
- RTC_DCHECK_EQ(histogram_samples_[type], 0); |
- histogram_samples_[type] = value; |
-} |
+ RTC_CHECK_GE(webrtc_jni::InitGlobalJniVariables(jvm), 0); |
+ RTC_CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()"; |
+ webrtc_jni::LoadGlobalClassReferenceHolder(); |
-int FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type, |
- int counter) const { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
- RTC_CHECK(counters_.size() > static_cast<size_t>(type)); |
- const auto& it = counters_[type].find(counter); |
- if (it == counters_[type].end()) { |
- return 0; |
- } |
- return it->second; |
+ webrtc::VoiceEngine::SetAndroidObjects(jvm, context); |
} |
-int FakeMetricsObserver::GetHistogramSample( |
- PeerConnectionMetricsName type) const { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
- return histogram_samples_[type]; |
+} // anonymous namespace |
+ |
+void InitializeAndroidObjects() { |
+ RTC_CHECK_EQ(0, pthread_once(&g_initialize_once, &EnsureInitializedOnce)); |
} |
} // namespace webrtc |