memory_metrics_logger_utils.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "android_webview/test/webview_instrumentation_test_native_jni/MemoryMetricsLoggerUtils_jni.h"
  5. #include "base/run_loop.h"
  6. #include "base/test/bind.h"
  7. #include "base/test/task_environment.h"
  8. #include "base/test/test_timeouts.h"
  9. #include "components/embedder_support/android/metrics/memory_metrics_logger.h"
  10. namespace android_webview {
  11. // static
  12. jboolean JNI_MemoryMetricsLoggerUtils_ForceRecordHistograms(JNIEnv* env) {
  13. auto* memory_metrics_logger =
  14. ::metrics::MemoryMetricsLogger::GetInstanceForTesting();
  15. if (!memory_metrics_logger)
  16. return false;
  17. TestTimeouts::Initialize();
  18. base::test::SingleThreadTaskEnvironment task_environment;
  19. base::RunLoop run_loop;
  20. bool result = false;
  21. memory_metrics_logger->ScheduleRecordForTesting(
  22. base::BindLambdaForTesting([&](bool success) {
  23. result = success;
  24. run_loop.Quit();
  25. }));
  26. run_loop.Run();
  27. return result;
  28. }
  29. } // namespace android_webview