Commit 0e2f7cb7 authored by Yao Xiao's avatar Yao Xiao Committed by Commit Bot

Update the floc computation scheduling pattern

Before: Schedule the computation events using a RepeatingTimer and use a
session number to address potential race conditions.

After: Use a flag |floc_computation_in_progress_| to guard the process
from ComputeFloc to OnComputeFlocCompleted. Incoming computation will be
ignored if there’s one ongoing. After each OnComputeFlocCompleted, a
ComputeFloc event will be scheduled 24 hours later / override the
existing scheduled event.

Why: The new pattern would be more suitable for a future plan where more
computation triggers are introduced (e.g. kHistoryDelete). In that case,
the caller can simply call
ComputeFloc(ComputeFlocTrigger::kHistoryDelete) without needing to reset
the timer.


Bug: 1062736
Change-Id: Ic128262272c71be3bc8998bb192ff7c7b615faa8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359394
Commit-Queue: Yao Xiao <yaoxia@chromium.org>
Reviewed-by: default avatarJosh Karlin <jkarlin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799547}
parent d8d68438
......@@ -278,7 +278,7 @@ IN_PROC_BROWSER_TEST_F(FlocIdProviderWithCustomizedServicesBrowserTest,
EXPECT_EQ(GetFlocId().ToDebugHeaderValue(), FlocId().ToDebugHeaderValue());
// Turn on sync-history to trigger the start of the 1st floc session.
// Turn on sync-history to trigger the 1st floc computation.
sync_service()->SetActiveDataTypes(syncer::ModelTypeSet::All());
sync_service()->FireStateChanged();
......@@ -313,7 +313,7 @@ IN_PROC_BROWSER_TEST_F(FlocIdProviderWithCustomizedServicesBrowserTest,
EXPECT_EQ(GetFlocId().ToDebugHeaderValue(), FlocId().ToDebugHeaderValue());
// Turn on sync-history to trigger the start of the 1st floc session.
// Turn on sync-history to trigger the 1st floc computation.
sync_service()->SetActiveDataTypes(syncer::ModelTypeSet::All());
sync_service()->FireStateChanged();
......
......@@ -25,7 +25,7 @@ namespace federated_learning {
namespace {
constexpr size_t kMinHistoryDomainSizeToReportFlocId = 1;
constexpr base::TimeDelta kFlocSessionRenewInterval =
constexpr base::TimeDelta kFlocScheduledUpdateInterval =
base::TimeDelta::FromDays(1);
constexpr int kQueryHistoryWindowInDays = 7;
......@@ -48,9 +48,7 @@ FlocIdProviderImpl::FlocIdProviderImpl(
FlocIdProviderImpl::~FlocIdProviderImpl() = default;
void FlocIdProviderImpl::NotifyFlocIdUpdated() {
DCHECK(floc_session_count_ > 0);
void FlocIdProviderImpl::NotifyFlocUpdated(ComputeFlocTrigger trigger) {
if (!base::FeatureList::IsEnabled(features::kFlocIdComputedEventLogging))
return;
......@@ -60,9 +58,9 @@ void FlocIdProviderImpl::NotifyFlocIdUpdated() {
specifics->mutable_floc_id_computed_event();
sync_pb::UserEventSpecifics_FlocIdComputed_EventTrigger event_trigger =
(floc_session_count_ == 1u)
? sync_pb::UserEventSpecifics::FlocIdComputed::NEW
: sync_pb::UserEventSpecifics::FlocIdComputed::REFRESHED;
(trigger == ComputeFlocTrigger::kBrowserStart)
? sync_pb::UserEventSpecifics_FlocIdComputed_EventTrigger_NEW
: sync_pb::UserEventSpecifics_FlocIdComputed_EventTrigger_REFRESHED;
floc_id_computed_event->set_event_trigger(event_trigger);
......@@ -86,7 +84,7 @@ bool FlocIdProviderImpl::AreThirdPartyCookiesAllowed() {
}
void FlocIdProviderImpl::IsSwaaNacAccountEnabled(
CanComputeFlocIdCallback callback) {
CanComputeFlocCallback callback) {
net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
net::DefinePartialNetworkTrafficAnnotation(
"floc_id_provider_impl", "floc_remote_permission_service",
......@@ -127,29 +125,59 @@ void FlocIdProviderImpl::Shutdown() {
}
void FlocIdProviderImpl::OnStateChanged(syncer::SyncService* sync_service) {
if (floc_session_count_ > 0)
if (first_floc_computation_triggered_)
return;
if (!IsSyncHistoryEnabled())
return;
CalculateFloc();
ComputeFloc(ComputeFlocTrigger::kBrowserStart);
}
void FlocIdProviderImpl::ComputeFloc(ComputeFlocTrigger trigger) {
DCHECK_NE(trigger == ComputeFlocTrigger::kBrowserStart,
first_floc_computation_triggered_);
DCHECK(trigger != ComputeFlocTrigger::kBrowserStart ||
!floc_computation_in_progress_);
// Skip computing as long as there's one still in progress.
if (floc_computation_in_progress_)
return;
floc_computation_in_progress_ = true;
first_floc_computation_triggered_ = true;
auto compute_floc_completed_callback =
base::BindOnce(&FlocIdProviderImpl::OnComputeFlocCompleted,
weak_ptr_factory_.GetWeakPtr(), trigger);
floc_session_start_timer_.Start(
FROM_HERE, kFlocSessionRenewInterval,
base::BindRepeating(&FlocIdProviderImpl::CalculateFloc,
weak_ptr_factory_.GetWeakPtr()));
CheckCanComputeFloc(
base::BindOnce(&FlocIdProviderImpl::OnCheckCanComputeFlocCompleted,
weak_ptr_factory_.GetWeakPtr(),
std::move(compute_floc_completed_callback)));
}
void FlocIdProviderImpl::CalculateFloc() {
floc_session_count_ += 1;
CheckCanComputeFlocId(
base::BindOnce(&FlocIdProviderImpl::OnCheckCanComputeFlocIdCompleted,
weak_ptr_factory_.GetWeakPtr()));
void FlocIdProviderImpl::OnComputeFlocCompleted(ComputeFlocTrigger trigger,
FlocId floc_id) {
DCHECK(floc_computation_in_progress_);
floc_computation_in_progress_ = false;
if (floc_id_ != floc_id) {
floc_id_ = floc_id;
NotifyFlocUpdated(trigger);
}
// Abandon the scheduled task if any, and schedule a new compute-floc task
// that is |kFlocScheduledUpdateInterval| from now.
compute_floc_timer_.Start(
FROM_HERE, kFlocScheduledUpdateInterval,
base::BindOnce(&FlocIdProviderImpl::ComputeFloc,
weak_ptr_factory_.GetWeakPtr(),
ComputeFlocTrigger::kScheduledUpdate));
}
void FlocIdProviderImpl::CheckCanComputeFlocId(
CanComputeFlocIdCallback callback) {
void FlocIdProviderImpl::CheckCanComputeFloc(CanComputeFlocCallback callback) {
if (!IsSyncHistoryEnabled() || !AreThirdPartyCookiesAllowed()) {
std::move(callback).Run(false);
return;
......@@ -158,19 +186,17 @@ void FlocIdProviderImpl::CheckCanComputeFlocId(
IsSwaaNacAccountEnabled(std::move(callback));
}
void FlocIdProviderImpl::OnCheckCanComputeFlocIdCompleted(
void FlocIdProviderImpl::OnCheckCanComputeFlocCompleted(
ComputeFlocCompletedCallback callback,
bool can_compute_floc) {
if (!can_compute_floc) {
if (floc_id_.IsValid()) {
floc_id_ = FlocId();
NotifyFlocIdUpdated();
}
std::move(callback).Run(FlocId());
return;
}
GetRecentlyVisitedURLs(
base::BindOnce(&FlocIdProviderImpl::OnGetRecentlyVisitedURLsCompleted,
weak_ptr_factory_.GetWeakPtr(), floc_session_count_));
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void FlocIdProviderImpl::GetRecentlyVisitedURLs(
......@@ -184,12 +210,8 @@ void FlocIdProviderImpl::GetRecentlyVisitedURLs(
}
void FlocIdProviderImpl::OnGetRecentlyVisitedURLsCompleted(
size_t floc_session_count,
ComputeFlocCompletedCallback callback,
history::QueryResults results) {
DCHECK_LE(floc_session_count, floc_session_count_);
if (floc_session_count < floc_session_count_)
return;
std::unordered_set<std::string> domains;
for (const history::URLResult& url_result : results) {
if (!url_result.publicly_routable())
......@@ -204,10 +226,7 @@ void FlocIdProviderImpl::OnGetRecentlyVisitedURLsCompleted(
? FlocId::CreateFromHistory(domains)
: FlocId();
if (floc_id_ != floc_id) {
floc_id_ = floc_id;
NotifyFlocIdUpdated();
}
std::move(callback).Run(floc_id);
}
} // namespace federated_learning
......@@ -25,19 +25,31 @@ namespace federated_learning {
class FlocRemotePermissionService;
// A service that regularly computes the floc id and logs it in a user event.
// A service that regularly computes the floc id and logs it in a user event. A
// computed floc can be in either a valid or invalid state, based on whether all
// the prerequisites are met:
// 1) Sync & sync-history are enabled.
// 2) 3rd party cookies are NOT blocked.
// 3) Supplemental Web and App Activity is enabled.
// 4) Supplemental Ad Personalization is enabled.
// 5) The account type is NOT a child account.
//
// A floc session starts when sync & sync-history is first enabled. We validate
// the following conditions in sequence before computing the floc id: user
// doesn’t block 3rd party cookies; all 3 of swaa & nac & account_type are
// enabled; the user has visited at least 1 domain with publicly routable ip in
// the past 7 days. Every 24 hours, it'll go over the conditions above again
// (including the sync & sync-history check), and reset or recompute the id
// accordingly.
// When all the prerequisites are met, the floc will be computed by sim-hashing
// navigation URL domains in the last 7 days; otherwise, an invalid floc will be
// given.
//
// The floc will be first computed after sync & sync-history are enabled. After
// each computation, another computation will be scheduled 24 hours later.
class FlocIdProviderImpl : public FlocIdProvider,
public syncer::SyncServiceObserver {
public:
using CanComputeFlocIdCallback = base::OnceCallback<void(bool)>;
enum class ComputeFlocTrigger {
kBrowserStart,
kScheduledUpdate,
};
using CanComputeFlocCallback = base::OnceCallback<void(bool)>;
using ComputeFlocCompletedCallback = base::OnceCallback<void(FlocId)>;
using GetRecentlyVisitedURLsCallback =
history::HistoryService::QueryHistoryCallback;
......@@ -53,10 +65,10 @@ class FlocIdProviderImpl : public FlocIdProvider,
protected:
// protected virtual for testing.
virtual void NotifyFlocIdUpdated();
virtual void NotifyFlocUpdated(ComputeFlocTrigger trigger);
virtual bool IsSyncHistoryEnabled();
virtual bool AreThirdPartyCookiesAllowed();
virtual void IsSwaaNacAccountEnabled(CanComputeFlocIdCallback callback);
virtual void IsSwaaNacAccountEnabled(CanComputeFlocCallback callback);
private:
friend class FlocIdProviderUnitTest;
......@@ -68,17 +80,20 @@ class FlocIdProviderImpl : public FlocIdProvider,
// syncer::SyncServiceObserver:
void OnStateChanged(syncer::SyncService* sync_service) override;
void CalculateFloc();
void ComputeFloc(ComputeFlocTrigger trigger);
void OnComputeFlocCompleted(ComputeFlocTrigger trigger, FlocId floc_id);
void CheckCanComputeFlocId(CanComputeFlocIdCallback callback);
void OnCheckCanComputeFlocIdCompleted(bool can_compute_floc);
void CheckCanComputeFloc(CanComputeFlocCallback callback);
void OnCheckCanComputeFlocCompleted(ComputeFlocCompletedCallback callback,
bool can_compute_floc);
void GetRecentlyVisitedURLs(GetRecentlyVisitedURLsCallback callback);
void OnGetRecentlyVisitedURLsCompleted(size_t floc_session_count,
void OnGetRecentlyVisitedURLsCompleted(ComputeFlocCompletedCallback callback,
history::QueryResults results);
FlocId floc_id_;
size_t floc_session_count_ = 0;
bool floc_computation_in_progress_ = false;
bool first_floc_computation_triggered_ = false;
syncer::SyncService* sync_service_;
scoped_refptr<content_settings::CookieSettings> cookie_settings_;
......@@ -89,8 +104,8 @@ class FlocIdProviderImpl : public FlocIdProvider,
// Used for the async tasks querying the HistoryService.
base::CancelableTaskTracker history_task_tracker_;
// The timer used to start the floc session at regular intervals.
base::RepeatingTimer floc_session_start_timer_;
// The timer used to schedule a floc computation.
base::OneShotTimer compute_floc_timer_;
base::WeakPtrFactory<FlocIdProviderImpl> weak_ptr_factory_{this};
};
......
......@@ -29,16 +29,17 @@ class MockFlocIdProvider : public FlocIdProviderImpl {
public:
using FlocIdProviderImpl::FlocIdProviderImpl;
void NotifyFlocIdUpdated() override {
void NotifyFlocUpdated(
FlocIdProviderImpl::ComputeFlocTrigger trigger) override {
++floc_update_notification_count_;
FlocIdProviderImpl::NotifyFlocIdUpdated();
FlocIdProviderImpl::NotifyFlocUpdated(trigger);
}
bool AreThirdPartyCookiesAllowed() override {
return third_party_cookies_allowed_;
}
void IsSwaaNacAccountEnabled(CanComputeFlocIdCallback callback) override {
void IsSwaaNacAccountEnabled(CanComputeFlocCallback callback) override {
std::move(callback).Run(swaa_nac_account_enabled_);
}
......@@ -90,15 +91,20 @@ class FlocIdProviderUnitTest : public testing::Test {
task_environment_.RunUntilIdle();
}
void CheckCanComputeFlocId(
FlocIdProviderImpl::CanComputeFlocIdCallback callback) {
floc_id_provider_->CheckCanComputeFlocId(std::move(callback));
void CheckCanComputeFloc(
FlocIdProviderImpl::CanComputeFlocCallback callback) {
floc_id_provider_->CheckCanComputeFloc(std::move(callback));
}
void OnGetRecentlyVisitedURLsCompleted(size_t floc_session_count,
void OnGetRecentlyVisitedURLsCompleted(
FlocIdProviderImpl::ComputeFlocTrigger trigger,
history::QueryResults results) {
floc_id_provider_->OnGetRecentlyVisitedURLsCompleted(floc_session_count,
std::move(results));
auto compute_floc_completed_callback =
base::BindOnce(&FlocIdProviderImpl::OnComputeFlocCompleted,
base::Unretained(floc_id_provider_.get()), trigger);
floc_id_provider_->OnGetRecentlyVisitedURLsCompleted(
std::move(compute_floc_completed_callback), std::move(results));
}
FlocId floc_id() const { return floc_id_provider_->floc_id_; }
......@@ -107,12 +113,21 @@ class FlocIdProviderUnitTest : public testing::Test {
floc_id_provider_->floc_id_ = floc_id;
}
size_t floc_session_count() const {
return floc_id_provider_->floc_session_count_;
bool floc_computation_in_progress() const {
return floc_id_provider_->floc_computation_in_progress_;
}
void set_floc_computation_in_progress(bool floc_computation_in_progress) {
floc_id_provider_->floc_computation_in_progress_ =
floc_computation_in_progress;
}
void set_floc_session_count(size_t count) {
floc_id_provider_->floc_session_count_ = count;
bool first_floc_computation_triggered() const {
return floc_id_provider_->first_floc_computation_triggered_;
}
void set_first_floc_computation_triggered(bool triggered) {
floc_id_provider_->first_floc_computation_triggered_ = triggered;
}
protected:
......@@ -140,13 +155,13 @@ TEST_F(FlocIdProviderUnitTest, QualifiedInitialHistory) {
task_environment_.RunUntilIdle();
// Expect that the floc session hasn't started, as the floc_id_provider hasn't
// been notified about state of the sync_service.
// Expect that the floc computation hasn't started, as the floc_id_provider
// hasn't been notified about state of the sync_service.
ASSERT_EQ(0u, floc_id_provider_->floc_update_notification_count());
ASSERT_FALSE(floc_id().IsValid());
ASSERT_EQ(0u, floc_session_count());
ASSERT_FALSE(first_floc_computation_triggered());
// Trigger the start of the 1st floc session.
// Trigger the 1st floc computation.
test_sync_service_->SetTransportState(
syncer::SyncService::TransportState::ACTIVE);
test_sync_service_->FireStateChanged();
......@@ -158,7 +173,7 @@ TEST_F(FlocIdProviderUnitTest, QualifiedInitialHistory) {
ASSERT_TRUE(floc_id().IsValid());
ASSERT_EQ(FlocId::CreateFromHistory({domain}).ToDebugHeaderValue(),
floc_id().ToDebugHeaderValue());
ASSERT_EQ(1u, floc_session_count());
ASSERT_TRUE(first_floc_computation_triggered());
// Advance the clock by 1 day. Expect a floc id update notification, as
// there's no history in the last 7 days so the id has been reset to empty.
......@@ -166,7 +181,6 @@ TEST_F(FlocIdProviderUnitTest, QualifiedInitialHistory) {
ASSERT_EQ(2u, floc_id_provider_->floc_update_notification_count());
ASSERT_FALSE(floc_id().IsValid());
ASSERT_EQ(2u, floc_session_count());
}
TEST_F(FlocIdProviderUnitTest, UnqualifiedInitialHistory) {
......@@ -181,13 +195,13 @@ TEST_F(FlocIdProviderUnitTest, UnqualifiedInitialHistory) {
task_environment_.RunUntilIdle();
// Expect that the floc session hasn't started, as the floc_id_provider hasn't
// been notified about state of the sync_service.
// Expect that the floc computation hasn't started, as the floc_id_provider
// hasn't been notified about state of the sync_service.
ASSERT_EQ(0u, floc_id_provider_->floc_update_notification_count());
ASSERT_FALSE(floc_id().IsValid());
ASSERT_EQ(0u, floc_session_count());
ASSERT_FALSE(first_floc_computation_triggered());
// Trigger the start of the 1st floc session.
// Trigger the 1st floc computation.
test_sync_service_->SetTransportState(
syncer::SyncService::TransportState::ACTIVE);
test_sync_service_->FireStateChanged();
......@@ -195,9 +209,9 @@ TEST_F(FlocIdProviderUnitTest, UnqualifiedInitialHistory) {
task_environment_.RunUntilIdle();
// Expect no floc id update notification, as there is no qualified history
// entry. However, the 1st session should already have started.
// entry. However, the 1st computation should already have started.
ASSERT_EQ(0u, floc_id_provider_->floc_update_notification_count());
ASSERT_EQ(1u, floc_session_count());
ASSERT_TRUE(first_floc_computation_triggered());
// Add a history entry with a timestamp 6 days back from now.
add_page_args.time = base::Time::Now() - base::TimeDelta::FromDays(6);
......@@ -208,7 +222,6 @@ TEST_F(FlocIdProviderUnitTest, UnqualifiedInitialHistory) {
task_environment_.FastForwardBy(base::TimeDelta::FromHours(23));
ASSERT_EQ(0u, floc_id_provider_->floc_update_notification_count());
ASSERT_EQ(1u, floc_session_count());
// Advance the clock by 1 hour. Expect a floc id update notification, as the
// refresh time is reached and there's a valid history entry in the last 7
......@@ -219,7 +232,6 @@ TEST_F(FlocIdProviderUnitTest, UnqualifiedInitialHistory) {
ASSERT_TRUE(floc_id().IsValid());
ASSERT_EQ(FlocId::CreateFromHistory({domain}).ToDebugHeaderValue(),
floc_id().ToDebugHeaderValue());
ASSERT_EQ(2u, floc_session_count());
}
TEST_F(FlocIdProviderUnitTest, ScheduledUpdateSameFloc_NoNotification) {
......@@ -234,7 +246,7 @@ TEST_F(FlocIdProviderUnitTest, ScheduledUpdateSameFloc_NoNotification) {
task_environment_.RunUntilIdle();
// Trigger the start of the 1st floc session.
// Trigger the 1st floc computation.
test_sync_service_->SetTransportState(
syncer::SyncService::TransportState::ACTIVE);
test_sync_service_->FireStateChanged();
......@@ -251,27 +263,27 @@ TEST_F(FlocIdProviderUnitTest, ScheduledUpdateSameFloc_NoNotification) {
ASSERT_EQ(1u, floc_id_provider_->floc_update_notification_count());
}
TEST_F(FlocIdProviderUnitTest, CheckCanComputeFlocId_Success) {
TEST_F(FlocIdProviderUnitTest, CheckCanComputeFloc_Success) {
test_sync_service_->SetTransportState(
syncer::SyncService::TransportState::ACTIVE);
base::OnceCallback<void(bool)> cb = base::BindOnce(
[](bool can_compute_floc) { ASSERT_TRUE(can_compute_floc); });
CheckCanComputeFlocId(std::move(cb));
CheckCanComputeFloc(std::move(cb));
task_environment_.RunUntilIdle();
}
TEST_F(FlocIdProviderUnitTest, CheckCanComputeFlocId_Failure_SyncDisabled) {
TEST_F(FlocIdProviderUnitTest, CheckCanComputeFloc_Failure_SyncDisabled) {
base::OnceCallback<void(bool)> cb = base::BindOnce(
[](bool can_compute_floc) { ASSERT_FALSE(can_compute_floc); });
CheckCanComputeFlocId(std::move(cb));
CheckCanComputeFloc(std::move(cb));
task_environment_.RunUntilIdle();
}
TEST_F(FlocIdProviderUnitTest,
CheckCanComputeFlocId_Failure_BlockThirdPartyCookies) {
CheckCanComputeFloc_Failure_BlockThirdPartyCookies) {
test_sync_service_->SetTransportState(
syncer::SyncService::TransportState::ACTIVE);
......@@ -280,12 +292,12 @@ TEST_F(FlocIdProviderUnitTest,
base::OnceCallback<void(bool)> cb = base::BindOnce(
[](bool can_compute_floc) { ASSERT_FALSE(can_compute_floc); });
CheckCanComputeFlocId(std::move(cb));
CheckCanComputeFloc(std::move(cb));
task_environment_.RunUntilIdle();
}
TEST_F(FlocIdProviderUnitTest,
CheckCanComputeFlocId_Failure_SwaaNacAccountDisabled) {
CheckCanComputeFloc_Failure_SwaaNacAccountDisabled) {
test_sync_service_->SetTransportState(
syncer::SyncService::TransportState::ACTIVE);
......@@ -294,7 +306,7 @@ TEST_F(FlocIdProviderUnitTest,
base::OnceCallback<void(bool)> cb = base::BindOnce(
[](bool can_compute_floc) { ASSERT_FALSE(can_compute_floc); });
CheckCanComputeFlocId(std::move(cb));
CheckCanComputeFloc(std::move(cb));
task_environment_.RunUntilIdle();
}
......@@ -302,9 +314,9 @@ TEST_F(FlocIdProviderUnitTest, EventLogging) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(features::kFlocIdComputedEventLogging);
set_floc_session_count(1u);
set_floc_id(FlocId(12345ULL));
floc_id_provider_->NotifyFlocIdUpdated();
floc_id_provider_->NotifyFlocUpdated(
FlocIdProviderImpl::ComputeFlocTrigger::kBrowserStart);
ASSERT_EQ(1u, fake_user_event_service_->GetRecordedUserEvents().size());
const sync_pb::UserEventSpecifics& specifics1 =
......@@ -318,9 +330,9 @@ TEST_F(FlocIdProviderUnitTest, EventLogging) {
event1.event_trigger());
EXPECT_EQ(12345ULL, event1.floc_id());
set_floc_session_count(2u);
set_floc_id(FlocId(999ULL));
floc_id_provider_->NotifyFlocIdUpdated();
floc_id_provider_->NotifyFlocUpdated(
FlocIdProviderImpl::ComputeFlocTrigger::kScheduledUpdate);
ASSERT_EQ(2u, fake_user_event_service_->GetRecordedUserEvents().size());
const sync_pb::UserEventSpecifics& specifics2 =
......@@ -335,7 +347,8 @@ TEST_F(FlocIdProviderUnitTest, EventLogging) {
EXPECT_EQ(999ULL, event2.floc_id());
set_floc_id(FlocId());
floc_id_provider_->NotifyFlocIdUpdated();
floc_id_provider_->NotifyFlocUpdated(
FlocIdProviderImpl::ComputeFlocTrigger::kScheduledUpdate);
ASSERT_EQ(3u, fake_user_event_service_->GetRecordedUserEvents().size());
const sync_pb::UserEventSpecifics& specifics3 =
......@@ -356,8 +369,12 @@ TEST_F(FlocIdProviderUnitTest, HistoryEntriesWithPrivateIP) {
{history::URLResult(GURL("https://a.test"),
base::Time::Now() - base::TimeDelta::FromDays(1))});
set_floc_session_count(1u);
OnGetRecentlyVisitedURLsCompleted(1u, std::move(query_results));
set_first_floc_computation_triggered(true);
set_floc_computation_in_progress(true);
OnGetRecentlyVisitedURLsCompleted(
FlocIdProviderImpl::ComputeFlocTrigger::kBrowserStart,
std::move(query_results));
ASSERT_FALSE(floc_id().IsValid());
}
......@@ -379,8 +396,12 @@ TEST_F(FlocIdProviderUnitTest, MultipleHistoryEntries) {
history::QueryResults query_results;
query_results.SetURLResults(std::move(url_results));
set_floc_session_count(1u);
OnGetRecentlyVisitedURLsCompleted(1u, std::move(query_results));
set_first_floc_computation_triggered(true);
set_floc_computation_in_progress(true);
OnGetRecentlyVisitedURLsCompleted(
FlocIdProviderImpl::ComputeFlocTrigger::kBrowserStart,
std::move(query_results));
ASSERT_EQ(
FlocId::CreateFromHistory({"a.test", "b.test"}).ToDebugHeaderValue(),
......@@ -398,7 +419,7 @@ TEST_F(FlocIdProviderUnitTest, TurnSyncOffAndOn) {
task_environment_.RunUntilIdle();
// Trigger the start of the 1st floc session.
// Trigger the 1st floc computation.
test_sync_service_->SetTransportState(
syncer::SyncService::TransportState::ACTIVE);
test_sync_service_->FireStateChanged();
......@@ -409,7 +430,6 @@ TEST_F(FlocIdProviderUnitTest, TurnSyncOffAndOn) {
ASSERT_EQ(1u, floc_id_provider_->floc_update_notification_count());
ASSERT_EQ(FlocId::CreateFromHistory({domain}).ToDebugHeaderValue(),
floc_id().ToDebugHeaderValue());
ASSERT_EQ(1u, floc_session_count());
// Turn off sync.
test_sync_service_->SetTransportState(
......@@ -421,7 +441,6 @@ TEST_F(FlocIdProviderUnitTest, TurnSyncOffAndOn) {
ASSERT_EQ(2u, floc_id_provider_->floc_update_notification_count());
ASSERT_FALSE(floc_id().IsValid());
ASSERT_EQ(2u, floc_session_count());
// Turn on sync.
test_sync_service_->SetTransportState(
......@@ -434,7 +453,6 @@ TEST_F(FlocIdProviderUnitTest, TurnSyncOffAndOn) {
ASSERT_EQ(3u, floc_id_provider_->floc_update_notification_count());
ASSERT_EQ(FlocId::CreateFromHistory({domain}).ToDebugHeaderValue(),
floc_id().ToDebugHeaderValue());
ASSERT_EQ(3u, floc_session_count());
}
} // namespace federated_learning
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