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

Side by Side Diff: components/metrics/net/compression_utils.cc

Issue 291153013: Make MetricsService upload logs through an interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698