// Copyright © 2010-2017 The CefSharp Authors. All rights reserved. // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; using System.Threading.Tasks; using CefSharp.Internals; namespace CefSharp { /// /// Provides a callback implementation of for use with geo positioning /// public class TaskGetGeolocationCallback : IGetGeolocationCallback { private readonly TaskCompletionSource taskCompletionSource; private bool hasData; private volatile bool isDisposed; public TaskGetGeolocationCallback() { taskCompletionSource = new TaskCompletionSource(); } void IGetGeolocationCallback.OnLocationUpdate(Geoposition position) { taskCompletionSource.TrySetResultAsync(position); hasData = true; } bool IGetGeolocationCallback.IsDisposed { get { return isDisposed; } } public Task Task { get { return taskCompletionSource.Task; } } void IDisposable.Dispose() { if (hasData == false) { //Set the result on the ThreadPool so the Task continuation is not run on the CEF UI Thread taskCompletionSource.TrySetResultAsync(null); } isDisposed = true; } } }