blob: 8b5b73dafd808065c37177794aa3f5f96a9bdf45 [file] [log] [blame]
// Copyright 2023 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef COBALT_BROWSER_METRICS_COBALT_METRICS_LOG_UPLOADER_H_
#define COBALT_BROWSER_METRICS_COBALT_METRICS_LOG_UPLOADER_H_
#include <string>
#include "base/callback.h"
#include "base/macros.h"
#include "base/strings/string_piece.h"
#include "cobalt/base/event_dispatcher.h"
#include "cobalt/h5vcc/metric_event_handler_wrapper.h"
#include "components/metrics/metrics_log_uploader.h"
#include "third_party/metrics_proto/reporting_info.pb.h"
namespace cobalt {
namespace browser {
namespace metrics {
class ReportingInfo;
// A Cobalt implementation of MetricsLogUploader that intercepts metric's logs
// when they're ready to be sent to the server and forwards them to the web
// client via the H5vcc API.
class CobaltMetricsLogUploader : public ::metrics::MetricsLogUploader {
public:
CobaltMetricsLogUploader(
::metrics::MetricsLogUploader::MetricServiceType service_type,
const ::metrics::MetricsLogUploader::UploadCallback& on_upload_complete);
virtual ~CobaltMetricsLogUploader() {}
// Set event dispatcher to be used to publish any metrics events (eg upload).
void SetEventDispatcher(const base::EventDispatcher* event_dispatcher);
// Uploads a log with the specified |compressed_log_data| and |log_hash|.
// |log_hash| is expected to be the hex-encoded SHA1 hash of the log data
// before compression.
void UploadLog(const std::string& compressed_log_data,
const std::string& log_hash,
const ::metrics::ReportingInfo& reporting_info);
private:
const ::metrics::MetricsLogUploader::MetricServiceType service_type_;
const ::metrics::MetricsLogUploader::UploadCallback on_upload_complete_;
const base::EventDispatcher* event_dispatcher_ = nullptr;
};
} // namespace metrics
} // namespace browser
} // namespace cobalt
#endif // COBALT_BROWSER_METRICS_COBALT_METRICS_LOG_UPLOADER_H_