Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / metrics / google_update_metrics_provider_win.cc
blob397049fc76c2a2f7898f7f2232860cc6154ba997
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/metrics/google_update_metrics_provider_win.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/task_runner_util.h"
9 #include "components/metrics/proto/system_profile.pb.h"
10 #include "content/public/browser/browser_thread.h"
12 typedef metrics::SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo;
14 namespace {
16 // Helper function for checking if this is an official build. Used instead of
17 // the macro to allow checking for successful code compilation on non-official
18 // builds.
19 bool IsOfficialBuild() {
20 #if defined(GOOGLE_CHROME_BUILD)
21 return true;
22 #else
23 return false;
24 #endif // defined(GOOGLE_CHROME_BUILD)
27 void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data,
28 ProductInfo* product_info) {
29 product_info->set_version(product_data.version);
30 product_info->set_last_update_success_timestamp(
31 product_data.last_success.ToTimeT());
32 product_info->set_last_error(product_data.last_error_code);
33 product_info->set_last_extra_error(product_data.last_extra_code);
34 if (ProductInfo::InstallResult_IsValid(product_data.last_result)) {
35 product_info->set_last_result(
36 static_cast<ProductInfo::InstallResult>(product_data.last_result));
40 } // namespace
42 GoogleUpdateMetricsProviderWin::GoogleUpdateMetricsProviderWin()
43 : weak_ptr_factory_(this) {
46 GoogleUpdateMetricsProviderWin::~GoogleUpdateMetricsProviderWin() {
49 void GoogleUpdateMetricsProviderWin::GetGoogleUpdateData(
50 const base::Closure& done_callback) {
51 if (!IsOfficialBuild()) {
52 base::MessageLoop::current()->PostTask(FROM_HERE, done_callback);
53 return;
56 // Schedules a task on a blocking pool thread to gather Google Update
57 // statistics (requires Registry reads).
58 base::PostTaskAndReplyWithResult(
59 content::BrowserThread::GetBlockingPool(),
60 FROM_HERE,
61 base::Bind(
62 &GoogleUpdateMetricsProviderWin::GetGoogleUpdateDataOnBlockingPool),
63 base::Bind(
64 &GoogleUpdateMetricsProviderWin::ReceiveGoogleUpdateData,
65 weak_ptr_factory_.GetWeakPtr(), done_callback));
68 void GoogleUpdateMetricsProviderWin::ProvideSystemProfileMetrics(
69 metrics::SystemProfileProto* system_profile_proto) {
70 if (!IsOfficialBuild())
71 return;
73 metrics::SystemProfileProto::GoogleUpdate* google_update =
74 system_profile_proto->mutable_google_update();
76 google_update->set_is_system_install(
77 google_update_metrics_.is_system_install);
79 if (!google_update_metrics_.last_started_automatic_update_check.is_null()) {
80 google_update->set_last_automatic_start_timestamp(
81 google_update_metrics_.last_started_automatic_update_check.ToTimeT());
84 if (!google_update_metrics_.last_checked.is_null()) {
85 google_update->set_last_update_check_timestamp(
86 google_update_metrics_.last_checked.ToTimeT());
89 if (!google_update_metrics_.google_update_data.version.empty()) {
90 ProductDataToProto(google_update_metrics_.google_update_data,
91 google_update->mutable_google_update_status());
94 if (!google_update_metrics_.product_data.version.empty()) {
95 ProductDataToProto(google_update_metrics_.product_data,
96 google_update->mutable_client_status());
100 GoogleUpdateMetricsProviderWin::GoogleUpdateMetrics::GoogleUpdateMetrics()
101 : is_system_install(false) {
104 GoogleUpdateMetricsProviderWin::GoogleUpdateMetrics::~GoogleUpdateMetrics() {
107 // static
108 GoogleUpdateMetricsProviderWin::GoogleUpdateMetrics
109 GoogleUpdateMetricsProviderWin::GetGoogleUpdateDataOnBlockingPool() {
110 GoogleUpdateMetrics google_update_metrics;
112 if (!IsOfficialBuild())
113 return google_update_metrics;
115 const bool is_system_install = GoogleUpdateSettings::IsSystemInstall();
116 google_update_metrics.is_system_install = is_system_install;
117 google_update_metrics.last_started_automatic_update_check =
118 GoogleUpdateSettings::GetGoogleUpdateLastStartedAU(is_system_install);
119 google_update_metrics.last_checked =
120 GoogleUpdateSettings::GetGoogleUpdateLastChecked(is_system_install);
121 GoogleUpdateSettings::GetUpdateDetailForGoogleUpdate(
122 is_system_install,
123 &google_update_metrics.google_update_data);
124 GoogleUpdateSettings::GetUpdateDetail(
125 is_system_install,
126 &google_update_metrics.product_data);
127 return google_update_metrics;
130 void GoogleUpdateMetricsProviderWin::ReceiveGoogleUpdateData(
131 const base::Closure& done_callback,
132 const GoogleUpdateMetrics& google_update_metrics) {
133 google_update_metrics_ = google_update_metrics;
134 done_callback.Run();