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 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/metrics/field_trial.h" | 18 #include "base/metrics/field_trial.h" |
19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
20 #include "base/metrics/sparse_histogram.h" | 20 #include "base/metrics/sparse_histogram.h" |
21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
22 #include "base/prefs/pref_registry_simple.h" | 22 #include "base/prefs/pref_registry_simple.h" |
23 #include "base/prefs/pref_service.h" | 23 #include "base/prefs/pref_service.h" |
24 #include "base/process/kill.h" | 24 #include "base/process/kill.h" |
25 #include "base/process/launch.h" | 25 #include "base/process/launch.h" |
26 #include "base/strings/stringprintf.h" | |
26 #include "base/task_runner_util.h" | 27 #include "base/task_runner_util.h" |
27 #include "base/threading/worker_pool.h" | 28 #include "base/threading/worker_pool.h" |
28 #include "base/time/time.h" | 29 #include "base/time/time.h" |
29 #include "base/win/registry.h" | 30 #include "base/win/registry.h" |
30 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
31 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 32 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
32 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/browser/safe_browsing/srt_global_error_win.h" | 34 #include "chrome/browser/safe_browsing/srt_global_error_win.h" |
34 #include "chrome/browser/ui/browser_finder.h" | 35 #include "chrome/browser/ui/browser_finder.h" |
35 #include "chrome/browser/ui/global_error/global_error_service.h" | 36 #include "chrome/browser/ui/global_error/global_error_service.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 0xf4, 0xc9, 0x78, 0x6c, 0x0c, 0x24, 0x73, 0x3e, | 76 0xf4, 0xc9, 0x78, 0x6c, 0x0c, 0x24, 0x73, 0x3e, |
76 0x05, 0xa5, 0x62, 0x4b, 0x2e, 0xc7, 0xb7, 0x1c, | 77 0x05, 0xa5, 0x62, 0x4b, 0x2e, 0xc7, 0xb7, 0x1c, |
77 0x5f, 0xea, 0xf0, 0x88, 0xf6, 0x97, 0x9b, 0xc7}; | 78 0x5f, 0xea, 0xf0, 0x88, 0xf6, 0x97, 0x9b, 0xc7}; |
78 | 79 |
79 const base::FilePath::CharType kSwReporterExeName[] = | 80 const base::FilePath::CharType kSwReporterExeName[] = |
80 FILE_PATH_LITERAL("software_reporter_tool.exe"); | 81 FILE_PATH_LITERAL("software_reporter_tool.exe"); |
81 | 82 |
82 // Where to fetch the reporter exit code in the registry. | 83 // Where to fetch the reporter exit code in the registry. |
83 const wchar_t kSoftwareRemovalToolRegistryKey[] = | 84 const wchar_t kSoftwareRemovalToolRegistryKey[] = |
84 L"Software\\Google\\Software Removal Tool"; | 85 L"Software\\Google\\Software Removal Tool"; |
86 const wchar_t kCleanerSuffixRegistryKey[] = L"%ls\\Cleaner"; | |
MAD
2014/10/20 01:38:33
Since the other string is simply at the beginning,
Georges Khalil
2014/10/24 12:37:58
Done.
| |
85 const wchar_t kExitCodeRegistryValueName[] = L"ExitCode"; | 87 const wchar_t kExitCodeRegistryValueName[] = L"ExitCode"; |
88 const wchar_t kVersionRegistryValueName[] = L"Version"; | |
89 const wchar_t kStartTimeRegistryValueName[] = L"StartTime"; | |
90 const wchar_t kEndTimeRegistryValueName[] = L"EndTime"; | |
86 | 91 |
87 // Field trial strings. | 92 // Field trial strings. |
88 const char kSRTPromptTrialName[] = "SRTPromptFieldTrial"; | 93 const char kSRTPromptTrialName[] = "SRTPromptFieldTrial"; |
89 const char kSRTPromptOnGroup[] = "On"; | 94 const char kSRTPromptOnGroup[] = "On"; |
90 | 95 |
91 // Exit codes that identify that a cleanup is needed. | 96 // Exit codes that identify that a cleanup is needed. |
92 const int kCleanupNeeded = 0; | 97 const int kCleanupNeeded = 0; |
93 const int kPostRebootCleanupNeeded = 4; | 98 const int kPostRebootCleanupNeeded = 4; |
94 | 99 |
95 void ReportUmaStep(SwReporterUmaValue value) { | 100 void ReportUmaStep(SwReporterUmaValue value) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 void RegisterSwReporterComponent(ComponentUpdateService* cus, | 328 void RegisterSwReporterComponent(ComponentUpdateService* cus, |
324 PrefService* prefs) { | 329 PrefService* prefs) { |
325 // The Sw reporter doesn't need to run if the user isn't reporting metrics and | 330 // The Sw reporter doesn't need to run if the user isn't reporting metrics and |
326 // isn't in the SRTPrompt field trial "On" group. | 331 // isn't in the SRTPrompt field trial "On" group. |
327 if (!ChromeMetricsServiceAccessor::IsMetricsReportingEnabled() && | 332 if (!ChromeMetricsServiceAccessor::IsMetricsReportingEnabled() && |
328 base::FieldTrialList::FindFullName(kSRTPromptTrialName) != | 333 base::FieldTrialList::FindFullName(kSRTPromptTrialName) != |
329 kSRTPromptOnGroup) { | 334 kSRTPromptOnGroup) { |
330 return; | 335 return; |
331 } | 336 } |
332 | 337 |
338 // Check if we have information from Cleaner and record UMA statistics. | |
339 base::string16 cleaner_key_name = base::StringPrintf( | |
340 kCleanerSuffixRegistryKey, kSoftwareRemovalToolRegistryKey); | |
341 base::win::RegKey cleaner_key( | |
342 HKEY_CURRENT_USER, cleaner_key_name.c_str(), KEY_ALL_ACCESS); | |
343 // Cleaner is assumed to have run if we have a start time. | |
344 if (cleaner_key.Valid() && | |
345 cleaner_key.HasValue(kStartTimeRegistryValueName)) { | |
346 int64 start_time_value; | |
347 cleaner_key.ReadInt64(kStartTimeRegistryValueName, &start_time_value); | |
MAD
2014/10/20 01:38:33
Since we only use the start_time when we have a va
Georges Khalil
2014/10/24 12:37:58
Done.
| |
348 base::Time start_time = base::Time::FromInternalValue(start_time_value); | |
MAD
2014/10/20 01:38:33
We usually prefer using the constructor instead of
Georges Khalil
2014/10/24 12:37:58
Done.
| |
349 cleaner_key.DeleteValue(kStartTimeRegistryValueName); | |
MAD
2014/10/20 01:38:33
Then this would need to move lower below of course
Georges Khalil
2014/10/24 12:37:58
Done.
| |
350 // Get version number. | |
351 if (cleaner_key.HasValue(kVersionRegistryValueName)) { | |
352 DWORD version; | |
353 cleaner_key.ReadValueDW(kVersionRegistryValueName, &version); | |
354 UMA_HISTOGRAM_SPARSE_SLOWLY("Cleaner.Version", version); | |
355 cleaner_key.DeleteValue(kVersionRegistryValueName); | |
356 } | |
357 // Get end time. | |
358 if (cleaner_key.HasValue(kEndTimeRegistryValueName)) { | |
359 int64 end_time_value; | |
360 cleaner_key.ReadInt64(kEndTimeRegistryValueName, &end_time_value); | |
361 base::Time end_time = base::Time::FromInternalValue(end_time_value); | |
MAD
2014/10/20 01:38:33
Use constructor instead, or use the return value d
Georges Khalil
2014/10/24 12:37:58
Done.
| |
362 cleaner_key.DeleteValue(kEndTimeRegistryValueName); | |
363 base::TimeDelta run_time = end_time - start_time; | |
364 UMA_HISTOGRAM_LONG_TIMES("Cleaner.RunTime", run_time); | |
365 } else { | |
366 // If we don't have an end time, we can assume the cleaner crashed and we | |
367 // represent this using an infinite delta. | |
368 UMA_HISTOGRAM_LONG_TIMES("Cleaner.RunTime", base::TimeDelta::Max()); | |
369 } | |
370 // Get exit code. | |
371 if (cleaner_key.HasValue(kExitCodeRegistryValueName)) { | |
372 DWORD exit_code; | |
373 cleaner_key.ReadValueDW(kExitCodeRegistryValueName, &exit_code); | |
374 UMA_HISTOGRAM_SPARSE_SLOWLY("Cleaner.ExitCode", exit_code); | |
375 cleaner_key.DeleteValue(kExitCodeRegistryValueName); | |
376 } | |
377 } | |
378 | |
333 // Install the component. | 379 // Install the component. |
334 scoped_ptr<ComponentInstallerTraits> traits( | 380 scoped_ptr<ComponentInstallerTraits> traits( |
335 new SwReporterInstallerTraits(prefs)); | 381 new SwReporterInstallerTraits(prefs)); |
336 // |cus| will take ownership of |installer| during installer->Register(cus). | 382 // |cus| will take ownership of |installer| during installer->Register(cus). |
337 DefaultComponentInstaller* installer = | 383 DefaultComponentInstaller* installer = |
338 new DefaultComponentInstaller(traits.Pass()); | 384 new DefaultComponentInstaller(traits.Pass()); |
339 installer->Register(cus); | 385 installer->Register(cus); |
340 } | 386 } |
341 | 387 |
342 void RegisterPrefsForSwReporter(PrefRegistrySimple* registry) { | 388 void RegisterPrefsForSwReporter(PrefRegistrySimple* registry) { |
343 registry->RegisterInt64Pref(prefs::kSwReporterLastTimeTriggered, 0); | 389 registry->RegisterInt64Pref(prefs::kSwReporterLastTimeTriggered, 0); |
344 registry->RegisterIntegerPref(prefs::kSwReporterLastExitCode, -1); | 390 registry->RegisterIntegerPref(prefs::kSwReporterLastExitCode, -1); |
345 } | 391 } |
346 | 392 |
347 void RegisterProfilePrefsForSwReporter( | 393 void RegisterProfilePrefsForSwReporter( |
348 user_prefs::PrefRegistrySyncable* registry) { | 394 user_prefs::PrefRegistrySyncable* registry) { |
349 registry->RegisterIntegerPref( | 395 registry->RegisterIntegerPref( |
350 prefs::kSwReporterPromptReason, | 396 prefs::kSwReporterPromptReason, |
351 -1, | 397 -1, |
352 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 398 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
353 | 399 |
354 registry->RegisterStringPref( | 400 registry->RegisterStringPref( |
355 prefs::kSwReporterPromptVersion, | 401 prefs::kSwReporterPromptVersion, |
356 "", | 402 "", |
357 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 403 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
358 } | 404 } |
359 | 405 |
360 } // namespace component_updater | 406 } // namespace component_updater |
OLD | NEW |