Chromium Code Reviews| 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 |
| 95 !staged_log_text().proto.empty() && | |
| 96 staged_log_text().proto != kDiscardedLog; | |
| 95 } | 97 } |
| 96 | 98 |
| 97 void MetricsLogManager::DiscardStagedLog() { | 99 bool MetricsLogManager::has_staged_log_xml() const { |
| 98 staged_log_text_.xml.clear(); | 100 return |
| 99 staged_log_text_.proto.clear(); | 101 !staged_log_text().xml.empty() && |
|
jar (doing other things)
2012/06/11 21:19:35
nit: don't bother to wrap line 100 this way, as it
Ilya Sherman
2012/06/11 22:22:25
Done.
| |
| 100 staged_log_type_ = NO_LOG; | 102 staged_log_text().xml != kDiscardedLog; |
| 101 } | 103 } |
| 102 | 104 |
| 103 void MetricsLogManager::DiscardStagedLogProto() { | 105 void MetricsLogManager::DiscardStagedLogProto() { |
| 104 staged_log_text_.proto = kDiscardedLog; | 106 staged_log_text_.proto = kDiscardedLog; |
| 107 | |
| 108 // If we're discarding the last piece of the log, reset the staged log state. | |
| 109 if (!has_staged_log()) | |
| 110 DiscardStagedLog(); | |
| 111 } | |
| 112 | |
| 113 void MetricsLogManager::DiscardStagedLogXml() { | |
| 114 staged_log_text_.xml = kDiscardedLog; | |
| 115 | |
| 116 // If we're discarding the last piece of the log, reset the staged log state. | |
| 117 if (!has_staged_log()) | |
| 118 DiscardStagedLog(); | |
| 105 } | 119 } |
| 106 | 120 |
| 107 void MetricsLogManager::DiscardCurrentLog() { | 121 void MetricsLogManager::DiscardCurrentLog() { |
| 108 current_log_->CloseLog(); | 122 current_log_->CloseLog(); |
| 109 current_log_.reset(); | 123 current_log_.reset(); |
| 110 current_log_type_ = NO_LOG; | 124 current_log_type_ = NO_LOG; |
| 111 } | 125 } |
| 112 | 126 |
| 113 void MetricsLogManager::PauseCurrentLog() { | 127 void MetricsLogManager::PauseCurrentLog() { |
| 114 DCHECK(!paused_log_.get()); | 128 DCHECK(!paused_log_.get()); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 DVLOG(1) << "METRICS LOG: " << log_text; | 227 DVLOG(1) << "METRICS LOG: " << log_text; |
| 214 | 228 |
| 215 // Note that we only save the protobuf version if we succeeded in | 229 // Note that we only save the protobuf version if we succeeded in |
| 216 // compressing the XML, so that the two data streams are the same. | 230 // compressing the XML, so that the two data streams are the same. |
| 217 current_log_->GetEncodedLogProto(&(compressed_log->proto)); | 231 current_log_->GetEncodedLogProto(&(compressed_log->proto)); |
| 218 } else { | 232 } else { |
| 219 NOTREACHED() << "Failed to compress log for transmission."; | 233 NOTREACHED() << "Failed to compress log for transmission."; |
| 220 } | 234 } |
| 221 } | 235 } |
| 222 | 236 |
| 237 void MetricsLogManager::DiscardStagedLog() { | |
| 238 staged_log_text_.xml.clear(); | |
| 239 staged_log_text_.proto.clear(); | |
| 240 staged_log_type_ = NO_LOG; | |
| 241 } | |
| 242 | |
| 223 // static | 243 // static |
| 224 // This implementation is based on the Firefox MetricsService implementation. | 244 // This implementation is based on the Firefox MetricsService implementation. |
| 225 bool MetricsLogManager::Bzip2Compress(const std::string& input, | 245 bool MetricsLogManager::Bzip2Compress(const std::string& input, |
| 226 std::string* output) { | 246 std::string* output) { |
| 227 bz_stream stream = {0}; | 247 bz_stream stream = {0}; |
| 228 // As long as our input is smaller than the bzip2 block size, we should get | 248 // As long as our input is smaller than the bzip2 block size, we should get |
| 229 // the best compression. For example, if your input was 250k, using a block | 249 // the best compression. For example, if your input was 250k, using a block |
| 230 // size of 300k or 500k should result in the same compression ratio. Since | 250 // size of 300k or 500k should result in the same compression ratio. Since |
| 231 // our data should be under 100k, using the minimum block size of 100k should | 251 // our data should be under 100k, using the minimum block size of 100k should |
| 232 // allocate less temporary memory, but result in the same compression ratio. | 252 // allocate less temporary memory, but result in the same compression ratio. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 255 // TODO(jar): See if it would be better to do a CHECK() here. | 275 // TODO(jar): See if it would be better to do a CHECK() here. |
| 256 return false; | 276 return false; |
| 257 } | 277 } |
| 258 result = BZ2_bzCompressEnd(&stream); | 278 result = BZ2_bzCompressEnd(&stream); |
| 259 DCHECK(result == BZ_OK); | 279 DCHECK(result == BZ_OK); |
| 260 | 280 |
| 261 output->resize(stream.total_out_lo32); | 281 output->resize(stream.total_out_lo32); |
| 262 | 282 |
| 263 return true; | 283 return true; |
| 264 } | 284 } |
| OLD | NEW |