diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index dccc92430..06ef26f53 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -10,6 +10,7 @@ #include "Internals/CefSharpApp.h" #include "Internals/CookieVisitor.h" +#include "Internals/CompletionHandler.h" #include "Internals/StringUtils.h" #include "ManagedCefBrowserAdapter.h" #include "CefSettings.h" @@ -333,6 +334,24 @@ namespace CefSharp } } + /// Flush the backing store (if any) to disk and execute the specified |handler| on the IO thread when done. Returns + /// A user-provided Cookie Visitor implementation. + /// Returns false if cookies cannot be accessed. + static bool FlushStore(IComplete^ handler) + { + CefRefPtr wrapper = new CompletionHandler(handler); + CefRefPtr manager = CefCookieManager::GetGlobalManager(); + + if (manager != nullptr) + { + manager->FlushStore(static_cast>(wrapper)); + return true; + } + else + { + return false; + } + } /// Shuts down CefSharp and the underlying CEF infrastructure. This method is safe to call multiple times; it will only /// shut down CEF on the first call (all subsequent calls will be ignored). /// diff --git a/CefSharp.Core/Internals/CompletionHandler.cpp b/CefSharp.Core/Internals/CompletionHandler.cpp new file mode 100644 index 000000000..f4dcbf29d --- /dev/null +++ b/CefSharp.Core/Internals/CompletionHandler.cpp @@ -0,0 +1,18 @@ +// Copyright © 2010-2014 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. + +#pragma once + +#include "Stdafx.h" +#include "CompletionHandler.h" + +using namespace System::Net; + +namespace CefSharp +{ + void CompletionHandler::OnComplete() + { + _handler->OnComplete(); + } +} \ No newline at end of file diff --git a/CefSharp.Core/Internals/CompletionHandler.h b/CefSharp.Core/Internals/CompletionHandler.h new file mode 100644 index 000000000..f7307a0de --- /dev/null +++ b/CefSharp.Core/Internals/CompletionHandler.h @@ -0,0 +1,27 @@ +// Copyright © 2010-2014 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. + +#pragma once + +#include "Stdafx.h" +#include "include/cef_cookie.h" + +namespace CefSharp +{ + private class CompletionHandler : public CefCompletionHandler + { + private: + gcroot _handler; + + public: + CompletionHandler(IComplete^ handler) + { + _handler = handler; + } + + virtual void OnComplete() OVERRIDE; + + IMPLEMENT_REFCOUNTING(CompletionHandler); + }; +} \ No newline at end of file diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 4280a28e1..5ae724c8c 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -97,6 +97,7 @@ + diff --git a/CefSharp/IComplete.cs b/CefSharp/IComplete.cs new file mode 100644 index 000000000..dffb1bb2b --- /dev/null +++ b/CefSharp/IComplete.cs @@ -0,0 +1,9 @@ +using System.Net; + +namespace CefSharp +{ + public interface IComplete + { + void OnComplete(); + } +}