OLD | NEW |
---|---|
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/component_updater/sw_reporter_installer_win.h" | 5 #include "chrome/browser/component_updater/sw_reporter_installer_win.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/base_paths.h" | 13 #include "base/base_paths.h" |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/metrics/field_trial.h" | 20 #include "base/metrics/field_trial.h" |
21 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
22 #include "base/metrics/sparse_histogram.h" | 22 #include "base/metrics/sparse_histogram.h" |
23 #include "base/path_service.h" | 23 #include "base/path_service.h" |
24 #include "base/prefs/pref_registry_simple.h" | 24 #include "base/prefs/pref_registry_simple.h" |
25 #include "base/prefs/pref_service.h" | 25 #include "base/prefs/pref_service.h" |
26 #include "base/process/kill.h" | 26 #include "base/process/kill.h" |
27 #include "base/process/launch.h" | 27 #include "base/process/launch.h" |
28 #include "base/strings/string_tokenizer.h" | |
28 #include "base/task_runner_util.h" | 29 #include "base/task_runner_util.h" |
29 #include "base/threading/worker_pool.h" | 30 #include "base/threading/worker_pool.h" |
30 #include "base/time/time.h" | 31 #include "base/time/time.h" |
31 #include "base/win/registry.h" | 32 #include "base/win/registry.h" |
32 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
33 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 34 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
34 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
35 #include "chrome/browser/safe_browsing/srt_global_error_win.h" | 36 #include "chrome/browser/safe_browsing/srt_global_error_win.h" |
36 #include "chrome/browser/ui/browser_finder.h" | 37 #include "chrome/browser/ui/browser_finder.h" |
37 #include "chrome/browser/ui/global_error/global_error_service.h" | 38 #include "chrome/browser/ui/global_error/global_error_service.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 0x05, 0xa5, 0x62, 0x4b, 0x2e, 0xc7, 0xb7, 0x1c, | 81 0x05, 0xa5, 0x62, 0x4b, 0x2e, 0xc7, 0xb7, 0x1c, |
81 0x5f, 0xea, 0xf0, 0x88, 0xf6, 0x97, 0x9b, 0xc7}; | 82 0x5f, 0xea, 0xf0, 0x88, 0xf6, 0x97, 0x9b, 0xc7}; |
82 | 83 |
83 const base::FilePath::CharType kSwReporterExeName[] = | 84 const base::FilePath::CharType kSwReporterExeName[] = |
84 FILE_PATH_LITERAL("software_reporter_tool.exe"); | 85 FILE_PATH_LITERAL("software_reporter_tool.exe"); |
85 | 86 |
86 // Where to fetch the reporter exit code in the registry. | 87 // Where to fetch the reporter exit code in the registry. |
87 const wchar_t kSoftwareRemovalToolRegistryKey[] = | 88 const wchar_t kSoftwareRemovalToolRegistryKey[] = |
88 L"Software\\Google\\Software Removal Tool"; | 89 L"Software\\Google\\Software Removal Tool"; |
89 const wchar_t kCleanerSuffixRegistryKey[] = L"Cleaner"; | 90 const wchar_t kCleanerSuffixRegistryKey[] = L"Cleaner"; |
91 const wchar_t kEndTimeRegistryValueName[] = L"EndTime"; | |
90 const wchar_t kExitCodeRegistryValueName[] = L"ExitCode"; | 92 const wchar_t kExitCodeRegistryValueName[] = L"ExitCode"; |
93 const wchar_t kStartTimeRegistryValueName[] = L"StartTime"; | |
94 const wchar_t kUploadResultsValueName[] = L"UploadResults"; | |
91 const wchar_t kVersionRegistryValueName[] = L"Version"; | 95 const wchar_t kVersionRegistryValueName[] = L"Version"; |
92 const wchar_t kStartTimeRegistryValueName[] = L"StartTime"; | |
93 const wchar_t kEndTimeRegistryValueName[] = L"EndTime"; | |
94 | 96 |
95 // Field trial strings. | 97 // Field trial strings. |
96 const char kSRTPromptTrialName[] = "SRTPromptFieldTrial"; | 98 const char kSRTPromptTrialName[] = "SRTPromptFieldTrial"; |
97 const char kSRTPromptOnGroup[] = "On"; | 99 const char kSRTPromptOnGroup[] = "On"; |
98 const char kSRTPromptSeedParamName[] = "Seed"; | 100 const char kSRTPromptSeedParamName[] = "Seed"; |
99 | 101 |
100 // Exit codes that identify that a cleanup is needed. | 102 // Exit codes that identify that a cleanup is needed. |
101 const int kCleanupNeeded = 0; | 103 const int kCleanupNeeded = 0; |
102 const int kNothingFound = 2; | 104 const int kNothingFound = 2; |
103 const int kPostRebootCleanupNeeded = 4; | 105 const int kPostRebootCleanupNeeded = 4; |
(...skipping 23 matching lines...) Expand all Loading... | |
127 DCHECK_LT(version.components()[1], 0x10000); | 129 DCHECK_LT(version.components()[1], 0x10000); |
128 major_version += 0x100 * version.components()[1]; | 130 major_version += 0x100 * version.components()[1]; |
129 } | 131 } |
130 if (version.components().size() >= 3) { | 132 if (version.components().size() >= 3) { |
131 DCHECK_LT(version.components()[2], 0x100); | 133 DCHECK_LT(version.components()[2], 0x100); |
132 major_version += version.components()[2]; | 134 major_version += version.components()[2]; |
133 } | 135 } |
134 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.MajorVersion", major_version); | 136 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.MajorVersion", major_version); |
135 } | 137 } |
136 | 138 |
139 void ReportUploadsWithUma(const base::string16& upload_results) { | |
140 base::WStringTokenizer tokenizer(upload_results, L";"); | |
141 int failure_count = 0; | |
142 int success_count = 0; | |
143 int longest_failure_run = 0; | |
144 int current_failure_run = 0; | |
145 bool last_result = false; | |
146 while (tokenizer.GetNext()) { | |
147 if (tokenizer.token() == L"0") { | |
148 ++failure_count; | |
149 ++current_failure_run; | |
150 last_result = false; | |
151 } else { | |
152 ++success_count; | |
153 current_failure_run = 0; | |
154 last_result = true; | |
155 } | |
156 | |
157 if (current_failure_run > longest_failure_run) | |
158 longest_failure_run = current_failure_run; | |
159 } | |
160 | |
161 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadFailureCount", | |
162 failure_count); | |
163 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadSuccessCount", | |
164 success_count); | |
165 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadLongestFailureRun", | |
166 longest_failure_run); | |
167 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.LastUploadResult", last_result); | |
168 } | |
169 | |
137 // This function is called on the UI thread to report the SwReporter exit code | 170 // This function is called on the UI thread to report the SwReporter exit code |
138 // and then clear it from the registry as well as clear the execution state | 171 // and then clear it from the registry as well as clear the execution state |
139 // from the local state. This could be called from an interruptible worker | 172 // from the local state. This could be called from an interruptible worker |
140 // thread so should be resilient to unexpected shutdown. |version| is provided | 173 // thread so should be resilient to unexpected shutdown. |version| is provided |
141 // so the kSwReporterPromptVersion prefs can be set. | 174 // so the kSwReporterPromptVersion prefs can be set. |
142 void ReportAndClearExitCode(int exit_code, const std::string& version) { | 175 void ReportAndClearExitCode(int exit_code, const std::string& version) { |
143 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.ExitCode", exit_code); | 176 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.ExitCode", exit_code); |
144 base::win::RegKey srt_key(HKEY_CURRENT_USER, kSoftwareRemovalToolRegistryKey, | 177 base::win::RegKey srt_key(HKEY_CURRENT_USER, kSoftwareRemovalToolRegistryKey, |
145 KEY_WRITE); | 178 KEY_WRITE); |
146 srt_key.DeleteValue(kExitCodeRegistryValueName); | 179 srt_key.DeleteValue(kExitCodeRegistryValueName); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 }; | 385 }; |
353 | 386 |
354 wchar_t SwReporterInstallerTraits::version_dir_[] = {}; | 387 wchar_t SwReporterInstallerTraits::version_dir_[] = {}; |
355 | 388 |
356 } // namespace | 389 } // namespace |
357 | 390 |
358 void RegisterSwReporterComponent(ComponentUpdateService* cus, | 391 void RegisterSwReporterComponent(ComponentUpdateService* cus, |
359 PrefService* prefs) { | 392 PrefService* prefs) { |
360 // The Sw reporter doesn't need to run if the user isn't reporting metrics and | 393 // The Sw reporter doesn't need to run if the user isn't reporting metrics and |
361 // isn't in the SRTPrompt field trial "On" group. | 394 // isn't in the SRTPrompt field trial "On" group. |
362 if (!ChromeMetricsServiceAccessor::IsMetricsReportingEnabled() && | 395 if (false && |
MAD
2015/02/11 22:26:49
Héhé... :-)
You know you can also simply enable U
robertshield
2015/02/11 22:36:16
Heh, oops, shouldn't leave test code lying around
| |
396 !ChromeMetricsServiceAccessor::IsMetricsReportingEnabled() && | |
363 base::FieldTrialList::FindFullName(kSRTPromptTrialName) != | 397 base::FieldTrialList::FindFullName(kSRTPromptTrialName) != |
364 kSRTPromptOnGroup) { | 398 kSRTPromptOnGroup) { |
365 return; | 399 return; |
366 } | 400 } |
367 | 401 |
368 // Check if we have information from Cleaner and record UMA statistics. | 402 // Check if we have information from Cleaner and record UMA statistics. |
369 base::string16 cleaner_key_name(kSoftwareRemovalToolRegistryKey); | 403 base::string16 cleaner_key_name(kSoftwareRemovalToolRegistryKey); |
370 cleaner_key_name.append(1, L'\\').append(kCleanerSuffixRegistryKey); | 404 cleaner_key_name.append(1, L'\\').append(kCleanerSuffixRegistryKey); |
371 base::win::RegKey cleaner_key( | 405 base::win::RegKey cleaner_key( |
372 HKEY_CURRENT_USER, cleaner_key_name.c_str(), KEY_ALL_ACCESS); | 406 HKEY_CURRENT_USER, cleaner_key_name.c_str(), KEY_ALL_ACCESS); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 if (exit_code == kPostRebootCleanupNeeded || | 443 if (exit_code == kPostRebootCleanupNeeded || |
410 exit_code == kDelayedPostRebootCleanupNeeded) { | 444 exit_code == kDelayedPostRebootCleanupNeeded) { |
411 // Check if we are running after the user has rebooted. | 445 // Check if we are running after the user has rebooted. |
412 base::TimeDelta elapsed(base::Time::Now() - | 446 base::TimeDelta elapsed(base::Time::Now() - |
413 base::Time::FromInternalValue(start_time_value)); | 447 base::Time::FromInternalValue(start_time_value)); |
414 DCHECK_GT(elapsed.InMilliseconds(), 0); | 448 DCHECK_GT(elapsed.InMilliseconds(), 0); |
415 UMA_HISTOGRAM_BOOLEAN( | 449 UMA_HISTOGRAM_BOOLEAN( |
416 "SoftwareReporter.Cleaner.HasRebooted", | 450 "SoftwareReporter.Cleaner.HasRebooted", |
417 static_cast<uint64>(elapsed.InMilliseconds()) > ::GetTickCount()); | 451 static_cast<uint64>(elapsed.InMilliseconds()) > ::GetTickCount()); |
418 } | 452 } |
453 | |
454 if (cleaner_key.HasValue(kUploadResultsValueName)) { | |
455 base::string16 upload_results; | |
456 cleaner_key.ReadValue(kUploadResultsValueName, &upload_results); | |
457 ReportUploadsWithUma(upload_results); | |
458 } | |
419 } | 459 } |
420 | 460 |
421 // Install the component. | 461 // Install the component. |
422 scoped_ptr<ComponentInstallerTraits> traits( | 462 scoped_ptr<ComponentInstallerTraits> traits( |
423 new SwReporterInstallerTraits(prefs)); | 463 new SwReporterInstallerTraits(prefs)); |
424 // |cus| will take ownership of |installer| during installer->Register(cus). | 464 // |cus| will take ownership of |installer| during installer->Register(cus). |
425 DefaultComponentInstaller* installer = | 465 DefaultComponentInstaller* installer = |
426 new DefaultComponentInstaller(traits.Pass()); | 466 new DefaultComponentInstaller(traits.Pass()); |
427 installer->Register(cus); | 467 installer->Register(cus); |
428 } | 468 } |
(...skipping 12 matching lines...) Expand all Loading... | |
441 registry->RegisterStringPref( | 481 registry->RegisterStringPref( |
442 prefs::kSwReporterPromptVersion, "", | 482 prefs::kSwReporterPromptVersion, "", |
443 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 483 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
444 | 484 |
445 registry->RegisterStringPref( | 485 registry->RegisterStringPref( |
446 prefs::kSwReporterPromptSeed, "", | 486 prefs::kSwReporterPromptSeed, "", |
447 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 487 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
448 } | 488 } |
449 | 489 |
450 } // namespace component_updater | 490 } // namespace component_updater |
OLD | NEW |