OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/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/sha1.h" | 10 #include "base/sha1.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/timer/elapsed_timer.h" | 12 #include "base/timer/elapsed_timer.h" |
13 #include "chrome/common/metrics/metrics_log_base.h" | 13 #include "components/metrics/metrics_log_base.h" |
14 | 14 |
| 15 namespace metrics { |
15 MetricsLogManager::SerializedLog::SerializedLog() {} | 16 MetricsLogManager::SerializedLog::SerializedLog() {} |
16 MetricsLogManager::SerializedLog::~SerializedLog() {} | 17 MetricsLogManager::SerializedLog::~SerializedLog() {} |
17 | 18 |
18 bool MetricsLogManager::SerializedLog::IsEmpty() const { | 19 bool MetricsLogManager::SerializedLog::IsEmpty() const { |
19 return log_text_.empty(); | 20 return log_text_.empty(); |
20 } | 21 } |
21 | 22 |
22 void MetricsLogManager::SerializedLog::SwapLogText(std::string* log_text) { | 23 void MetricsLogManager::SerializedLog::SwapLogText(std::string* log_text) { |
23 log_text_.swap(*log_text); | 24 log_text_.swap(*log_text); |
24 if (log_text_.empty()) | 25 if (log_text_.empty()) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 if (store_type == PROVISIONAL_STORE) { | 137 if (store_type == PROVISIONAL_STORE) { |
137 last_provisional_store_index_ = destination_list->size() - 1; | 138 last_provisional_store_index_ = destination_list->size() - 1; |
138 last_provisional_store_type_ = log_type; | 139 last_provisional_store_type_ = log_type; |
139 } | 140 } |
140 } | 141 } |
141 | 142 |
142 void MetricsLogManager::DiscardLastProvisionalStore() { | 143 void MetricsLogManager::DiscardLastProvisionalStore() { |
143 if (last_provisional_store_index_ == -1) | 144 if (last_provisional_store_index_ == -1) |
144 return; | 145 return; |
145 std::vector<SerializedLog>* source_list = | 146 std::vector<SerializedLog>* source_list = |
146 (last_provisional_store_type_ == MetricsLogBase::ONGOING_LOG) ? | 147 (last_provisional_store_type_ == MetricsLogBase::ONGOING_LOG) |
147 &unsent_ongoing_logs_ : &unsent_initial_logs_; | 148 ? &unsent_ongoing_logs_ |
| 149 : &unsent_initial_logs_; |
148 DCHECK_LT(static_cast<unsigned int>(last_provisional_store_index_), | 150 DCHECK_LT(static_cast<unsigned int>(last_provisional_store_index_), |
149 source_list->size()); | 151 source_list->size()); |
150 source_list->erase(source_list->begin() + last_provisional_store_index_); | 152 source_list->erase(source_list->begin() + last_provisional_store_index_); |
151 last_provisional_store_index_ = -1; | 153 last_provisional_store_index_ = -1; |
152 } | 154 } |
153 | 155 |
154 void MetricsLogManager::PersistUnsentLogs() { | 156 void MetricsLogManager::PersistUnsentLogs() { |
155 DCHECK(log_serializer_.get()); | 157 DCHECK(log_serializer_.get()); |
156 if (!log_serializer_.get()) | 158 if (!log_serializer_.get()) |
157 return; | 159 return; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 UMA_HISTOGRAM_TIMES("UMA.LoadLogsTime", timer.Elapsed()); | 196 UMA_HISTOGRAM_TIMES("UMA.LoadLogsTime", timer.Elapsed()); |
195 | 197 |
196 unsent_logs_loaded_ = true; | 198 unsent_logs_loaded_ = true; |
197 } | 199 } |
198 | 200 |
199 void MetricsLogManager::CompressCurrentLog(SerializedLog* compressed_log) { | 201 void MetricsLogManager::CompressCurrentLog(SerializedLog* compressed_log) { |
200 std::string log_text; | 202 std::string log_text; |
201 current_log_->GetEncodedLog(&log_text); | 203 current_log_->GetEncodedLog(&log_text); |
202 compressed_log->SwapLogText(&log_text); | 204 compressed_log->SwapLogText(&log_text); |
203 } | 205 } |
| 206 } // namespace metrics |
OLD | NEW |