1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47

android_webview / browser / tracing / aw_background_tracing_metrics_provider.h [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ANDROID_WEBVIEW_BROWSER_TRACING_AW_BACKGROUND_TRACING_METRICS_PROVIDER_H_
#define ANDROID_WEBVIEW_BROWSER_TRACING_AW_BACKGROUND_TRACING_METRICS_PROVIDER_H_

#include <optional>

#include "base/memory/weak_ptr.h"
#include "components/tracing/common/background_tracing_metrics_provider.h"

namespace tracing {

// Only upload traces under 512 KB to decrease the risk of filling up
// the app's IPC binder buffer (1 MB) and causing crashes.
constexpr static int kCompressedUploadLimitBytes = 512 * 1024;

class AwBackgroundTracingMetricsProvider
    : public BackgroundTracingMetricsProvider {
 public:
  AwBackgroundTracingMetricsProvider();

  AwBackgroundTracingMetricsProvider(
      const AwBackgroundTracingMetricsProvider&) = delete;
  AwBackgroundTracingMetricsProvider& operator=(
      const AwBackgroundTracingMetricsProvider&) = delete;

  ~AwBackgroundTracingMetricsProvider() override;

  // metrics::MetricsProvider:
  void DoInit() override;

  void RecordCoreSystemProfileMetrics(
      metrics::SystemProfileProto* system_profile_proto) override;

 private:
  // BackgroundTracingMetricsProvider:
  base::OnceCallback<bool(metrics::ChromeUserMetricsExtension*, std::string&&)>
  GetEmbedderMetricsProvider() override;

  base::WeakPtrFactory<AwBackgroundTracingMetricsProvider> weak_factory_{this};
};

}  // namespace tracing

#endif  // ANDROID_WEBVIEW_BROWSER_TRACING_AW_BACKGROUND_TRACING_METRICS_PROVIDER_H_