Commit 778fe83a authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Put rethrowable first user action in a cancelable Callback

And cancel it on expiration.

Bug: 881907
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I09af1c34ebf11b51a9cd7d0bb4925d7e97ddc3bb
Reviewed-on: https://chromium-review.googlesource.com/1219611
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590304}
parent 8952ae00
......@@ -109,6 +109,10 @@ FirstUserActionRecorder::~FirstUserActionRecorder() {
void FirstUserActionRecorder::Expire() {
std::string log_message = "Recording 'Expiration' for first user action type";
// If there is a pending rethrowable action, it could technically be logged.
// But as FirstUserActionRecorder will be destroyed in this runloop, it is too
// late.
rethrow_callback_.Cancel();
RecordAction(EXPIRATION, log_message);
}
......@@ -183,9 +187,11 @@ bool FirstUserActionRecorder::ShouldProcessAction(
if (!action_pending_ &&
ArrayContainsString(kRethrownActions, arraysize(kRethrownActions),
action_name.c_str())) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&FirstUserActionRecorder::OnUserAction,
base::Unretained(this), action_name));
rethrow_callback_.Reset(
base::BindOnce(&FirstUserActionRecorder::OnUserAction,
base::Unretained(this), action_name));
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
rethrow_callback_.callback());
action_pending_ = true;
return false;
}
......
......@@ -7,6 +7,7 @@
#include <vector>
#include "base/cancelable_callback.h"
#include "base/metrics/user_metrics.h"
#include "base/time/time.h"
......@@ -88,6 +89,10 @@ class FirstUserActionRecorder {
// The callback to invoke when an action is recorded.
base::ActionCallback action_callback_;
// A potential action that needs to be confirmed if there is no other relevant
// action.
base::CancelableOnceClosure rethrow_callback_;
DISALLOW_COPY_AND_ASSIGN(FirstUserActionRecorder);
};
......
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