@@ -33,8 +33,8 @@ bool IsInvalid(const ftl::WeakPtr<Rasterizer>& rasterizer) {
3333 return !rasterizer;
3434}
3535
36- bool IsViewInvalid (const ftl::WeakPtr <PlatformView>& platform_view) {
37- return !platform_view;
36+ bool IsViewInvalid (const std::weak_ptr <PlatformView>& platform_view) {
37+ return !( platform_view. expired ()) ;
3838}
3939
4040template <typename T>
@@ -242,58 +242,41 @@ void Shell::GetRasterizers(std::vector<ftl::WeakPtr<Rasterizer>>* rasterizers) {
242242 *rasterizers = rasterizers_;
243243}
244244
245- void Shell::AddPlatformView (const ftl::WeakPtr<PlatformView>& platform_view) {
246- FTL_DCHECK (ui_thread_checker_ &&
247- ui_thread_checker_->IsCreationThreadCurrent ());
245+ void Shell::AddPlatformView (const std::shared_ptr<PlatformView>& platform_view) {
246+ std::lock_guard<std::mutex> lk (platform_views_mutex_);
248247 if (platform_view) {
249248 platform_views_.push_back (platform_view);
250249 }
251250}
252251
253252void Shell::PurgePlatformViews () {
254- FTL_DCHECK (ui_thread_checker_ &&
255- ui_thread_checker_->IsCreationThreadCurrent ());
253+ std::lock_guard<std::mutex> lk (platform_views_mutex_);
256254 platform_views_.erase (std::remove_if (platform_views_.begin (),
257255 platform_views_.end (), IsViewInvalid),
258256 platform_views_.end ());
259257}
260258
261259void Shell::GetPlatformViews (
262- std::vector<ftl::WeakPtr<PlatformView>>* platform_views) {
263- FTL_DCHECK (ui_thread_checker_ &&
264- ui_thread_checker_->IsCreationThreadCurrent ());
260+ std::vector<std::weak_ptr<PlatformView>>* platform_views) {
261+ std::lock_guard<std::mutex> lk (platform_views_mutex_);
265262 *platform_views = platform_views_;
266263}
267264
268265void Shell::WaitForPlatformViewIds (
269266 std::vector<PlatformViewInfo>* platform_view_ids) {
270- ftl::AutoResetWaitableEvent latch;
271-
272- blink::Threads::UI ()->PostTask ([this , platform_view_ids, &latch]() {
273- WaitForPlatformViewsIdsUIThread (platform_view_ids, &latch);
274- });
275-
276- latch.Wait ();
277- }
278-
279- void Shell::WaitForPlatformViewsIdsUIThread (
280- std::vector<PlatformViewInfo>* platform_view_ids,
281- ftl::AutoResetWaitableEvent* latch) {
282- std::vector<ftl::WeakPtr<PlatformView>> platform_views;
283- GetPlatformViews (&platform_views);
284- for (auto it = platform_views.begin (); it != platform_views.end (); it++) {
285- PlatformView* view = it->get ();
267+ std::lock_guard<std::mutex> lk (platform_views_mutex_);
268+ for (auto it = platform_views_.begin (); it != platform_views_.end (); it++) {
269+ std::shared_ptr <PlatformView> view{*it};
286270 if (!view) {
287271 // Skip dead views.
288272 continue ;
289273 }
290274 PlatformViewInfo info;
291- info.view_id = reinterpret_cast <uintptr_t >(view);
275+ info.view_id = reinterpret_cast <uintptr_t >(view. get () );
292276 info.isolate_id = view->engine ().GetUIIsolateMainPort ();
293277 info.isolate_name = view->engine ().GetUIIsolateName ();
294278 platform_view_ids->push_back (info);
295279 }
296- latch->Signal ();
297280}
298281
299282void Shell::RunInPlatformView (uintptr_t view_id,
@@ -334,8 +317,9 @@ void Shell::RunInPlatformViewUIThread(uintptr_t view_id,
334317 *view_existed = false ;
335318
336319 for (auto it = platform_views_.begin (); it != platform_views_.end (); it++) {
337- PlatformView* view = it->get ();
338- if (reinterpret_cast <uintptr_t >(view) == view_id) {
320+ std::shared_ptr<PlatformView> view{*it};
321+ if (!view) continue ;
322+ if (reinterpret_cast <uintptr_t >(view.get ()) == view_id) {
339323 *view_existed = true ;
340324 view->RunFromSource (assets_directory, main, packages);
341325 *dart_isolate_id = view->engine ().GetUIIsolateMainPort ();
0 commit comments