OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/rappor/sample.h" | 5 #include "components/rappor/sample.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 sizes_[field_name] = (num_flags + 7) / 8; | 49 sizes_[field_name] = (num_flags + 7) / 8; |
50 } | 50 } |
51 | 51 |
52 void Sample::ExportMetrics(const std::string& secret, | 52 void Sample::ExportMetrics(const std::string& secret, |
53 const std::string& metric_name, | 53 const std::string& metric_name, |
54 RapporReports* reports) const { | 54 RapporReports* reports) const { |
55 for (const auto& kv : fields_) { | 55 for (const auto& kv : fields_) { |
56 uint64_t value = kv.second; | 56 uint64_t value = kv.second; |
57 const auto it = sizes_.find(kv.first); | 57 const auto it = sizes_.find(kv.first); |
58 DCHECK(it != sizes_.end()); | 58 DCHECK(it != sizes_.end()); |
59 uint64_t size = it->second; | 59 size_t size = it->second; |
60 ByteVector value_bytes(size); | 60 ByteVector value_bytes(size); |
61 for (size_t i = 0; i < size; i++) { | 61 Uint64ToByteVector(value, size, &value_bytes); |
62 // Get the value of the i-th smallest byte and copy it to the byte vector. | |
63 uint64_t shift = i * 8; | |
64 uint64_t byte_mask = 0xff << shift; | |
65 value_bytes[i] = (value & byte_mask) >> shift; | |
66 } | |
67 ByteVector report_bytes = internal::GenerateReport( | 62 ByteVector report_bytes = internal::GenerateReport( |
68 secret, parameters_, value_bytes); | 63 secret, parameters_, value_bytes); |
69 | 64 |
70 RapporReports::Report* report = reports->add_report(); | 65 RapporReports::Report* report = reports->add_report(); |
71 report->set_name_hash(metrics::HashMetricName( | 66 report->set_name_hash(metrics::HashMetricName( |
72 metric_name + "." + kv.first)); | 67 metric_name + "." + kv.first)); |
73 report->set_bits(std::string(report_bytes.begin(), report_bytes.end())); | 68 report->set_bits(std::string(report_bytes.begin(), report_bytes.end())); |
74 } | 69 } |
75 } | 70 } |
76 | 71 |
77 } // namespace rappor | 72 } // namespace rappor |
OLD | NEW |