Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7848)

Unified Diff: chrome/common/metrics/metrics_log_manager.cc

Issue 26646003: MetricsService: Send a hash of the UMA log in a header. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/metrics/metrics_log_manager.h ('k') | chrome/common/metrics/metrics_log_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/metrics/metrics_log_manager.cc
===================================================================
--- chrome/common/metrics/metrics_log_manager.cc (revision 229433)
+++ chrome/common/metrics/metrics_log_manager.cc (working copy)
@@ -7,9 +7,36 @@
#include <algorithm>
#include "base/metrics/histogram.h"
+#include "base/sha1.h"
#include "base/strings/string_util.h"
#include "chrome/common/metrics/metrics_log_base.h"
+MetricsLogManager::SerializedLog::SerializedLog() {}
+MetricsLogManager::SerializedLog::~SerializedLog() {}
+
+bool MetricsLogManager::SerializedLog::IsEmpty() const {
+ return log_text_.empty();
+}
+
+void MetricsLogManager::SerializedLog::SwapLogText(std::string* log_text) {
+ log_text_.swap(*log_text);
+ if (log_text_.empty())
+ log_hash_.clear();
+ else
+ log_hash_ = base::SHA1HashString(log_text_);
+}
+
+void MetricsLogManager::SerializedLog::Clear() {
+ log_text_.clear();
+ log_hash_.clear();
+}
+
+void MetricsLogManager::SerializedLog::Swap(
+ MetricsLogManager::SerializedLog* other) {
+ log_text_.swap(other->log_text_);
+ log_hash_.swap(other->log_hash_);
+}
+
MetricsLogManager::MetricsLogManager()
: current_log_type_(NO_LOG),
paused_log_type_(NO_LOG),
@@ -32,9 +59,9 @@
DCHECK(current_log_.get());
DCHECK(current_log_type_ != NO_LOG);
current_log_->CloseLog();
- std::string compressed_log;
+ SerializedLog compressed_log;
CompressCurrentLog(&compressed_log);
- if (!compressed_log.empty())
+ if (!compressed_log.IsEmpty())
StoreLog(&compressed_log, current_log_type_, NORMAL_STORE);
current_log_.reset();
current_log_type_ = NO_LOG;
@@ -42,7 +69,7 @@
void MetricsLogManager::StageNextLogForUpload() {
// Prioritize initial logs for uploading.
- std::vector<std::string>* source_list =
+ std::vector<SerializedLog>* source_list =
unsent_initial_logs_.empty() ? &unsent_ongoing_logs_
: &unsent_initial_logs_;
LogType source_type = (source_list == &unsent_ongoing_logs_) ? ONGOING_LOG
@@ -50,9 +77,9 @@
// CHECK, rather than DCHECK, because swap()ing with an empty list causes
// hard-to-identify crashes much later.
CHECK(!source_list->empty());
- DCHECK(staged_log_text_.empty());
+ DCHECK(staged_log_.IsEmpty());
DCHECK(staged_log_type_ == NO_LOG);
- staged_log_text_.swap(source_list->back());
+ staged_log_.Swap(&source_list->back());
staged_log_type_ = source_type;
source_list->pop_back();
@@ -67,11 +94,11 @@
}
bool MetricsLogManager::has_staged_log() const {
- return !staged_log_text().empty();
+ return !staged_log_.IsEmpty();
}
void MetricsLogManager::DiscardStagedLog() {
- staged_log_text_.clear();
+ staged_log_.Clear();
staged_log_type_ = NO_LOG;
}
@@ -101,22 +128,22 @@
DCHECK(has_staged_log());
// If compressing the log failed, there's nothing to store.
- if (staged_log_text_.empty())
+ if (staged_log_.IsEmpty())
return;
- StoreLog(&staged_log_text_, staged_log_type_, store_type);
+ StoreLog(&staged_log_, staged_log_type_, store_type);
DiscardStagedLog();
}
-void MetricsLogManager::StoreLog(std::string* log_text,
+void MetricsLogManager::StoreLog(SerializedLog* log,
LogType log_type,
StoreType store_type) {
DCHECK(log_type != NO_LOG);
- std::vector<std::string>* destination_list =
+ std::vector<SerializedLog>* destination_list =
(log_type == INITIAL_LOG) ? &unsent_initial_logs_
: &unsent_ongoing_logs_;
- destination_list->push_back(std::string());
- destination_list->back().swap(*log_text);
+ destination_list->push_back(SerializedLog());
+ destination_list->back().Swap(log);
if (store_type == PROVISIONAL_STORE) {
last_provisional_store_index_ = destination_list->size() - 1;
@@ -127,7 +154,7 @@
void MetricsLogManager::DiscardLastProvisionalStore() {
if (last_provisional_store_index_ == -1)
return;
- std::vector<std::string>* source_list =
+ std::vector<SerializedLog>* source_list =
(last_provisional_store_type_ == ONGOING_LOG) ? &unsent_ongoing_logs_
: &unsent_initial_logs_;
DCHECK_LT(static_cast<unsigned int>(last_provisional_store_index_),
@@ -142,9 +169,9 @@
return;
// Remove any ongoing logs that are over the serialization size limit.
if (max_ongoing_log_store_size_) {
- for (std::vector<std::string>::iterator it = unsent_ongoing_logs_.begin();
+ for (std::vector<SerializedLog>::iterator it = unsent_ongoing_logs_.begin();
it != unsent_ongoing_logs_.end();) {
- size_t log_size = it->length();
+ size_t log_size = it->log_text().length();
if (log_size > max_ongoing_log_store_size_) {
UMA_HISTOGRAM_COUNTS("UMA.Large Accumulated Log Not Persisted",
static_cast<int>(log_size));
@@ -166,6 +193,8 @@
log_serializer_->DeserializeLogs(ONGOING_LOG, &unsent_ongoing_logs_);
}
-void MetricsLogManager::CompressCurrentLog(std::string* compressed_log) {
- current_log_->GetEncodedLog(compressed_log);
+void MetricsLogManager::CompressCurrentLog(SerializedLog* compressed_log) {
+ std::string log_text;
+ current_log_->GetEncodedLog(&log_text);
+ compressed_log->SwapLogText(&log_text);
}
« no previous file with comments | « chrome/common/metrics/metrics_log_manager.h ('k') | chrome/common/metrics/metrics_log_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698