| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // is a long series of very small logs. | 36 // is a long series of very small logs. |
| 37 const size_t kStorageByteLimitPerLogType = 300000; | 37 const size_t kStorageByteLimitPerLogType = 300000; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 MetricsLogManager::MetricsLogManager(PrefService* local_state, | 41 MetricsLogManager::MetricsLogManager(PrefService* local_state, |
| 42 size_t max_ongoing_log_size) | 42 size_t max_ongoing_log_size) |
| 43 : unsent_logs_loaded_(false), | 43 : unsent_logs_loaded_(false), |
| 44 initial_log_queue_(local_state, | 44 initial_log_queue_(local_state, |
| 45 prefs::kMetricsInitialLogs, | 45 prefs::kMetricsInitialLogs, |
| 46 prefs::kMetricsInitialLogsOld, |
| 46 kInitialLogsPersistLimit, | 47 kInitialLogsPersistLimit, |
| 47 kStorageByteLimitPerLogType, | 48 kStorageByteLimitPerLogType, |
| 48 0), | 49 0), |
| 49 ongoing_log_queue_(local_state, | 50 ongoing_log_queue_(local_state, |
| 50 prefs::kMetricsOngoingLogs, | 51 prefs::kMetricsOngoingLogs, |
| 52 prefs::kMetricsOngoingLogsOld, |
| 51 kOngoingLogsPersistLimit, | 53 kOngoingLogsPersistLimit, |
| 52 kStorageByteLimitPerLogType, | 54 kStorageByteLimitPerLogType, |
| 53 max_ongoing_log_size) {} | 55 max_ongoing_log_size) {} |
| 54 | 56 |
| 55 MetricsLogManager::~MetricsLogManager() {} | 57 MetricsLogManager::~MetricsLogManager() {} |
| 56 | 58 |
| 57 void MetricsLogManager::BeginLoggingWithLog(scoped_ptr<MetricsLog> log) { | 59 void MetricsLogManager::BeginLoggingWithLog(scoped_ptr<MetricsLog> log) { |
| 58 DCHECK(!current_log_); | 60 DCHECK(!current_log_); |
| 59 current_log_ = log.Pass(); | 61 current_log_ = log.Pass(); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void MetricsLogManager::FinishCurrentLog() { | 64 void MetricsLogManager::FinishCurrentLog() { |
| 63 DCHECK(current_log_.get()); | 65 DCHECK(current_log_.get()); |
| 64 current_log_->CloseLog(); | 66 current_log_->CloseLog(); |
| 65 std::string log_text; | 67 std::string log_data; |
| 66 current_log_->GetEncodedLog(&log_text); | 68 current_log_->GetEncodedLog(&log_data); |
| 67 if (!log_text.empty()) | 69 if (!log_data.empty()) |
| 68 StoreLog(&log_text, current_log_->log_type()); | 70 StoreLog(log_data, current_log_->log_type()); |
| 69 current_log_.reset(); | 71 current_log_.reset(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void MetricsLogManager::StageNextLogForUpload() { | 74 void MetricsLogManager::StageNextLogForUpload() { |
| 73 DCHECK(!has_staged_log()); | 75 DCHECK(!has_staged_log()); |
| 74 if (!initial_log_queue_.empty()) | 76 if (!initial_log_queue_.empty()) |
| 75 initial_log_queue_.StageLog(); | 77 initial_log_queue_.StageLog(); |
| 76 else | 78 else |
| 77 ongoing_log_queue_.StageLog(); | 79 ongoing_log_queue_.StageLog(); |
| 78 } | 80 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 94 void MetricsLogManager::PauseCurrentLog() { | 96 void MetricsLogManager::PauseCurrentLog() { |
| 95 DCHECK(!paused_log_.get()); | 97 DCHECK(!paused_log_.get()); |
| 96 paused_log_.reset(current_log_.release()); | 98 paused_log_.reset(current_log_.release()); |
| 97 } | 99 } |
| 98 | 100 |
| 99 void MetricsLogManager::ResumePausedLog() { | 101 void MetricsLogManager::ResumePausedLog() { |
| 100 DCHECK(!current_log_.get()); | 102 DCHECK(!current_log_.get()); |
| 101 current_log_.reset(paused_log_.release()); | 103 current_log_.reset(paused_log_.release()); |
| 102 } | 104 } |
| 103 | 105 |
| 104 void MetricsLogManager::StoreLog(std::string* log, | 106 void MetricsLogManager::StoreLog(const std::string& log_data, |
| 105 MetricsLog::LogType log_type) { | 107 MetricsLog::LogType log_type) { |
| 106 switch (log_type) { | 108 switch (log_type) { |
| 107 case MetricsLog::INITIAL_STABILITY_LOG: | 109 case MetricsLog::INITIAL_STABILITY_LOG: |
| 108 initial_log_queue_.StoreLog(log); | 110 initial_log_queue_.StoreLog(log_data); |
| 109 break; | 111 break; |
| 110 case MetricsLog::ONGOING_LOG: | 112 case MetricsLog::ONGOING_LOG: |
| 111 ongoing_log_queue_.StoreLog(log); | 113 ongoing_log_queue_.StoreLog(log_data); |
| 112 break; | 114 break; |
| 113 } | 115 } |
| 114 } | 116 } |
| 115 | 117 |
| 116 void MetricsLogManager::StoreStagedLogAsUnsent( | 118 void MetricsLogManager::StoreStagedLogAsUnsent( |
| 117 metrics::PersistedLogs::StoreType store_type) { | 119 PersistedLogs::StoreType store_type) { |
| 118 DCHECK(has_staged_log()); | 120 DCHECK(has_staged_log()); |
| 119 if (initial_log_queue_.has_staged_log()) | 121 if (initial_log_queue_.has_staged_log()) |
| 120 initial_log_queue_.StoreStagedLogAsUnsent(store_type); | 122 initial_log_queue_.StoreStagedLogAsUnsent(store_type); |
| 121 else | 123 else |
| 122 ongoing_log_queue_.StoreStagedLogAsUnsent(store_type); | 124 ongoing_log_queue_.StoreStagedLogAsUnsent(store_type); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void MetricsLogManager::DiscardLastProvisionalStore() { | 127 void MetricsLogManager::DiscardLastProvisionalStore() { |
| 126 // We have at most one provisional store, (since at most one log is being | 128 // We have at most one provisional store, (since at most one log is being |
| 127 // uploaded at a time), so at least one of these will be a no-op. | 129 // uploaded at a time), so at least one of these will be a no-op. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 143 void MetricsLogManager::LoadPersistedUnsentLogs() { | 145 void MetricsLogManager::LoadPersistedUnsentLogs() { |
| 144 base::ElapsedTimer timer; | 146 base::ElapsedTimer timer; |
| 145 initial_log_queue_.DeserializeLogs(); | 147 initial_log_queue_.DeserializeLogs(); |
| 146 ongoing_log_queue_.DeserializeLogs(); | 148 ongoing_log_queue_.DeserializeLogs(); |
| 147 UMA_HISTOGRAM_TIMES("UMA.LoadLogsTime", timer.Elapsed()); | 149 UMA_HISTOGRAM_TIMES("UMA.LoadLogsTime", timer.Elapsed()); |
| 148 | 150 |
| 149 unsent_logs_loaded_ = true; | 151 unsent_logs_loaded_ = true; |
| 150 } | 152 } |
| 151 | 153 |
| 152 } // namespace metrics | 154 } // namespace metrics |
| OLD | NEW |