Commit 917405ee authored by alexeypa@chromium.org's avatar alexeypa@chromium.org

Made sure NativeMessagingHostTest.All can handle out of order responses.

This CL tags every request NativeMessagingHostTest.All sends and process the responses out of order since the native messaging host does not guarantee the order. It also removes the call log because of the same reason - the order is not reliable unless the client wait for the resonse before sending another request.

Also with this CL NativeMessagingHost delays shutdown until all replies have been sent.

BUG=284704

Review URL: https://chromiumcodereview.appspot.com/23461030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221888 0039d316-1c4b-4281-b951-d872f2087c98
parent ae170e10
......@@ -76,6 +76,8 @@ NativeMessagingHost::NativeMessagingHost(
daemon_controller_(daemon_controller.Pass()),
pairing_registry_(pairing_registry),
oauth_client_(oauth_client.Pass()),
pending_requests_(0),
shutdown_(false),
weak_factory_(this) {
weak_ptr_ = weak_factory_.GetWeakPtr();
}
......@@ -92,17 +94,20 @@ void NativeMessagingHost::Start() {
void NativeMessagingHost::Shutdown() {
DCHECK(caller_task_runner_->BelongsToCurrentThread());
if (!quit_closure_.is_null()) {
if (shutdown_)
return;
shutdown_ = true;
if (!pending_requests_)
caller_task_runner_->PostTask(FROM_HERE, quit_closure_);
quit_closure_.Reset();
}
}
void NativeMessagingHost::ProcessMessage(scoped_ptr<base::Value> message) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());
// Don't process any more messages if Shutdown() has been called.
if (quit_closure_.is_null())
if (shutdown_)
return;
const base::DictionaryValue* message_dict;
......@@ -129,6 +134,9 @@ void NativeMessagingHost::ProcessMessage(scoped_ptr<base::Value> message) {
response_dict->SetString("type", type + "Response");
DCHECK_GE(pending_requests_, 0);
pending_requests_++;
bool success = false;
if (type == "hello") {
success = ProcessHello(*message_dict, response_dict.Pass());
......@@ -165,8 +173,12 @@ void NativeMessagingHost::ProcessMessage(scoped_ptr<base::Value> message) {
LOG(ERROR) << "Unsupported request type: " << type;
}
if (!success)
if (!success) {
pending_requests_--;
DCHECK_GE(pending_requests_, 0);
Shutdown();
}
}
bool NativeMessagingHost::ProcessHello(
......@@ -406,6 +418,12 @@ void NativeMessagingHost::SendResponse(
if (!native_messaging_writer_.WriteMessage(*response))
Shutdown();
pending_requests_--;
DCHECK_GE(pending_requests_, 0);
if (shutdown_ && !pending_requests_)
caller_task_runner_->PostTask(FROM_HERE, quit_closure_);
}
void NativeMessagingHost::SendConfigResponse(
......
......@@ -138,6 +138,13 @@ class NativeMessagingHost {
// Used to exchange the service account authorization code for credentials.
scoped_ptr<OAuthClient> oauth_client_;
// Keeps track of pending requests. Used to delay shutdown until all responses
// have been sent.
int pending_requests_;
// True if Shutdown() has been called.
bool shutdown_;
base::WeakPtrFactory<NativeMessagingHost> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(NativeMessagingHost);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment