Commit ecb81a76 authored by robertshield's avatar robertshield Committed by Commit bot

Add UMA metrics to recovery component.

BUG=447695
TEST=NONE

Review URL: https://codereview.chromium.org/846663003

Cr-Commit-Position: refs/heads/master@{#311501}
parent a20c13f3
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/json/json_file_value_serializer.h" #include "base/json/json_file_value_serializer.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
...@@ -59,6 +60,24 @@ enum ChromeRecoveryExitCode { ...@@ -59,6 +60,24 @@ enum ChromeRecoveryExitCode {
EXIT_CODE_ELEVATION_NEEDED = 2, 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) #if !defined(OS_CHROMEOS)
// Checks if elevated recovery simulation switch was present on the command // Checks if elevated recovery simulation switch was present on the command
// line. This is for testing purpose. // line. This is for testing purpose.
...@@ -66,7 +85,7 @@ bool SimulatingElevatedRecovery() { ...@@ -66,7 +85,7 @@ bool SimulatingElevatedRecovery() {
return base::CommandLine::ForCurrentProcess()->HasSwitch( return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kSimulateElevatedRecovery); switches::kSimulateElevatedRecovery);
} }
#endif #endif // !defined(OS_CHROMEOS)
#if defined(OS_WIN) #if defined(OS_WIN)
scoped_ptr<base::DictionaryValue> ReadManifest(const base::FilePath& manifest) { scoped_ptr<base::DictionaryValue> ReadManifest(const base::FilePath& manifest) {
...@@ -80,6 +99,20 @@ 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>(); 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) { void DoElevatedInstallRecoveryComponent(const base::FilePath& path) {
const base::FilePath main_file = path.Append(kRecoveryFileName); const base::FilePath main_file = path.Append(kRecoveryFileName);
const base::FilePath manifest_file = const base::FilePath manifest_file =
...@@ -108,9 +141,16 @@ void DoElevatedInstallRecoveryComponent(const base::FilePath& path) { ...@@ -108,9 +141,16 @@ void DoElevatedInstallRecoveryComponent(const base::FilePath& path) {
cmdline.AppendSwitchASCII("version", version.GetString()); cmdline.AppendSwitchASCII("version", version.GetString());
} }
RecordRecoveryComponentUMAEvent(RCE_RUNNING_ELEVATED);
base::LaunchOptions options; base::LaunchOptions options;
options.start_hidden = true; 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) { void ElevatedInstallRecoveryComponent(const base::FilePath& installer_path) {
...@@ -119,7 +159,7 @@ void ElevatedInstallRecoveryComponent(const base::FilePath& installer_path) { ...@@ -119,7 +159,7 @@ void ElevatedInstallRecoveryComponent(const base::FilePath& installer_path) {
base::Bind(&DoElevatedInstallRecoveryComponent, installer_path), base::Bind(&DoElevatedInstallRecoveryComponent, installer_path),
true); true);
} }
#endif #endif // defined(OS_WIN)
} // namespace } // namespace
...@@ -194,6 +234,7 @@ RecoveryComponentInstaller::RecoveryComponentInstaller(const Version& version, ...@@ -194,6 +234,7 @@ RecoveryComponentInstaller::RecoveryComponentInstaller(const Version& version,
} }
void RecoveryComponentInstaller::OnUpdateError(int error) { void RecoveryComponentInstaller::OnUpdateError(int error) {
RecordRecoveryComponentUMAEvent(RCE_COMPONENT_DOWNLOAD_ERROR);
NOTREACHED() << "Recovery component update error: " << error; NOTREACHED() << "Recovery component update error: " << error;
} }
...@@ -203,20 +244,31 @@ void WaitForInstallToComplete(base::Process process, ...@@ -203,20 +244,31 @@ void WaitForInstallToComplete(base::Process process,
PrefService* prefs) { PrefService* prefs) {
int installer_exit_code = 0; int installer_exit_code = 0;
const base::TimeDelta kMaxWaitTime = base::TimeDelta::FromSeconds(600); const base::TimeDelta kMaxWaitTime = base::TimeDelta::FromSeconds(600);
if (process.WaitForExitWithTimeout(kMaxWaitTime, &installer_exit_code) && if (process.WaitForExitWithTimeout(kMaxWaitTime, &installer_exit_code)) {
installer_exit_code == EXIT_CODE_ELEVATION_NEEDED) { if (installer_exit_code == EXIT_CODE_ELEVATION_NEEDED) {
BrowserThread::PostTask( RecordRecoveryComponentUMAEvent(RCE_ELEVATION_NEEDED);
BrowserThread::UI,
FROM_HERE, BrowserThread::PostTask(
base::Bind(&SetPrefsForElevatedRecoveryInstall, BrowserThread::UI,
installer_folder, FROM_HERE,
prefs)); 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( bool RecoveryComponentInstaller::RunInstallCommand(
const base::CommandLine& cmdline, const base::CommandLine& cmdline,
const base::FilePath& installer_folder) const { const base::FilePath& installer_folder) const {
RecordRecoveryComponentUMAEvent(RCE_RUNNING_NON_ELEVATED);
base::LaunchOptions options; base::LaunchOptions options;
options.start_hidden = true; options.start_hidden = true;
base::Process process = base::LaunchProcess(cmdline, options); base::Process process = base::LaunchProcess(cmdline, options);
...@@ -241,7 +293,7 @@ bool RecoveryComponentInstaller::RunInstallCommand( ...@@ -241,7 +293,7 @@ bool RecoveryComponentInstaller::RunInstallCommand(
const base::FilePath&) const { const base::FilePath&) const {
return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid(); return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid();
} }
#endif #endif // defined(OS_WIN)
bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest, bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest,
const base::FilePath& unpack_path) { const base::FilePath& unpack_path) {
...@@ -322,7 +374,7 @@ void RegisterRecoveryComponent(ComponentUpdateService* cus, ...@@ -322,7 +374,7 @@ void RegisterRecoveryComponent(ComponentUpdateService* cus,
FROM_HERE, FROM_HERE,
base::Bind(&RecoveryRegisterHelper, cus, prefs), base::Bind(&RecoveryRegisterHelper, cus, prefs),
base::TimeDelta::FromSeconds(6)); base::TimeDelta::FromSeconds(6));
#endif #endif // !defined(OS_CHROMEOS)
} }
void RegisterPrefsForRecoveryComponent(PrefRegistrySimple* registry) { void RegisterPrefsForRecoveryComponent(PrefRegistrySimple* registry) {
...@@ -338,7 +390,7 @@ void AcceptedElevatedRecoveryInstall(PrefService* prefs) { ...@@ -338,7 +390,7 @@ void AcceptedElevatedRecoveryInstall(PrefService* prefs) {
#if defined(OS_WIN) #if defined(OS_WIN)
ElevatedInstallRecoveryComponent( ElevatedInstallRecoveryComponent(
prefs->GetFilePath(prefs::kRecoveryComponentUnpackPath)); prefs->GetFilePath(prefs::kRecoveryComponentUnpackPath));
#endif #endif // OS_WIN
prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false);
} }
......
...@@ -28367,6 +28367,11 @@ Therefore, the affected-histogram name has to have at least one dot in it. ...@@ -28367,6 +28367,11 @@ Therefore, the affected-histogram name has to have at least one dot in it.
</summary> </summary>
</histogram> </histogram>
<histogram name="RecoveryComponent.Event" enum="RecoveryComponentEvent">
<owner>robertshield@chromium.org</owner>
<summary>Log each stage of a recovery component event.</summary>
</histogram>
<histogram name="Renderer.AcceleratedFixedRootBackground" <histogram name="Renderer.AcceleratedFixedRootBackground"
enum="AcceleratedFixedRootBackground"> enum="AcceleratedFixedRootBackground">
<owner>Please list the metric's owners. Add more owner tags as needed.</owner> <owner>Please list the metric's owners. Add more owner tags as needed.</owner>
...@@ -55169,6 +55174,19 @@ To add a new entry, add it with any value and run test to compute valid value. ...@@ -55169,6 +55174,19 @@ To add a new entry, add it with any value and run test to compute valid value.
<int value="3" label="Show More"/> <int value="3" label="Show More"/>
</enum> </enum>
<enum name="RecoveryComponentEvent" type="int">
<int value="0" label="RunningNonElevated"/>
<int value="1" label="ElevationNeeded"/>
<int value="2" label="RunFailed"/>
<int value="3" label="RunSucceeded"/>
<int value="4" label="RunSkipped"/>
<int value="5" label="RunningElevated"/>
<int value="6" label="RunElevatedFailed"/>
<int value="7" label="RunElevatedSucceeded"/>
<int value="8" label="RunElevatedSkipped"/>
<int value="9" label="DownloadError"/>
</enum>
<enum name="RemotePlaybackDeviceType" type="int"> <enum name="RemotePlaybackDeviceType" type="int">
<int value="0" label="Cast Generic Media Player"/> <int value="0" label="Cast Generic Media Player"/>
<int value="1" label="Cast YouTube Player"/> <int value="1" label="Cast YouTube Player"/>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment