Commit 73cdd86b authored by Caitlin Fischer's avatar Caitlin Fischer Committed by Commit Bot

[Partial reland] Replace GzipUncompress() with DecodeLogDataToProto().

Original description:
Replace GzipUncompress calls with DecodeLogDataToProto.

Also, remove "ukm::", where applicable, from ukm_service_unittest.cc

Bug: 1086910

Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2222521Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Caitlin Fischer <caitlinfischer@google.com>
Cr-Original-Commit-Position: refs/heads/master@{#777137}
Change-Id: Ia59944a291b095755f5b9cb889f6c16b5388a704
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2248750
Cr-Commit-Position: refs/heads/master@{#780252}
parent eb1475dc
......@@ -21,3 +21,9 @@ include_rules = [
"-net",
"+url"
]
specific_include_rules = {
"log_decoder\.cc": [
"+third_party/protobuf/src/google/protobuf",
],
}
......@@ -4,6 +4,7 @@
#include "components/metrics/log_decoder.h"
#include "third_party/protobuf/src/google/protobuf/message_lite.h"
#include "third_party/zlib/google/compression_utils.h"
namespace metrics {
......@@ -14,12 +15,12 @@ bool DecodeLogData(const std::string& compressed_log_data,
}
bool DecodeLogDataToProto(const std::string& compressed_log_data,
ChromeUserMetricsExtension* uma_proto) {
google::protobuf::MessageLite* proto) {
std::string log_data;
if (!DecodeLogData(compressed_log_data, &log_data))
return false;
return uma_proto->ParseFromString(log_data);
return proto->ParseFromString(log_data);
}
} // namespace metrics
......@@ -7,7 +7,13 @@
#include <string>
#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
namespace google {
namespace protobuf {
class MessageLite;
} // namespace protobuf
} // namespace google
namespace metrics {
......@@ -18,10 +24,10 @@ namespace metrics {
bool DecodeLogData(const std::string& compressed_log_data,
std::string* log_data);
// Decodes |compressed_log_data| and populates |uma_proto| with the decompressed
// log data. Returns true on success and false on failure.
// Decodes |compressed_log_data| and populates |proto| with the decompressed log
// data. Returns true on success and false on failure.
bool DecodeLogDataToProto(const std::string& compressed_log_data,
ChromeUserMetricsExtension* uma_proto);
google::protobuf::MessageLite* proto);
} // namespace metrics
......
......@@ -7,12 +7,12 @@
#include "base/strings/stringprintf.h"
#include "base/time/default_clock.h"
#include "base/time/default_tick_clock.h"
#include "components/metrics/log_decoder.h"
#include "components/sync/base/pref_names.h"
#include "components/sync/base/user_demographics.h"
#include "components/sync/engine_impl/loopback_server/persistent_unique_client_entity.h"
#include "components/sync/protocol/sync.pb.h"
#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
#include "third_party/zlib/google/compression_utils.h"
namespace metrics {
namespace test {
......@@ -94,18 +94,11 @@ bool HasUnsentLogs(MetricsService* metrics_service) {
// Returns an UMA log if the MetricsService has a staged log.
std::unique_ptr<ChromeUserMetricsExtension> GetLastUmaLog(
MetricsService* metrics_service) {
// Decompress the staged log.
std::string uncompressed_log;
if (!compression::GzipUncompress(
metrics_service->LogStoreForTest()->staged_log(),
&uncompressed_log)) {
return nullptr;
}
// Deserialize and return the log.
// Decompress and deserialize the staged log.
std::unique_ptr<ChromeUserMetricsExtension> log =
std::make_unique<ChromeUserMetricsExtension>();
if (!log->ParseFromString(uncompressed_log)) {
if (!DecodeLogDataToProto(metrics_service->LogStoreForTest()->staged_log(),
log.get())) {
return nullptr;
}
return log;
......
......@@ -136,6 +136,5 @@ static_library("ukm_test_helper") {
"//components/metrics",
"//services/metrics/public/cpp:metrics_cpp",
"//third_party/metrics_proto",
"//third_party/zlib/google:compression_utils",
]
}
......@@ -111,6 +111,7 @@ void PurgeExtensionDataFromUnsentLogStore(
const std::string& compressed_log_data =
ukm_log_store->GetLogAtIndex(index);
std::string uncompressed_log_data;
// TODO(crbug/1086910): Use the utilities in log_decoder.h instead.
const bool uncompress_successful = compression::GzipUncompress(
compressed_log_data, &uncompressed_log_data);
DCHECK(uncompress_successful);
......
This diff is collapsed.
......@@ -10,8 +10,8 @@
#include "base/feature_list.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "components/metrics/log_decoder.h"
#include "components/metrics/unsent_log_store.h"
#include "third_party/zlib/google/compression_utils.h"
namespace ukm {
......@@ -51,13 +51,8 @@ std::unique_ptr<Report> UkmTestHelper::GetUkmReport() {
if (!log_store->has_staged_log())
return nullptr;
std::string uncompressed_log_data;
if (!compression::GzipUncompress(log_store->staged_log(),
&uncompressed_log_data))
return nullptr;
std::unique_ptr<ukm::Report> report = std::make_unique<ukm::Report>();
if (!report->ParseFromString(uncompressed_log_data))
if (!metrics::DecodeLogDataToProto(log_store->staged_log(), report.get()))
return nullptr;
return report;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment