OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_log_manager.h" | 5 #include "chrome/common/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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 void MetricsLogManager::CompressStagedLog() { | 105 void MetricsLogManager::CompressStagedLog() { |
106 int text_size = staged_log_->GetEncodedLogSize(); | 106 int text_size = staged_log_->GetEncodedLogSize(); |
107 std::string staged_log_text; | 107 std::string staged_log_text; |
108 // Leave room for the NULL terminator. | 108 // Leave room for the NULL terminator. |
109 staged_log_->GetEncodedLog(WriteInto(&staged_log_text, text_size + 1), | 109 staged_log_->GetEncodedLog(WriteInto(&staged_log_text, text_size + 1), |
110 text_size); | 110 text_size); |
111 | 111 |
112 bool success = Bzip2Compress(staged_log_text, &compressed_staged_log_text_); | 112 bool success = Bzip2Compress(staged_log_text, &compressed_staged_log_text_); |
113 if (success) { | 113 if (success) { |
114 // Allow security-conscious users to see all metrics logs that we send. | 114 // Allow security-conscious users to see all metrics logs that we send. |
115 VLOG(1) << "METRICS LOG: " << staged_log_text; | 115 DVLOG(1) << "METRICS LOG: " << staged_log_text; |
116 } else { | 116 } else { |
117 LOG(DFATAL) << "Failed to compress log for transmission."; | 117 NOTREACHED() << "Failed to compress log for transmission."; |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 // static | 121 // static |
122 // This implementation is based on the Firefox MetricsService implementation. | 122 // This implementation is based on the Firefox MetricsService implementation. |
123 bool MetricsLogManager::Bzip2Compress(const std::string& input, | 123 bool MetricsLogManager::Bzip2Compress(const std::string& input, |
124 std::string* output) { | 124 std::string* output) { |
125 bz_stream stream = {0}; | 125 bz_stream stream = {0}; |
126 // As long as our input is smaller than the bzip2 block size, we should get | 126 // As long as our input is smaller than the bzip2 block size, we should get |
127 // the best compression. For example, if your input was 250k, using a block | 127 // the best compression. For example, if your input was 250k, using a block |
(...skipping 25 matching lines...) Expand all Loading... |
153 // TODO(jar): See if it would be better to do a CHECK() here. | 153 // TODO(jar): See if it would be better to do a CHECK() here. |
154 return false; | 154 return false; |
155 } | 155 } |
156 result = BZ2_bzCompressEnd(&stream); | 156 result = BZ2_bzCompressEnd(&stream); |
157 DCHECK(result == BZ_OK); | 157 DCHECK(result == BZ_OK); |
158 | 158 |
159 output->resize(stream.total_out_lo32); | 159 output->resize(stream.total_out_lo32); |
160 | 160 |
161 return true; | 161 return true; |
162 } | 162 } |
OLD | NEW |