Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: components/compression/compression_utils.cc

Issue 1304563003: Move //components/metrics/compression_utils into standalone component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/metrics/compression_utils.h" 5 #include "components/compression/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 "base/logging.h" 10 #include "base/logging.h"
11 #include "base/sys_byteorder.h" 11 #include "base/sys_byteorder.h"
12 #include "third_party/zlib/zlib.h" 12 #include "third_party/zlib/zlib.h"
13 13
14 namespace { 14 namespace {
15 15
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 uint32 size; 116 uint32 size;
117 if (compressed_data.length() < sizeof(size)) 117 if (compressed_data.length() < sizeof(size))
118 return 0; 118 return 0;
119 memcpy(&size, &compressed_data[compressed_data.length() - sizeof(size)], 119 memcpy(&size, &compressed_data[compressed_data.length() - sizeof(size)],
120 sizeof(size)); 120 sizeof(size));
121 return base::ByteSwapToLE32(size); 121 return base::ByteSwapToLE32(size);
122 } 122 }
123 123
124 } // namespace 124 } // namespace
125 125
126 namespace metrics { 126 namespace compression {
127 127
128 bool GzipCompress(const std::string& input, std::string* output) { 128 bool GzipCompress(const std::string& input, std::string* output) {
129 const uLongf input_size = static_cast<uLongf>(input.size()); 129 const uLongf input_size = static_cast<uLongf>(input.size());
130 std::vector<Bytef> compressed_data(kGzipZlibHeaderDifferenceBytes + 130 std::vector<Bytef> compressed_data(kGzipZlibHeaderDifferenceBytes +
131 compressBound(input_size)); 131 compressBound(input_size));
132 132
133 uLongf compressed_size = static_cast<uLongf>(compressed_data.size()); 133 uLongf compressed_size = static_cast<uLongf>(compressed_data.size());
134 if (GzipCompressHelper(&compressed_data.front(), 134 if (GzipCompressHelper(&compressed_data.front(),
135 &compressed_size, 135 &compressed_size,
136 bit_cast<const Bytef*>(input.data()), 136 bit_cast<const Bytef*>(input.data()),
(...skipping 14 matching lines...) Expand all
151 if (GzipUncompressHelper(bit_cast<Bytef*>(uncompressed_output.data()), 151 if (GzipUncompressHelper(bit_cast<Bytef*>(uncompressed_output.data()),
152 &uncompressed_size, 152 &uncompressed_size,
153 bit_cast<const Bytef*>(input.data()), 153 bit_cast<const Bytef*>(input.data()),
154 static_cast<uLongf>(input.length())) == Z_OK) { 154 static_cast<uLongf>(input.length())) == Z_OK) {
155 output->swap(uncompressed_output); 155 output->swap(uncompressed_output);
156 return true; 156 return true;
157 } 157 }
158 return false; 158 return false;
159 } 159 }
160 160
161 } // namespace metrics 161 } // namespace compression
OLDNEW
« no previous file with comments | « components/compression/compression_utils.h ('k') | components/compression/compression_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698