Skip to content

Commit

Permalink
[M100] Fix timer delay for tailored security integration
Browse files Browse the repository at this point in the history
The current implementation has a small defect where a call to
RemoveQueryRequest followed by AddQueryRequest will result in an
immediate query, rather than waiting up to 5 minutes. This is
especially bad when the user is frequently navigating.

(cherry picked from commit c898e6d)

Bug: 1305301
Change-Id: I0bddcb7b411d88f791c783932f90de0113189f11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3516949
Reviewed-by: Rohit Bhatia <bhatiarohit@google.com>
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#980021}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3537188
Auto-Submit: Daniel Rubery <drubery@chromium.org>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/4896@{#680}
Cr-Branched-From: 1f63ff4-refs/heads/main@{#972766}
  • Loading branch information
Daniel Rubery authored and Chromium LUCI CQ committed Mar 18, 2022
1 parent 7d1730f commit ead816a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Expand Up @@ -280,13 +280,23 @@ void TailoredSecurityService::AddQueryRequest() {
DCHECK(!is_shut_down_);
active_query_request_++;
if (active_query_request_ == 1) {
// Query now and register a repeating timer to get the tailored security bit
// every `kRepeatingCheckTailoredSecurityBitDelayInMinutes` minutes.
QueryTailoredSecurityBit();
timer_.Start(
FROM_HERE,
base::Minutes(kRepeatingCheckTailoredSecurityBitDelayInMinutes), this,
&TailoredSecurityService::QueryTailoredSecurityBit);
if (base::Time::Now() - last_updated_ <=
base::Minutes(kRepeatingCheckTailoredSecurityBitDelayInMinutes)) {
// Since we queried recently, start the timer with a shorter delay.
base::TimeDelta delay =
base::Minutes(kRepeatingCheckTailoredSecurityBitDelayInMinutes) -
(base::Time::Now() - last_updated_);
timer_.Start(FROM_HERE, delay, this,
&TailoredSecurityService::QueryTailoredSecurityBit);
} else {
// Query now and register a timer to get the tailored security bit
// every `kRepeatingCheckTailoredSecurityBitDelayInMinutes` minutes.
QueryTailoredSecurityBit();
timer_.Start(
FROM_HERE,
base::Minutes(kRepeatingCheckTailoredSecurityBitDelayInMinutes), this,
&TailoredSecurityService::QueryTailoredSecurityBit);
}
}
}

Expand Down Expand Up @@ -362,6 +372,12 @@ void TailoredSecurityService::OnTailoredSecurityBitRetrieved(
}
is_tailored_security_enabled_ = is_enabled;
last_updated_ = base::Time::Now();
if (active_query_request_ > 0) {
timer_.Start(
FROM_HERE,
base::Minutes(kRepeatingCheckTailoredSecurityBitDelayInMinutes), this,
&TailoredSecurityService::QueryTailoredSecurityBit);
}
}

void TailoredSecurityService::QueryTailoredSecurityBitCompletionCallback(
Expand Down
Expand Up @@ -174,7 +174,7 @@ class TailoredSecurityService : public KeyedService {
size_t active_query_request_ = 0;

// Timer to periodically check tailored security bit.
base::RepeatingTimer timer_;
base::OneShotTimer timer_;

bool is_tailored_security_enabled_ = false;
base::Time last_updated_;
Expand Down

0 comments on commit ead816a

Please sign in to comment.