From 419375fcd244239ce28a33f445175e2edeb40542 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Mon, 29 Jan 2024 23:07:45 +0200 Subject: [PATCH] Uplift of #21746 (squashed) to release --- chromium_src/components/sync/engine/syncer.cc | 32 ------------ components/sync/engine/BUILD.gn | 6 +-- .../sync/engine/brave_syncer_device_poll.cc | 42 ---------------- .../sync/engine/brave_syncer_device_poll.h | 36 -------------- .../brave_syncer_device_poll_unittest.cc | 49 ------------------- components/sync/engine/sources.gni | 2 - .../components-sync-engine-syncer.cc.patch | 12 ----- 7 files changed, 2 insertions(+), 177 deletions(-) delete mode 100644 chromium_src/components/sync/engine/syncer.cc delete mode 100644 components/sync/engine/brave_syncer_device_poll.cc delete mode 100644 components/sync/engine/brave_syncer_device_poll.h delete mode 100644 components/sync/engine/brave_syncer_device_poll_unittest.cc delete mode 100644 patches/components-sync-engine-syncer.cc.patch diff --git a/chromium_src/components/sync/engine/syncer.cc b/chromium_src/components/sync/engine/syncer.cc deleted file mode 100644 index 000a24cb156c..000000000000 --- a/chromium_src/components/sync/engine/syncer.cc +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (c) 2023 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#include "brave/components/sync/engine/brave_syncer_device_poll.h" -// Forward include to avoid redefine CommitProcessor at upstream header -#include "components/sync/engine/commit_processor.h" - -// CommitProcessor is occurred just once in upstream syncer.cc -// so we can use it to redefine and introduce own variable. -#define CommitProcessor \ - BraveSyncerDevicePoll brave_syncer_device_poll; \ - CommitProcessor - -#define BRAVE_SYNCER_BUILD_AND_POST_COMMITS_POLLER_CHECK \ - brave_syncer_device_poll.CheckIntervalAndPoll(base::BindOnce( \ - [](Syncer* the_syncer, SyncCycle* cycle, NudgeTracker* nudge_tracker, \ - BraveSyncerDevicePoll* the_brave_syncer_device_poll) { \ - VLOG(1) << "Forced poll of device info during long commit. Passed " \ - "time since begin of commit operation is " \ - << the_brave_syncer_device_poll->SinceBegin(); \ - ModelTypeSet device_only({ModelType::DEVICE_INFO}); \ - the_syncer->DownloadAndApplyUpdates( \ - &device_only, cycle, NormalGetUpdatesDelegate(*nudge_tracker)); \ - }, \ - this, cycle, nudge_tracker, &brave_syncer_device_poll)); - -#include "src/components/sync/engine/syncer.cc" - -#undef BRAVE_SYNCER_BUILD_AND_POST_COMMITS_POLLER_CHECK -#undef CommitProcessor diff --git a/components/sync/engine/BUILD.gn b/components/sync/engine/BUILD.gn index d8021fe83cfc..ccea127996ed 100644 --- a/components/sync/engine/BUILD.gn +++ b/components/sync/engine/BUILD.gn @@ -6,10 +6,8 @@ source_set("unit_tests") { testonly = true - sources = [ - "//brave/components/sync/engine/brave_model_type_worker_unittest.cc", - "//brave/components/sync/engine/brave_syncer_device_poll_unittest.cc", - ] + sources = + [ "//brave/components/sync/engine/brave_model_type_worker_unittest.cc" ] deps = [ "//base", diff --git a/components/sync/engine/brave_syncer_device_poll.cc b/components/sync/engine/brave_syncer_device_poll.cc deleted file mode 100644 index ee7de36dea92..000000000000 --- a/components/sync/engine/brave_syncer_device_poll.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (c) 2023 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#include "brave/components/sync/engine/brave_syncer_device_poll.h" - -#include - -#include "base/functional/callback.h" -#include "base/time/time.h" - -using base::TimeTicks; - -namespace syncer { - -namespace { -constexpr base::TimeDelta kDelayBeforeForcedPoll = base::Seconds(15); -} - -BraveSyncerDevicePoll::BraveSyncerDevicePoll() - : ticks_at_begin_(TimeTicks::Now()), ticks_(ticks_at_begin_) {} - -void BraveSyncerDevicePoll::CheckIntervalAndPoll( - base::OnceClosure poll_devices) { - auto now = TimeTicks::Now(); - if (now - ticks_ > kDelayBeforeForcedPoll) { - std::move(poll_devices).Run(); - ticks_ = now; - } -} - -/* static */ -base::TimeDelta BraveSyncerDevicePoll::GetDelayBeforeForcedPollForTesting() { - return kDelayBeforeForcedPoll; -} - -base::TimeDelta BraveSyncerDevicePoll::SinceBegin() { - return TimeTicks::Now() - ticks_at_begin_; -} - -} // namespace syncer diff --git a/components/sync/engine/brave_syncer_device_poll.h b/components/sync/engine/brave_syncer_device_poll.h deleted file mode 100644 index 7450114834d0..000000000000 --- a/components/sync/engine/brave_syncer_device_poll.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (c) 2023 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_COMPONENTS_SYNC_ENGINE_BRAVE_SYNCER_DEVICE_POLL_H_ -#define BRAVE_COMPONENTS_SYNC_ENGINE_BRAVE_SYNCER_DEVICE_POLL_H_ - -#include "base/functional/callback_forward.h" -#include "base/gtest_prod_util.h" -#include "base/time/time.h" - -namespace syncer { - -FORWARD_DECLARE_TEST(BraveSyncerDevicePoll, ForcedPolling); - -class BraveSyncerDevicePoll { - public: - BraveSyncerDevicePoll(const BraveSyncerDevicePoll&) = delete; - BraveSyncerDevicePoll& operator=(const BraveSyncerDevicePoll&) = delete; - BraveSyncerDevicePoll(); - - void CheckIntervalAndPoll(base::OnceClosure poll_devices); - base::TimeDelta SinceBegin(); - - private: - FRIEND_TEST_ALL_PREFIXES(BraveSyncerDevicePoll, ForcedPolling); - static base::TimeDelta GetDelayBeforeForcedPollForTesting(); - - const base::TimeTicks ticks_at_begin_; - base::TimeTicks ticks_; -}; - -} // namespace syncer - -#endif // BRAVE_COMPONENTS_SYNC_ENGINE_BRAVE_SYNCER_DEVICE_POLL_H_ diff --git a/components/sync/engine/brave_syncer_device_poll_unittest.cc b/components/sync/engine/brave_syncer_device_poll_unittest.cc deleted file mode 100644 index dc050728ee40..000000000000 --- a/components/sync/engine/brave_syncer_device_poll_unittest.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (c) 2023 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#include "brave/components/sync/engine/brave_syncer_device_poll.h" - -#include - -#include "base/functional/callback.h" -#include "base/test/mock_callback.h" -#include "base/test/scoped_mock_clock_override.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace syncer { - -TEST(BraveSyncerDevicePoll, ForcedPolling) { - base::ScopedMockClockOverride clock; - BraveSyncerDevicePoll brave_syncer_device_poll; - const auto kDelayBeforeForcedPoll = - BraveSyncerDevicePoll::GetDelayBeforeForcedPollForTesting(); - - base::MockCallback mock_callback; - EXPECT_CALL(mock_callback, Run).Times(0); - brave_syncer_device_poll.CheckIntervalAndPoll(mock_callback.Get()); - testing::Mock::VerifyAndClearExpectations(&mock_callback); - - clock.Advance(kDelayBeforeForcedPoll - base::Seconds(1)); - EXPECT_CALL(mock_callback, Run).Times(0); - brave_syncer_device_poll.CheckIntervalAndPoll(mock_callback.Get()); - testing::Mock::VerifyAndClearExpectations(&mock_callback); - - clock.Advance(base::Seconds(2)); - EXPECT_CALL(mock_callback, Run).Times(1); - brave_syncer_device_poll.CheckIntervalAndPoll(mock_callback.Get()); - testing::Mock::VerifyAndClearExpectations(&mock_callback); - - clock.Advance(kDelayBeforeForcedPoll - base::Seconds(2)); - EXPECT_CALL(mock_callback, Run).Times(0); - brave_syncer_device_poll.CheckIntervalAndPoll(mock_callback.Get()); - testing::Mock::VerifyAndClearExpectations(&mock_callback); - - clock.Advance(base::Seconds(3)); - EXPECT_CALL(mock_callback, Run).Times(1); - brave_syncer_device_poll.CheckIntervalAndPoll(mock_callback.Get()); - testing::Mock::VerifyAndClearExpectations(&mock_callback); -} - -} // namespace syncer diff --git a/components/sync/engine/sources.gni b/components/sync/engine/sources.gni index f9231919a094..b8dc1a45a9bc 100644 --- a/components/sync/engine/sources.gni +++ b/components/sync/engine/sources.gni @@ -10,6 +10,4 @@ brave_components_sync_engine_sources = [ "//brave/components/sync/engine/brave_sync_manager_impl.h", "//brave/components/sync/engine/brave_sync_server_commands.cc", "//brave/components/sync/engine/brave_sync_server_commands.h", - "//brave/components/sync/engine/brave_syncer_device_poll.cc", - "//brave/components/sync/engine/brave_syncer_device_poll.h", ] diff --git a/patches/components-sync-engine-syncer.cc.patch b/patches/components-sync-engine-syncer.cc.patch deleted file mode 100644 index c8a08282ad9a..000000000000 --- a/patches/components-sync-engine-syncer.cc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/components/sync/engine/syncer.cc b/components/sync/engine/syncer.cc -index e8228e827e62496725d339e1527c58f94ac836fc..5153672fe14f7180fabaeef29ca870e6dd683279 100644 ---- a/components/sync/engine/syncer.cc -+++ b/components/sync/engine/syncer.cc -@@ -245,6 +245,7 @@ SyncerError Syncer::BuildAndPostCommits(const ModelTypeSet& request_types, - } - nudge_tracker->RecordSuccessfulCommitMessage( - commit->GetContributingDataTypes()); -+ BRAVE_SYNCER_BUILD_AND_POST_COMMITS_POLLER_CHECK - } - - return SyncerError::Success();