Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Unified Diff: remoting/host/setup/native_messaging_host.cc

Issue 23461030: Made sure NativeMessagingHostTest.All can handle out of order responses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more feedback Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/setup/native_messaging_host.h ('k') | remoting/host/setup/native_messaging_host_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/setup/native_messaging_host.cc
diff --git a/remoting/host/setup/native_messaging_host.cc b/remoting/host/setup/native_messaging_host.cc
index 0492736c61743bcc381b5b1ebfcd026b1706ca3b..a98de3a6a69c70db66bdb8ee718c02914669d009 100644
--- a/remoting/host/setup/native_messaging_host.cc
+++ b/remoting/host/setup/native_messaging_host.cc
@@ -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(
« no previous file with comments | « remoting/host/setup/native_messaging_host.h ('k') | remoting/host/setup/native_messaging_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698