Skip to content

Commit

Permalink
Add API for embedder clients to process platform events (flutter#4549)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekamit authored and chinmaygarde committed Jan 18, 2018
1 parent 2dfeaa6 commit 31f223f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions fml/message_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ void MessageLoop::RemoveTaskObserver(TaskObserver* observer) {
loop_->RemoveTaskObserver(observer);
}

void MessageLoop::RunExpiredTasksNow() {
loop_->RunExpiredTasksNow();
}

} // namespace fml
4 changes: 4 additions & 0 deletions fml/message_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class MessageLoop {

fxl::RefPtr<fxl::TaskRunner> GetTaskRunner() const;

// Exposed for the embedder shell which allows clients to poll for events
// instead of dedicating a thread to the message loop.
void RunExpiredTasksNow();

static void EnsureInitializedForCurrentThread();

static bool IsInitializedForCurrentThread();
Expand Down
6 changes: 4 additions & 2 deletions fml/message_loop_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ class MessageLoopImpl : public fxl::RefCountedThreadSafe<MessageLoopImpl> {

void DoTerminate();

// Exposed for the embedder shell which allows clients to poll for events
// instead of dedicating a thread to the message loop.
void RunExpiredTasksNow();

protected:
MessageLoopImpl();

void RunExpiredTasksNow();

private:
struct DelayedTask {
size_t order;
Expand Down
6 changes: 6 additions & 0 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <type_traits>
#include "flutter/common/threads.h"
#include "flutter/fml/message_loop.h"
#include "flutter/shell/platform/embedder/platform_view_embedder.h"
#include "lib/fxl/functional/make_copyable.h"

Expand Down Expand Up @@ -321,3 +322,8 @@ FlutterResult FlutterEngineSendPlatformMessageResponse(

return kSuccess;
}

FlutterResult __FlutterEngineFlushPendingTasksNow() {
fml::MessageLoop::GetCurrent().RunExpiredTasksNow();
return kSuccess;
}
6 changes: 6 additions & 0 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ FlutterResult FlutterEngineSendPlatformMessageResponse(
const uint8_t* data,
size_t data_length);

// This API is only meant to be used by platforms that need to flush tasks on a
// message loop not controlled by the Flutter engine. This API will be
// deprecated soon.
FLUTTER_EXPORT
FlutterResult __FlutterEngineFlushPendingTasksNow();

#if defined(__cplusplus)
} // extern "C"
#endif
Expand Down

0 comments on commit 31f223f

Please sign in to comment.