2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "libcef/common/response_manager.h"
|
2017-05-19 11:06:00 +02:00
|
|
|
#include "libcef/common/cef_messages.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefResponseManager::CefResponseManager() : next_request_id_(0) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
int CefResponseManager::GetNextRequestId() {
|
2017-07-27 01:19:27 +02:00
|
|
|
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
2012-04-03 03:34:16 +02:00
|
|
|
return ++next_request_id_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefResponseManager::RegisterHandler(CefRefPtr<Handler> handler) {
|
2017-07-27 01:19:27 +02:00
|
|
|
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
2012-04-03 03:34:16 +02:00
|
|
|
int request_id = GetNextRequestId();
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT_ASYNC_BEGIN1("cef", "CefResponseManager::Handler", request_id,
|
2017-05-17 11:29:28 +02:00
|
|
|
"request_id", request_id);
|
2012-04-03 03:34:16 +02:00
|
|
|
handlers_.insert(std::make_pair(request_id, handler));
|
|
|
|
return request_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefResponseManager::RunHandler(const Cef_Response_Params& params) {
|
2017-07-27 01:19:27 +02:00
|
|
|
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK_GT(params.request_id, 0);
|
|
|
|
HandlerMap::iterator it = handlers_.find(params.request_id);
|
|
|
|
if (it != handlers_.end()) {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT0("cef", "CefResponseManager::RunHandler");
|
2012-04-03 03:34:16 +02:00
|
|
|
it->second->OnResponse(params);
|
|
|
|
handlers_.erase(it);
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT_ASYNC_END1("cef", "CefResponseManager::Handler",
|
2017-05-17 11:29:28 +02:00
|
|
|
params.request_id, "success", 1);
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT_ASYNC_END1("cef", "CefResponseManager::Handler",
|
2017-05-17 11:29:28 +02:00
|
|
|
params.request_id, "success", 0);
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefResponseManager::RegisterAckHandler(int request_id,
|
|
|
|
CefRefPtr<AckHandler> handler) {
|
2017-07-27 01:19:27 +02:00
|
|
|
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
2012-04-03 03:34:16 +02:00
|
|
|
ack_handlers_.insert(std::make_pair(request_id, handler));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefResponseManager::RunAckHandler(int request_id) {
|
2017-07-27 01:19:27 +02:00
|
|
|
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
2012-04-03 03:34:16 +02:00
|
|
|
DCHECK_GT(request_id, 0);
|
|
|
|
AckHandlerMap::iterator it = ack_handlers_.find(request_id);
|
|
|
|
if (it != ack_handlers_.end()) {
|
|
|
|
it->second->OnResponseAck();
|
|
|
|
ack_handlers_.erase(it);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|