Skip to content

Commit

Permalink
Move part of metrics from chrome/common to components
Browse files Browse the repository at this point in the history
Chrome OS needs to have access to the metrics aggretion and serialization logic
to build a metric sender service replacing chrome. Protobuf definitions are
moved to components too.
The code remaining will be extrated in components/metrics and
components/variation during a refactoring later this year.

BUG=chromium:360183
TEST=run unittests
TBR=sky@chromium.org, benwells@chromium.org

Review URL: https://codereview.chromium.org/239093004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267709 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
bsimonnet@chromium.org committed May 2, 2014
1 parent 8e05f0f commit 064107e
Show file tree
Hide file tree
Showing 38 changed files with 182 additions and 110 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/autocomplete/autocomplete_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/feedback/feedback_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/metrics/extension_metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/metrics/extension_metrics_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 26 additions & 3 deletions chrome/browser/metrics/metrics_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/metrics/metrics_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/metrics/metrics_log_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/metrics/metrics_log_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions chrome/browser/metrics/metrics_log_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/metrics/metrics_log_serializer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions chrome/browser/metrics/metrics_log_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/metrics/metrics_network_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/metrics/metrics_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -252,6 +252,7 @@ using content::BrowserThread;
using content::ChildProcessData;
using content::LoadNotificationDetails;
using content::PluginService;
using metrics::MetricsLogManager;

namespace {

Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/metrics/metrics_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

namespace {

using metrics::MetricsLogManager;

class TestMetricsService : public MetricsService {
public:
TestMetricsService() {}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/metrics/perf_provider_chromeos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ui/app_list/search/omnibox_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions chrome/chrome_browser.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 0 additions & 11 deletions chrome/chrome_common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions chrome/chrome_tests_unit.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion chrome/common/metrics/metrics_service_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <cstdlib>

#include "chrome/common/metrics/metrics_log_base.h"
#include "components/metrics/metrics_log_base.h"

using base::Histogram;

Expand Down
4 changes: 2 additions & 2 deletions chrome/common/metrics/metrics_service_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions components/components_tests.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading

0 comments on commit 064107e

Please sign in to comment.