[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | cac267c | 2011-09-29 15:18:10 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 5 | #include "components/metrics/metrics_log_manager.h" |
[email protected] | cac267c | 2011-09-29 15:18:10 | [diff] [blame] | 6 | |
[email protected] | 418c2ee | 2012-06-11 23:15:38 | [diff] [blame] | 7 | #include <algorithm> |
dcheng | 5160635 | 2015-12-26 21:16:23 | [diff] [blame] | 8 | #include <utility> |
[email protected] | 418c2ee | 2012-06-11 23:15:38 | [diff] [blame] | 9 | |
[email protected] | 3c8a6b0 | 2013-06-11 00:49:49 | [diff] [blame] | 10 | #include "base/strings/string_util.h" |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 11 | #include "components/metrics/metrics_log.h" |
holte | ade6fdf | 2017-02-23 02:42:39 | [diff] [blame] | 12 | #include "components/metrics/metrics_log_store.h" |
[email protected] | 7f07db6 | 2014-05-15 01:12:45 | [diff] [blame] | 13 | #include "components/metrics/metrics_pref_names.h" |
[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 14 | |
15 | namespace metrics { | ||||
[email protected] | cac267c | 2011-09-29 15:18:10 | [diff] [blame] | 16 | |
holte | ade6fdf | 2017-02-23 02:42:39 | [diff] [blame] | 17 | MetricsLogManager::MetricsLogManager() {} |
[email protected] | cac267c | 2011-09-29 15:18:10 | [diff] [blame] | 18 | |
19 | MetricsLogManager::~MetricsLogManager() {} | ||||
20 | |||||
dcheng | d99c42a | 2016-04-21 21:54:13 | [diff] [blame] | 21 | void MetricsLogManager::BeginLoggingWithLog(std::unique_ptr<MetricsLog> log) { |
[email protected] | 09dee82d | 2014-05-22 14:00:53 | [diff] [blame] | 22 | DCHECK(!current_log_); |
dcheng | 5160635 | 2015-12-26 21:16:23 | [diff] [blame] | 23 | current_log_ = std::move(log); |
[email protected] | 2994826 | 2012-03-01 12:15:08 | [diff] [blame] | 24 | } |
25 | |||||
holte | ade6fdf | 2017-02-23 02:42:39 | [diff] [blame] | 26 | void MetricsLogManager::FinishCurrentLog(MetricsLogStore* log_store) { |
Zinovy Nis | 3c5a779e | 2018-05-11 07:09:50 | [diff] [blame] | 27 | DCHECK(current_log_); |
[email protected] | cac267c | 2011-09-29 15:18:10 | [diff] [blame] | 28 | current_log_->CloseLog(); |
[email protected] | 9706e1b | 2014-06-11 16:31:24 | [diff] [blame] | 29 | std::string log_data; |
30 | current_log_->GetEncodedLog(&log_data); | ||||
31 | if (!log_data.empty()) | ||||
holte | ade6fdf | 2017-02-23 02:42:39 | [diff] [blame] | 32 | log_store->StoreLog(log_data, current_log_->log_type()); |
[email protected] | 2994826 | 2012-03-01 12:15:08 | [diff] [blame] | 33 | current_log_.reset(); |
34 | } | ||||
35 | |||||
[email protected] | cac267c | 2011-09-29 15:18:10 | [diff] [blame] | 36 | void MetricsLogManager::DiscardCurrentLog() { |
37 | current_log_->CloseLog(); | ||||
38 | current_log_.reset(); | ||||
39 | } | ||||
40 | |||||
41 | void MetricsLogManager::PauseCurrentLog() { | ||||
Zinovy Nis | 3c5a779e | 2018-05-11 07:09:50 | [diff] [blame] | 42 | DCHECK(!paused_log_); |
Yoonjae.Cho92 | 0d074f7 | 2016-11-22 12:42:17 | [diff] [blame] | 43 | paused_log_ = std::move(current_log_); |
[email protected] | cac267c | 2011-09-29 15:18:10 | [diff] [blame] | 44 | } |
45 | |||||
46 | void MetricsLogManager::ResumePausedLog() { | ||||
Zinovy Nis | 3c5a779e | 2018-05-11 07:09:50 | [diff] [blame] | 47 | DCHECK(!current_log_); |
Yoonjae.Cho92 | 0d074f7 | 2016-11-22 12:42:17 | [diff] [blame] | 48 | current_log_ = std::move(paused_log_); |
[email protected] | cac267c | 2011-09-29 15:18:10 | [diff] [blame] | 49 | } |
50 | |||||
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 51 | } // namespace metrics |