diff options
38 files changed, 182 insertions, 110 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_provider.h b/chrome/browser/autocomplete/autocomplete_provider.h index f55e9f6..02e247e 100644 --- a/chrome/browser/autocomplete/autocomplete_provider.h +++ b/chrome/browser/autocomplete/autocomplete_provider.h @@ -11,7 +11,7 @@ #include "base/memory/ref_counted.h" #include "base/strings/string16.h" #include "chrome/browser/autocomplete/autocomplete_match.h" -#include "chrome/common/metrics/proto/omnibox_event.pb.h" +#include "components/metrics/proto/omnibox_event.pb.h" class AutocompleteInput; class AutocompleteProviderListener; diff --git a/chrome/browser/feedback/feedback_util.cc b/chrome/browser/feedback/feedback_util.cc index 688891a..23e5406 100644 --- a/chrome/browser/feedback/feedback_util.cc +++ b/chrome/browser/feedback/feedback_util.cc @@ -34,7 +34,7 @@ #include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_version_info.h" -#include "chrome/common/metrics/metrics_log_manager.h" +#include "components/metrics/metrics_log_manager.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/metrics/extension_metrics.cc b/chrome/browser/metrics/extension_metrics.cc index b57a6f0..46d3084 100644 --- a/chrome/browser/metrics/extension_metrics.cc +++ b/chrome/browser/metrics/extension_metrics.cc @@ -11,7 +11,7 @@ #include "base/strings/stringprintf.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile_manager.h" -#include "chrome/common/metrics/proto/system_profile.pb.h" +#include "components/metrics/proto/system_profile.pb.h" #include "extensions/browser/extension_registry.h" #include "extensions/common/extension_set.h" #include "third_party/smhasher/src/City.h" diff --git a/chrome/browser/metrics/extension_metrics_unittest.cc b/chrome/browser/metrics/extension_metrics_unittest.cc index a75cc1e..0f5af0a 100644 --- a/chrome/browser/metrics/extension_metrics_unittest.cc +++ b/chrome/browser/metrics/extension_metrics_unittest.cc @@ -6,7 +6,7 @@ #include <string> -#include "chrome/common/metrics/proto/system_profile.pb.h" +#include "components/metrics/proto/system_profile.pb.h" #include "extensions/common/extension.h" #include "extensions/common/extension_builder.h" #include "extensions/common/extension_set.h" diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc index 8ef2484..30db742 100644 --- a/chrome/browser/metrics/metrics_log.cc +++ b/chrome/browser/metrics/metrics_log.cc @@ -37,12 +37,12 @@ #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/logging_chrome.h" -#include "chrome/common/metrics/proto/omnibox_event.pb.h" -#include "chrome/common/metrics/proto/profiler_event.pb.h" -#include "chrome/common/metrics/proto/system_profile.pb.h" #include "chrome/common/metrics/variations/variations_util.h" #include "chrome/common/pref_names.h" #include "chrome/installer/util/google_update_settings.h" +#include "components/metrics/proto/omnibox_event.pb.h" +#include "components/metrics/proto/profiler_event.pb.h" +#include "components/metrics/proto/system_profile.pb.h" #include "components/nacl/common/nacl_process_type.h" #include "content/public/browser/gpu_data_manager.h" #include "content/public/common/content_client.h" @@ -67,6 +67,7 @@ extern "C" IMAGE_DOS_HEADER __ImageBase; #endif // OS_CHROMEOS using content::GpuDataManager; +using metrics::MetricsLogBase; using metrics::OmniboxEventProto; using metrics::ProfilerEventProto; using metrics::SystemProfileProto; @@ -207,6 +208,25 @@ ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType( } } +SystemProfileProto::Channel AsProtobufChannel( + chrome::VersionInfo::Channel channel) { + switch (channel) { + case chrome::VersionInfo::CHANNEL_UNKNOWN: + return SystemProfileProto::CHANNEL_UNKNOWN; + case chrome::VersionInfo::CHANNEL_CANARY: + return SystemProfileProto::CHANNEL_CANARY; + case chrome::VersionInfo::CHANNEL_DEV: + return SystemProfileProto::CHANNEL_DEV; + case chrome::VersionInfo::CHANNEL_BETA: + return SystemProfileProto::CHANNEL_BETA; + case chrome::VersionInfo::CHANNEL_STABLE: + return SystemProfileProto::CHANNEL_STABLE; + default: + NOTREACHED(); + return SystemProfileProto::CHANNEL_UNKNOWN; + } +} + // Computes a SHA-1 hash of |data| and returns it as a hex string. std::string ComputeSHA1(const std::string& data) { const std::string sha1 = base::SHA1HashString(data); @@ -386,6 +406,9 @@ MetricsLog::MetricsLog(const std::string& client_id, MetricsLog::GetVersionString()), creation_time_(base::TimeTicks::Now()), extension_metrics_(uma_proto()->client_id()) { + uma_proto()->mutable_system_profile()->set_channel( + AsProtobufChannel(chrome::VersionInfo::CHANNEL_STABLE)); + #if defined(OS_CHROMEOS) metrics_log_chromeos_.reset(new MetricsLogChromeOS(uma_proto())); #endif // OS_CHROMEOS diff --git a/chrome/browser/metrics/metrics_log.h b/chrome/browser/metrics/metrics_log.h index 0af6f35..0c063c5 100644 --- a/chrome/browser/metrics/metrics_log.h +++ b/chrome/browser/metrics/metrics_log.h @@ -14,9 +14,9 @@ #include "base/basictypes.h" #include "chrome/browser/metrics/extension_metrics.h" #include "chrome/browser/metrics/metrics_network_observer.h" -#include "chrome/common/metrics/metrics_log_base.h" #include "chrome/common/metrics/variations/variations_util.h" #include "chrome/installer/util/google_update_settings.h" +#include "components/metrics/metrics_log_base.h" #include "ui/gfx/size.h" class HashedExtensionMetrics; @@ -64,7 +64,7 @@ struct GoogleUpdateMetrics { GoogleUpdateSettings::ProductData product_data; }; -class MetricsLog : public MetricsLogBase { +class MetricsLog : public metrics::MetricsLogBase { public: // Creates a new metrics log of the specified type. // client_id is the identifier for this profile on this installation diff --git a/chrome/browser/metrics/metrics_log_chromeos.cc b/chrome/browser/metrics/metrics_log_chromeos.cc index 55dcc62..517447f 100644 --- a/chrome/browser/metrics/metrics_log_chromeos.cc +++ b/chrome/browser/metrics/metrics_log_chromeos.cc @@ -9,8 +9,8 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/chromeos/login/user_manager.h" -#include "chrome/common/metrics/proto/chrome_user_metrics_extension.pb.h" #include "chrome/common/pref_names.h" +#include "components/metrics/proto/chrome_user_metrics_extension.pb.h" #include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_device.h" diff --git a/chrome/browser/metrics/metrics_log_serializer.cc b/chrome/browser/metrics/metrics_log_serializer.cc index b086f84..0d545ec 100644 --- a/chrome/browser/metrics/metrics_log_serializer.cc +++ b/chrome/browser/metrics/metrics_log_serializer.cc @@ -14,6 +14,9 @@ #include "chrome/browser/browser_process.h" #include "chrome/common/pref_names.h" +using metrics::MetricsLogBase; +using metrics::MetricsLogManager; + namespace { // The number of "initial" logs to save, and hope to send during a future Chrome diff --git a/chrome/browser/metrics/metrics_log_serializer.h b/chrome/browser/metrics/metrics_log_serializer.h index ae85b13..74d39e5 100644 --- a/chrome/browser/metrics/metrics_log_serializer.h +++ b/chrome/browser/metrics/metrics_log_serializer.h @@ -9,14 +9,14 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" -#include "chrome/common/metrics/metrics_log_manager.h" +#include "components/metrics/metrics_log_manager.h" namespace base { class ListValue; } // Serializer for persisting metrics logs to prefs. -class MetricsLogSerializer : public MetricsLogManager::LogSerializer { +class MetricsLogSerializer : public metrics::MetricsLogManager::LogSerializer { public: // Used to produce a histogram that keeps track of the status of recalling // persisted per logs. @@ -39,13 +39,13 @@ class MetricsLogSerializer : public MetricsLogManager::LogSerializer { MetricsLogSerializer(); virtual ~MetricsLogSerializer(); - // Implementation of MetricsLogManager::LogSerializer + // Implementation of metrics::MetricsLogManager::LogSerializer virtual void SerializeLogs( - const std::vector<MetricsLogManager::SerializedLog>& logs, - MetricsLogManager::LogType log_type) OVERRIDE; + const std::vector<metrics::MetricsLogManager::SerializedLog>& logs, + metrics::MetricsLogManager::LogType log_type) OVERRIDE; virtual void DeserializeLogs( - MetricsLogManager::LogType log_type, - std::vector<MetricsLogManager::SerializedLog>* logs) OVERRIDE; + metrics::MetricsLogManager::LogType log_type, + std::vector<metrics::MetricsLogManager::SerializedLog>* logs) OVERRIDE; private: // Encodes the textual log data from |local_list| and writes it to the given @@ -54,7 +54,7 @@ class MetricsLogSerializer : public MetricsLogManager::LogSerializer { // |list_length_limit| logs and |byte_limit| bytes of logs have been // stored. At least one of those two arguments must be non-zero. static void WriteLogsToPrefList( - const std::vector<MetricsLogManager::SerializedLog>& local_list, + const std::vector<metrics::MetricsLogManager::SerializedLog>& local_list, size_t list_length_limit, size_t byte_limit, base::ListValue* list); @@ -63,7 +63,7 @@ class MetricsLogSerializer : public MetricsLogManager::LogSerializer { // |local_list| and returning a status code. static LogReadStatus ReadLogsFromPrefList( const base::ListValue& list, - std::vector<MetricsLogManager::SerializedLog>* local_list); + std::vector<metrics::MetricsLogManager::SerializedLog>* local_list); FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, EmptyLogList); FRIEND_TEST_ALL_PREFIXES(MetricsLogSerializerTest, SingleElementLogList); diff --git a/chrome/browser/metrics/metrics_log_serializer_unittest.cc b/chrome/browser/metrics/metrics_log_serializer_unittest.cc index 58339402..386a3cb 100644 --- a/chrome/browser/metrics/metrics_log_serializer_unittest.cc +++ b/chrome/browser/metrics/metrics_log_serializer_unittest.cc @@ -8,6 +8,8 @@ #include "chrome/browser/metrics/metrics_log_serializer.h" #include "testing/gtest/include/gtest/gtest.h" +using metrics::MetricsLogManager; + namespace { const size_t kListLengthLimit = 3; diff --git a/chrome/browser/metrics/metrics_log_unittest.cc b/chrome/browser/metrics/metrics_log_unittest.cc index 2f112a9..9ff887f 100644 --- a/chrome/browser/metrics/metrics_log_unittest.cc +++ b/chrome/browser/metrics/metrics_log_unittest.cc @@ -23,12 +23,13 @@ #include "chrome/browser/google/google_util.h" #include "chrome/browser/prefs/browser_prefs.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/metrics/proto/profiler_event.pb.h" -#include "chrome/common/metrics/proto/system_profile.pb.h" +#include "chrome/common/chrome_version_info.h" #include "chrome/common/metrics/variations/variations_util.h" #include "chrome/common/pref_names.h" #include "chrome/installer/util/google_update_settings.h" #include "components/metrics/metrics_hashes.h" +#include "components/metrics/proto/profiler_event.pb.h" +#include "components/metrics/proto/system_profile.pb.h" #include "components/variations/metrics_util.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/process_type.h" @@ -650,6 +651,11 @@ TEST_F(MetricsLogTest, RecordProfilerData) { } } +TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) { + TestMetricsLog log("user@test.com", kSessionId, MetricsLog::ONGOING_LOG); + EXPECT_TRUE(log.uma_proto().system_profile().has_channel()); +} + #if defined(OS_CHROMEOS) TEST_F(MetricsLogTest, MultiProfileUserCount) { std::string user1("user1@example.com"); diff --git a/chrome/browser/metrics/metrics_network_observer.h b/chrome/browser/metrics/metrics_network_observer.h index bcec85e..e64800b 100644 --- a/chrome/browser/metrics/metrics_network_observer.h +++ b/chrome/browser/metrics/metrics_network_observer.h @@ -8,7 +8,7 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "chrome/common/metrics/proto/system_profile.pb.h" +#include "components/metrics/proto/system_profile.pb.h" #include "net/base/net_util.h" #include "net/base/network_change_notifier.h" diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index c082ccf..55c1321 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -207,10 +207,10 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/crash_keys.h" #include "chrome/common/metrics/caching_permuted_entropy_provider.h" -#include "chrome/common/metrics/metrics_log_manager.h" #include "chrome/common/net/test_server_locations.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" +#include "components/metrics/metrics_log_manager.h" #include "components/variations/entropy_provider.h" #include "components/variations/metrics_util.h" #include "content/public/browser/child_process_data.h" @@ -252,6 +252,7 @@ using content::BrowserThread; using content::ChildProcessData; using content::LoadNotificationDetails; using content::PluginService; +using metrics::MetricsLogManager; namespace { diff --git a/chrome/browser/metrics/metrics_service_unittest.cc b/chrome/browser/metrics/metrics_service_unittest.cc index 262cce4..48f7ec1 100644 --- a/chrome/browser/metrics/metrics_service_unittest.cc +++ b/chrome/browser/metrics/metrics_service_unittest.cc @@ -26,6 +26,8 @@ namespace { +using metrics::MetricsLogManager; + class TestMetricsService : public MetricsService { public: TestMetricsService() {} diff --git a/chrome/browser/metrics/perf_provider_chromeos.h b/chrome/browser/metrics/perf_provider_chromeos.h index b08c845..2822710 100644 --- a/chrome/browser/metrics/perf_provider_chromeos.h +++ b/chrome/browser/metrics/perf_provider_chromeos.h @@ -12,7 +12,7 @@ #include "base/threading/non_thread_safe.h" #include "base/time/time.h" #include "base/timer/timer.h" -#include "chrome/common/metrics/proto/perf_data.pb.h" +#include "components/metrics/proto/perf_data.pb.h" namespace metrics { diff --git a/chrome/browser/ui/app_list/search/omnibox_provider.cc b/chrome/browser/ui/app_list/search/omnibox_provider.cc index 1793964..de71f00 100644 --- a/chrome/browser/ui/app_list/search/omnibox_provider.cc +++ b/chrome/browser/ui/app_list/search/omnibox_provider.cc @@ -11,7 +11,7 @@ #include "chrome/browser/autocomplete/search_provider.h" #include "chrome/browser/ui/app_list/search/chrome_search_result.h" #include "chrome/browser/ui/browser_navigator.h" -#include "chrome/common/metrics/proto/omnibox_event.pb.h" +#include "components/metrics/proto/omnibox_event.pb.h" #include "grit/theme_resources.h" #include "ui/base/resource/resource_bundle.h" diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index f0fb33f..e10cca7 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -31,11 +31,13 @@ '../components/components.gyp:bookmarks_core_browser', '../components/components.gyp:captive_portal', '../components/components.gyp:cloud_devices_common', + '../components/components.gyp:component_metrics_proto', '../components/components.gyp:data_reduction_proxy_browser', '../components/components.gyp:domain_reliability', '../components/components.gyp:favicon_base', '../components/components.gyp:favicon_core', '../components/components.gyp:infobars_core', + '../components/components.gyp:metrics', '../components/components.gyp:navigation_metrics', '../components/components.gyp:os_crypt', '../components/components.gyp:password_manager_core_browser', diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index ae6ae90..e9b1dbe 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -253,10 +253,6 @@ 'common/media/webrtc_logging_message_data.h', 'common/metrics/caching_permuted_entropy_provider.cc', 'common/metrics/caching_permuted_entropy_provider.h', - 'common/metrics/metrics_log_base.cc', - 'common/metrics/metrics_log_base.h', - 'common/metrics/metrics_log_manager.cc', - 'common/metrics/metrics_log_manager.h', 'common/metrics/metrics_service_base.cc', 'common/metrics/metrics_service_base.h', 'common/metrics/variations/experiment_labels.cc', @@ -684,14 +680,7 @@ 'type': 'static_library', 'sources': [ 'common/metrics/proto/chrome_experiments.proto', - 'common/metrics/proto/chrome_user_metrics_extension.proto', - 'common/metrics/proto/histogram_event.proto', - 'common/metrics/proto/omnibox_event.proto', - 'common/metrics/proto/perf_data.proto', 'common/metrics/proto/permuted_entropy_cache.proto', - 'common/metrics/proto/profiler_event.proto', - 'common/metrics/proto/system_profile.proto', - 'common/metrics/proto/user_action_event.proto', ], 'variables': { 'proto_in_dir': 'common/metrics/proto', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 27b8567..4ebb577 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -1855,8 +1855,6 @@ 'common/mac/objc_method_swizzle_unittest.mm', 'common/mac/objc_zombie_unittest.mm', 'common/metrics/caching_permuted_entropy_provider_unittest.cc', - 'common/metrics/metrics_log_base_unittest.cc', - 'common/metrics/metrics_log_manager_unittest.cc', 'common/metrics/variations/experiment_labels_unittest.cc', 'common/metrics/variations/variations_util_unittest.cc', 'common/multi_process_lock_unittest.cc', @@ -1980,6 +1978,7 @@ ['OS!="ios"', { 'dependencies': [ '../components/components.gyp:autofill_content_test_support', + '../components/components.gyp:component_metrics_proto', '../components/components.gyp:data_reduction_proxy_test_support', '../components/components_strings.gyp:components_strings', '../device/bluetooth/bluetooth.gyp:device_bluetooth_mocks', diff --git a/chrome/common/metrics/metrics_service_base.cc b/chrome/common/metrics/metrics_service_base.cc index 66e8238..a0a8182 100644 --- a/chrome/common/metrics/metrics_service_base.cc +++ b/chrome/common/metrics/metrics_service_base.cc @@ -6,7 +6,7 @@ #include <cstdlib> -#include "chrome/common/metrics/metrics_log_base.h" +#include "components/metrics/metrics_log_base.h" using base::Histogram; diff --git a/chrome/common/metrics/metrics_service_base.h b/chrome/common/metrics/metrics_service_base.h index f3a4a67..d2e9043 100644 --- a/chrome/common/metrics/metrics_service_base.h +++ b/chrome/common/metrics/metrics_service_base.h @@ -9,7 +9,7 @@ #include "base/metrics/histogram_base.h" #include "base/metrics/histogram_flattener.h" #include "base/metrics/histogram_snapshot_manager.h" -#include "chrome/common/metrics/metrics_log_manager.h" +#include "components/metrics/metrics_log_manager.h" namespace base { class HistogramSamples; @@ -48,7 +48,7 @@ class MetricsServiceBase : public base::HistogramFlattener { void RecordCurrentStabilityHistograms(); // Manager for the various in-flight logs. - MetricsLogManager log_manager_; + metrics::MetricsLogManager log_manager_; private: // |histogram_snapshot_manager_| prepares histogram deltas for transmission. diff --git a/components/components_tests.gyp b/components/components_tests.gyp index fc31dea..1a4229e 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -95,6 +95,8 @@ 'keyed_service/core/dependency_graph_unittest.cc', 'language_usage_metrics/language_usage_metrics_unittest.cc', 'metrics/metrics_hashes_unittest.cc', + 'metrics/metrics_log_base_unittest.cc', + 'metrics/metrics_log_manager_unittest.cc', 'navigation_interception/intercept_navigation_resource_throttle_unittest.cc', 'os_crypt/ie7_password_win_unittest.cc', 'os_crypt/keychain_password_mac_unittest.mm', diff --git a/components/metrics.gypi b/components/metrics.gypi index 6036cae..e0fe848 100644 --- a/components/metrics.gypi +++ b/components/metrics.gypi @@ -12,11 +12,35 @@ ], 'dependencies': [ '../base/base.gyp:base', + 'component_metrics_proto', ], 'sources': [ 'metrics/metrics_hashes.cc', 'metrics/metrics_hashes.h', + 'metrics/metrics_log_base.cc', + 'metrics/metrics_log_base.h', + 'metrics/metrics_log_manager.cc', + 'metrics/metrics_log_manager.h', ], }, + { + # Protobuf compiler / generator for UMA (User Metrics Analysis). + 'target_name': 'component_metrics_proto', + 'type': 'static_library', + 'sources': [ + 'metrics/proto/chrome_user_metrics_extension.proto', + 'metrics/proto/histogram_event.proto', + 'metrics/proto/omnibox_event.proto', + 'metrics/proto/perf_data.proto', + 'metrics/proto/profiler_event.proto', + 'metrics/proto/system_profile.proto', + 'metrics/proto/user_action_event.proto', + ], + 'variables': { + 'proto_in_dir': 'metrics/proto', + 'proto_out_dir': 'components/metrics/proto', + }, + 'includes': [ '../build/protoc.gypi' ], + }, ], } diff --git a/components/metrics/DEPS b/components/metrics/DEPS new file mode 100644 index 0000000..ccaaef4 --- /dev/null +++ b/components/metrics/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "-content", + "-net", +] diff --git a/components/metrics/README b/components/metrics/README new file mode 100644 index 0000000..3461dea --- /dev/null +++ b/components/metrics/README @@ -0,0 +1,22 @@ +This component contains the base classes for the metrics service and only +depends on //base. It is used by ChromeOS as the base for a standalone service +that will upload the metrics when ChromeOS is not installed (headless install). + +This is the first step towards the componentization of metrics that will happen +later this spring. + +A proposed structure for the metrics component is: +//components/metrics/base, + Depends on base only. Contains the protobuf definitions. +//components/metrics/core + Depends on everything iOS depends on +//components/metrics/content + Depends on content + +Ideally, the component would abstract the network stack and have a clean +separation between the metrics upload logic (protbuf generation, retry, etc...), +the chrome part (gathering histogram from all the threads, populating the +log with hardware characteristics, plugin state, etc.). + +It is a plus if the component stays in a single directory as it would be easier +for ChromeOS to pull it :). diff --git a/chrome/common/metrics/metrics_log_base.cc b/components/metrics/metrics_log_base.cc index 3eb4972..99e4edb 100644 --- a/chrome/common/metrics/metrics_log_base.cc +++ b/components/metrics/metrics_log_base.cc @@ -1,16 +1,15 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#include "chrome/common/metrics/metrics_log_base.h" +#include "components/metrics/metrics_log_base.h" #include "base/metrics/histogram_base.h" #include "base/metrics/histogram_samples.h" -#include "chrome/common/chrome_version_info.h" -#include "chrome/common/metrics/proto/histogram_event.pb.h" -#include "chrome/common/metrics/proto/system_profile.pb.h" -#include "chrome/common/metrics/proto/user_action_event.pb.h" #include "components/metrics/metrics_hashes.h" +#include "components/metrics/proto/histogram_event.pb.h" +#include "components/metrics/proto/system_profile.pb.h" +#include "components/metrics/proto/user_action_event.pb.h" using base::Histogram; using base::HistogramBase; @@ -22,6 +21,7 @@ using metrics::HistogramEventProto; using metrics::SystemProfileProto; using metrics::UserActionEventProto; +namespace metrics { namespace { // Any id less than 16 bytes is considered to be a testing id. @@ -29,25 +29,6 @@ bool IsTestingID(const std::string& id) { return id.size() < 16; } -SystemProfileProto::Channel AsProtobufChannel( - chrome::VersionInfo::Channel channel) { - switch (channel) { - case chrome::VersionInfo::CHANNEL_UNKNOWN: - return SystemProfileProto::CHANNEL_UNKNOWN; - case chrome::VersionInfo::CHANNEL_CANARY: - return SystemProfileProto::CHANNEL_CANARY; - case chrome::VersionInfo::CHANNEL_DEV: - return SystemProfileProto::CHANNEL_DEV; - case chrome::VersionInfo::CHANNEL_BETA: - return SystemProfileProto::CHANNEL_BETA; - case chrome::VersionInfo::CHANNEL_STABLE: - return SystemProfileProto::CHANNEL_STABLE; - default: - NOTREACHED(); - return SystemProfileProto::CHANNEL_UNKNOWN; - } -} - } // namespace MetricsLogBase::MetricsLogBase(const std::string& client_id, @@ -66,8 +47,6 @@ MetricsLogBase::MetricsLogBase(const std::string& client_id, uma_proto_.set_session_id(session_id); uma_proto_.mutable_system_profile()->set_build_timestamp(GetBuildTime()); uma_proto_.mutable_system_profile()->set_app_version(version_string); - uma_proto_.mutable_system_profile()->set_channel( - AsProtobufChannel(chrome::VersionInfo::GetChannel())); } MetricsLogBase::~MetricsLogBase() {} @@ -136,8 +115,7 @@ void MetricsLogBase::RecordHistogramDelta(const std::string& histogram_name, histogram_proto->set_name_hash(Hash(histogram_name)); histogram_proto->set_sum(snapshot.sum()); - for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator(); - !it->Done(); + for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator(); !it->Done(); it->Next()) { HistogramBase::Sample min; HistogramBase::Sample max; @@ -160,3 +138,5 @@ void MetricsLogBase::RecordHistogramDelta(const std::string& histogram_name, } } } + +} // namespace metrics diff --git a/chrome/common/metrics/metrics_log_base.h b/components/metrics/metrics_log_base.h index f0124d8..25a6bd0 100644 --- a/chrome/common/metrics/metrics_log_base.h +++ b/components/metrics/metrics_log_base.h @@ -1,27 +1,26 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. // This file defines a set of user experience metrics data recorded by // the MetricsService. This is the unit of data that is sent to the server. -#ifndef CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ -#define CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ +#ifndef COMPONENTS_METRICS_METRICS_LOG_BASE_H_ +#define COMPONENTS_METRICS_METRICS_LOG_BASE_H_ #include <string> #include "base/basictypes.h" #include "base/metrics/histogram.h" #include "base/time/time.h" -#include "chrome/common/metrics/proto/chrome_user_metrics_extension.pb.h" -#include "content/public/common/page_transition_types.h" - -class GURL; +#include "components/metrics/proto/chrome_user_metrics_extension.pb.h" namespace base { class HistogramSamples; } // namespace base +namespace metrics { + // This class provides base functionality for logging metrics data. class MetricsLogBase { public: @@ -106,4 +105,6 @@ class MetricsLogBase { DISALLOW_COPY_AND_ASSIGN(MetricsLogBase); }; -#endif // CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ +} // namespace metrics + +#endif // COMPONENTS_METRICS_METRICS_LOG_BASE_H_ diff --git a/chrome/common/metrics/metrics_log_base_unittest.cc b/components/metrics/metrics_log_base_unittest.cc index 4c77f60..cc7a173 100644 --- a/chrome/common/metrics/metrics_log_base_unittest.cc +++ b/components/metrics/metrics_log_base_unittest.cc @@ -1,17 +1,19 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#include "chrome/common/metrics/metrics_log_base.h" +#include "components/metrics/metrics_log_base.h" #include <string> #include "base/base64.h" #include "base/metrics/bucket_ranges.h" #include "base/metrics/sample_vector.h" -#include "chrome/common/metrics/proto/chrome_user_metrics_extension.pb.h" +#include "components/metrics/proto/chrome_user_metrics_extension.pb.h" #include "testing/gtest/include/gtest/gtest.h" +namespace metrics { + namespace { class TestMetricsLogBase : public MetricsLogBase { @@ -57,8 +59,6 @@ TEST(MetricsLogBaseTest, EmptyRecord) { expected.mutable_system_profile()->set_build_timestamp( parsed.system_profile().build_timestamp()); expected.mutable_system_profile()->set_app_version("bogus version"); - expected.mutable_system_profile()->set_channel( - parsed.system_profile().channel()); expected.mutable_system_profile()->mutable_hardware()->set_hardware_class( "sample-class"); @@ -78,9 +78,9 @@ TEST(MetricsLogBaseTest, HistogramBucketFields) { ranges.set_range(7, 12); base::SampleVector samples(&ranges); - samples.Accumulate(3, 1); // Bucket 1-5. - samples.Accumulate(6, 1); // Bucket 5-7. - samples.Accumulate(8, 1); // Bucket 8-9. (7-8 skipped) + samples.Accumulate(3, 1); // Bucket 1-5. + samples.Accumulate(6, 1); // Bucket 5-7. + samples.Accumulate(8, 1); // Bucket 8-9. (7-8 skipped) samples.Accumulate(10, 1); // Bucket 10-11. (9-10 skipped) samples.Accumulate(11, 1); // Bucket 11-12. @@ -121,3 +121,5 @@ TEST(MetricsLogBaseTest, HistogramBucketFields) { EXPECT_TRUE(histogram_proto.bucket(4).has_max()); EXPECT_EQ(12, histogram_proto.bucket(4).max()); } + +} // namespace metrics diff --git a/chrome/common/metrics/metrics_log_manager.cc b/components/metrics/metrics_log_manager.cc index bd49de9..e537eef 100644 --- a/chrome/common/metrics/metrics_log_manager.cc +++ b/components/metrics/metrics_log_manager.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#include "chrome/common/metrics/metrics_log_manager.h" +#include "components/metrics/metrics_log_manager.h" #include <algorithm> @@ -10,7 +10,9 @@ #include "base/sha1.h" #include "base/strings/string_util.h" #include "base/timer/elapsed_timer.h" -#include "chrome/common/metrics/metrics_log_base.h" +#include "components/metrics/metrics_log_base.h" + +namespace metrics { MetricsLogManager::SerializedLog::SerializedLog() {} MetricsLogManager::SerializedLog::~SerializedLog() {} @@ -143,8 +145,9 @@ void MetricsLogManager::DiscardLastProvisionalStore() { if (last_provisional_store_index_ == -1) return; std::vector<SerializedLog>* source_list = - (last_provisional_store_type_ == MetricsLogBase::ONGOING_LOG) ? - &unsent_ongoing_logs_ : &unsent_initial_logs_; + (last_provisional_store_type_ == MetricsLogBase::ONGOING_LOG) + ? &unsent_ongoing_logs_ + : &unsent_initial_logs_; DCHECK_LT(static_cast<unsigned int>(last_provisional_store_index_), source_list->size()); source_list->erase(source_list->begin() + last_provisional_store_index_); @@ -201,3 +204,5 @@ void MetricsLogManager::CompressCurrentLog(SerializedLog* compressed_log) { current_log_->GetEncodedLog(&log_text); compressed_log->SwapLogText(&log_text); } + +} // namespace metrics diff --git a/chrome/common/metrics/metrics_log_manager.h b/components/metrics/metrics_log_manager.h index d9ff380..006d4ed 100644 --- a/chrome/common/metrics/metrics_log_manager.h +++ b/components/metrics/metrics_log_manager.h @@ -1,17 +1,18 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#ifndef CHROME_COMMON_METRICS_METRICS_LOG_MANAGER_H_ -#define CHROME_COMMON_METRICS_METRICS_LOG_MANAGER_H_ - +#ifndef COMPONENTS_METRICS_METRICS_LOG_MANAGER_H_ +#define COMPONENTS_METRICS_METRICS_LOG_MANAGER_H_ #include <string> #include <vector> #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" -#include "chrome/common/metrics/metrics_log_base.h" +#include "components/metrics/metrics_log_base.h" + +namespace metrics { // Manages all the log objects used by a MetricsService implementation. Keeps // track of both an in progress log and a log that is staged for uploading as @@ -165,9 +166,7 @@ class MetricsLogManager { // |max_ongoing_log_store_size_|). // NOTE: This clears the contents of |log| (to avoid an expensive copy), // so the log should be discarded after this call. - void StoreLog(SerializedLog* log, - LogType log_type, - StoreType store_type); + void StoreLog(SerializedLog* log, LogType log_type, StoreType store_type); // Compresses |current_log_| into |compressed_log|. void CompressCurrentLog(SerializedLog* compressed_log); @@ -209,4 +208,6 @@ class MetricsLogManager { DISALLOW_COPY_AND_ASSIGN(MetricsLogManager); }; -#endif // CHROME_COMMON_METRICS_METRICS_LOG_MANAGER_H_ +} // namespace metrics + +#endif // COMPONENTS_METRICS_METRICS_LOG_MANAGER_H_ diff --git a/chrome/common/metrics/metrics_log_manager_unittest.cc b/components/metrics/metrics_log_manager_unittest.cc index 899cc0b..ec0ca38f 100644 --- a/chrome/common/metrics/metrics_log_manager_unittest.cc +++ b/components/metrics/metrics_log_manager_unittest.cc @@ -1,17 +1,19 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. -#include "chrome/common/metrics/metrics_log_manager.h" +#include "components/metrics/metrics_log_manager.h" #include <string> #include <utility> #include <vector> #include "base/sha1.h" -#include "chrome/common/metrics/metrics_log_base.h" +#include "components/metrics/metrics_log_base.h" #include "testing/gtest/include/gtest/gtest.h" +namespace metrics { + namespace { // Dummy serializer that just stores logs in memory. @@ -421,3 +423,5 @@ TEST(MetricsLogManagerTest, SerializedLog) { EXPECT_TRUE(log2.log_text().empty()); EXPECT_TRUE(log2.log_hash().empty()); } + +} // namespace metrics diff --git a/chrome/common/metrics/proto/chrome_user_metrics_extension.proto b/components/metrics/proto/chrome_user_metrics_extension.proto index a5a6de0..80f3499 100644 --- a/chrome/common/metrics/proto/chrome_user_metrics_extension.proto +++ b/components/metrics/proto/chrome_user_metrics_extension.proto @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. // diff --git a/chrome/common/metrics/proto/histogram_event.proto b/components/metrics/proto/histogram_event.proto index e004dca..7cb0e8c 100644 --- a/chrome/common/metrics/proto/histogram_event.proto +++ b/components/metrics/proto/histogram_event.proto @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. // diff --git a/chrome/common/metrics/proto/omnibox_event.proto b/components/metrics/proto/omnibox_event.proto index a630973..6e3f91c 100644 --- a/chrome/common/metrics/proto/omnibox_event.proto +++ b/components/metrics/proto/omnibox_event.proto @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. // diff --git a/chrome/common/metrics/proto/perf_data.proto b/components/metrics/proto/perf_data.proto index 8f9b342..6278649 100644 --- a/chrome/common/metrics/proto/perf_data.proto +++ b/components/metrics/proto/perf_data.proto @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. diff --git a/chrome/common/metrics/proto/profiler_event.proto b/components/metrics/proto/profiler_event.proto index c42bc5a..1f18b2a 100644 --- a/chrome/common/metrics/proto/profiler_event.proto +++ b/components/metrics/proto/profiler_event.proto @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. // diff --git a/chrome/common/metrics/proto/system_profile.proto b/components/metrics/proto/system_profile.proto index fd339ec..98a0f5d 100644 --- a/chrome/common/metrics/proto/system_profile.proto +++ b/components/metrics/proto/system_profile.proto @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. // diff --git a/chrome/common/metrics/proto/user_action_event.proto b/components/metrics/proto/user_action_event.proto index ff688b6..6817dcd 100644 --- a/chrome/common/metrics/proto/user_action_event.proto +++ b/components/metrics/proto/user_action_event.proto @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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. // |