| Index: chrome/browser/component_updater/recovery_component_installer.cc
|
| diff --git a/chrome/browser/component_updater/recovery_component_installer.cc b/chrome/browser/component_updater/recovery_component_installer.cc
|
| index 240bce1008c05415aca55ed2f1919e664eaab7a7..96fb8e6df6c90cd31e3979d5b13d8539300de5e0 100644
|
| --- a/chrome/browser/component_updater/recovery_component_installer.cc
|
| +++ b/chrome/browser/component_updater/recovery_component_installer.cc
|
| @@ -16,6 +16,7 @@
|
| #include "base/json/json_file_value_serializer.h"
|
| #include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/metrics/histogram.h"
|
| #include "base/path_service.h"
|
| #include "base/prefs/pref_registry_simple.h"
|
| #include "base/prefs/pref_service.h"
|
| @@ -59,6 +60,24 @@ enum ChromeRecoveryExitCode {
|
| EXIT_CODE_ELEVATION_NEEDED = 2,
|
| };
|
|
|
| +enum RecoveryComponentEvent {
|
| + RCE_RUNNING_NON_ELEVATED = 0,
|
| + RCE_ELEVATION_NEEDED = 1,
|
| + RCE_FAILED = 2,
|
| + RCE_SUCCEEDED = 3,
|
| + RCE_SKIPPED = 4,
|
| + RCE_RUNNING_ELEVATED = 5,
|
| + RCE_ELEVATED_FAILED = 6,
|
| + RCE_ELEVATED_SUCCEEDED = 7,
|
| + RCE_ELEVATED_SKIPPED = 8,
|
| + RCE_COMPONENT_DOWNLOAD_ERROR = 9,
|
| + RCE_COUNT
|
| +};
|
| +
|
| +void RecordRecoveryComponentUMAEvent(RecoveryComponentEvent event) {
|
| + UMA_HISTOGRAM_ENUMERATION("RecoveryComponent.Event", event, RCE_COUNT);
|
| +}
|
| +
|
| #if !defined(OS_CHROMEOS)
|
| // Checks if elevated recovery simulation switch was present on the command
|
| // line. This is for testing purpose.
|
| @@ -66,7 +85,7 @@ bool SimulatingElevatedRecovery() {
|
| return base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| switches::kSimulateElevatedRecovery);
|
| }
|
| -#endif
|
| +#endif // !defined(OS_CHROMEOS)
|
|
|
| #if defined(OS_WIN)
|
| scoped_ptr<base::DictionaryValue> ReadManifest(const base::FilePath& manifest) {
|
| @@ -80,6 +99,20 @@ scoped_ptr<base::DictionaryValue> ReadManifest(const base::FilePath& manifest) {
|
| return scoped_ptr<base::DictionaryValue>();
|
| }
|
|
|
| +void WaitForElevatedInstallToComplete(base::Process process) {
|
| + int installer_exit_code = 0;
|
| + const base::TimeDelta kMaxWaitTime = base::TimeDelta::FromSeconds(600);
|
| + if (process.WaitForExitWithTimeout(kMaxWaitTime, &installer_exit_code)) {
|
| + if (installer_exit_code == EXIT_CODE_RECOVERY_SUCCEEDED) {
|
| + RecordRecoveryComponentUMAEvent(RCE_ELEVATED_SUCCEEDED);
|
| + } else {
|
| + RecordRecoveryComponentUMAEvent(RCE_ELEVATED_SKIPPED);
|
| + }
|
| + } else {
|
| + RecordRecoveryComponentUMAEvent(RCE_ELEVATED_FAILED);
|
| + }
|
| +}
|
| +
|
| void DoElevatedInstallRecoveryComponent(const base::FilePath& path) {
|
| const base::FilePath main_file = path.Append(kRecoveryFileName);
|
| const base::FilePath manifest_file =
|
| @@ -108,9 +141,16 @@ void DoElevatedInstallRecoveryComponent(const base::FilePath& path) {
|
| cmdline.AppendSwitchASCII("version", version.GetString());
|
| }
|
|
|
| + RecordRecoveryComponentUMAEvent(RCE_RUNNING_ELEVATED);
|
| +
|
| base::LaunchOptions options;
|
| options.start_hidden = true;
|
| - base::LaunchElevatedProcess(cmdline, options);
|
| + base::Process process = base::LaunchElevatedProcess(cmdline, options);
|
| +
|
| + base::WorkerPool::PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&WaitForElevatedInstallToComplete, base::Passed(&process)),
|
| + true);
|
| }
|
|
|
| void ElevatedInstallRecoveryComponent(const base::FilePath& installer_path) {
|
| @@ -119,7 +159,7 @@ void ElevatedInstallRecoveryComponent(const base::FilePath& installer_path) {
|
| base::Bind(&DoElevatedInstallRecoveryComponent, installer_path),
|
| true);
|
| }
|
| -#endif
|
| +#endif // defined(OS_WIN)
|
|
|
| } // namespace
|
|
|
| @@ -194,6 +234,7 @@ RecoveryComponentInstaller::RecoveryComponentInstaller(const Version& version,
|
| }
|
|
|
| void RecoveryComponentInstaller::OnUpdateError(int error) {
|
| + RecordRecoveryComponentUMAEvent(RCE_COMPONENT_DOWNLOAD_ERROR);
|
| NOTREACHED() << "Recovery component update error: " << error;
|
| }
|
|
|
| @@ -203,20 +244,31 @@ void WaitForInstallToComplete(base::Process process,
|
| PrefService* prefs) {
|
| int installer_exit_code = 0;
|
| const base::TimeDelta kMaxWaitTime = base::TimeDelta::FromSeconds(600);
|
| - if (process.WaitForExitWithTimeout(kMaxWaitTime, &installer_exit_code) &&
|
| - installer_exit_code == EXIT_CODE_ELEVATION_NEEDED) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI,
|
| - FROM_HERE,
|
| - base::Bind(&SetPrefsForElevatedRecoveryInstall,
|
| - installer_folder,
|
| - prefs));
|
| + if (process.WaitForExitWithTimeout(kMaxWaitTime, &installer_exit_code)) {
|
| + if (installer_exit_code == EXIT_CODE_ELEVATION_NEEDED) {
|
| + RecordRecoveryComponentUMAEvent(RCE_ELEVATION_NEEDED);
|
| +
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI,
|
| + FROM_HERE,
|
| + base::Bind(&SetPrefsForElevatedRecoveryInstall,
|
| + installer_folder,
|
| + prefs));
|
| + } else if (installer_exit_code == EXIT_CODE_RECOVERY_SUCCEEDED) {
|
| + RecordRecoveryComponentUMAEvent(RCE_SUCCEEDED);
|
| + } else if (installer_exit_code == EXIT_CODE_RECOVERY_SKIPPED) {
|
| + RecordRecoveryComponentUMAEvent(RCE_SKIPPED);
|
| + }
|
| + } else {
|
| + RecordRecoveryComponentUMAEvent(RCE_FAILED);
|
| }
|
| }
|
|
|
| bool RecoveryComponentInstaller::RunInstallCommand(
|
| const base::CommandLine& cmdline,
|
| const base::FilePath& installer_folder) const {
|
| + RecordRecoveryComponentUMAEvent(RCE_RUNNING_NON_ELEVATED);
|
| +
|
| base::LaunchOptions options;
|
| options.start_hidden = true;
|
| base::Process process = base::LaunchProcess(cmdline, options);
|
| @@ -241,7 +293,7 @@ bool RecoveryComponentInstaller::RunInstallCommand(
|
| const base::FilePath&) const {
|
| return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid();
|
| }
|
| -#endif
|
| +#endif // defined(OS_WIN)
|
|
|
| bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest,
|
| const base::FilePath& unpack_path) {
|
| @@ -322,7 +374,7 @@ void RegisterRecoveryComponent(ComponentUpdateService* cus,
|
| FROM_HERE,
|
| base::Bind(&RecoveryRegisterHelper, cus, prefs),
|
| base::TimeDelta::FromSeconds(6));
|
| -#endif
|
| +#endif // !defined(OS_CHROMEOS)
|
| }
|
|
|
| void RegisterPrefsForRecoveryComponent(PrefRegistrySimple* registry) {
|
| @@ -338,7 +390,7 @@ void AcceptedElevatedRecoveryInstall(PrefService* prefs) {
|
| #if defined(OS_WIN)
|
| ElevatedInstallRecoveryComponent(
|
| prefs->GetFilePath(prefs::kRecoveryComponentUnpackPath));
|
| -#endif
|
| +#endif // OS_WIN
|
| prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false);
|
| }
|
|
|
|
|