| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/metrics/compression_utils.h" | 5 #include "components/metrics/net/compression_utils.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "third_party/zlib/zlib.h" | 10 #include "third_party/zlib/zlib.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // The difference in bytes between a zlib header and a gzip header. | 14 // The difference in bytes between a zlib header and a gzip header. |
| 15 const size_t kGzipZlibHeaderDifferenceBytes = 16; | 15 const size_t kGzipZlibHeaderDifferenceBytes = 16; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 err = deflate(&stream, Z_FINISH); | 63 err = deflate(&stream, Z_FINISH); |
| 64 if (err != Z_STREAM_END) { | 64 if (err != Z_STREAM_END) { |
| 65 deflateEnd(&stream); | 65 deflateEnd(&stream); |
| 66 return err == Z_OK ? Z_BUF_ERROR : err; | 66 return err == Z_OK ? Z_BUF_ERROR : err; |
| 67 } | 67 } |
| 68 *dest_length = stream.total_out; | 68 *dest_length = stream.total_out; |
| 69 | 69 |
| 70 err = deflateEnd(&stream); | 70 err = deflateEnd(&stream); |
| 71 return err; | 71 return err; |
| 72 } | 72 } |
| 73 |
| 73 } // namespace | 74 } // namespace |
| 74 | 75 |
| 75 namespace chrome { | 76 namespace metrics { |
| 76 | 77 |
| 77 bool GzipCompress(const std::string& input, std::string* output) { | 78 bool GzipCompress(const std::string& input, std::string* output) { |
| 78 std::vector<Bytef> compressed_data(kGzipZlibHeaderDifferenceBytes + | 79 std::vector<Bytef> compressed_data(kGzipZlibHeaderDifferenceBytes + |
| 79 compressBound(input.size())); | 80 compressBound(input.size())); |
| 80 | 81 |
| 81 uLongf compressed_size = compressed_data.size(); | 82 uLongf compressed_size = compressed_data.size(); |
| 82 if (GzipCompressHelper(&compressed_data.front(), | 83 if (GzipCompressHelper(&compressed_data.front(), |
| 83 &compressed_size, | 84 &compressed_size, |
| 84 bit_cast<const Bytef*>(input.data()), | 85 bit_cast<const Bytef*>(input.data()), |
| 85 input.size()) != Z_OK) | 86 input.size()) != Z_OK) |
| 86 return false; | 87 return false; |
| 87 | 88 |
| 88 compressed_data.resize(compressed_size); | 89 compressed_data.resize(compressed_size); |
| 89 output->assign(compressed_data.begin(), compressed_data.end()); | 90 output->assign(compressed_data.begin(), compressed_data.end()); |
| 90 return true; | 91 return true; |
| 91 } | 92 } |
| 92 } // namespace chrome | 93 |
| 94 } // namespace metrics |
| OLD | NEW |