I am facing problem regarding saving cache. I have already posted this in this forum.
viewtopic.php?f=6&t=13559
In brief the problem is: Saving any value to cache->localstorage getting saved only after a delay of around 10 seconds.
I got this issue with version "cef_binary_3.2454.1328" for win32. Below steps causing me this problem. But I am not sure what wrong am I doing.
I am creating a pointer variable
insideipThreadFunc_
as below.OnAfterCreated
- Code: Select all
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
browser_count_++;
if (!message_router_) {
// Create the browser-side router for query handling.
CefMessageRouterConfig config;
message_router_ = CefMessageRouterBrowserSide::Create(config);
// Register handlers with the router.
test_runner::CreateMessageHandlers(message_handler_set_);
MessageHandlerSet::const_iterator it = message_handler_set_.begin();
for (; it != message_handler_set_.end(); ++it)
message_router_->AddHandler(*(it), false);
}
// Disable mouse cursor change if requested via the command-line flag.
if (mouse_cursor_change_disabled_)
browser->GetHost()->SetMouseCursorChangeDisabled(true);
if (NULL == ipThreadFunc_ )
{
ipThreadFunc_ = new IpThreadFunc(browser);
}
NotifyBrowserCreated(browser);
}
Below is the piece of code for
ipThreadFunc_
//IpThreadFunc class declaration
- Code: Select all
//IpThreadFunc class declaration
class IpThreadFunc
{
public:
/* Constructor and Destructor */
IpThreadFunc(const CefRefPtr<CefBrowser>&);
virtual ~IpThreadFunc();
private:
/*Private varibales*/
NetworkIpAddressEventSink* mEventSink;
};
- Code: Select all
// definition
IpThreadFunc::IpThreadFunc(const CefRefPtr<CefBrowser>& browser)
:mEventSink(NULL)
{
HRESULT hr = S_OK;
hr = NetworkIpAddressEventSink::StartNotifyAddrChange(&mEventSink, browser);
if (FAILED(hr))
{
LOG(ERROR) << "NetworkThreadFunc:: StartNotifyAddrChange failed, hr- " << hr;
}
}
/*
Destructor definition
*/
IpThreadFunc::~IpThreadFunc()
{
if (mEventSink)
{
mEventSink->StopListeningForEvents();
}
}
---------------------------------------
- Code: Select all
/*
NetworkIpAddressEventSink class declaration, contains all functions
*/
class NetworkIpAddressEventSink
{
/* private member variable*/
HANDLE m_hThread;
DWORD m_dwThreadId;
CefRefPtr<CefBrowser> mBrowser;
private:
/* private member function*/
static DWORD WINAPI StartListeningForIpAddrThread(LPVOID pArg);
public:
HRESULT StopListeningForEvents();
static HRESULT StartNotifyAddrChange(NetworkIpAddressEventSink** ppEventResponse, const CefRefPtr<CefBrowser>&);
protected:
/* Constructor and Destructor */
NetworkIpAddressEventSink()
{
mBrowser = NULL;
m_hThread = NULL;
m_dwThreadId = 0;
}
~NetworkIpAddressEventSink(){}
};
- Code: Select all
HRESULT NetworkIpAddressEventSink::StartNotifyAddrChange(NetworkIpAddressEventSink** ppEventResponse, const CefRefPtr<CefBrowser>& browser)
{
if (!ppEventResponse)
{
LOG(ERROR) << "StartNotifyAddrChange:: ppEventResponse is NULL";
return false;
}
HRESULT hr = S_OK;
NetworkIpAddressEventSink *pEventResponse = new NetworkIpAddressEventSink();
if (pEventResponse)
{
pEventResponse->mBrowser = browser; //if I comment it cache problem resolved
pEventResponse->m_hThread = CreateThread(NULL, 0, &StartListeningForIpAddrThread, reinterpret_cast<LPVOID>(pEventResponse), 0, &(pEventResponse->m_dwThreadId));
if (pEventResponse->m_hThread == INVALID_HANDLE_VALUE)
{
DWORD dwError = GetLastError();
hr = HRESULT_FROM_WIN32(dwError);
LOG(ERROR) << "StartNotifyAddrChange:: CreateThread failed, hr- " << hr;
}
}
else
{
hr = E_OUTOFMEMORY;
LOG(ERROR) << "StartNotifyAddrChange:: pEventResponse is NULL";
}
return hr;
}
/*
FUNCTION: StartListeningForEventsThread
This is our thread entry proc for the thread that will listen on events.
*/
DWORD WINAPI NetworkIpAddressEventSink::StartListeningForIpAddrThread(LPVOID pArg)
{
// thread function
return 0;
}
HRESULT NetworkIpAddressEventSink::StopListeningForEvents()
{
HRESULT hr = S_OK;
if (m_hThread != INVALID_HANDLE_VALUE)
{
TerminateThread(m_hThread, 0);
CloseHandle(m_hThread);
}
return hr;
}
Now if i comment below line in the just above code, cache problem is no more. otherwise it takes around 10 seconds to save the value in local storage.
pEventResponse->mBrowser = browser; //if I comment it cache problem resolved