Commit ec8f4f09 authored by tzik's avatar tzik Committed by Commit Bot

Use the shared instance of base::Default{,Tick}Clock in media/

This CL changes the ownership of base::Clock and base::TickClock from
injectee-owned to injecter-owned. Before this CL, these instances are
owned by the owner of the injectee or one of the injectees themselves.
That makes the ownership handling complex.

After this CL, the injectee of clocks never own the clock. Instead,
injecters owns a clock for testing, and a shared clock is used on the
production code.

Bug: 789079
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ic6e68a02228f1678e22569c38257e599d4d4e432
Reviewed-on: https://chromium-review.googlesource.com/937009Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542119}
parent 78e5247d
...@@ -117,7 +117,7 @@ class DesktopCaptureDevice::Core : public webrtc::DesktopCapturer::Callback { ...@@ -117,7 +117,7 @@ class DesktopCaptureDevice::Core : public webrtc::DesktopCapturer::Callback {
void SetMockTimeForTesting( void SetMockTimeForTesting(
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
std::unique_ptr<base::TickClock> tick_clock); base::TickClock* tick_clock);
private: private:
// webrtc::DesktopCapturer::Callback interface. // webrtc::DesktopCapturer::Callback interface.
...@@ -166,7 +166,7 @@ class DesktopCaptureDevice::Core : public webrtc::DesktopCapturer::Callback { ...@@ -166,7 +166,7 @@ class DesktopCaptureDevice::Core : public webrtc::DesktopCapturer::Callback {
// be returned to the caller directly then this is NULL. // be returned to the caller directly then this is NULL.
std::unique_ptr<webrtc::DesktopFrame> output_frame_; std::unique_ptr<webrtc::DesktopFrame> output_frame_;
std::unique_ptr<base::TickClock> tick_clock_; base::TickClock* tick_clock_ = nullptr;
// Timer used to capture the frame. // Timer used to capture the frame.
std::unique_ptr<base::OneShotTimer> capture_timer_; std::unique_ptr<base::OneShotTimer> capture_timer_;
...@@ -204,7 +204,6 @@ DesktopCaptureDevice::Core::Core( ...@@ -204,7 +204,6 @@ DesktopCaptureDevice::Core::Core(
DesktopMediaID::Type type) DesktopMediaID::Type type)
: task_runner_(task_runner), : task_runner_(task_runner),
desktop_capturer_(std::move(capturer)), desktop_capturer_(std::move(capturer)),
tick_clock_(nullptr),
capture_timer_(new base::OneShotTimer()), capture_timer_(new base::OneShotTimer()),
max_cpu_consumption_percentage_(GetMaximumCpuConsumptionPercentage()), max_cpu_consumption_percentage_(GetMaximumCpuConsumptionPercentage()),
capture_in_progress_(false), capture_in_progress_(false),
...@@ -268,9 +267,9 @@ void DesktopCaptureDevice::Core::SetNotificationWindowId( ...@@ -268,9 +267,9 @@ void DesktopCaptureDevice::Core::SetNotificationWindowId(
void DesktopCaptureDevice::Core::SetMockTimeForTesting( void DesktopCaptureDevice::Core::SetMockTimeForTesting(
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
std::unique_ptr<base::TickClock> tick_clock) { base::TickClock* tick_clock) {
tick_clock_ = std::move(tick_clock); tick_clock_ = tick_clock;
capture_timer_.reset(new base::OneShotTimer(tick_clock_.get())); capture_timer_.reset(new base::OneShotTimer(tick_clock_));
capture_timer_->SetTaskRunner(task_runner); capture_timer_->SetTaskRunner(task_runner);
} }
...@@ -577,8 +576,8 @@ DesktopCaptureDevice::DesktopCaptureDevice( ...@@ -577,8 +576,8 @@ DesktopCaptureDevice::DesktopCaptureDevice(
void DesktopCaptureDevice::SetMockTimeForTesting( void DesktopCaptureDevice::SetMockTimeForTesting(
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
std::unique_ptr<base::TickClock> tick_clock) { base::TickClock* tick_clock) {
core_->SetMockTimeForTesting(task_runner, std::move(tick_clock)); core_->SetMockTimeForTesting(task_runner, tick_clock);
} }
} // namespace content } // namespace content
...@@ -63,7 +63,7 @@ class CONTENT_EXPORT DesktopCaptureDevice : public media::VideoCaptureDevice { ...@@ -63,7 +63,7 @@ class CONTENT_EXPORT DesktopCaptureDevice : public media::VideoCaptureDevice {
// other testing entities inheriting the common runner and tick interfaces. // other testing entities inheriting the common runner and tick interfaces.
void SetMockTimeForTesting( void SetMockTimeForTesting(
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
std::unique_ptr<base::TickClock> tick_clock); base::TickClock* tick_clock);
base::Thread thread_; base::Thread thread_;
std::unique_ptr<Core> core_; std::unique_ptr<Core> core_;
......
...@@ -602,7 +602,7 @@ class DesktopCaptureDeviceThrottledTest : public DesktopCaptureDeviceTest { ...@@ -602,7 +602,7 @@ class DesktopCaptureDeviceThrottledTest : public DesktopCaptureDeviceTest {
base::TestMockTimeTaskRunner::Type::kStandalone); base::TestMockTimeTaskRunner::Type::kStandalone);
capture_device_->SetMockTimeForTesting( capture_device_->SetMockTimeForTesting(
task_runner, task_runner->DeprecatedGetMockTickClock()); task_runner, task_runner->GetMockTickClock());
})); }));
EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _)) EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _, _, _))
......
...@@ -33,7 +33,7 @@ AudioTrackOutputStream::AudioTrackOutputStream(AudioManagerBase* manager, ...@@ -33,7 +33,7 @@ AudioTrackOutputStream::AudioTrackOutputStream(AudioManagerBase* manager,
const AudioParameters& params) const AudioParameters& params)
: params_(params), : params_(params),
audio_manager_(manager), audio_manager_(manager),
tick_clock_(new base::DefaultTickClock()) { tick_clock_(base::DefaultTickClock::GetInstance()) {
if (!params_.IsBitstreamFormat()) { if (!params_.IsBitstreamFormat()) {
audio_bus_ = AudioBus::Create(params_); audio_bus_ = AudioBus::Create(params_);
} }
......
...@@ -54,7 +54,7 @@ class MEDIA_EXPORT AudioTrackOutputStream : public MuteableAudioOutputStream { ...@@ -54,7 +54,7 @@ class MEDIA_EXPORT AudioTrackOutputStream : public MuteableAudioOutputStream {
// Extra buffer for PCM format. // Extra buffer for PCM format.
std::unique_ptr<AudioBus> audio_bus_; std::unique_ptr<AudioBus> audio_bus_;
std::unique_ptr<base::TickClock> tick_clock_; base::TickClock* tick_clock_;
// Java AudioTrackOutputStream instance. // Java AudioTrackOutputStream instance.
base::android::ScopedJavaGlobalRef<jobject> j_audio_output_stream_; base::android::ScopedJavaGlobalRef<jobject> j_audio_output_stream_;
......
...@@ -32,7 +32,8 @@ static std::string RoleToString(ERole role) { ...@@ -32,7 +32,8 @@ static std::string RoleToString(ERole role) {
} }
AudioDeviceListenerWin::AudioDeviceListenerWin(const base::Closure& listener_cb) AudioDeviceListenerWin::AudioDeviceListenerWin(const base::Closure& listener_cb)
: listener_cb_(listener_cb), tick_clock_(new base::DefaultTickClock()) { : listener_cb_(listener_cb),
tick_clock_(base::DefaultTickClock::GetInstance()) {
// CreateDeviceEnumerator can fail on some installations of Windows such // CreateDeviceEnumerator can fail on some installations of Windows such
// as "Windows Server 2008 R2" where the desktop experience isn't available. // as "Windows Server 2008 R2" where the desktop experience isn't available.
Microsoft::WRL::ComPtr<IMMDeviceEnumerator> device_enumerator( Microsoft::WRL::ComPtr<IMMDeviceEnumerator> device_enumerator(
......
...@@ -65,7 +65,7 @@ class MEDIA_EXPORT AudioDeviceListenerWin : public IMMNotificationClient { ...@@ -65,7 +65,7 @@ class MEDIA_EXPORT AudioDeviceListenerWin : public IMMNotificationClient {
// AudioDeviceListenerWin must be constructed and destructed on one thread. // AudioDeviceListenerWin must be constructed and destructed on one thread.
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
std::unique_ptr<base::TickClock> tick_clock_; base::TickClock* tick_clock_;
DISALLOW_COPY_AND_ASSIGN(AudioDeviceListenerWin); DISALLOW_COPY_AND_ASSIGN(AudioDeviceListenerWin);
}; };
......
...@@ -39,13 +39,12 @@ class AudioDeviceListenerWinTest : public testing::Test { ...@@ -39,13 +39,12 @@ class AudioDeviceListenerWinTest : public testing::Test {
output_device_listener_.reset(new AudioDeviceListenerWin(base::Bind( output_device_listener_.reset(new AudioDeviceListenerWin(base::Bind(
&AudioDeviceListenerWinTest::OnDeviceChange, base::Unretained(this)))); &AudioDeviceListenerWinTest::OnDeviceChange, base::Unretained(this))));
tick_clock_ = new base::SimpleTestTickClock(); tick_clock_.Advance(base::TimeDelta::FromSeconds(12345));
tick_clock_->Advance(base::TimeDelta::FromSeconds(12345)); output_device_listener_->tick_clock_ = &tick_clock_;
output_device_listener_->tick_clock_.reset(tick_clock_);
} }
void AdvanceLastDeviceChangeTime() { void AdvanceLastDeviceChangeTime() {
tick_clock_->Advance(base::TimeDelta::FromMilliseconds( tick_clock_.Advance(base::TimeDelta::FromMilliseconds(
AudioDeviceListenerWin::kDeviceChangeLimitMs + 1)); AudioDeviceListenerWin::kDeviceChangeLimitMs + 1));
} }
...@@ -68,7 +67,7 @@ class AudioDeviceListenerWinTest : public testing::Test { ...@@ -68,7 +67,7 @@ class AudioDeviceListenerWinTest : public testing::Test {
private: private:
ScopedCOMInitializer com_init_; ScopedCOMInitializer com_init_;
std::unique_ptr<AudioDeviceListenerWin> output_device_listener_; std::unique_ptr<AudioDeviceListenerWin> output_device_listener_;
base::SimpleTestTickClock* tick_clock_; base::SimpleTestTickClock tick_clock_;
DISALLOW_COPY_AND_ASSIGN(AudioDeviceListenerWinTest); DISALLOW_COPY_AND_ASSIGN(AudioDeviceListenerWinTest);
}; };
......
...@@ -84,7 +84,7 @@ MediaServiceThrottler* MediaServiceThrottler::GetInstance() { ...@@ -84,7 +84,7 @@ MediaServiceThrottler* MediaServiceThrottler::GetInstance() {
MediaServiceThrottler::~MediaServiceThrottler() {} MediaServiceThrottler::~MediaServiceThrottler() {}
MediaServiceThrottler::MediaServiceThrottler() MediaServiceThrottler::MediaServiceThrottler()
: clock_(new base::DefaultTickClock()), : clock_(base::DefaultTickClock::GetInstance()),
current_crashes_(0), current_crashes_(0),
crash_listener_task_runner_(base::ThreadTaskRunnerHandle::Get()) { crash_listener_task_runner_(base::ThreadTaskRunnerHandle::Get()) {
// base::Unretained is safe because the MediaServiceThrottler is supposed to // base::Unretained is safe because the MediaServiceThrottler is supposed to
...@@ -95,7 +95,7 @@ MediaServiceThrottler::MediaServiceThrottler() ...@@ -95,7 +95,7 @@ MediaServiceThrottler::MediaServiceThrottler()
} }
void MediaServiceThrottler::SetTickClockForTesting(base::TickClock* clock) { void MediaServiceThrottler::SetTickClockForTesting(base::TickClock* clock) {
clock_.reset(clock); clock_ = clock;
} }
base::TimeDelta MediaServiceThrottler::GetBaseThrottlingRateForTesting() { base::TimeDelta MediaServiceThrottler::GetBaseThrottlingRateForTesting() {
......
...@@ -79,7 +79,7 @@ class MEDIA_EXPORT MediaServiceThrottler { ...@@ -79,7 +79,7 @@ class MEDIA_EXPORT MediaServiceThrottler {
// based on |current_crashes_|. // based on |current_crashes_|.
base::TimeDelta GetThrottlingDelayFromServerCrashes(); base::TimeDelta GetThrottlingDelayFromServerCrashes();
std::unique_ptr<base::TickClock> clock_; base::TickClock* clock_;
// Effective number of media server crashes. // Effective number of media server crashes.
// NOTE: This is of type double because we decay the number of crashes at a // NOTE: This is of type double because we decay the number of crashes at a
......
...@@ -18,12 +18,12 @@ const int kMaxBurstClients = 10; ...@@ -18,12 +18,12 @@ const int kMaxBurstClients = 10;
class MediaServiceThrottlerTest : public testing::Test { class MediaServiceThrottlerTest : public testing::Test {
public: public:
MediaServiceThrottlerTest() : clock_(new base::SimpleTestTickClock()) { MediaServiceThrottlerTest() {
throttler_ = MediaServiceThrottler::GetInstance(); throttler_ = MediaServiceThrottler::GetInstance();
clock_->SetNowTicks(base::TimeTicks()); clock_.SetNowTicks(base::TimeTicks());
throttler_->SetTickClockForTesting(clock_); throttler_->SetTickClockForTesting(&clock_);
test_task_runner_ = test_task_runner_ =
base::MakeRefCounted<FakeSingleThreadTaskRunner>(clock_); base::MakeRefCounted<FakeSingleThreadTaskRunner>(&clock_);
throttler_->ResetInternalStateForTesting(); throttler_->ResetInternalStateForTesting();
throttler_->SetCrashListenerTaskRunnerForTesting(test_task_runner_); throttler_->SetCrashListenerTaskRunnerForTesting(test_task_runner_);
base_delay_ = throttler_->GetBaseThrottlingRateForTesting(); base_delay_ = throttler_->GetBaseThrottlingRateForTesting();
...@@ -50,10 +50,10 @@ class MediaServiceThrottlerTest : public testing::Test { ...@@ -50,10 +50,10 @@ class MediaServiceThrottlerTest : public testing::Test {
throttler_->GetDelayForClientCreation()); throttler_->GetDelayForClientCreation());
} }
base::TimeTicks TestNow() { return clock_->NowTicks(); } base::TimeTicks TestNow() { return clock_.NowTicks(); }
MediaServiceThrottler* throttler_; MediaServiceThrottler* throttler_;
base::SimpleTestTickClock* clock_; base::SimpleTestTickClock clock_;
base::TimeDelta base_delay_; base::TimeDelta base_delay_;
...@@ -114,7 +114,7 @@ TEST_F(MediaServiceThrottlerTest, ...@@ -114,7 +114,7 @@ TEST_F(MediaServiceThrottlerTest,
// Schedule some clients below the burst threshold. // Schedule some clients below the burst threshold.
SimulateClientCreations(7); SimulateClientCreations(7);
clock_->Advance(base_delay_ * 5); clock_.Advance(base_delay_ * 5);
// Make sure the passage of allows for more clients to be scheduled, since // Make sure the passage of allows for more clients to be scheduled, since
// 7 + 8 > kMaxBurstClients. // 7 + 8 > kMaxBurstClients.
...@@ -129,7 +129,7 @@ TEST_F(MediaServiceThrottlerTest, ...@@ -129,7 +129,7 @@ TEST_F(MediaServiceThrottlerTest,
SimulateClientCreations(3 * kMaxBurstClients); SimulateClientCreations(3 * kMaxBurstClients);
// Advance the time so there are still 2 * kMaxBurstClients pending clients. // Advance the time so there are still 2 * kMaxBurstClients pending clients.
clock_->Advance(base_delay_ * kMaxBurstClients); clock_.Advance(base_delay_ * kMaxBurstClients);
// Make sure delay we do not burst schedule new clients. // Make sure delay we do not burst schedule new clients.
EXPECT_NE(base::TimeDelta(), throttler_->GetDelayForClientCreation()); EXPECT_NE(base::TimeDelta(), throttler_->GetDelayForClientCreation());
...@@ -142,7 +142,7 @@ TEST_F(MediaServiceThrottlerTest, NoCrash_LongInactivity_ShouldReset) { ...@@ -142,7 +142,7 @@ TEST_F(MediaServiceThrottlerTest, NoCrash_LongInactivity_ShouldReset) {
SimulateClientCreations(base::TimeDelta::FromMinutes(2) / base_delay_); SimulateClientCreations(base::TimeDelta::FromMinutes(2) / base_delay_);
// Advance the time so the scheduler perceived a full minute of inactivity. // Advance the time so the scheduler perceived a full minute of inactivity.
clock_->Advance(base::TimeDelta::FromSeconds(61)); clock_.Advance(base::TimeDelta::FromSeconds(61));
// Make sure new clients are burst scheduled. // Make sure new clients are burst scheduled.
EXPECT_EQ(base::TimeDelta(), throttler_->GetDelayForClientCreation()); EXPECT_EQ(base::TimeDelta(), throttler_->GetDelayForClientCreation());
...@@ -170,7 +170,7 @@ TEST_F(MediaServiceThrottlerTest, ...@@ -170,7 +170,7 @@ TEST_F(MediaServiceThrottlerTest,
SimulateClientCreations(kMaxBurstClients); SimulateClientCreations(kMaxBurstClients);
SimulateCrashes(1); SimulateCrashes(1);
clock_->Advance(base::TimeDelta::FromMilliseconds(1)); clock_.Advance(base::TimeDelta::FromMilliseconds(1));
// Because we use the floor function when calculating crashes, a small time // Because we use the floor function when calculating crashes, a small time
// advance should nullify a single crash. // advance should nullify a single crash.
...@@ -183,7 +183,7 @@ TEST_F(MediaServiceThrottlerTest, WithCrash_ManyCrashes_DelayShouldIncrease) { ...@@ -183,7 +183,7 @@ TEST_F(MediaServiceThrottlerTest, WithCrash_ManyCrashes_DelayShouldIncrease) {
SimulateClientCreations(kMaxBurstClients); SimulateClientCreations(kMaxBurstClients);
SimulateCrashes(2); SimulateCrashes(2);
clock_->Advance(base::TimeDelta::FromMilliseconds(1)); clock_.Advance(base::TimeDelta::FromMilliseconds(1));
// The delay after crashes should be greater than the base delay. // The delay after crashes should be greater than the base delay.
EXPECT_LT(base_delay_, GetCurrentDelayBetweenClients()); EXPECT_LT(base_delay_, GetCurrentDelayBetweenClients());
...@@ -236,7 +236,7 @@ TEST_F(MediaServiceThrottlerTest, WithCrash_NoCrashesForAMinute_ShouldReset) { ...@@ -236,7 +236,7 @@ TEST_F(MediaServiceThrottlerTest, WithCrash_NoCrashesForAMinute_ShouldReset) {
// The effective server crash count should be reset because it has been over // The effective server crash count should be reset because it has been over
// a minute since the last crash. // a minute since the last crash.
clock_->Advance(base::TimeDelta::FromSeconds(61)); clock_.Advance(base::TimeDelta::FromSeconds(61));
SimulateClientCreations(kMaxBurstClients); SimulateClientCreations(kMaxBurstClients);
...@@ -248,9 +248,9 @@ TEST_F(MediaServiceThrottlerTest, WithCrash_ConstantCrashes_ShouldNotReset) { ...@@ -248,9 +248,9 @@ TEST_F(MediaServiceThrottlerTest, WithCrash_ConstantCrashes_ShouldNotReset) {
SimulateCrashes(9); SimulateCrashes(9);
// The effective server crash count should not be reset. // The effective server crash count should not be reset.
clock_->Advance(base::TimeDelta::FromSeconds(59)); clock_.Advance(base::TimeDelta::FromSeconds(59));
SimulateCrashes(1); SimulateCrashes(1);
clock_->Advance(base::TimeDelta::FromSeconds(2)); clock_.Advance(base::TimeDelta::FromSeconds(2));
SimulateClientCreations(kMaxBurstClients); SimulateClientCreations(kMaxBurstClients);
...@@ -266,7 +266,7 @@ TEST_F(MediaServiceThrottlerTest, CrashListener_NoRequests_ShouldShutDown) { ...@@ -266,7 +266,7 @@ TEST_F(MediaServiceThrottlerTest, CrashListener_NoRequests_ShouldShutDown) {
SimulateClientCreations(base::TimeDelta::FromMinutes(3) / base_delay_); SimulateClientCreations(base::TimeDelta::FromMinutes(3) / base_delay_);
// The MediaServerCrashListener should be alive, with 1s second to spare. // The MediaServerCrashListener should be alive, with 1s second to spare.
clock_->Advance(base::TimeDelta::FromSeconds(59)); clock_.Advance(base::TimeDelta::FromSeconds(59));
test_task_runner_->RunTasks(); test_task_runner_->RunTasks();
EXPECT_TRUE(throttler_->IsCrashListenerAliveForTesting()); EXPECT_TRUE(throttler_->IsCrashListenerAliveForTesting());
...@@ -275,12 +275,12 @@ TEST_F(MediaServiceThrottlerTest, CrashListener_NoRequests_ShouldShutDown) { ...@@ -275,12 +275,12 @@ TEST_F(MediaServiceThrottlerTest, CrashListener_NoRequests_ShouldShutDown) {
throttler_->GetDelayForClientCreation(); throttler_->GetDelayForClientCreation();
// The MediaServerCrashListener should be alive, with 58s second to spare. // The MediaServerCrashListener should be alive, with 58s second to spare.
clock_->Advance(base::TimeDelta::FromSeconds(2)); clock_.Advance(base::TimeDelta::FromSeconds(2));
test_task_runner_->RunTasks(); test_task_runner_->RunTasks();
EXPECT_TRUE(throttler_->IsCrashListenerAliveForTesting()); EXPECT_TRUE(throttler_->IsCrashListenerAliveForTesting());
// The MediaServerCrashListener should be dead. // The MediaServerCrashListener should be dead.
clock_->Advance(base::TimeDelta::FromSeconds(59)); clock_.Advance(base::TimeDelta::FromSeconds(59));
test_task_runner_->RunTasks(); test_task_runner_->RunTasks();
EXPECT_FALSE(throttler_->IsCrashListenerAliveForTesting()); EXPECT_FALSE(throttler_->IsCrashListenerAliveForTesting());
} }
...@@ -295,7 +295,7 @@ TEST_F(MediaServiceThrottlerTest, ...@@ -295,7 +295,7 @@ TEST_F(MediaServiceThrottlerTest,
SimulateClientCreations(base::TimeDelta::FromMinutes(3) / base_delay_); SimulateClientCreations(base::TimeDelta::FromMinutes(3) / base_delay_);
// The MediaServerCrashListener should be alive, with 1s second to spare. // The MediaServerCrashListener should be alive, with 1s second to spare.
clock_->Advance(base::TimeDelta::FromSeconds(59)); clock_.Advance(base::TimeDelta::FromSeconds(59));
test_task_runner_->RunTasks(); test_task_runner_->RunTasks();
EXPECT_TRUE(throttler_->IsCrashListenerAliveForTesting()); EXPECT_TRUE(throttler_->IsCrashListenerAliveForTesting());
...@@ -303,7 +303,7 @@ TEST_F(MediaServiceThrottlerTest, ...@@ -303,7 +303,7 @@ TEST_F(MediaServiceThrottlerTest,
SimulateCrashes(1); SimulateCrashes(1);
// The MediaServerCrashListener should be dead. // The MediaServerCrashListener should be dead.
clock_->Advance(base::TimeDelta::FromSeconds(2)); clock_.Advance(base::TimeDelta::FromSeconds(2));
test_task_runner_->RunTasks(); test_task_runner_->RunTasks();
EXPECT_FALSE(throttler_->IsCrashListenerAliveForTesting()); EXPECT_FALSE(throttler_->IsCrashListenerAliveForTesting());
} }
......
...@@ -22,10 +22,8 @@ AndroidVideoSurfaceChooserImpl::AndroidVideoSurfaceChooserImpl( ...@@ -22,10 +22,8 @@ AndroidVideoSurfaceChooserImpl::AndroidVideoSurfaceChooserImpl(
tick_clock_(tick_clock), tick_clock_(tick_clock),
weak_factory_(this) { weak_factory_(this) {
// Use a DefaultTickClock if one wasn't provided. // Use a DefaultTickClock if one wasn't provided.
if (!tick_clock_) { if (!tick_clock_)
optional_tick_clock_ = std::make_unique<base::DefaultTickClock>(); tick_clock_ = base::DefaultTickClock::GetInstance();
tick_clock_ = optional_tick_clock_.get();
}
} }
AndroidVideoSurfaceChooserImpl::~AndroidVideoSurfaceChooserImpl() {} AndroidVideoSurfaceChooserImpl::~AndroidVideoSurfaceChooserImpl() {}
......
...@@ -86,9 +86,6 @@ class MEDIA_GPU_EXPORT AndroidVideoSurfaceChooserImpl ...@@ -86,9 +86,6 @@ class MEDIA_GPU_EXPORT AndroidVideoSurfaceChooserImpl
// Not owned by us. // Not owned by us.
base::TickClock* tick_clock_; base::TickClock* tick_clock_;
// Owned copy of |tick_clock_|, or nullptr if one was provided to us.
std::unique_ptr<base::TickClock> optional_tick_clock_;
// Time at which we most recently got a failed overlay request. // Time at which we most recently got a failed overlay request.
base::TimeTicks most_recent_overlay_failure_; base::TimeTicks most_recent_overlay_failure_;
......
...@@ -455,7 +455,7 @@ AVDACodecAllocator::AVDACodecAllocator( ...@@ -455,7 +455,7 @@ AVDACodecAllocator::AVDACodecAllocator(
factory_cb_(std::move(factory_cb)), factory_cb_(std::move(factory_cb)),
weak_this_factory_(this) { weak_this_factory_(this) {
// We leak the clock we create, but that's okay because we're a singleton. // We leak the clock we create, but that's okay because we're a singleton.
auto* clock = tick_clock ? tick_clock : new base::DefaultTickClock(); auto* clock = tick_clock ? tick_clock : base::DefaultTickClock::GetInstance();
// Create threads with names and indices that match up with TaskType. // Create threads with names and indices that match up with TaskType.
threads_.push_back(new ThreadAndHangDetector("AVDAAutoThread", clock)); threads_.push_back(new ThreadAndHangDetector("AVDAAutoThread", clock));
......
...@@ -30,11 +30,8 @@ constexpr base::TimeDelta MinimumUnpromotableFrameTime = ...@@ -30,11 +30,8 @@ constexpr base::TimeDelta MinimumUnpromotableFrameTime =
PromotionHintAggregatorImpl::PromotionHintAggregatorImpl( PromotionHintAggregatorImpl::PromotionHintAggregatorImpl(
base::TickClock* tick_clock) base::TickClock* tick_clock)
: weak_ptr_factory_(this) { : weak_ptr_factory_(this) {
if (!tick_clock) { if (!tick_clock)
clock_we_own_ = std::make_unique<base::DefaultTickClock>(); tick_clock = base::DefaultTickClock::GetInstance();
tick_clock = clock_we_own_.get();
}
tick_clock_ = tick_clock; tick_clock_ = tick_clock;
} }
......
...@@ -32,9 +32,6 @@ class MEDIA_GPU_EXPORT PromotionHintAggregatorImpl ...@@ -32,9 +32,6 @@ class MEDIA_GPU_EXPORT PromotionHintAggregatorImpl
// Clock, which we might not own, that we'll use. // Clock, which we might not own, that we'll use.
base::TickClock* tick_clock_; base::TickClock* tick_clock_;
// Will be non-null if we allocate our own clock. Use |tick_clock| instead.
std::unique_ptr<base::TickClock> clock_we_own_;
// When did we receive the most recent "not promotable" frame? // When did we receive the most recent "not promotable" frame?
base::TimeTicks most_recent_unpromotable_; base::TimeTicks most_recent_unpromotable_;
......
...@@ -34,15 +34,15 @@ SurfaceChooserHelper::SurfaceChooserHelper( ...@@ -34,15 +34,15 @@ SurfaceChooserHelper::SurfaceChooserHelper(
bool is_overlay_required, bool is_overlay_required,
bool promote_aggressively, bool promote_aggressively,
std::unique_ptr<PromotionHintAggregator> promotion_hint_aggregator, std::unique_ptr<PromotionHintAggregator> promotion_hint_aggregator,
std::unique_ptr<base::TickClock> tick_clock) base::TickClock* tick_clock)
: surface_chooser_(std::move(surface_chooser)), : surface_chooser_(std::move(surface_chooser)),
is_overlay_required_(is_overlay_required), is_overlay_required_(is_overlay_required),
promotion_hint_aggregator_( promotion_hint_aggregator_(
promotion_hint_aggregator promotion_hint_aggregator
? std::move(promotion_hint_aggregator) ? std::move(promotion_hint_aggregator)
: std::make_unique<PromotionHintAggregatorImpl>()), : std::make_unique<PromotionHintAggregatorImpl>()),
tick_clock_(tick_clock ? std::move(tick_clock) tick_clock_(tick_clock ? tick_clock
: std::make_unique<base::DefaultTickClock>()) { : base::DefaultTickClock::GetInstance()) {
surface_chooser_state_.is_required = is_overlay_required_; surface_chooser_state_.is_required = is_overlay_required_;
surface_chooser_state_.promote_aggressively = promote_aggressively; surface_chooser_state_.promote_aggressively = promote_aggressively;
} }
......
...@@ -34,7 +34,7 @@ class MEDIA_GPU_EXPORT SurfaceChooserHelper { ...@@ -34,7 +34,7 @@ class MEDIA_GPU_EXPORT SurfaceChooserHelper {
bool promote_aggressively, bool promote_aggressively,
std::unique_ptr<PromotionHintAggregator> promotion_hint_aggregator = std::unique_ptr<PromotionHintAggregator> promotion_hint_aggregator =
nullptr, nullptr,
std::unique_ptr<base::TickClock> tick_clock = nullptr); base::TickClock* tick_clock = nullptr);
~SurfaceChooserHelper(); ~SurfaceChooserHelper();
enum class SecureSurfaceMode { enum class SecureSurfaceMode {
...@@ -105,7 +105,7 @@ class MEDIA_GPU_EXPORT SurfaceChooserHelper { ...@@ -105,7 +105,7 @@ class MEDIA_GPU_EXPORT SurfaceChooserHelper {
// Time since we last updated the chooser state. // Time since we last updated the chooser state.
base::TimeTicks most_recent_chooser_retry_; base::TimeTicks most_recent_chooser_retry_;
std::unique_ptr<base::TickClock> tick_clock_; base::TickClock* tick_clock_;
// Number of promotion hints that we need to receive before clearing the // Number of promotion hints that we need to receive before clearing the
// "delay overlay promotion" flag in |surface_chooser_state_|. We do this so // "delay overlay promotion" flag in |surface_chooser_state_|. We do this so
......
...@@ -35,10 +35,7 @@ class SurfaceChooserHelperTest : public testing::Test { ...@@ -35,10 +35,7 @@ class SurfaceChooserHelperTest : public testing::Test {
void ReplaceHelper(bool is_overlay_required, bool promote_aggressively) { void ReplaceHelper(bool is_overlay_required, bool promote_aggressively) {
// Advance the clock so that time 0 isn't recent. // Advance the clock so that time 0 isn't recent.
std::unique_ptr<base::SimpleTestTickClock> tick_clock = tick_clock_.Advance(TimeDelta::FromSeconds(10000));
std::make_unique<base::SimpleTestTickClock>();
tick_clock_ = tick_clock.get();
tick_clock_->Advance(TimeDelta::FromSeconds(10000));
std::unique_ptr<MockAndroidVideoSurfaceChooser> chooser = std::unique_ptr<MockAndroidVideoSurfaceChooser> chooser =
std::make_unique<MockAndroidVideoSurfaceChooser>(); std::make_unique<MockAndroidVideoSurfaceChooser>();
...@@ -48,7 +45,7 @@ class SurfaceChooserHelperTest : public testing::Test { ...@@ -48,7 +45,7 @@ class SurfaceChooserHelperTest : public testing::Test {
aggregator_ = aggregator.get(); aggregator_ = aggregator.get();
helper_ = std::make_unique<SurfaceChooserHelper>( helper_ = std::make_unique<SurfaceChooserHelper>(
std::move(chooser), is_overlay_required, promote_aggressively, std::move(chooser), is_overlay_required, promote_aggressively,
std::move(aggregator), std::move(tick_clock)); std::move(aggregator), &tick_clock_);
} }
// Convenience function. // Convenience function.
...@@ -57,7 +54,7 @@ class SurfaceChooserHelperTest : public testing::Test { ...@@ -57,7 +54,7 @@ class SurfaceChooserHelperTest : public testing::Test {
helper_->UpdateChooserState(base::Optional<AndroidOverlayFactoryCB>()); helper_->UpdateChooserState(base::Optional<AndroidOverlayFactoryCB>());
} }
base::SimpleTestTickClock* tick_clock_ = nullptr; base::SimpleTestTickClock tick_clock_;
MockPromotionHintAggregator* aggregator_ = nullptr; MockPromotionHintAggregator* aggregator_ = nullptr;
...@@ -217,7 +214,7 @@ TEST_F(SurfaceChooserHelperTest, PromotionHintsUpdateChooserStatePeriodically) { ...@@ -217,7 +214,7 @@ TEST_F(SurfaceChooserHelperTest, PromotionHintsUpdateChooserStatePeriodically) {
helper_->NotifyPromotionHintAndUpdateChooser(hint, false); helper_->NotifyPromotionHintAndUpdateChooser(hint, false);
// Advancing the time and using an overlay should not send a hint. // Advancing the time and using an overlay should not send a hint.
tick_clock_->Advance(base::TimeDelta::FromSeconds(10)); tick_clock_.Advance(base::TimeDelta::FromSeconds(10));
EXPECT_CALL(*chooser_, MockUpdateState()).Times(0); EXPECT_CALL(*chooser_, MockUpdateState()).Times(0);
helper_->NotifyPromotionHintAndUpdateChooser(hint, true); helper_->NotifyPromotionHintAndUpdateChooser(hint, true);
......
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