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

Unified Diff: extensions/browser/api/sockets_tcp/sockets_tcp_api.cc

Issue 494573002: A change for the setPause() api in chrome.sockets.tcp: Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cosmetics and commentary. Created 5 years 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
Index: extensions/browser/api/sockets_tcp/sockets_tcp_api.cc
diff --git a/extensions/browser/api/sockets_tcp/sockets_tcp_api.cc b/extensions/browser/api/sockets_tcp/sockets_tcp_api.cc
index 0d20cd60f6f3bcc7b5c56ea7ea133d61b700c9fd..7380fd379101df0f19eaa81fba90b1a942938a6c 100644
--- a/extensions/browser/api/sockets_tcp/sockets_tcp_api.cc
+++ b/extensions/browser/api/sockets_tcp/sockets_tcp_api.cc
@@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <hash_set>
Ken Rockot(use gerrit already) 2015/12/15 17:17:49 Thanks for adding this :) But it should be "base/
+#include <string>
+#include <vector>
+
#include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h"
#include "content/public/browser/browser_context.h"
@@ -157,7 +161,7 @@ void SocketsTcpUpdateFunction::Work() {
}
SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction()
- : socket_event_dispatcher_(NULL) {}
+ : socket_event_dispatcher_(NULL), defer_completion_(false) {}
SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {}
@@ -183,6 +187,16 @@ void SocketsTcpSetPausedFunction::Work() {
if (socket->paused() != params_->paused) {
socket->set_paused(params_->paused);
+ // If this is a client socket, we can delay the callback's invocation
+ // until the socket is really paused.
+ BufferingTCPClientSocket* client_sock = socket->ClientStream();
+ if (client_sock && params_->paused) {
+ // Don't automatically call AsyncWorkCompleted() when Work() returns.
+ defer_completion_ = true;
+ socket->set_api_pause_complete_callback(
+ base::Bind(&SocketsTcpSetPausedFunction::AsyncWorkCompleted, this));
+ client_sock->Pause();
Ken Rockot(use gerrit already) 2015/12/15 17:17:49 How about just making Pause take a callback? Or if
+ }
if (socket->IsConnected() && !params_->paused) {
socket_event_dispatcher_->OnSocketResume(extension_->id(),
params_->socket_id);
@@ -192,6 +206,13 @@ void SocketsTcpSetPausedFunction::Work() {
results_ = sockets_tcp::SetPaused::Results::Create();
}
+void SocketsTcpSetPausedFunction::AsyncWorkStart() {
+ Work();
+ if (!defer_completion_) {
+ AsyncWorkCompleted();
+ }
+}
+
SocketsTcpSetKeepAliveFunction::SocketsTcpSetKeepAliveFunction() {}
SocketsTcpSetKeepAliveFunction::~SocketsTcpSetKeepAliveFunction() {}

Powered by Google App Engine
This is Rietveld 408576698