blob: d90aa7b3dc4e05223c884bc29fe3d72f1be0d3fd [file] [log] [blame]
[email protected]064107e2014-05-02 00:59:061// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]cac267c2011-09-29 15:18:102// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]064107e2014-05-02 00:59:065#include "components/metrics/metrics_log_manager.h"
[email protected]cac267c2011-09-29 15:18:106
[email protected]418c2ee2012-06-11 23:15:387#include <algorithm>
dcheng51606352015-12-26 21:16:238#include <utility>
[email protected]418c2ee2012-06-11 23:15:389
[email protected]3c8a6b02013-06-11 00:49:4910#include "base/strings/string_util.h"
[email protected]bfb77b52014-06-07 01:54:0111#include "components/metrics/metrics_log.h"
holteade6fdf2017-02-23 02:42:3912#include "components/metrics/metrics_log_store.h"
[email protected]7f07db62014-05-15 01:12:4513#include "components/metrics/metrics_pref_names.h"
[email protected]064107e2014-05-02 00:59:0614
15namespace metrics {
[email protected]cac267c2011-09-29 15:18:1016
holteade6fdf2017-02-23 02:42:3917MetricsLogManager::MetricsLogManager() {}
[email protected]cac267c2011-09-29 15:18:1018
19MetricsLogManager::~MetricsLogManager() {}
20
dchengd99c42a2016-04-21 21:54:1321void MetricsLogManager::BeginLoggingWithLog(std::unique_ptr<MetricsLog> log) {
[email protected]09dee82d2014-05-22 14:00:5322 DCHECK(!current_log_);
dcheng51606352015-12-26 21:16:2323 current_log_ = std::move(log);
[email protected]29948262012-03-01 12:15:0824}
25
holteade6fdf2017-02-23 02:42:3926void MetricsLogManager::FinishCurrentLog(MetricsLogStore* log_store) {
Zinovy Nis3c5a779e2018-05-11 07:09:5027 DCHECK(current_log_);
[email protected]cac267c2011-09-29 15:18:1028 current_log_->CloseLog();
[email protected]9706e1b2014-06-11 16:31:2429 std::string log_data;
30 current_log_->GetEncodedLog(&log_data);
31 if (!log_data.empty())
holteade6fdf2017-02-23 02:42:3932 log_store->StoreLog(log_data, current_log_->log_type());
[email protected]29948262012-03-01 12:15:0833 current_log_.reset();
34}
35
[email protected]cac267c2011-09-29 15:18:1036void MetricsLogManager::DiscardCurrentLog() {
37 current_log_->CloseLog();
38 current_log_.reset();
39}
40
41void MetricsLogManager::PauseCurrentLog() {
Zinovy Nis3c5a779e2018-05-11 07:09:5042 DCHECK(!paused_log_);
Yoonjae.Cho920d074f72016-11-22 12:42:1743 paused_log_ = std::move(current_log_);
[email protected]cac267c2011-09-29 15:18:1044}
45
46void MetricsLogManager::ResumePausedLog() {
Zinovy Nis3c5a779e2018-05-11 07:09:5047 DCHECK(!current_log_);
Yoonjae.Cho920d074f72016-11-22 12:42:1748 current_log_ = std::move(paused_log_);
[email protected]cac267c2011-09-29 15:18:1049}
50
[email protected]bfb77b52014-06-07 01:54:0151} // namespace metrics