Add API for embedder clients to process platform events (flutter/engine#4549)

This commit is contained in:
Abhishek Amit
2018-01-17 16:59:36 -08:00
committed by Chinmay Garde
parent 8faa2b6bc1
commit 9cd77fd071
5 changed files with 24 additions and 2 deletions

View File

@@ -71,4 +71,8 @@ void MessageLoop::RemoveTaskObserver(TaskObserver* observer) {
loop_->RemoveTaskObserver(observer);
}
void MessageLoop::RunExpiredTasksNow() {
loop_->RunExpiredTasksNow();
}
} // namespace fml

View File

@@ -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();

View File

@@ -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;

View File

@@ -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"
@@ -321,3 +322,8 @@ FlutterResult FlutterEngineSendPlatformMessageResponse(
return kSuccess;
}
FlutterResult __FlutterEngineFlushPendingTasksNow() {
fml::MessageLoop::GetCurrent().RunExpiredTasksNow();
return kSuccess;
}

View File

@@ -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