| 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" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 if (last_provisional_store_index_ != -1) { | 80 if (last_provisional_store_index_ != -1) { |
| 81 if (source_type == last_provisional_store_type_ && | 81 if (source_type == last_provisional_store_type_ && |
| 82 static_cast<unsigned int>(last_provisional_store_index_) == | 82 static_cast<unsigned int>(last_provisional_store_index_) == |
| 83 source_list->size()) { | 83 source_list->size()) { |
| 84 last_provisional_store_index_ = -1; | 84 last_provisional_store_index_ = -1; |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool MetricsLogManager::has_staged_log() const { | 89 bool MetricsLogManager::has_staged_log() const { |
| 90 return !staged_log_text().empty(); | 90 return has_staged_log_proto() || has_staged_log_xml(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool MetricsLogManager::has_staged_log_proto() const { | 93 bool MetricsLogManager::has_staged_log_proto() const { |
| 94 return has_staged_log() && staged_log_text().proto != kDiscardedLog; | 94 return !staged_log_text().proto.empty() && |
| 95 staged_log_text().proto != kDiscardedLog; |
| 96 } |
| 97 |
| 98 bool MetricsLogManager::has_staged_log_xml() const { |
| 99 return !staged_log_text().xml.empty() && |
| 100 staged_log_text().xml != kDiscardedLog; |
| 95 } | 101 } |
| 96 | 102 |
| 97 void MetricsLogManager::DiscardStagedLog() { | 103 void MetricsLogManager::DiscardStagedLog() { |
| 98 staged_log_text_.xml.clear(); | 104 staged_log_text_.xml.clear(); |
| 99 staged_log_text_.proto.clear(); | 105 staged_log_text_.proto.clear(); |
| 100 staged_log_type_ = NO_LOG; | 106 staged_log_type_ = NO_LOG; |
| 101 } | 107 } |
| 102 | 108 |
| 103 void MetricsLogManager::DiscardStagedLogProto() { | 109 void MetricsLogManager::DiscardStagedLogProto() { |
| 104 staged_log_text_.proto = kDiscardedLog; | 110 staged_log_text_.proto = kDiscardedLog; |
| 111 |
| 112 // If we're discarding the last piece of the log, reset the staged log state. |
| 113 if (!has_staged_log()) |
| 114 DiscardStagedLog(); |
| 115 } |
| 116 |
| 117 void MetricsLogManager::DiscardStagedLogXml() { |
| 118 staged_log_text_.xml = kDiscardedLog; |
| 119 |
| 120 // If we're discarding the last piece of the log, reset the staged log state. |
| 121 if (!has_staged_log()) |
| 122 DiscardStagedLog(); |
| 105 } | 123 } |
| 106 | 124 |
| 107 void MetricsLogManager::DiscardCurrentLog() { | 125 void MetricsLogManager::DiscardCurrentLog() { |
| 108 current_log_->CloseLog(); | 126 current_log_->CloseLog(); |
| 109 current_log_.reset(); | 127 current_log_.reset(); |
| 110 current_log_type_ = NO_LOG; | 128 current_log_type_ = NO_LOG; |
| 111 } | 129 } |
| 112 | 130 |
| 113 void MetricsLogManager::PauseCurrentLog() { | 131 void MetricsLogManager::PauseCurrentLog() { |
| 114 DCHECK(!paused_log_.get()); | 132 DCHECK(!paused_log_.get()); |
| (...skipping 140 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. | 273 // TODO(jar): See if it would be better to do a CHECK() here. |
| 256 return false; | 274 return false; |
| 257 } | 275 } |
| 258 result = BZ2_bzCompressEnd(&stream); | 276 result = BZ2_bzCompressEnd(&stream); |
| 259 DCHECK(result == BZ_OK); | 277 DCHECK(result == BZ_OK); |
| 260 | 278 |
| 261 output->resize(stream.total_out_lo32); | 279 output->resize(stream.total_out_lo32); |
| 262 | 280 |
| 263 return true; | 281 return true; |
| 264 } | 282 } |
| OLD | NEW |