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/histogram.h" | 19 #include "base/metrics/histogram.h" |
19 #include "base/metrics/sparse_histogram.h" | 20 #include "base/metrics/sparse_histogram.h" |
20 #include "base/path_service.h" | 21 #include "base/path_service.h" |
21 #include "base/prefs/pref_registry_simple.h" | 22 #include "base/prefs/pref_registry_simple.h" |
22 #include "base/prefs/pref_service.h" | 23 #include "base/prefs/pref_service.h" |
23 #include "base/process/kill.h" | 24 #include "base/process/kill.h" |
24 #include "base/process/launch.h" | 25 #include "base/process/launch.h" |
25 #include "base/task_runner_util.h" | 26 #include "base/task_runner_util.h" |
26 #include "base/threading/worker_pool.h" | 27 #include "base/threading/worker_pool.h" |
27 #include "base/time/time.h" | 28 #include "base/time/time.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 0x5f, 0xea, 0xf0, 0x88, 0xf6, 0x97, 0x9b, 0xc7}; | 77 0x5f, 0xea, 0xf0, 0x88, 0xf6, 0x97, 0x9b, 0xc7}; |
77 | 78 |
78 const base::FilePath::CharType kSwReporterExeName[] = | 79 const base::FilePath::CharType kSwReporterExeName[] = |
79 FILE_PATH_LITERAL("software_reporter_tool.exe"); | 80 FILE_PATH_LITERAL("software_reporter_tool.exe"); |
80 | 81 |
81 // Where to fetch the reporter exit code in the registry. | 82 // Where to fetch the reporter exit code in the registry. |
82 const wchar_t kSoftwareRemovalToolRegistryKey[] = | 83 const wchar_t kSoftwareRemovalToolRegistryKey[] = |
83 L"Software\\Google\\Software Removal Tool"; | 84 L"Software\\Google\\Software Removal Tool"; |
84 const wchar_t kExitCodeRegistryValueName[] = L"ExitCode"; | 85 const wchar_t kExitCodeRegistryValueName[] = L"ExitCode"; |
85 | 86 |
| 87 // Field trial strings. |
| 88 const char kSRTPromptTrialName[] = "SRTPromptFieldTrial"; |
| 89 const char kSRTPromptOnGroup[] = "On"; |
| 90 |
86 // Exit codes that identify that a cleanup is needed. | 91 // Exit codes that identify that a cleanup is needed. |
87 const int kCleanupNeeded = 0; | 92 const int kCleanupNeeded = 0; |
88 const int kPostRebootCleanupNeeded = 4; | 93 const int kPostRebootCleanupNeeded = 4; |
89 | 94 |
90 void ReportUmaStep(SwReporterUmaValue value) { | 95 void ReportUmaStep(SwReporterUmaValue value) { |
91 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Step", value, SW_REPORTER_MAX); | 96 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Step", value, SW_REPORTER_MAX); |
92 } | 97 } |
93 | 98 |
94 void ReportUmaVersion(const base::Version& version) { | 99 void ReportUmaVersion(const base::Version& version) { |
95 DCHECK(!version.components().empty()); | 100 DCHECK(!version.components().empty()); |
(...skipping 22 matching lines...) Expand all Loading... |
118 // from the local state. This could be called from an interruptible worker | 123 // from the local state. This could be called from an interruptible worker |
119 // thread so should be resilient to unexpected shutdown. |version| is provided | 124 // thread so should be resilient to unexpected shutdown. |version| is provided |
120 // so the kSwReporterPromptVersion prefs can be set. | 125 // so the kSwReporterPromptVersion prefs can be set. |
121 void ReportAndClearExitCode(int exit_code, const std::string& version) { | 126 void ReportAndClearExitCode(int exit_code, const std::string& version) { |
122 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.ExitCode", exit_code); | 127 UMA_HISTOGRAM_SPARSE_SLOWLY("SoftwareReporter.ExitCode", exit_code); |
123 if (g_browser_process && g_browser_process->local_state()) { | 128 if (g_browser_process && g_browser_process->local_state()) { |
124 g_browser_process->local_state()->SetInteger(prefs::kSwReporterLastExitCode, | 129 g_browser_process->local_state()->SetInteger(prefs::kSwReporterLastExitCode, |
125 exit_code); | 130 exit_code); |
126 } | 131 } |
127 | 132 |
128 if (exit_code == kPostRebootCleanupNeeded || exit_code == kCleanupNeeded) { | 133 if ((exit_code == kPostRebootCleanupNeeded || exit_code == kCleanupNeeded) && |
| 134 base::FieldTrialList::FindFullName(kSRTPromptTrialName) == |
| 135 kSRTPromptOnGroup) { |
129 // Find the last active browser, which may be NULL, in which case we won't | 136 // Find the last active browser, which may be NULL, in which case we won't |
130 // show the prompt this time and will wait until the next run of the | 137 // show the prompt this time and will wait until the next run of the |
131 // reporter. We can't use other ways of finding a browser because we don't | 138 // reporter. We can't use other ways of finding a browser because we don't |
132 // have a profile. | 139 // have a profile. |
133 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); | 140 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); |
134 Browser* browser = chrome::FindLastActiveWithHostDesktopType(desktop_type); | 141 Browser* browser = chrome::FindLastActiveWithHostDesktopType(desktop_type); |
135 if (browser) { | 142 if (browser) { |
136 Profile* profile = browser->profile(); | 143 Profile* profile = browser->profile(); |
137 DCHECK(profile); | 144 DCHECK(profile); |
138 // Now that we have a profile, make sure we have a tabbed browser since we | 145 // Now that we have a profile, make sure we have a tabbed browser since we |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 PrefService* prefs_; | 314 PrefService* prefs_; |
308 static wchar_t version_dir_[_MAX_PATH]; | 315 static wchar_t version_dir_[_MAX_PATH]; |
309 }; | 316 }; |
310 | 317 |
311 wchar_t SwReporterInstallerTraits::version_dir_[] = {}; | 318 wchar_t SwReporterInstallerTraits::version_dir_[] = {}; |
312 | 319 |
313 } // namespace | 320 } // namespace |
314 | 321 |
315 void RegisterSwReporterComponent(ComponentUpdateService* cus, | 322 void RegisterSwReporterComponent(ComponentUpdateService* cus, |
316 PrefService* prefs) { | 323 PrefService* prefs) { |
| 324 // The Sw reporter doesn't need to run if the user isn't reporting metrics and |
| 325 // isn't in the SRTPrompt field trial "On" group. |
| 326 if (!ChromeMetricsServiceAccessor::IsMetricsReportingEnabled() && |
| 327 base::FieldTrialList::FindFullName(kSRTPromptTrialName) != |
| 328 kSRTPromptOnGroup) { |
| 329 return; |
| 330 } |
| 331 |
317 // Install the component. | 332 // Install the component. |
318 scoped_ptr<ComponentInstallerTraits> traits( | 333 scoped_ptr<ComponentInstallerTraits> traits( |
319 new SwReporterInstallerTraits(prefs)); | 334 new SwReporterInstallerTraits(prefs)); |
320 // |cus| will take ownership of |installer| during installer->Register(cus). | 335 // |cus| will take ownership of |installer| during installer->Register(cus). |
321 DefaultComponentInstaller* installer = | 336 DefaultComponentInstaller* installer = |
322 new DefaultComponentInstaller(traits.Pass()); | 337 new DefaultComponentInstaller(traits.Pass()); |
323 installer->Register(cus); | 338 installer->Register(cus); |
324 } | 339 } |
325 | 340 |
326 void RegisterPrefsForSwReporter(PrefRegistrySimple* registry) { | 341 void RegisterPrefsForSwReporter(PrefRegistrySimple* registry) { |
327 registry->RegisterInt64Pref(prefs::kSwReporterLastTimeTriggered, 0); | 342 registry->RegisterInt64Pref(prefs::kSwReporterLastTimeTriggered, 0); |
328 registry->RegisterIntegerPref(prefs::kSwReporterLastExitCode, -1); | 343 registry->RegisterIntegerPref(prefs::kSwReporterLastExitCode, -1); |
329 } | 344 } |
330 | 345 |
331 void RegisterProfilePrefsForSwReporter( | 346 void RegisterProfilePrefsForSwReporter( |
332 user_prefs::PrefRegistrySyncable* registry) { | 347 user_prefs::PrefRegistrySyncable* registry) { |
333 registry->RegisterIntegerPref( | 348 registry->RegisterIntegerPref( |
334 prefs::kSwReporterPromptReason, | 349 prefs::kSwReporterPromptReason, |
335 -1, | 350 -1, |
336 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 351 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
337 | 352 |
338 registry->RegisterStringPref( | 353 registry->RegisterStringPref( |
339 prefs::kSwReporterPromptVersion, | 354 prefs::kSwReporterPromptVersion, |
340 "", | 355 "", |
341 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 356 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
342 } | 357 } |
343 | 358 |
344 } // namespace component_updater | 359 } // namespace component_updater |
OLD | NEW |