| 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 "chrome/common/metrics/metrics_log_manager.h" |
| 6 | 6 |
| 7 #if defined(USE_SYSTEM_LIBBZ2) | 7 #if defined(USE_SYSTEM_LIBBZ2) |
| 8 #include <bzlib.h> | 8 #include <bzlib.h> |
| 9 #else | 9 #else |
| 10 #include "third_party/bzip2/bzlib.h" | 10 #include "third_party/bzip2/bzlib.h" |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include <algorithm> |
| 14 |
| 13 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 14 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 15 #include "chrome/common/metrics/metrics_log_base.h" | 17 #include "chrome/common/metrics/metrics_log_base.h" |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 // Used to keep track of discarded protobuf logs without having to track xml and | 21 // Used to keep track of discarded protobuf logs without having to track xml and |
| 20 // protobuf logs in separate lists. | 22 // protobuf logs in separate lists. |
| 21 const char kDiscardedLog[] = "Log discarded"; | 23 const char kDiscardedLog[] = "Log discarded"; |
| 22 | 24 |
| 23 } // anonymous namespace | 25 } // anonymous namespace |
| 24 | 26 |
| 25 MetricsLogManager::MetricsLogManager() | 27 MetricsLogManager::MetricsLogManager() |
| 26 : current_log_type_(NO_LOG), | 28 : current_log_type_(NO_LOG), |
| 27 paused_log_type_(NO_LOG), | 29 paused_log_type_(NO_LOG), |
| 28 staged_log_type_(NO_LOG), | 30 staged_log_type_(NO_LOG), |
| 29 max_ongoing_log_store_size_(0), | 31 max_ongoing_log_store_size_(0), |
| 30 last_provisional_store_index_(-1), | 32 last_provisional_store_index_(-1), |
| 31 last_provisional_store_type_(INITIAL_LOG) {} | 33 last_provisional_store_type_(INITIAL_LOG) {} |
| 32 | 34 |
| 33 MetricsLogManager::~MetricsLogManager() {} | 35 MetricsLogManager::~MetricsLogManager() {} |
| 34 | 36 |
| 35 bool MetricsLogManager::SerializedLog::empty() const { | 37 bool MetricsLogManager::SerializedLog::empty() const { |
| 36 DCHECK_EQ(xml.empty(), proto.empty()); | 38 DCHECK_EQ(xml.empty(), proto.empty()); |
| 37 return xml.empty(); | 39 return xml.empty(); |
| 38 } | 40 } |
| 39 | 41 |
| 42 size_t MetricsLogManager::SerializedLog::length() const { |
| 43 return std::max(xml.length(), proto.length()); |
| 44 } |
| 45 |
| 40 void MetricsLogManager::SerializedLog::swap(SerializedLog& log) { | 46 void MetricsLogManager::SerializedLog::swap(SerializedLog& log) { |
| 41 xml.swap(log.xml); | 47 xml.swap(log.xml); |
| 42 proto.swap(log.proto); | 48 proto.swap(log.proto); |
| 43 } | 49 } |
| 44 | 50 |
| 45 void MetricsLogManager::BeginLoggingWithLog(MetricsLogBase* log, | 51 void MetricsLogManager::BeginLoggingWithLog(MetricsLogBase* log, |
| 46 LogType log_type) { | 52 LogType log_type) { |
| 47 DCHECK(log_type != NO_LOG); | 53 DCHECK(log_type != NO_LOG); |
| 48 DCHECK(!current_log_.get()); | 54 DCHECK(!current_log_.get()); |
| 49 current_log_.reset(log); | 55 current_log_.reset(log); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // TODO(jar): See if it would be better to do a CHECK() here. | 261 // TODO(jar): See if it would be better to do a CHECK() here. |
| 256 return false; | 262 return false; |
| 257 } | 263 } |
| 258 result = BZ2_bzCompressEnd(&stream); | 264 result = BZ2_bzCompressEnd(&stream); |
| 259 DCHECK(result == BZ_OK); | 265 DCHECK(result == BZ_OK); |
| 260 | 266 |
| 261 output->resize(stream.total_out_lo32); | 267 output->resize(stream.total_out_lo32); |
| 262 | 268 |
| 263 return true; | 269 return true; |
| 264 } | 270 } |
| OLD | NEW |