Cookie Delay
Posted: Sun May 08, 2016 5:45 pm
Hey Everybody,
I've got a very simple cookie-based application that is showing unexpected behavior in my CEF browser versus a conventional Chrome or IE browser. The app, pictured in the attached, just keeps track of the times at which a flag is set in a cookie. The PHP code is straightforward:
So! That's the code I'm using to test out and profile this issue. The issue that I'm observing is a substantial delay in cookie write speeds. If I build up a few timestamps in the cookie, like in the attached image, and then I quickly clear them and close the browser, I would expect that when I navigate back to the cookie app in a new window my list would be empty. In Chrome and IE, this is definitely the case. In my CEF application, however, it is not. There seems to be a delay between when a cookie is written and accessible in program memory and when that value gets committed to the file system.
My CEF application's cookie management is relatively straight forward. I have based my implementation of Cookie Management off an old forum posting from back in 2014. I base my application off CEF Simple, so my cookie manager comes into play in OnContextInitialized:
The code for the RequestContextHandler is also very straight-forward:
So... Is there a way that I can get my cookies to "take hold" on the file system more quickly in my CEF Application? I'm pretty sure it's not by web-app that's the limiting factor, here. Can I, for example, flush the contents of the cookie in memory to the file system more often?
I've got a very simple cookie-based application that is showing unexpected behavior in my CEF browser versus a conventional Chrome or IE browser. The app, pictured in the attached, just keeps track of the times at which a flag is set in a cookie. The PHP code is straightforward:
- Code: Select all
<?php
// Keep a list of each time we set the cookie
if (isset($_GET["set"]))
{
// Keep the cookie around for 3 days for this entire domain
setcookie("flag", (isset($_COOKIE["flag"]) ? $_COOKIE["flag"] : "") .
"time: ". time() . "<br>\r\n",
time()+60*60*24*3, "/");
$_COOKIE["flag"] = (isset($_COOKIE["flag"]) ? $_COOKIE["flag"] : "") .
"time: ". time() . "<br>\r\n";
$_GET["show"] = 1;
}
// Pop the first flag timestamp off the list
else if (isset($_GET["unset"]))
{
if (isset($_COOKIE["flag"]))
setcookie("flag", strstr(strstr($_COOKIE["flag"], "<br>\r\n"), "time:") ,time()+60*60*24*3, "/");
$_COOKIE["flag"] =
strstr(strstr($_COOKIE["flag"], "<br>\r\n"), "time:");
$_GET["show"] = 1;
}
if (isset($_GET["clear"]))
{
setcookie("flag", "", time()+60*60*24*3, "/");
$_COOKIE["flag"] = "";
$_GET["show"] = 1;
}
echo "<center>";
echo "It's a cookie app!<br>\r\n";
echo "<a href=\"?show\">Show</a>       ";
echo "<a href=\"?set\">Set</a>       ";
echo "<a href=\"?show\">Show</a>       ";
echo "<a href=\"?unset\">Unset</a>       ";
echo "<a href=\"?show\">Show</a>       ";
echo "<a href=\"?clear\">Clear</a>       ";
echo "<a href=\"?show\">Show</a>";
echo "<br>\r\n<br>\r\n";
echo (isset($_COOKIE["flag"]) ? $_COOKIE["flag"] : "");
echo "</center>";
?>
So! That's the code I'm using to test out and profile this issue. The issue that I'm observing is a substantial delay in cookie write speeds. If I build up a few timestamps in the cookie, like in the attached image, and then I quickly clear them and close the browser, I would expect that when I navigate back to the cookie app in a new window my list would be empty. In Chrome and IE, this is definitely the case. In my CEF application, however, it is not. There seems to be a delay between when a cookie is written and accessible in program memory and when that value gets committed to the file system.
My CEF application's cookie management is relatively straight forward. I have based my implementation of Cookie Management off an old forum posting from back in 2014. I base my application off CEF Simple, so my cookie manager comes into play in OnContextInitialized:
- Code: Select all
void MyApp::OnContextInitialized() {
CEF_REQUIRE_UI_THREAD();
// Information used when creating the native window.
CefWindowInfo window_info;
#if defined(OS_WIN)
// Set Window Size... Boring stuff...
#endif
// SimpleHandler implements browser-level callbacks.
CefRefPtr<MyApp_Handler> handler(new MyApp_Handler());
// Specify CEF browser settings here.
CefBrowserSettings browser_settings;
// Here's where I implement the cookie manager!
CefRefPtr<CefRequestContext> rc = CefRequestContext::CreateContext(new WXRequestContextHandler());
// Create the first browser window.
CefBrowserHost::CreateBrowser(window_info, handler.get(), "mycookieapp.com",
browser_settings, rc);
}
The code for the RequestContextHandler is also very straight-forward:
- Code: Select all
class WXRequestContextHandler :public CefRequestContextHandler
{
public:
CefRefPtr<CefCookieManager> ourMan;
WXRequestContextHandler()
{
CHAR szPath[MAX_PATH];
// Create our path... Boring stuff
this->ourMan = CefCookieManager::CreateManager(szPath, TRUE);
}
~WXRequestContextHandler(){};
CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE{
return this->ourMan;
}
private:
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(WXRequestContextHandler);
};
So... Is there a way that I can get my cookies to "take hold" on the file system more quickly in my CEF Application? I'm pretty sure it's not by web-app that's the limiting factor, here. Can I, for example, flush the contents of the cookie in memory to the file system more often?