Commit c1c66c64 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

[base] Use DoSomeWork() in MessagePumpFuchsia.

MessagePump::Delegate::DoWork/DoDelayedWork are being removed in favor
of DoSomeWork. This CL updates MessagePumpFuchsia to use
DoSomeWork to unblock that migration.

Bug: 885371
Change-Id: Ibe7ca894ac866e3287f301f70505195a2b5d6d10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2068827Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751347}
parent 4ab993c6
...@@ -246,7 +246,7 @@ bool MessagePumpFuchsia::WatchZxHandle(zx_handle_t handle, ...@@ -246,7 +246,7 @@ bool MessagePumpFuchsia::WatchZxHandle(zx_handle_t handle,
return controller->WaitBegin(); return controller->WaitBegin();
} }
bool MessagePumpFuchsia::HandleEvents(zx_time_t deadline) { bool MessagePumpFuchsia::HandleIoEventsUntil(zx_time_t deadline) {
zx_status_t status = async_loop_->Run(zx::time(deadline), /*once=*/true); zx_status_t status = async_loop_->Run(zx::time(deadline), /*once=*/true);
switch (status) { switch (status) {
// Return true if some tasks or events were dispatched or if the dispatcher // Return true if some tasks or events were dispatched or if the dispatcher
...@@ -271,33 +271,31 @@ void MessagePumpFuchsia::Run(Delegate* delegate) { ...@@ -271,33 +271,31 @@ void MessagePumpFuchsia::Run(Delegate* delegate) {
AutoReset<bool> auto_reset_keep_running(&keep_running_, true); AutoReset<bool> auto_reset_keep_running(&keep_running_, true);
for (;;) { for (;;) {
bool did_work = delegate->DoWork(); const Delegate::NextWorkInfo next_work_info = delegate->DoSomeWork();
if (!keep_running_) if (!keep_running_)
break; break;
did_work |= delegate->DoDelayedWork(&delayed_work_time_); const bool did_handle_io_event = HandleIoEventsUntil(/*deadline=*/0);
if (!keep_running_) if (!keep_running_)
break; break;
did_work |= HandleEvents(/*deadline=*/0); bool attempt_more_work =
if (!keep_running_) next_work_info.is_immediate() || did_handle_io_event;
break; if (attempt_more_work)
if (did_work)
continue; continue;
did_work = delegate->DoIdleWork(); attempt_more_work = delegate->DoIdleWork();
if (!keep_running_) if (!keep_running_)
break; break;
if (did_work) if (attempt_more_work)
continue; continue;
zx_time_t deadline = delayed_work_time_.is_null() zx_time_t deadline = next_work_info.delayed_run_time.is_max()
? ZX_TIME_INFINITE ? ZX_TIME_INFINITE
: delayed_work_time_.ToZxTime(); : next_work_info.delayed_run_time.ToZxTime();
HandleEvents(deadline); HandleIoEventsUntil(deadline);
} }
} }
...@@ -312,10 +310,11 @@ void MessagePumpFuchsia::ScheduleWork() { ...@@ -312,10 +310,11 @@ void MessagePumpFuchsia::ScheduleWork() {
void MessagePumpFuchsia::ScheduleDelayedWork( void MessagePumpFuchsia::ScheduleDelayedWork(
const TimeTicks& delayed_work_time) { const TimeTicks& delayed_work_time) {
// We know that we can't be blocked right now since this method can only be // Since this is always called from the same thread as Run(), there is nothing
// called on the same thread as Run, so we only need to update our record of // to do as the loop is already running. It will wait in Run() with the
// how long to sleep when we do sleep. // correct timeout when it's out of immediate tasks.
delayed_work_time_ = delayed_work_time; // TODO(https://crbug.com/885371): Consider removing ScheduleDelayedWork()
// when all pumps function this way (bit.ly/merge-message-pump-do-work).
} }
} // namespace base } // namespace base
...@@ -138,18 +138,15 @@ class BASE_EXPORT MessagePumpFuchsia : public MessagePump, ...@@ -138,18 +138,15 @@ class BASE_EXPORT MessagePumpFuchsia : public MessagePump,
void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override; void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
private: private:
// Handles IO events by running |async_dispatcher_|. Returns true if any // Handles IO events by running |async_dispatcher_| until |deadline|. Returns
// events were received or if ScheduleWork() was called. // true if any events were received or if ScheduleWork() was called.
bool HandleEvents(zx_time_t deadline); bool HandleIoEventsUntil(zx_time_t deadline);
// This flag is set to false when Run should return. // This flag is set to false when Run should return.
bool keep_running_ = true; bool keep_running_ = true;
std::unique_ptr<async::Loop> async_loop_; std::unique_ptr<async::Loop> async_loop_;
// The time at which we should call DoDelayedWork.
TimeTicks delayed_work_time_;
base::WeakPtrFactory<MessagePumpFuchsia> weak_factory_; base::WeakPtrFactory<MessagePumpFuchsia> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MessagePumpFuchsia); DISALLOW_COPY_AND_ASSIGN(MessagePumpFuchsia);
......
...@@ -33,53 +33,9 @@ namespace base { ...@@ -33,53 +33,9 @@ namespace base {
namespace { namespace {
bool PumpTypeUsesDoSomeWork(MessagePumpType type) { bool PumpTypeUsesDoSomeWork(MessagePumpType type) {
switch (type) { // TODO(https://crbug.com/885371): All MessagePumps use DoSomeWork(). As a
case MessagePumpType::DEFAULT: // result, tests should be simplified.
return true; return true;
case MessagePumpType::UI:
#if defined(OS_WIN) || defined(OS_ANDROID) || defined(USE_GLIB) || \
defined(OS_MACOSX)
return true;
#elif defined(OS_POSIX) && !defined(OS_NACL_SFI)
// MessagePumpLibevent was migrated (ref. message_pump_for_ui.h and
// |use_libevent| in base/BUILD.gn for enabled conditions).
return std::is_same<MessagePumpForUI, MessagePumpLibevent>::value;
#else
// TODO(gab): Complete migration of all UI pumps to DoSomeWork() as part
// of crbug.com/885371.
return false;
#endif
case MessagePumpType::IO:
#if defined(OS_WIN) || defined(OS_MACOSX)
return true;
#elif defined(OS_POSIX) && !defined(OS_NACL_SFI)
// MessagePumpLibevent was migrated (ref. message_pump_for_io.h and
// |use_libevent| in base/BUILD.gn for enabled conditions).
return std::is_same<MessagePumpForIO, MessagePumpLibevent>::value;
#else
// TODO(gab): Complete migration of all IO pumps to DoSomeWork() as part
// of crbug.com/885371.
return false;
#endif
case MessagePumpType::CUSTOM:
#if defined(OS_ANDROID)
case MessagePumpType::JAVA:
#endif // defined(OS_ANDROID)
#if defined(OS_MACOSX)
case MessagePumpType::NS_RUNLOOP:
#endif // defined(OS_MACOSX)
#if defined(OS_WIN)
case MessagePumpType::UI_WITH_WM_QUIT_SUPPORT:
#endif // defined(OS_WIN)
// Not tested in this file.
NOTREACHED();
return false;
}
NOTREACHED();
return false;
} }
class MockMessagePumpDelegate : public MessagePump::Delegate { class MockMessagePumpDelegate : public MessagePump::Delegate {
......
...@@ -328,8 +328,19 @@ TEST_F(CookieManagerImplTest, UpdateBatching) { ...@@ -328,8 +328,19 @@ TEST_F(CookieManagerImplTest, UpdateBatching) {
CreateAndSetCookieAsync(kCookieName1, kCookieValue1); CreateAndSetCookieAsync(kCookieName1, kCookieValue1);
CreateAndSetCookieAsync(kCookieName2, kCookieValue2); CreateAndSetCookieAsync(kCookieName2, kCookieValue2);
CreateAndSetCookieAsync(kCookieName1, kCookieValue3); CreateAndSetCookieAsync(kCookieName1, kCookieValue3);
// Flush the Cookie Manager so that all cookie changes are processed.
mojo_cookie_manager_.FlushForTesting(); mojo_cookie_manager_.FlushForTesting();
// Run all pending tasks so that CookiesIteratorImpl receives all cookie
// changes through network::mojom::CookieChangeListener::OnCookieChange().
// This is important because fuchsia::web::CookiesIterator::GetNext() only
// returns cookie updates that have already been received by the iterator
// implementation.
base::RunLoop().RunUntilIdle();
// Request cookie updates through fuchsia::web::CookiesIterator::GetNext().
// Multiple updates to the same cookie should be coalesced.
GetNextCookiesIteratorResult global_updates(global_changes.get()); GetNextCookiesIteratorResult global_updates(global_changes.get());
global_updates.ExpectCookieUpdates( global_updates.ExpectCookieUpdates(
{{kCookieName1, kCookieValue3}, {kCookieName2, kCookieValue2}}); {{kCookieName1, kCookieValue3}, {kCookieName2, kCookieValue2}});
......
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