Commit 6b7b1845 authored by Qiang Xu's avatar Qiang Xu Committed by Commit Bot

cros: use callback to record TapDragging started uma

changes:
Instead of using ScopedUmaRecorder, which is essentially implementing
in a "callback" way. This CL replaces it with base::OnceCallback, which
makes code more concise.

Bug: 817643
Test: covered by tests
Change-Id: Id99e9c08e8fe49886ca7c30a5901fb4128b04a42
Reviewed-on: https://chromium-review.googlesource.com/957816
Commit-Queue: Qiang Xu <warx@google.com>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542546}
parent dca3bb15
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ash/touch/touch_devices_controller.h" #include "ash/touch/touch_devices_controller.h"
#include <utility>
#include "ash/accessibility/accessibility_controller.h" #include "ash/accessibility/accessibility_controller.h"
#include "ash/public/cpp/accessibility_types.h" #include "ash/public/cpp/accessibility_types.h"
#include "ash/public/cpp/ash_pref_names.h" #include "ash/public/cpp/ash_pref_names.h"
...@@ -39,23 +41,6 @@ PrefService* GetActivePrefService() { ...@@ -39,23 +41,6 @@ PrefService* GetActivePrefService() {
} // namespace } // namespace
// Used to record pref started UMA. It is created on user session added and
// destroyed on active user pref changed, which is a point of pref started.
class TouchDevicesController::ScopedUmaRecorder {
public:
ScopedUmaRecorder() = default;
~ScopedUmaRecorder() {
PrefService* prefs = GetActivePrefService();
if (!prefs)
return;
UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Started",
prefs->GetBoolean(prefs::kTapDraggingEnabled));
}
private:
DISALLOW_COPY_AND_ASSIGN(ScopedUmaRecorder);
};
// static // static
void TouchDevicesController::RegisterProfilePrefs(PrefRegistrySimple* registry, void TouchDevicesController::RegisterProfilePrefs(PrefRegistrySimple* registry,
bool for_test) { bool for_test) {
...@@ -131,7 +116,10 @@ void TouchDevicesController::SetTouchscreenEnabled( ...@@ -131,7 +116,10 @@ void TouchDevicesController::SetTouchscreenEnabled(
} }
void TouchDevicesController::OnUserSessionAdded(const AccountId& account_id) { void TouchDevicesController::OnUserSessionAdded(const AccountId& account_id) {
scoped_uma_recorder_ = std::make_unique<ScopedUmaRecorder>(); uma_record_callback_ = base::BindOnce([](PrefService* prefs) {
UMA_HISTOGRAM_BOOLEAN("Touchpad.TapDragging.Started",
prefs->GetBoolean(prefs::kTapDraggingEnabled));
});
} }
void TouchDevicesController::OnSigninScreenPrefServiceInitialized( void TouchDevicesController::OnSigninScreenPrefServiceInitialized(
...@@ -141,7 +129,8 @@ void TouchDevicesController::OnSigninScreenPrefServiceInitialized( ...@@ -141,7 +129,8 @@ void TouchDevicesController::OnSigninScreenPrefServiceInitialized(
void TouchDevicesController::OnActiveUserPrefServiceChanged( void TouchDevicesController::OnActiveUserPrefServiceChanged(
PrefService* prefs) { PrefService* prefs) {
scoped_uma_recorder_.reset(); if (uma_record_callback_)
std::move(uma_record_callback_).Run(prefs);
ObservePrefs(prefs); ObservePrefs(prefs);
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/session/session_observer.h" #include "ash/session/session_observer.h"
#include "base/callback.h"
class AccountId; class AccountId;
class PrefChangeRegistrar; class PrefChangeRegistrar;
...@@ -52,8 +53,6 @@ class ASH_EXPORT TouchDevicesController : public SessionObserver { ...@@ -52,8 +53,6 @@ class ASH_EXPORT TouchDevicesController : public SessionObserver {
void SetTouchscreenEnabled(bool enabled, TouchscreenEnabledSource source); void SetTouchscreenEnabled(bool enabled, TouchscreenEnabledSource source);
private: private:
class ScopedUmaRecorder;
// Overridden from SessionObserver: // Overridden from SessionObserver:
void OnUserSessionAdded(const AccountId& account_id) override; void OnUserSessionAdded(const AccountId& account_id) override;
void OnSigninScreenPrefServiceInitialized(PrefService* prefs) override; void OnSigninScreenPrefServiceInitialized(PrefService* prefs) override;
...@@ -83,8 +82,10 @@ class ASH_EXPORT TouchDevicesController : public SessionObserver { ...@@ -83,8 +82,10 @@ class ASH_EXPORT TouchDevicesController : public SessionObserver {
// Observes user profile prefs for touch devices. // Observes user profile prefs for touch devices.
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
// Used to record pref started UMA. // Used to record pref started UMA, bound on user session added and run on
std::unique_ptr<ScopedUmaRecorder> scoped_uma_recorder_; // active user pref service changed. The goal is to record the initial state
// of the feature.
base::OnceCallback<void(PrefService* prefs)> uma_record_callback_;
DISALLOW_COPY_AND_ASSIGN(TouchDevicesController); DISALLOW_COPY_AND_ASSIGN(TouchDevicesController);
}; };
......
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