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 = [ ...@@ -21,3 +21,9 @@ include_rules = [
"-net", "-net",
"+url" "+url"
] ]
specific_include_rules = {
"log_decoder\.cc": [
"+third_party/protobuf/src/google/protobuf",
],
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "components/metrics/log_decoder.h" #include "components/metrics/log_decoder.h"
#include "third_party/protobuf/src/google/protobuf/message_lite.h"
#include "third_party/zlib/google/compression_utils.h" #include "third_party/zlib/google/compression_utils.h"
namespace metrics { namespace metrics {
...@@ -14,12 +15,12 @@ bool DecodeLogData(const std::string& compressed_log_data, ...@@ -14,12 +15,12 @@ bool DecodeLogData(const std::string& compressed_log_data,
} }
bool DecodeLogDataToProto(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; std::string log_data;
if (!DecodeLogData(compressed_log_data, &log_data)) if (!DecodeLogData(compressed_log_data, &log_data))
return false; return false;
return uma_proto->ParseFromString(log_data); return proto->ParseFromString(log_data);
} }
} // namespace metrics } // namespace metrics
...@@ -7,7 +7,13 @@ ...@@ -7,7 +7,13 @@
#include <string> #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 { namespace metrics {
...@@ -18,10 +24,10 @@ namespace metrics { ...@@ -18,10 +24,10 @@ namespace metrics {
bool DecodeLogData(const std::string& compressed_log_data, bool DecodeLogData(const std::string& compressed_log_data,
std::string* log_data); std::string* log_data);
// Decodes |compressed_log_data| and populates |uma_proto| with the decompressed // Decodes |compressed_log_data| and populates |proto| with the decompressed log
// log data. Returns true on success and false on failure. // data. Returns true on success and false on failure.
bool DecodeLogDataToProto(const std::string& compressed_log_data, bool DecodeLogDataToProto(const std::string& compressed_log_data,
ChromeUserMetricsExtension* uma_proto); google::protobuf::MessageLite* proto);
} // namespace metrics } // namespace metrics
......
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/time/default_clock.h" #include "base/time/default_clock.h"
#include "base/time/default_tick_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/pref_names.h"
#include "components/sync/base/user_demographics.h" #include "components/sync/base/user_demographics.h"
#include "components/sync/engine_impl/loopback_server/persistent_unique_client_entity.h" #include "components/sync/engine_impl/loopback_server/persistent_unique_client_entity.h"
#include "components/sync/protocol/sync.pb.h" #include "components/sync/protocol/sync.pb.h"
#include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h" #include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
#include "third_party/zlib/google/compression_utils.h"
namespace metrics { namespace metrics {
namespace test { namespace test {
...@@ -94,18 +94,11 @@ bool HasUnsentLogs(MetricsService* metrics_service) { ...@@ -94,18 +94,11 @@ bool HasUnsentLogs(MetricsService* metrics_service) {
// Returns an UMA log if the MetricsService has a staged log. // Returns an UMA log if the MetricsService has a staged log.
std::unique_ptr<ChromeUserMetricsExtension> GetLastUmaLog( std::unique_ptr<ChromeUserMetricsExtension> GetLastUmaLog(
MetricsService* metrics_service) { MetricsService* metrics_service) {
// Decompress the staged log. // Decompress and deserialize the staged log.
std::string uncompressed_log;
if (!compression::GzipUncompress(
metrics_service->LogStoreForTest()->staged_log(),
&uncompressed_log)) {
return nullptr;
}
// Deserialize and return the log.
std::unique_ptr<ChromeUserMetricsExtension> log = std::unique_ptr<ChromeUserMetricsExtension> log =
std::make_unique<ChromeUserMetricsExtension>(); std::make_unique<ChromeUserMetricsExtension>();
if (!log->ParseFromString(uncompressed_log)) { if (!DecodeLogDataToProto(metrics_service->LogStoreForTest()->staged_log(),
log.get())) {
return nullptr; return nullptr;
} }
return log; return log;
......
...@@ -136,6 +136,5 @@ static_library("ukm_test_helper") { ...@@ -136,6 +136,5 @@ static_library("ukm_test_helper") {
"//components/metrics", "//components/metrics",
"//services/metrics/public/cpp:metrics_cpp", "//services/metrics/public/cpp:metrics_cpp",
"//third_party/metrics_proto", "//third_party/metrics_proto",
"//third_party/zlib/google:compression_utils",
] ]
} }
...@@ -111,6 +111,7 @@ void PurgeExtensionDataFromUnsentLogStore( ...@@ -111,6 +111,7 @@ void PurgeExtensionDataFromUnsentLogStore(
const std::string& compressed_log_data = const std::string& compressed_log_data =
ukm_log_store->GetLogAtIndex(index); ukm_log_store->GetLogAtIndex(index);
std::string uncompressed_log_data; std::string uncompressed_log_data;
// TODO(crbug/1086910): Use the utilities in log_decoder.h instead.
const bool uncompress_successful = compression::GzipUncompress( const bool uncompress_successful = compression::GzipUncompress(
compressed_log_data, &uncompressed_log_data); compressed_log_data, &uncompressed_log_data);
DCHECK(uncompress_successful); DCHECK(uncompress_successful);
......
This diff is collapsed.
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "components/metrics/log_decoder.h"
#include "components/metrics/unsent_log_store.h" #include "components/metrics/unsent_log_store.h"
#include "third_party/zlib/google/compression_utils.h"
namespace ukm { namespace ukm {
...@@ -51,13 +51,8 @@ std::unique_ptr<Report> UkmTestHelper::GetUkmReport() { ...@@ -51,13 +51,8 @@ std::unique_ptr<Report> UkmTestHelper::GetUkmReport() {
if (!log_store->has_staged_log()) if (!log_store->has_staged_log())
return nullptr; 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>(); 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 nullptr;
return report; 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