diff options
author | 2023-12-20 17:49:00 +0000 | |
---|---|---|
committer | 2023-12-20 17:49:00 +0000 | |
commit | d1e37cda5713d7fe47848e348bb4cc682ac17b62 (patch) | |
tree | 7dda114fc055a5c44be016a8bdd51b7c4ff539d9 | |
parent | c517040465a9550a3b4a90454d2c67d35288fa4f (diff) | |
parent | c684cae3c2bd3913404a6dfe17afb39e51921b82 (diff) |
Merge "Convert all uses of base::TimeDelta to std::chrono::microseconds" into main
26 files changed, 74 insertions, 168 deletions
diff --git a/system/bta/av/bta_av_main.cc b/system/bta/av/bta_av_main.cc index 30dbbbde32..ece2b83a78 100644 --- a/system/bta/av/bta_av_main.cc +++ b/system/bta/av/bta_av_main.cc @@ -159,12 +159,8 @@ static void bta_av_api_enable(tBTA_AV_DATA* p_data) { tBTA_AV_API_ENABLE* p_buf = (tBTA_AV_API_ENABLE*)osi_malloc(sizeof(tBTA_AV_API_ENABLE)); memcpy(p_buf, &p_data->api_enable, sizeof(tBTA_AV_API_ENABLE)); -#if BASE_VER < 931007 - bta_sys_sendmsg_delayed(p_buf, base::TimeDelta::FromMilliseconds( -#else - bta_sys_sendmsg_delayed(p_buf, base::Milliseconds( -#endif - kEnablingAttemptsIntervalMs)); + bta_sys_sendmsg_delayed( + p_buf, std::chrono::milliseconds(kEnablingAttemptsIntervalMs)); return; } if (bta_av_cb.sdp_a2dp_handle) { @@ -465,11 +461,7 @@ static void bta_av_api_register(tBTA_AV_DATA* p_data) { (tBTA_AV_API_REG*)osi_malloc(sizeof(tBTA_AV_API_REG)); memcpy(p_buf, &p_data->api_reg, sizeof(tBTA_AV_API_REG)); bta_sys_sendmsg_delayed( -#if BASE_VER < 931007 - p_buf, base::TimeDelta::FromMilliseconds(kEnablingAttemptsIntervalMs)); -#else - p_buf, base::Milliseconds(kEnablingAttemptsIntervalMs)); -#endif + p_buf, std::chrono::milliseconds(kEnablingAttemptsIntervalMs)); return; } diff --git a/system/bta/hearing_aid/hearing_aid_audio_source.cc b/system/bta/hearing_aid/hearing_aid_audio_source.cc index ba308843ca..7143dc8b5f 100644 --- a/system/bta/hearing_aid/hearing_aid_audio_source.cc +++ b/system/bta/hearing_aid/hearing_aid_audio_source.cc @@ -128,14 +128,9 @@ void start_audio_ticks() { } wakelock_acquire(); - audio_timer.SchedulePeriodic( - get_main_thread()->GetWeakPtr(), FROM_HERE, - base::BindRepeating(&send_audio_data), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(data_interval_ms)); -#else - base::Milliseconds(data_interval_ms)); -#endif + audio_timer.SchedulePeriodic(get_main_thread()->GetWeakPtr(), FROM_HERE, + base::BindRepeating(&send_audio_data), + std::chrono::milliseconds(data_interval_ms)); LOG_INFO("running with data interval: %d", data_interval_ms); } diff --git a/system/bta/le_audio/audio_hal_client/audio_source_hal_client.cc b/system/bta/le_audio/audio_hal_client/audio_source_hal_client.cc index 79227fb7cf..26dfb55400 100644 --- a/system/bta/le_audio/audio_hal_client/audio_source_hal_client.cc +++ b/system/bta/le_audio/audio_hal_client/audio_source_hal_client.cc @@ -254,11 +254,7 @@ void SourceImpl::StartAudioTicks() { audio_timer_.SchedulePeriodic( worker_thread_->GetWeakPtr(), FROM_HERE, base::BindRepeating(&SourceImpl::SendAudioData, base::Unretained(this)), -#if BASE_VER < 931007 - base::TimeDelta::FromMicroseconds(source_codec_config_.data_interval_us)); -#else - base::Microseconds(source_codec_config_.data_interval_us)); -#endif + std::chrono::microseconds(source_codec_config_.data_interval_us)); } void SourceImpl::StopAudioTicks() { diff --git a/system/bta/le_audio/client.cc b/system/bta/le_audio/client.cc index 7ca3cd4855..f6d169f73d 100644 --- a/system/bta/le_audio/client.cc +++ b/system/bta/le_audio/client.cc @@ -2211,12 +2211,7 @@ class LeAudioClientImpl : public LeAudioClient { base::BindOnce( &LeAudioClientImpl::checkGroupConnectionStateAfterMemberDisconnect, weak_factory_.GetWeakPtr(), group_id), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(kGroupConnectedWatchDelayMs) -#else - base::Milliseconds(kDeviceAttachDelayMs) -#endif - ); + std::chrono::milliseconds(kGroupConnectedWatchDelayMs)); } void autoConnect(RawAddress address) { @@ -2236,12 +2231,7 @@ class LeAudioClientImpl : public LeAudioClient { FROM_HERE, base::BindOnce(&LeAudioClientImpl::autoConnect, weak_factory_.GetWeakPtr(), address), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(kAutoConnectAfterOwnDisconnectDelayMs) -#else - base::Milliseconds(kDeviceAttachDelayMs) -#endif - ); + std::chrono::milliseconds(kAutoConnectAfterOwnDisconnectDelayMs)); } void recoveryReconnect(RawAddress address) { @@ -2275,12 +2265,7 @@ class LeAudioClientImpl : public LeAudioClient { FROM_HERE, base::BindOnce(&LeAudioClientImpl::recoveryReconnect, weak_factory_.GetWeakPtr(), address), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(kRecoveryReconnectDelayMs) -#else - base::Milliseconds(kDeviceAttachDelayMs) -#endif - ); + std::chrono::milliseconds(kRecoveryReconnectDelayMs)); } void checkIfGroupMember(RawAddress address) { @@ -2316,12 +2301,7 @@ class LeAudioClientImpl : public LeAudioClient { FROM_HERE, base::BindOnce(&LeAudioClientImpl::checkIfGroupMember, weak_factory_.GetWeakPtr(), address), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(kCsisGroupMemberDelayMs) -#else - base::Milliseconds(kCsisGroupMemberDelayMs) -#endif - ); + std::chrono::milliseconds(kCsisGroupMemberDelayMs)); } void OnGattDisconnected(uint16_t conn_id, tGATT_IF client_if, @@ -3127,12 +3107,7 @@ class LeAudioClientImpl : public LeAudioClient { FROM_HERE, base::BindOnce(&LeAudioClientImpl::restartAttachToTheStream, weak_factory_.GetWeakPtr(), addr), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(kDeviceAttachDelayMs) -#else - base::Milliseconds(kDeviceAttachDelayMs) -#endif - ); + std::chrono::milliseconds(kDeviceAttachDelayMs)); } void SendAudioGroupSelectableCodecConfigChanged(LeAudioDeviceGroup* group) { diff --git a/system/bta/le_audio/le_audio_client_test.cc b/system/bta/le_audio/le_audio_client_test.cc index c4595201e4..b34584ffba 100644 --- a/system/bta/le_audio/le_audio_client_test.cc +++ b/system/bta/le_audio/le_audio_client_test.cc @@ -144,7 +144,7 @@ bt_status_t do_in_main_thread(const base::Location& from_here, bt_status_t do_in_main_thread_delayed(const base::Location& from_here, base::OnceClosure task, - const base::TimeDelta& delay) { + std::chrono::microseconds delay) { /* For testing purpose it is ok to just skip delay */ return do_in_main_thread(from_here, std::move(task)); } diff --git a/system/bta/sys/bta_sys.h b/system/bta/sys/bta_sys.h index 0e791a23d6..19a6b5be8b 100644 --- a/system/bta/sys/bta_sys.h +++ b/system/bta/sys/bta_sys.h @@ -25,8 +25,8 @@ #define BTA_SYS_H #include <base/strings/stringprintf.h> -#include <base/time/time.h> +#include <chrono> #include <cstdint> #include <string> @@ -234,7 +234,7 @@ void bta_sys_register(uint8_t id, const tBTA_SYS_REG* p_reg); void bta_sys_deregister(uint8_t id); bool bta_sys_is_register(uint8_t id); void bta_sys_sendmsg(void* p_msg); -void bta_sys_sendmsg_delayed(void* p_msg, const base::TimeDelta& delay); +void bta_sys_sendmsg_delayed(void* p_msg, std::chrono::microseconds delay); void bta_sys_start_timer(alarm_t* alarm, uint64_t interval_ms, uint16_t event, uint16_t layer_specific); void bta_sys_disable(); diff --git a/system/bta/sys/bta_sys_main.cc b/system/bta/sys/bta_sys_main.cc index c09895b7e3..64da55ad3f 100644 --- a/system/bta/sys/bta_sys_main.cc +++ b/system/bta/sys/bta_sys_main.cc @@ -165,7 +165,7 @@ void bta_sys_sendmsg(void* p_msg) { } } -void bta_sys_sendmsg_delayed(void* p_msg, const base::TimeDelta& delay) { +void bta_sys_sendmsg_delayed(void* p_msg, std::chrono::microseconds delay) { if (do_in_main_thread_delayed( FROM_HERE, base::Bind(&bta_sys_event, static_cast<BT_HDR_RIGID*>(p_msg)), diff --git a/system/btif/src/btif_a2dp_source.cc b/system/btif/src/btif_a2dp_source.cc index 02b458f578..41f24d9b04 100644 --- a/system/btif/src/btif_a2dp_source.cc +++ b/system/btif/src/btif_a2dp_source.cc @@ -826,11 +826,7 @@ static void btif_a2dp_source_audio_tx_start_event(void) { btif_a2dp_source_cb.media_alarm.SchedulePeriodic( btif_a2dp_source_thread.GetWeakPtr(), FROM_HERE, base::BindRepeating(&btif_a2dp_source_audio_handle_timer), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds( -#else - base::Milliseconds( -#endif + std::chrono::milliseconds( btif_a2dp_source_cb.encoder_interface->get_encoder_interval_ms())); btif_a2dp_source_cb.sw_audio_is_encoding = true; diff --git a/system/common/message_loop_thread.cc b/system/common/message_loop_thread.cc index 7d9240cee5..faca7f0754 100644 --- a/system/common/message_loop_thread.cc +++ b/system/common/message_loop_thread.cc @@ -20,6 +20,7 @@ #include <base/location.h> #include <base/logging.h> #include <base/strings/stringprintf.h> +#include <base/time/time.h> #include <sys/syscall.h> #include <unistd.h> @@ -33,6 +34,14 @@ namespace common { static constexpr int kRealTimeFifoSchedulingPriority = 1; +static base::TimeDelta timeDeltaFromMicroseconds(std::chrono::microseconds t) { +#if BASE_VER < 931007 + return base::TimeDelta::FromMicroseconds(t.count()); +#else + return base::Microseconds(t.count()); +#endif +} + MessageLoopThread::MessageLoopThread(const std::string& thread_name) : thread_name_(thread_name), message_loop_(nullptr), @@ -63,12 +72,13 @@ void MessageLoopThread::StartUp() { bool MessageLoopThread::DoInThread(const base::Location& from_here, base::OnceClosure task) { - return DoInThreadDelayed(from_here, std::move(task), base::TimeDelta()); + return DoInThreadDelayed(from_here, std::move(task), + std::chrono::microseconds(0)); } bool MessageLoopThread::DoInThreadDelayed(const base::Location& from_here, base::OnceClosure task, - const base::TimeDelta& delay) { + std::chrono::microseconds delay) { std::lock_guard<std::recursive_mutex> api_lock(api_mutex_); if (message_loop_ == nullptr) { @@ -76,8 +86,8 @@ bool MessageLoopThread::DoInThreadDelayed(const base::Location& from_here, << ", from " << from_here.ToString(); return false; } - if (!message_loop_->task_runner()->PostDelayedTask(from_here, std::move(task), - delay)) { + if (!message_loop_->task_runner()->PostDelayedTask( + from_here, std::move(task), timeDeltaFromMicroseconds(delay))) { LOG(ERROR) << __func__ << ": failed to post task to message loop for thread " << *this << ", from " << from_here.ToString(); diff --git a/system/common/message_loop_thread.h b/system/common/message_loop_thread.h index 2f0c5a3517..a8392f3000 100644 --- a/system/common/message_loop_thread.h +++ b/system/common/message_loop_thread.h @@ -166,7 +166,8 @@ class MessageLoopThread final : public IPostableContext { * scheduled */ bool DoInThreadDelayed(const base::Location& from_here, - base::OnceClosure task, const base::TimeDelta& delay); + base::OnceClosure task, + std::chrono::microseconds delay); /** * Wrapper around DoInThread without a location. */ diff --git a/system/common/repeating_timer.cc b/system/common/repeating_timer.cc index 0f7c59266f..9abea46b72 100644 --- a/system/common/repeating_timer.cc +++ b/system/common/repeating_timer.cc @@ -26,11 +26,8 @@ namespace bluetooth { namespace common { -#if BASE_VER < 931007 -constexpr base::TimeDelta kMinimumPeriod = base::TimeDelta::FromMicroseconds(1); -#else -constexpr base::TimeDelta kMinimumPeriod = base::Microseconds(1); -#endif +constexpr std::chrono::microseconds kMinimumPeriod = + std::chrono::microseconds(1); // This runs on user thread RepeatingTimer::~RepeatingTimer() { @@ -44,14 +41,15 @@ RepeatingTimer::~RepeatingTimer() { bool RepeatingTimer::SchedulePeriodic( const base::WeakPtr<MessageLoopThread>& thread, const base::Location& from_here, base::RepeatingClosure task, - base::TimeDelta period) { + std::chrono::microseconds period) { if (period < kMinimumPeriod) { - LOG(ERROR) << __func__ << ": period must be at least " << kMinimumPeriod; + LOG(ERROR) << __func__ << ": period must be at least " + << kMinimumPeriod.count(); return false; } uint64_t time_now_us = time_get_os_boottime_us(); - uint64_t time_next_task_us = time_now_us + period.InMicroseconds(); + uint64_t time_next_task_us = time_now_us + period.count(); std::lock_guard<std::recursive_mutex> api_lock(api_mutex_); if (thread == nullptr) { LOG(ERROR) << __func__ << ": thread must be non-null"; @@ -67,11 +65,7 @@ bool RepeatingTimer::SchedulePeriodic( uint64_t time_until_next_us = time_next_task_us - time_get_os_boottime_us(); if (!thread->DoInThreadDelayed( from_here, task_wrapper_.callback(), -#if BASE_VER < 931007 - base::TimeDelta::FromMicroseconds(time_until_next_us))) { -#else - base::Microseconds(time_until_next_us))) { -#endif + std::chrono::microseconds(time_until_next_us))) { LOG(ERROR) << __func__ << ": failed to post task to message loop for thread " << *thread << ", from " << from_here.ToString(); @@ -124,7 +118,7 @@ void RepeatingTimer::CancelClosure(std::promise<void> promise) { #else task_ = base::NullCallback(); #endif - period_ = base::TimeDelta(); + period_ = std::chrono::microseconds(0); expected_time_next_task_us_ = 0; promise.set_value(); } @@ -146,7 +140,7 @@ void RepeatingTimer::RunTask() { base::PlatformThread::CurrentId()) << ": task must run on message loop thread"; - int64_t period_us = period_.InMicroseconds(); + int64_t period_us = period_.count(); expected_time_next_task_us_ += period_us; uint64_t time_now_us = time_get_os_boottime_us(); int64_t remaining_time_us = expected_time_next_task_us_ - time_now_us; @@ -157,21 +151,17 @@ void RepeatingTimer::RunTask() { } message_loop_thread_->DoInThreadDelayed( FROM_HERE, task_wrapper_.callback(), -#if BASE_VER < 931007 - base::TimeDelta::FromMicroseconds(remaining_time_us)); -#else - base::Microseconds(remaining_time_us)); -#endif + std::chrono::microseconds(remaining_time_us)); uint64_t time_before_task_us = time_get_os_boottime_us(); task_.Run(); uint64_t time_after_task_us = time_get_os_boottime_us(); auto task_time_us = static_cast<int64_t>(time_after_task_us - time_before_task_us); - if (task_time_us > period_.InMicroseconds()) { + if (task_time_us > period_.count()) { LOG(ERROR) << __func__ << ": Periodic task execution took " << task_time_us - << " microseconds, longer than interval " - << period_.InMicroseconds() << " microseconds"; + << " microseconds, longer than interval " << period_.count() + << " microseconds"; } } diff --git a/system/common/repeating_timer.h b/system/common/repeating_timer.h index 9319fa9880..6398af224b 100644 --- a/system/common/repeating_timer.h +++ b/system/common/repeating_timer.h @@ -19,8 +19,8 @@ #include <base/cancelable_callback.h> #include <base/functional/bind.h> #include <base/location.h> -#include <base/time/time.h> +#include <chrono> #include <future> namespace bluetooth { @@ -58,7 +58,8 @@ class RepeatingTimer final { */ bool SchedulePeriodic(const base::WeakPtr<MessageLoopThread>& thread, const base::Location& from_here, - base::RepeatingClosure task, base::TimeDelta period); + base::RepeatingClosure task, + std::chrono::microseconds period); /** * Post an event which cancels the current task asynchronously @@ -81,7 +82,7 @@ class RepeatingTimer final { base::WeakPtr<MessageLoopThread> message_loop_thread_; base::CancelableClosure task_wrapper_; base::RepeatingClosure task_; - base::TimeDelta period_; + std::chrono::microseconds period_; uint64_t expected_time_next_task_us_; // Using clock boot time in time_util.h mutable std::recursive_mutex api_mutex_; void CancelHelper(std::promise<void> promise); diff --git a/system/common/repeating_timer_unittest.cc b/system/common/repeating_timer_unittest.cc index 65bee83b76..510e2483fe 100644 --- a/system/common/repeating_timer_unittest.cc +++ b/system/common/repeating_timer_unittest.cc @@ -86,11 +86,7 @@ class RepeatingTimerTest : public ::testing::Test { base::Unretained(this), start_time, interval_between_tasks_ms, scheduled_tasks, task_length_ms, promise_), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(interval_between_tasks_ms)); -#else - base::Milliseconds(interval_between_tasks_ms)); -#endif + std::chrono::milliseconds(interval_between_tasks_ms)); future.get(); timer_->CancelAndWait(); } @@ -147,11 +143,7 @@ TEST_F(RepeatingTimerTest, periodic_run) { message_loop_thread.GetWeakPtr(), FROM_HERE, base::BindRepeating(&RepeatingTimerTest::IncreaseTaskCounter, base::Unretained(this), num_tasks, promise_), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(delay_ms)); -#else - base::Milliseconds(delay_ms)); -#endif + std::chrono::milliseconds(delay_ms)); future.get(); ASSERT_GE(counter_, num_tasks); timer_->CancelAndWait(); @@ -167,11 +159,7 @@ TEST_F(RepeatingTimerTest, schedule_periodic_task_zero_interval) { message_loop_thread.GetWeakPtr(), FROM_HERE, base::BindRepeating(&RepeatingTimerTest::ShouldNotHappen, base::Unretained(this)), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(interval_ms))); -#else - base::Milliseconds(interval_ms))); -#endif + std::chrono::milliseconds(interval_ms))); std::this_thread::sleep_for(std::chrono::milliseconds(delay_error_ms)); } @@ -185,11 +173,7 @@ TEST_F(RepeatingTimerTest, periodic_delete_without_cancel) { message_loop_thread.GetWeakPtr(), FROM_HERE, base::BindRepeating(&RepeatingTimerTest::ShouldNotHappen, base::Unretained(this)), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(delay_ms)); -#else - base::Milliseconds(delay_ms)); -#endif + std::chrono::milliseconds(delay_ms)); delete timer_; timer_ = nullptr; std::this_thread::sleep_for(std::chrono::milliseconds(delay_error_ms)); @@ -202,11 +186,7 @@ TEST_F(RepeatingTimerTest, cancel_single_task_near_fire_no_race_condition) { uint32_t delay_ms = 5; timer_->SchedulePeriodic(message_loop_thread.GetWeakPtr(), FROM_HERE, base::DoNothing(), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(delay_ms)); -#else - base::Milliseconds(delay_ms)); -#endif + std::chrono::milliseconds(delay_ms)); std::this_thread::sleep_for(std::chrono::milliseconds(delay_ms)); timer_->CancelAndWait(); } @@ -223,11 +203,7 @@ TEST_F(RepeatingTimerTest, cancel_periodic_task) { message_loop_thread.GetWeakPtr(), FROM_HERE, base::BindRepeating(&RepeatingTimerTest::IncreaseTaskCounter, base::Unretained(this), num_tasks, promise_), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(delay_ms)); -#else - base::Milliseconds(delay_ms)); -#endif + std::chrono::milliseconds(delay_ms)); future.wait(); timer_->CancelAndWait(); std::this_thread::sleep_for( @@ -264,11 +240,7 @@ TEST_F(RepeatingTimerTest, message_loop_thread.GetWeakPtr(), FROM_HERE, base::BindRepeating(&RepeatingTimerTest::IncreaseTaskCounter, base::Unretained(this), num_tasks, promise_), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(delay_ms)); -#else - base::Milliseconds(delay_ms)); -#endif + std::chrono::milliseconds(delay_ms)); future.wait(); message_loop_thread.ShutDown(); std::this_thread::sleep_for( diff --git a/system/osi/test/alarm_test.cc b/system/osi/test/alarm_test.cc index f0e4d71da7..f6ec145472 100644 --- a/system/osi/test/alarm_test.cc +++ b/system/osi/test/alarm_test.cc @@ -29,7 +29,6 @@ #include "osi/semaphore.h" using base::Closure; -using base::TimeDelta; using bluetooth::common::MessageLoopThread; static semaphore_t* semaphore; diff --git a/system/osi/test/fuzzers/alarm/fuzz_alarm.cc b/system/osi/test/fuzzers/alarm/fuzz_alarm.cc index 126078ded3..f312dde363 100644 --- a/system/osi/test/fuzzers/alarm/fuzz_alarm.cc +++ b/system/osi/test/fuzzers/alarm/fuzz_alarm.cc @@ -21,7 +21,6 @@ #include "common/message_loop_thread.h" using base::Closure; -using base::TimeDelta; using bluetooth::common::MessageLoopThread; #define MAX_CONCURRENT_ALARMS 25 diff --git a/system/stack/btm/btm_sec.cc b/system/stack/btm/btm_sec.cc index b4550d17af..cbc84dd36c 100644 --- a/system/stack/btm/btm_sec.cc +++ b/system/stack/btm/btm_sec.cc @@ -4493,11 +4493,7 @@ static void btm_sec_wait_and_start_authentication(tBTM_SEC_DEV_REC* p_dev_rec) { bt_status_t status = do_in_main_thread_delayed( FROM_HERE, base::Bind(&btm_sec_auth_timer_timeout, addr), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(delay_auth)); -#else - base::Milliseconds(delay_auth)); -#endif + std::chrono::milliseconds(delay_auth)); if (status != BT_STATUS_SUCCESS) { LOG_ERROR("do_in_main_thread_delayed failed. directly calling"); btm_sec_auth_timer_timeout(addr); diff --git a/system/stack/btu/main_thread.cc b/system/stack/btu/main_thread.cc index b41a56bcfb..f29c4b8020 100644 --- a/system/stack/btu/main_thread.cc +++ b/system/stack/btu/main_thread.cc @@ -46,7 +46,7 @@ bt_status_t do_in_main_thread(const base::Location& from_here, bt_status_t do_in_main_thread_delayed(const base::Location& from_here, base::OnceClosure task, - const base::TimeDelta& delay) { + std::chrono::microseconds delay) { if (!main_thread.DoInThreadDelayed(from_here, std::move(task), delay)) { LOG(ERROR) << __func__ << ": failed from " << from_here.ToString(); return BT_STATUS_FAIL; diff --git a/system/stack/eatt/eatt_impl.h b/system/stack/eatt/eatt_impl.h index 240ac7e57b..63cd990fc9 100644 --- a/system/stack/eatt/eatt_impl.h +++ b/system/stack/eatt/eatt_impl.h @@ -240,12 +240,7 @@ struct eatt_impl { FROM_HERE, base::BindOnce(&eatt_impl::upper_tester_delay_connect_cb, base::Unretained(this), bda), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(timeout_ms) -#else - base::Milliseconds(timeout_ms) -#endif - ); + std::chrono::milliseconds(timeout_ms)); LOG_INFO("Scheduled peripheral connect eatt for device with status: %d", (int)status); @@ -292,12 +287,7 @@ struct eatt_impl { FROM_HERE, base::BindOnce(&eatt_impl::reconfigure_all, base::Unretained(this), bda, 300), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(4000) -#else - base::Milliseconds(4000) -#endif - ); + std::chrono::seconds(4)); LOG_INFO("Scheduled ECOC reconfiguration with status: %d", (int)status); } } @@ -456,12 +446,7 @@ struct eatt_impl { FROM_HERE, base::BindOnce(&eatt_impl::upper_tester_send_data_if_needed, base::Unretained(this), bda, lcid), -#if BASE_VER < 931007 - base::TimeDelta::FromMilliseconds(1000) -#else - base::Milliseconds(1000) -#endif - ); + std::chrono::seconds(1)); } } diff --git a/system/stack/fuzzers/gatt_fuzzer.cc b/system/stack/fuzzers/gatt_fuzzer.cc index 6444e5a870..03f5a0f123 100644 --- a/system/stack/fuzzers/gatt_fuzzer.cc +++ b/system/stack/fuzzers/gatt_fuzzer.cc @@ -24,7 +24,7 @@ bt_status_t do_in_main_thread(base::Location const&, } bt_status_t do_in_main_thread_delayed(base::Location const&, base::OnceCallback<void()>, - base::TimeDelta const&) { + std::chrono::microseconds) { // this is not properly mocked, so we use abort to catch if this is used in // any test cases abort(); diff --git a/system/stack/fuzzers/l2cap_fuzzer.cc b/system/stack/fuzzers/l2cap_fuzzer.cc index 01d7d7de30..5551f1773a 100644 --- a/system/stack/fuzzers/l2cap_fuzzer.cc +++ b/system/stack/fuzzers/l2cap_fuzzer.cc @@ -55,7 +55,7 @@ bt_status_t do_in_main_thread(base::Location const&, } bt_status_t do_in_main_thread_delayed(base::Location const&, base::OnceCallback<void()>, - base::TimeDelta const&) { + std::chrono::microseconds) { // this is not properly mocked, so we use abort to catch if this is used in // any test cases abort(); diff --git a/system/stack/include/main_thread.h b/system/stack/include/main_thread.h index 454c0db696..5c3b124048 100644 --- a/system/stack/include/main_thread.h +++ b/system/stack/include/main_thread.h @@ -31,7 +31,7 @@ bt_status_t do_in_main_thread(const base::Location& from_here, base::OnceClosure task); bt_status_t do_in_main_thread_delayed(const base::Location& from_here, base::OnceClosure task, - const base::TimeDelta& delay); + std::chrono::microseconds delay); void post_on_bt_main(BtMainClosure closure); void main_thread_start_up(); void main_thread_shut_down(); diff --git a/system/test/common/main_handler.cc b/system/test/common/main_handler.cc index af7cc06efa..fa1b853c83 100644 --- a/system/test/common/main_handler.cc +++ b/system/test/common/main_handler.cc @@ -17,9 +17,9 @@ #include <base/functional/bind.h> #include <base/functional/callback_forward.h> #include <base/location.h> -#include <base/time/time.h> #include <sys/types.h> #include <unistd.h> + #include <functional> #include <future> @@ -46,7 +46,7 @@ bt_status_t do_in_main_thread(const base::Location& from_here, bt_status_t do_in_main_thread_delayed(const base::Location& from_here, base::OnceClosure task, - const base::TimeDelta& delay) { + std::chrono::microseconds delay) { ASSERT_LOG(!main_thread.DoInThreadDelayed(from_here, std::move(task), delay), "Unable to run on main thread delayed"); return BT_STATUS_SUCCESS; diff --git a/system/test/common/main_handler.h b/system/test/common/main_handler.h index 9719fa4a5c..2fee7aaa5e 100644 --- a/system/test/common/main_handler.h +++ b/system/test/common/main_handler.h @@ -18,7 +18,7 @@ #include <base/functional/callback_forward.h> #include <base/location.h> -#include <base/time/time.h> + #include <functional> #include "common/message_loop_thread.h" @@ -30,7 +30,7 @@ bt_status_t do_in_main_thread(const base::Location& from_here, base::OnceClosure task); bt_status_t do_in_main_thread_delayed(const base::Location& from_here, base::OnceClosure task, - const base::TimeDelta& delay); + std::chrono::microseconds delay); void post_on_bt_main(BtMainClosure closure); void main_thread_start_up(); void main_thread_shut_down(); diff --git a/system/test/mock/mock_bta_sys_main.cc b/system/test/mock/mock_bta_sys_main.cc index 56ae8ea8bb..2b023e3ceb 100644 --- a/system/test/mock/mock_bta_sys_main.cc +++ b/system/test/mock/mock_bta_sys_main.cc @@ -83,7 +83,7 @@ void bta_sys_sendmsg(void* p_msg) { inc_func_call_count(__func__); test::mock::bta_sys_main::bta_sys_sendmsg(p_msg); } -void bta_sys_sendmsg_delayed(void* p_msg, const base::TimeDelta& delay) { +void bta_sys_sendmsg_delayed(void* p_msg, std::chrono::microseconds delay) { inc_func_call_count(__func__); test::mock::bta_sys_main::bta_sys_sendmsg_delayed(p_msg, delay); } diff --git a/system/test/mock/mock_bta_sys_main.h b/system/test/mock/mock_bta_sys_main.h index 5ddf18b41d..0659ded844 100644 --- a/system/test/mock/mock_bta_sys_main.h +++ b/system/test/mock/mock_bta_sys_main.h @@ -111,12 +111,12 @@ struct bta_sys_sendmsg { extern struct bta_sys_sendmsg bta_sys_sendmsg; // Name: bta_sys_sendmsg_delayed -// Params: void* p_msg, const base::TimeDelta& delay +// Params: void* p_msg, std::chrono::microseconds delay // Return: void struct bta_sys_sendmsg_delayed { - std::function<void(void* p_msg, const base::TimeDelta& delay)> body{ - [](void* p_msg, const base::TimeDelta& delay) {}}; - void operator()(void* p_msg, const base::TimeDelta& delay) { + std::function<void(void* p_msg, std::chrono::microseconds delay)> body{ + [](void* p_msg, std::chrono::microseconds delay) {}}; + void operator()(void* p_msg, std::chrono::microseconds delay) { body(p_msg, delay); }; }; diff --git a/system/test/mock/mock_stack_btm_ble_scanner.cc b/system/test/mock/mock_stack_btm_ble_scanner.cc index 63951f555e..e65f1f7e59 100644 --- a/system/test/mock/mock_stack_btm_ble_scanner.cc +++ b/system/test/mock/mock_stack_btm_ble_scanner.cc @@ -19,7 +19,6 @@ #include <base/logging.h> #include <base/memory/weak_ptr.h> #include <base/strings/string_number_conversions.h> -#include <base/time/time.h> #include "ble_scanner.h" #include "stack/btm/ble_scanner_hci_interface.h" |