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
;
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
19 bool IsOfficialBuild() {
20 #if defined(GOOGLE_CHROME_BUILD)
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
));
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
);
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(),
62 &GoogleUpdateMetricsProviderWin::GetGoogleUpdateDataOnBlockingPool
),
64 &GoogleUpdateMetricsProviderWin::ReceiveGoogleUpdateData
,
65 weak_ptr_factory_
.GetWeakPtr(), done_callback
));
68 void GoogleUpdateMetricsProviderWin::ProvideSystemProfileMetrics(
69 metrics::SystemProfileProto
* system_profile_proto
) {
70 if (!IsOfficialBuild())
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() {
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(
123 &google_update_metrics
.google_update_data
);
124 GoogleUpdateSettings::GetUpdateDetail(
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
;