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 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const wchar_t kVersionRegistryValueName[] = L"Version"; | 87 const wchar_t kVersionRegistryValueName[] = L"Version"; |
88 const wchar_t kStartTimeRegistryValueName[] = L"StartTime"; | 88 const wchar_t kStartTimeRegistryValueName[] = L"StartTime"; |
89 const wchar_t kEndTimeRegistryValueName[] = L"EndTime"; | 89 const wchar_t kEndTimeRegistryValueName[] = L"EndTime"; |
90 | 90 |
91 // Field trial strings. | 91 // Field trial strings. |
92 const char kSRTPromptTrialName[] = "SRTPromptFieldTrial"; | 92 const char kSRTPromptTrialName[] = "SRTPromptFieldTrial"; |
93 const char kSRTPromptOnGroup[] = "On"; | 93 const char kSRTPromptOnGroup[] = "On"; |
94 | 94 |
95 // Exit codes that identify that a cleanup is needed. | 95 // Exit codes that identify that a cleanup is needed. |
96 const int kCleanupNeeded = 0; | 96 const int kCleanupNeeded = 0; |
97 const int kNothingFound = 2; | |
98 const int kPostRebootCleanupNeeded = 4; | 97 const int kPostRebootCleanupNeeded = 4; |
99 const int kDelayedPostRebootCleanupNeeded = 15; | |
100 | 98 |
101 void ReportUmaStep(SwReporterUmaValue value) { | 99 void ReportUmaStep(SwReporterUmaValue value) { |
102 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Step", value, SW_REPORTER_MAX); | 100 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Step", value, SW_REPORTER_MAX); |
103 } | 101 } |
104 | 102 |
105 void ReportVersionWithUma(const base::Version& version) { | 103 void ReportVersionWithUma(const base::Version& version) { |
106 DCHECK(!version.components().empty()); | 104 DCHECK(!version.components().empty()); |
107 // The minor version is the 2nd last component of the version, | 105 // The minor version is the 2nd last component of the version, |
108 // or just the first component if there is only 1. | 106 // or just the first component if there is only 1. |
109 uint32_t minor_version = 0; | 107 uint32_t minor_version = 0; |
110 if (version.components().size() > 1) | 108 if (version.components().size() > 1) |
111 minor_version = version.components()[version.components().size() - 2]; | 109 minor_version = version.components()[version.components().size() - 2]; |
112 else | 110 else |
113 minor_version = version.components()[0]; | 111 minor_version = version.components()[0]; |
114 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.MinorVersion", minor_version); | 112 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.MinorVersion", minor_version); |
115 | 113 |
116 // The major version for X.Y.Z is X*256^3+Y*256+Z. If there are additional | 114 // The major version for X.Y.Z is X*256^3+Y*256+Z. If there are additional |
117 // components, only the first three count, and if there are less than 3, the | 115 // components, only the first three count, and if there are less than 3, the |
118 // missing values are just replaced by zero. So 1 is equivalent 1.0.0. | 116 // missing values are just replaced by zero. So 1 is equivalent 1.0.0. |
119 DCHECK_LT(version.components()[0], 0x100); | 117 DCHECK(version.components()[0] < 0x100); |
120 uint32_t major_version = 0x1000000 * version.components()[0]; | 118 uint32_t major_version = 0x1000000 * version.components()[0]; |
121 if (version.components().size() >= 2) { | 119 if (version.components().size() >= 2) { |
122 DCHECK_LT(version.components()[1], 0x10000); | 120 DCHECK(version.components()[1] < 0x10000); |
123 major_version += 0x100 * version.components()[1]; | 121 major_version += 0x100 * version.components()[1]; |
124 } | 122 } |
125 if (version.components().size() >= 3) { | 123 if (version.components().size() >= 3) { |
126 DCHECK_LT(version.components()[2], 0x100); | 124 DCHECK(version.components()[2] < 0x100); |
127 major_version += version.components()[2]; | 125 major_version += version.components()[2]; |
128 } | 126 } |
129 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.MajorVersion", major_version); | 127 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.MajorVersion", major_version); |
130 } | 128 } |
131 | 129 |
132 // This function is called on the UI thread to report the SwReporter exit code | 130 // This function is called on the UI thread to report the SwReporter exit code |
133 // and then clear it from the registry as well as clear the execution state | 131 // and then clear it from the registry as well as clear the execution state |
134 // from the local state. This could be called from an interruptible worker | 132 // from the local state. This could be called from an interruptible worker |
135 // thread so should be resilient to unexpected shutdown. |version| is provided | 133 // thread so should be resilient to unexpected shutdown. |version| is provided |
136 // so the kSwReporterPromptVersion prefs can be set. | 134 // so the kSwReporterPromptVersion prefs can be set. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 if (cleaner_key.Valid() && | 345 if (cleaner_key.Valid() && |
348 cleaner_key.HasValue(kStartTimeRegistryValueName)) { | 346 cleaner_key.HasValue(kStartTimeRegistryValueName)) { |
349 // Get version number. | 347 // Get version number. |
350 if (cleaner_key.HasValue(kVersionRegistryValueName)) { | 348 if (cleaner_key.HasValue(kVersionRegistryValueName)) { |
351 DWORD version; | 349 DWORD version; |
352 cleaner_key.ReadValueDW(kVersionRegistryValueName, &version); | 350 cleaner_key.ReadValueDW(kVersionRegistryValueName, &version); |
353 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.Cleaner.Version", version); | 351 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.Cleaner.Version", version); |
354 cleaner_key.DeleteValue(kVersionRegistryValueName); | 352 cleaner_key.DeleteValue(kVersionRegistryValueName); |
355 } | 353 } |
356 // Get start & end time. If we don't have an end time, we can assume the | 354 // Get start & end time. If we don't have an end time, we can assume the |
357 // cleaner has not completed. | 355 // cleaner has crashed. |
358 int64 start_time_value; | |
359 cleaner_key.ReadInt64(kStartTimeRegistryValueName, &start_time_value); | |
360 | |
361 bool completed = cleaner_key.HasValue(kEndTimeRegistryValueName); | 356 bool completed = cleaner_key.HasValue(kEndTimeRegistryValueName); |
362 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.Cleaner.HasCompleted", completed); | 357 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.Cleaner.HasCompleted", completed); |
363 if (completed) { | 358 if (completed) { |
| 359 int64 start_time_value; |
| 360 cleaner_key.ReadInt64(kStartTimeRegistryValueName, &start_time_value); |
364 int64 end_time_value; | 361 int64 end_time_value; |
365 cleaner_key.ReadInt64(kEndTimeRegistryValueName, &end_time_value); | 362 cleaner_key.ReadInt64(kEndTimeRegistryValueName, &end_time_value); |
366 cleaner_key.DeleteValue(kEndTimeRegistryValueName); | 363 cleaner_key.DeleteValue(kEndTimeRegistryValueName); |
367 base::TimeDelta run_time(base::Time::FromInternalValue(end_time_value) - | 364 base::TimeDelta run_time(base::Time::FromInternalValue(end_time_value) - |
368 base::Time::FromInternalValue(start_time_value)); | 365 base::Time::FromInternalValue(start_time_value)); |
369 UMA_HISTOGRAM_LONG_TIMES("SoftwareReporter.Cleaner.RunningTime", | 366 UMA_HISTOGRAM_LONG_TIMES("SoftwareReporter.Cleaner.RunningTime", |
370 run_time); | 367 run_time); |
371 } | 368 } |
372 // Get exit code. Assume nothing was found if we can't read the exit code. | 369 // Get exit code. |
373 DWORD exit_code = kNothingFound; | |
374 if (cleaner_key.HasValue(kExitCodeRegistryValueName)) { | 370 if (cleaner_key.HasValue(kExitCodeRegistryValueName)) { |
| 371 DWORD exit_code; |
375 cleaner_key.ReadValueDW(kExitCodeRegistryValueName, &exit_code); | 372 cleaner_key.ReadValueDW(kExitCodeRegistryValueName, &exit_code); |
376 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.Cleaner.ExitCode", | 373 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.Cleaner.ExitCode", |
377 exit_code); | 374 exit_code); |
378 cleaner_key.DeleteValue(kExitCodeRegistryValueName); | 375 cleaner_key.DeleteValue(kExitCodeRegistryValueName); |
379 } | 376 } |
380 cleaner_key.DeleteValue(kStartTimeRegistryValueName); | 377 cleaner_key.DeleteValue(kStartTimeRegistryValueName); |
381 | |
382 if (exit_code == kPostRebootCleanupNeeded || | |
383 exit_code == kDelayedPostRebootCleanupNeeded) { | |
384 // Check if we are running after the user has rebooted. | |
385 base::TimeDelta elapsed(base::Time::Now() - | |
386 base::Time::FromInternalValue(start_time_value)); | |
387 DCHECK_GT(elapsed.InMilliseconds(), 0); | |
388 UMA_HISTOGRAM_BOOLEAN( | |
389 "SoftwareReporter.Cleaner.HasRebooted", | |
390 static_cast<uint64>(elapsed.InMilliseconds()) > ::GetTickCount64()); | |
391 } | |
392 } | 378 } |
393 | 379 |
394 // Install the component. | 380 // Install the component. |
395 scoped_ptr<ComponentInstallerTraits> traits( | 381 scoped_ptr<ComponentInstallerTraits> traits( |
396 new SwReporterInstallerTraits(prefs)); | 382 new SwReporterInstallerTraits(prefs)); |
397 // |cus| will take ownership of |installer| during installer->Register(cus). | 383 // |cus| will take ownership of |installer| during installer->Register(cus). |
398 DefaultComponentInstaller* installer = | 384 DefaultComponentInstaller* installer = |
399 new DefaultComponentInstaller(traits.Pass()); | 385 new DefaultComponentInstaller(traits.Pass()); |
400 installer->Register(cus); | 386 installer->Register(cus); |
401 } | 387 } |
(...skipping 10 matching lines...) Expand all Loading... |
412 -1, | 398 -1, |
413 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 399 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
414 | 400 |
415 registry->RegisterStringPref( | 401 registry->RegisterStringPref( |
416 prefs::kSwReporterPromptVersion, | 402 prefs::kSwReporterPromptVersion, |
417 "", | 403 "", |
418 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 404 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
419 } | 405 } |
420 | 406 |
421 } // namespace component_updater | 407 } // namespace component_updater |
OLD | NEW |