| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/metrics/metrics_log_manager.h" | 5 #include "components/metrics/metrics_log_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/timer/elapsed_timer.h" | 11 #include "base/timer/elapsed_timer.h" |
| 12 #include "components/metrics/metrics_log_base.h" | 12 #include "components/metrics/metrics_log.h" |
| 13 #include "components/metrics/metrics_pref_names.h" | 13 #include "components/metrics/metrics_pref_names.h" |
| 14 | 14 |
| 15 namespace metrics { | 15 namespace metrics { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // The number of "initial" logs to save, and hope to send during a future Chrome | 19 // The number of "initial" logs to save, and hope to send during a future Chrome |
| 20 // session. Initial logs contain crash stats, and are pretty small. | 20 // session. Initial logs contain crash stats, and are pretty small. |
| 21 const size_t kInitialLogsPersistLimit = 20; | 21 const size_t kInitialLogsPersistLimit = 20; |
| 22 | 22 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 47 kStorageByteLimitPerLogType, | 47 kStorageByteLimitPerLogType, |
| 48 0), | 48 0), |
| 49 ongoing_log_queue_(local_state, | 49 ongoing_log_queue_(local_state, |
| 50 prefs::kMetricsOngoingLogs, | 50 prefs::kMetricsOngoingLogs, |
| 51 kOngoingLogsPersistLimit, | 51 kOngoingLogsPersistLimit, |
| 52 kStorageByteLimitPerLogType, | 52 kStorageByteLimitPerLogType, |
| 53 max_ongoing_log_size) {} | 53 max_ongoing_log_size) {} |
| 54 | 54 |
| 55 MetricsLogManager::~MetricsLogManager() {} | 55 MetricsLogManager::~MetricsLogManager() {} |
| 56 | 56 |
| 57 void MetricsLogManager::BeginLoggingWithLog(scoped_ptr<MetricsLogBase> log) { | 57 void MetricsLogManager::BeginLoggingWithLog(scoped_ptr<MetricsLog> log) { |
| 58 DCHECK(!current_log_); | 58 DCHECK(!current_log_); |
| 59 current_log_ = log.Pass(); | 59 current_log_ = log.Pass(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void MetricsLogManager::FinishCurrentLog() { | 62 void MetricsLogManager::FinishCurrentLog() { |
| 63 DCHECK(current_log_.get()); | 63 DCHECK(current_log_.get()); |
| 64 current_log_->CloseLog(); | 64 current_log_->CloseLog(); |
| 65 std::string log_text; | 65 std::string log_text; |
| 66 current_log_->GetEncodedLog(&log_text); | 66 current_log_->GetEncodedLog(&log_text); |
| 67 if (!log_text.empty()) | 67 if (!log_text.empty()) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 94 void MetricsLogManager::PauseCurrentLog() { | 94 void MetricsLogManager::PauseCurrentLog() { |
| 95 DCHECK(!paused_log_.get()); | 95 DCHECK(!paused_log_.get()); |
| 96 paused_log_.reset(current_log_.release()); | 96 paused_log_.reset(current_log_.release()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void MetricsLogManager::ResumePausedLog() { | 99 void MetricsLogManager::ResumePausedLog() { |
| 100 DCHECK(!current_log_.get()); | 100 DCHECK(!current_log_.get()); |
| 101 current_log_.reset(paused_log_.release()); | 101 current_log_.reset(paused_log_.release()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void MetricsLogManager::StoreLog(std::string* log, LogType log_type) { | 104 void MetricsLogManager::StoreLog(std::string* log, |
| 105 MetricsLog::LogType log_type) { |
| 105 switch (log_type) { | 106 switch (log_type) { |
| 106 case MetricsLogBase::INITIAL_STABILITY_LOG: | 107 case MetricsLog::INITIAL_STABILITY_LOG: |
| 107 initial_log_queue_.StoreLog(log); | 108 initial_log_queue_.StoreLog(log); |
| 108 break; | 109 break; |
| 109 case MetricsLogBase::ONGOING_LOG: | 110 case MetricsLog::ONGOING_LOG: |
| 110 ongoing_log_queue_.StoreLog(log); | 111 ongoing_log_queue_.StoreLog(log); |
| 111 break; | 112 break; |
| 112 } | 113 } |
| 113 } | 114 } |
| 114 | 115 |
| 115 void MetricsLogManager::StoreStagedLogAsUnsent( | 116 void MetricsLogManager::StoreStagedLogAsUnsent( |
| 116 metrics::PersistedLogs::StoreType store_type) { | 117 metrics::PersistedLogs::StoreType store_type) { |
| 117 DCHECK(has_staged_log()); | 118 DCHECK(has_staged_log()); |
| 118 if (initial_log_queue_.has_staged_log()) | 119 if (initial_log_queue_.has_staged_log()) |
| 119 initial_log_queue_.StoreStagedLogAsUnsent(store_type); | 120 initial_log_queue_.StoreStagedLogAsUnsent(store_type); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 141 | 142 |
| 142 void MetricsLogManager::LoadPersistedUnsentLogs() { | 143 void MetricsLogManager::LoadPersistedUnsentLogs() { |
| 143 base::ElapsedTimer timer; | 144 base::ElapsedTimer timer; |
| 144 initial_log_queue_.DeserializeLogs(); | 145 initial_log_queue_.DeserializeLogs(); |
| 145 ongoing_log_queue_.DeserializeLogs(); | 146 ongoing_log_queue_.DeserializeLogs(); |
| 146 UMA_HISTOGRAM_TIMES("UMA.LoadLogsTime", timer.Elapsed()); | 147 UMA_HISTOGRAM_TIMES("UMA.LoadLogsTime", timer.Elapsed()); |
| 147 | 148 |
| 148 unsent_logs_loaded_ = true; | 149 unsent_logs_loaded_ = true; |
| 149 } | 150 } |
| 150 | 151 |
| 151 } // namespace metrics | 152 } // namespace metrics |
| OLD | NEW |