diff options
author | blundell <blundell@chromium.org> | 2015-08-25 05:22:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-25 12:23:06 +0000 |
commit | 64fedf1a9022ce13d9885cf3bebac417f4a73b45 (patch) | |
tree | 8175ebf96b5538ca49c7ec5e8da71604ee8b5a31 | |
parent | 2937bd298c392a6e3b320991958cee152be307b7 (diff) | |
download | chromium_src-64fedf1a9022ce13d9885cf3bebac417f4a73b45.zip chromium_src-64fedf1a9022ce13d9885cf3bebac417f4a73b45.tar.gz chromium_src-64fedf1a9022ce13d9885cf3bebac417f4a73b45.tar.bz2 |
Move //components/metrics/compression_utils into standalone component
This file is used by code in //chrome/browser/metrics/variations that itself is
slated for componentization. As //components/metrics depends on
//components/variations, the code in question would not be able to be
componentized into //components/variations. To enable that, this CL moves
compression_utils* to a standalone lower-level component.
BUG=516662, 515695
TBR=agl
Review URL: https://codereview.chromium.org/1304563003
Cr-Commit-Position: refs/heads/master@{#345309}
23 files changed, 102 insertions, 37 deletions
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index 10202ed..9b7771a 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -108,6 +108,7 @@ source_set("browser") { "//components/captive_portal", "//components/cloud_devices/common", "//components/component_updater", + "//components/compression", "//components/content_settings/content/common", "//components/content_settings/core/browser", "//components/content_settings/core/common", diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 640f9b9..753c683 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -26,6 +26,7 @@ include_rules = [ "+components/cdm/browser", "+components/cloud_devices/common", "+components/component_updater", + "+components/compression", "+components/content_settings", "+components/copresence", "+components/crash", diff --git a/chrome/browser/metrics/variations/variations_seed_store.cc b/chrome/browser/metrics/variations/variations_seed_store.cc index 3eb15a8..209cd88 100644 --- a/chrome/browser/metrics/variations/variations_seed_store.cc +++ b/chrome/browser/metrics/variations/variations_seed_store.cc @@ -11,7 +11,7 @@ #include "base/prefs/pref_service.h" #include "base/sha1.h" #include "base/strings/string_number_conversions.h" -#include "components/metrics/compression_utils.h" +#include "components/compression/compression_utils.h" #include "components/variations/pref_names.h" #include "components/variations/proto/variations_seed.pb.h" #include "crypto/signature_verifier.h" @@ -331,7 +331,7 @@ bool VariationsSeedStore::ReadSeedData(std::string* seed_data) { if (!is_compressed) { seed_data->swap(decoded_data); - } else if (!metrics::GzipUncompress(decoded_data, seed_data)) { + } else if (!compression::GzipUncompress(decoded_data, seed_data)) { ClearPrefs(); RecordVariationSeedEmptyHistogram(VARIATIONS_SEED_CORRUPT_GZIP); return false; @@ -371,7 +371,7 @@ bool VariationsSeedStore::StoreSeedDataNoDelta( // Compress the seed before base64-encoding and storing. std::string compressed_seed_data; - if (!metrics::GzipCompress(seed_data, &compressed_seed_data)) { + if (!compression::GzipCompress(seed_data, &compressed_seed_data)) { RecordSeedStoreHistogram(VARIATIONS_SEED_STORE_FAILED_GZIP); return false; } diff --git a/chrome/browser/metrics/variations/variations_seed_store_unittest.cc b/chrome/browser/metrics/variations/variations_seed_store_unittest.cc index 7e3c6c7..50a7546 100644 --- a/chrome/browser/metrics/variations/variations_seed_store_unittest.cc +++ b/chrome/browser/metrics/variations/variations_seed_store_unittest.cc @@ -6,7 +6,7 @@ #include "base/base64.h" #include "base/prefs/testing_pref_service.h" -#include "components/metrics/compression_utils.h" +#include "components/compression/compression_utils.h" #include "components/variations/pref_names.h" #include "components/variations/proto/study.pb.h" #include "components/variations/proto/variations_seed.pb.h" @@ -64,7 +64,7 @@ std::string SerializeSeed(const variations::VariationsSeed& seed) { // Compresses |data| using Gzip compression and returns the result. std::string Compress(const std::string& data) { std::string compressed; - const bool result = metrics::GzipCompress(data, &compressed); + const bool result = compression::GzipCompress(data, &compressed); EXPECT_TRUE(result); return compressed; } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index ef36c8c..338011c 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3117,6 +3117,7 @@ '../components/components.gyp:cloud_devices_common', '../components/components.gyp:component_metrics_proto', '../components/components.gyp:component_updater', + '../components/components.gyp:compression', '../components/components.gyp:content_settings_content_common', '../components/components.gyp:content_settings_core_browser', '../components/components.gyp:content_settings_core_common', diff --git a/components/BUILD.gn b/components/BUILD.gn index 7d2729b..9478c17 100644 --- a/components/BUILD.gn +++ b/components/BUILD.gn @@ -30,6 +30,7 @@ group("all_components") { "//components/cloud_devices/common", "//components/chrome_apps", "//components/component_updater", + "//components/compression", "//components/content_settings/core/browser", "//components/content_settings/core/common", "//components/crash/app", diff --git a/components/components.gyp b/components/components.gyp index 9990cbf..e8012d5 100644 --- a/components/components.gyp +++ b/components/components.gyp @@ -17,6 +17,7 @@ 'captive_portal.gypi', 'cloud_devices.gypi', 'component_updater.gypi', + 'compression.gypi', 'content_settings.gypi', 'crash.gypi', 'crash_keys.gypi', diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 70cbb79..d19f2cc 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -11,7 +11,7 @@ # Note: sources list duplicated in GN build. In the GN build, # each component has its own unit tests target defined in its - # directory that are then linked into the final content_unittests. + # directory that are then linked into the final components_unittests. 'auto_login_parser_unittest_sources': [ 'auto_login_parser/auto_login_parser_unittest.cc', ], @@ -92,6 +92,9 @@ 'component_updater/component_updater_service_unittest.cc', 'component_updater/timer_unittest.cc', ], + 'compression_unittest_sources': [ + 'compression/compression_utils_unittest.cc', + ], 'content_settings_unittest_sources': [ 'content_settings/core/browser/content_settings_mock_provider.cc', 'content_settings/core/browser/content_settings_mock_provider.h', @@ -306,7 +309,6 @@ ], 'metrics_unittest_sources': [ 'metrics/call_stack_profile_metrics_provider_unittest.cc', - 'metrics/compression_utils_unittest.cc', 'metrics/daily_event_unittest.cc', 'metrics/drive_metrics_provider_unittest.cc', 'metrics/gpu/gpu_metrics_provider_unittest.cc', @@ -750,6 +752,7 @@ '<@(captive_portal_unittest_sources)', '<@(cloud_devices_unittest_sources)', '<@(component_updater_unittest_sources)', + '<@(compression_unittest_sources)', '<@(content_settings_unittest_sources)', '<@(crash_unittest_sources)', '<@(crx_file_unittest_sources)', @@ -844,6 +847,7 @@ 'components.gyp:captive_portal_test_support', 'components.gyp:cloud_devices_common', 'components.gyp:component_updater', + 'components.gyp:compression', 'components.gyp:content_settings_core_browser', 'components.gyp:content_settings_core_common', 'components.gyp:content_settings_core_test_support', diff --git a/components/compression.gypi b/components/compression.gypi new file mode 100644 index 0000000..4c98971 --- /dev/null +++ b/components/compression.gypi @@ -0,0 +1,24 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'targets': [ + { + # GN version: //components/compression + 'target_name': 'compression', + 'type': 'static_library', + 'include_dirs': [ + '..', + ], + 'dependencies': [ + '../base/base.gyp:base', + '../third_party/zlib/zlib.gyp:zlib', + ], + 'sources': [ + 'compression/compression_utils.cc', + 'compression/compression_utils.h', + ], + }, + ], +} diff --git a/components/compression/BUILD.gn b/components/compression/BUILD.gn new file mode 100644 index 0000000..e35fe23 --- /dev/null +++ b/components/compression/BUILD.gn @@ -0,0 +1,26 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# GYP version: components/compression.gypi:compression +source_set("compression") { + sources = [ + "compression_utils.cc", + "compression_utils.h", + ] + deps = [ + "//base", + "//third_party/zlib", + ] +} + +source_set("unit_tests") { + testonly = true + sources = [ + "compression_utils_unittest.cc", + ] + deps = [ + ":compression", + "//testing/gtest", + ] +} diff --git a/components/compression/DEPS b/components/compression/DEPS new file mode 100644 index 0000000..670343e --- /dev/null +++ b/components/compression/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+third_party/zlib", +] diff --git a/components/compression/OWNERS b/components/compression/OWNERS new file mode 100644 index 0000000..e17cf14 --- /dev/null +++ b/components/compression/OWNERS @@ -0,0 +1,6 @@ +asvitkine@chromium.org +holte@chromium.org +isherman@chromium.org +jar@chromium.org +mpearson@chromium.org +rkaplow@chromium.org diff --git a/components/metrics/compression_utils.cc b/components/compression/compression_utils.cc index da099ae..19de730 100644 --- a/components/metrics/compression_utils.cc +++ b/components/compression/compression_utils.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "components/metrics/compression_utils.h" +#include "components/compression/compression_utils.h" #include <vector> @@ -123,7 +123,7 @@ uint32 GetUncompressedSize(const std::string& compressed_data) { } // namespace -namespace metrics { +namespace compression { bool GzipCompress(const std::string& input, std::string* output) { const uLongf input_size = static_cast<uLongf>(input.size()); @@ -158,4 +158,4 @@ bool GzipUncompress(const std::string& input, std::string* output) { return false; } -} // namespace metrics +} // namespace compression diff --git a/components/metrics/compression_utils.h b/components/compression/compression_utils.h index 0aa407f..46cfd51 100644 --- a/components/metrics/compression_utils.h +++ b/components/compression/compression_utils.h @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef COMPONENTS_METRICS_COMPRESSION_UTILS_H_ -#define COMPONENTS_METRICS_COMPRESSION_UTILS_H_ +#ifndef COMPONENTS_COMPRESSION_COMPRESSION_UTILS_H_ +#define COMPONENTS_COMPRESSION_COMPRESSION_UTILS_H_ #include <string> -namespace metrics { +namespace compression { // Compresses the data in |input| using gzip, storing the result in |output|. // |input| and |output| are allowed to be the same string (in-place operation). @@ -17,6 +17,6 @@ bool GzipCompress(const std::string& input, std::string* output); // |input| and |output| are allowed to be the same string (in-place operation). bool GzipUncompress(const std::string& input, std::string* output); -} // namespace metrics +} // namespace compression -#endif // COMPONENTS_METRICS_COMPRESSION_UTILS_H_ +#endif // COMPONENTS_COMPRESSION_COMPRESSION_UTILS_H_ diff --git a/components/metrics/compression_utils_unittest.cc b/components/compression/compression_utils_unittest.cc index 722e835..793a706 100644 --- a/components/metrics/compression_utils_unittest.cc +++ b/components/compression/compression_utils_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "components/metrics/compression_utils.h" +#include "components/compression/compression_utils.h" #include <string> @@ -10,7 +10,7 @@ #include "base/logging.h" #include "testing/gtest/include/gtest/gtest.h" -namespace metrics { +namespace compression { namespace { @@ -87,4 +87,4 @@ TEST(CompressionUtilsTest, InPlace) { EXPECT_EQ(original_data, data); } -} // namespace metrics +} // namespace compression diff --git a/components/metrics.gypi b/components/metrics.gypi index d6bdbdc..28126bd 100644 --- a/components/metrics.gypi +++ b/components/metrics.gypi @@ -15,8 +15,8 @@ '../base/base.gyp:base', '../base/base.gyp:base_i18n', '../base/base.gyp:base_prefs', - '../third_party/zlib/zlib.gyp:zlib', 'component_metrics_proto', + 'compression', 'variations', ], 'export_dependent_settings': [ @@ -31,8 +31,6 @@ 'metrics/client_info.h', 'metrics/cloned_install_detector.cc', 'metrics/cloned_install_detector.h', - 'metrics/compression_utils.cc', - 'metrics/compression_utils.h', 'metrics/daily_event.cc', 'metrics/daily_event.h', 'metrics/drive_metrics_provider.cc', diff --git a/components/metrics/BUILD.gn b/components/metrics/BUILD.gn index 3a5fd4d..114fc3d 100644 --- a/components/metrics/BUILD.gn +++ b/components/metrics/BUILD.gn @@ -13,8 +13,6 @@ source_set("metrics") { "client_info.h", "cloned_install_detector.cc", "cloned_install_detector.h", - "compression_utils.cc", - "compression_utils.h", "daily_event.cc", "daily_event.h", "drive_metrics_provider.cc", @@ -66,8 +64,8 @@ source_set("metrics") { "//base", "//base:i18n", "//base:prefs", + "//components/compression", "//components/variations", - "//third_party/zlib", ] if (is_chromeos) { @@ -178,7 +176,6 @@ source_set("unit_tests") { testonly = true sources = [ "call_stack_profile_metrics_provider_unittest.cc", - "compression_utils_unittest.cc", "daily_event_unittest.cc", "drive_metrics_provider_unittest.cc", "gpu/gpu_metrics_provider_unittest.cc", diff --git a/components/metrics/DEPS b/components/metrics/DEPS index aa5bdc7..2f4d413 100644 --- a/components/metrics/DEPS +++ b/components/metrics/DEPS @@ -2,8 +2,8 @@ # dependencies to a minimal set. include_rules = [ "-components", + "+components/compression", "+components/metrics", "+components/variations", "-net", - "+third_party/zlib", ] diff --git a/components/metrics/metrics_service_unittest.cc b/components/metrics/metrics_service_unittest.cc index 621e2ba..453e118 100644 --- a/components/metrics/metrics_service_unittest.cc +++ b/components/metrics/metrics_service_unittest.cc @@ -12,8 +12,8 @@ #include "base/metrics/statistics_recorder.h" #include "base/prefs/testing_pref_service.h" #include "base/threading/platform_thread.h" +#include "components/compression/compression_utils.h" #include "components/metrics/client_info.h" -#include "components/metrics/compression_utils.h" #include "components/metrics/metrics_hashes.h" #include "components/metrics/metrics_log.h" #include "components/metrics/metrics_pref_names.h" @@ -229,7 +229,8 @@ TEST_F(MetricsServiceTest, InitialStabilityLogAtProviderRequest) { EXPECT_TRUE(log_manager->has_staged_log()); std::string uncompressed_log; - EXPECT_TRUE(GzipUncompress(log_manager->staged_log(), &uncompressed_log)); + EXPECT_TRUE(compression::GzipUncompress(log_manager->staged_log(), + &uncompressed_log)); ChromeUserMetricsExtension uma_log; EXPECT_TRUE(uma_log.ParseFromString(uncompressed_log)); @@ -291,7 +292,8 @@ TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) { EXPECT_TRUE(log_manager->has_staged_log()); std::string uncompressed_log; - EXPECT_TRUE(GzipUncompress(log_manager->staged_log(), &uncompressed_log)); + EXPECT_TRUE(compression::GzipUncompress(log_manager->staged_log(), + &uncompressed_log)); ChromeUserMetricsExtension uma_log; EXPECT_TRUE(uma_log.ParseFromString(uncompressed_log)); diff --git a/components/metrics/persisted_logs.cc b/components/metrics/persisted_logs.cc index ef562d6..e28ae4a 100644 --- a/components/metrics/persisted_logs.cc +++ b/components/metrics/persisted_logs.cc @@ -13,7 +13,7 @@ #include "base/prefs/scoped_user_pref_update.h" #include "base/sha1.h" #include "base/timer/elapsed_timer.h" -#include "components/metrics/compression_utils.h" +#include "components/compression/compression_utils.h" namespace metrics { @@ -49,7 +49,7 @@ void AppendBase64String(const std::string& str, base::ListValue* list_value) { void PersistedLogs::LogHashPair::Init(const std::string& log_data) { DCHECK(!log_data.empty()); - if (!GzipCompress(log_data, &compressed_log_data)) { + if (!compression::GzipCompress(log_data, &compressed_log_data)) { NOTREACHED(); return; } diff --git a/components/metrics/persisted_logs_unittest.cc b/components/metrics/persisted_logs_unittest.cc index c9153de..09b84af 100644 --- a/components/metrics/persisted_logs_unittest.cc +++ b/components/metrics/persisted_logs_unittest.cc @@ -11,7 +11,7 @@ #include "base/rand_util.h" #include "base/sha1.h" #include "base/values.h" -#include "components/metrics/compression_utils.h" +#include "components/compression/compression_utils.h" #include "testing/gtest/include/gtest/gtest.h" namespace metrics { @@ -25,7 +25,7 @@ const size_t kLogByteLimit = 1000; // Compresses |log_data| and returns the result. std::string Compress(const std::string& log_data) { std::string compressed_log_data; - EXPECT_TRUE(GzipCompress(log_data, &compressed_log_data)); + EXPECT_TRUE(compression::GzipCompress(log_data, &compressed_log_data)); return compressed_log_data; } diff --git a/sync/internal_api/http_bridge.cc b/sync/internal_api/http_bridge.cc index e5729f2..04e339c 100644 --- a/sync/internal_api/http_bridge.cc +++ b/sync/internal_api/http_bridge.cc @@ -62,9 +62,9 @@ void RecordSyncResponseContentLengthHistograms(int64 compressed_content_length, // ----------------------------------------------------------------------------- // The rest of the code in the anon namespace is copied from -// components/metrics/compression_utils.cc +// components/compression/compression_utils.cc // TODO(gangwu): crbug.com/515695. The following code is copied from -// components/metrics/compression_utils.cc. We copied them because if we +// components/compression/compression_utils.cc. We copied them because if we // reference them, we will get cycle dependency warning. Once the functions // have been moved from //component to //base, we can remove the following // functions. diff --git a/sync/internal_api/http_bridge_unittest.cc b/sync/internal_api/http_bridge_unittest.cc index 24fc6cd..4ea4e70 100644 --- a/sync/internal_api/http_bridge_unittest.cc +++ b/sync/internal_api/http_bridge_unittest.cc @@ -27,9 +27,9 @@ const base::FilePath::CharType kDocRoot[] = // ----------------------------------------------------------------------------- // The rest of the code in the anon namespace is copied from -// components/metrics/compression_utils.cc +// components/compression/compression_utils.cc // TODO(gangwu): crbug.com/515695. The following codes are copied from -// components/metrics/compression_utils.cc, we copied them because if we +// components/compression/compression_utils.cc, we copied them because if we // reference them, we will get cycle dependency warning. Once the functions // have been moved from //component to //base, we can remove the following // functions. |