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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <hash_set>
Ken Rockot(use gerrit already) 2015/12/15 17:17:49 Thanks for adding this :) But it should be "base/
6 #include <string>
7 #include <vector>
8
5 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" 9 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h"
6 10
7 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_context.h"
8 #include "content/public/common/socket_permission_request.h" 12 #include "content/public/common/socket_permission_request.h"
9 #include "extensions/browser/api/socket/tcp_socket.h" 13 #include "extensions/browser/api/socket/tcp_socket.h"
10 #include "extensions/browser/api/socket/tls_socket.h" 14 #include "extensions/browser/api/socket/tls_socket.h"
11 #include "extensions/browser/api/sockets_tcp/tcp_socket_event_dispatcher.h" 15 #include "extensions/browser/api/sockets_tcp/tcp_socket_event_dispatcher.h"
12 #include "extensions/common/api/sockets/sockets_manifest_data.h" 16 #include "extensions/common/api/sockets/sockets_manifest_data.h"
13 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
14 #include "net/url_request/url_request_context.h" 18 #include "net/url_request/url_request_context.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (!socket) { 154 if (!socket) {
151 error_ = kSocketNotFoundError; 155 error_ = kSocketNotFoundError;
152 return; 156 return;
153 } 157 }
154 158
155 SetSocketProperties(socket, &params_.get()->properties); 159 SetSocketProperties(socket, &params_.get()->properties);
156 results_ = sockets_tcp::Update::Results::Create(); 160 results_ = sockets_tcp::Update::Results::Create();
157 } 161 }
158 162
159 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction() 163 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction()
160 : socket_event_dispatcher_(NULL) {} 164 : socket_event_dispatcher_(NULL), defer_completion_(false) {}
161 165
162 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {} 166 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {}
163 167
164 bool SocketsTcpSetPausedFunction::Prepare() { 168 bool SocketsTcpSetPausedFunction::Prepare() {
165 params_ = api::sockets_tcp::SetPaused::Params::Create(*args_); 169 params_ = api::sockets_tcp::SetPaused::Params::Create(*args_);
166 EXTENSION_FUNCTION_VALIDATE(params_.get()); 170 EXTENSION_FUNCTION_VALIDATE(params_.get());
167 171
168 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context()); 172 socket_event_dispatcher_ = TCPSocketEventDispatcher::Get(browser_context());
169 DCHECK(socket_event_dispatcher_) 173 DCHECK(socket_event_dispatcher_)
170 << "There is no socket event dispatcher. " 174 << "There is no socket event dispatcher. "
171 "If this assertion is failing during a test, then it is likely that " 175 "If this assertion is failing during a test, then it is likely that "
172 "TestExtensionSystem is failing to provide an instance of " 176 "TestExtensionSystem is failing to provide an instance of "
173 "TCPSocketEventDispatcher."; 177 "TCPSocketEventDispatcher.";
174 return socket_event_dispatcher_ != NULL; 178 return socket_event_dispatcher_ != NULL;
175 } 179 }
176 180
177 void SocketsTcpSetPausedFunction::Work() { 181 void SocketsTcpSetPausedFunction::Work() {
178 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); 182 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id);
179 if (!socket) { 183 if (!socket) {
180 error_ = kSocketNotFoundError; 184 error_ = kSocketNotFoundError;
181 return; 185 return;
182 } 186 }
183 187
184 if (socket->paused() != params_->paused) { 188 if (socket->paused() != params_->paused) {
185 socket->set_paused(params_->paused); 189 socket->set_paused(params_->paused);
190 // If this is a client socket, we can delay the callback's invocation
191 // until the socket is really paused.
192 BufferingTCPClientSocket* client_sock = socket->ClientStream();
193 if (client_sock && params_->paused) {
194 // Don't automatically call AsyncWorkCompleted() when Work() returns.
195 defer_completion_ = true;
196 socket->set_api_pause_complete_callback(
197 base::Bind(&SocketsTcpSetPausedFunction::AsyncWorkCompleted, this));
198 client_sock->Pause();
Ken Rockot(use gerrit already) 2015/12/15 17:17:49 How about just making Pause take a callback? Or if
199 }
186 if (socket->IsConnected() && !params_->paused) { 200 if (socket->IsConnected() && !params_->paused) {
187 socket_event_dispatcher_->OnSocketResume(extension_->id(), 201 socket_event_dispatcher_->OnSocketResume(extension_->id(),
188 params_->socket_id); 202 params_->socket_id);
189 } 203 }
190 } 204 }
191 205
192 results_ = sockets_tcp::SetPaused::Results::Create(); 206 results_ = sockets_tcp::SetPaused::Results::Create();
193 } 207 }
194 208
209 void SocketsTcpSetPausedFunction::AsyncWorkStart() {
210 Work();
211 if (!defer_completion_) {
212 AsyncWorkCompleted();
213 }
214 }
215
195 SocketsTcpSetKeepAliveFunction::SocketsTcpSetKeepAliveFunction() {} 216 SocketsTcpSetKeepAliveFunction::SocketsTcpSetKeepAliveFunction() {}
196 217
197 SocketsTcpSetKeepAliveFunction::~SocketsTcpSetKeepAliveFunction() {} 218 SocketsTcpSetKeepAliveFunction::~SocketsTcpSetKeepAliveFunction() {}
198 219
199 bool SocketsTcpSetKeepAliveFunction::Prepare() { 220 bool SocketsTcpSetKeepAliveFunction::Prepare() {
200 params_ = api::sockets_tcp::SetKeepAlive::Params::Create(*args_); 221 params_ = api::sockets_tcp::SetKeepAlive::Params::Create(*args_);
201 EXTENSION_FUNCTION_VALIDATE(params_.get()); 222 EXTENSION_FUNCTION_VALIDATE(params_.get());
202 return true; 223 return true;
203 } 224 }
204 225
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 RemoveSocket(params_->socket_id); 558 RemoveSocket(params_->socket_id);
538 error_ = net::ErrorToString(result); 559 error_ = net::ErrorToString(result);
539 } 560 }
540 561
541 results_ = api::sockets_tcp::Secure::Results::Create(result); 562 results_ = api::sockets_tcp::Secure::Results::Create(result);
542 AsyncWorkCompleted(); 563 AsyncWorkCompleted();
543 } 564 }
544 565
545 } // namespace api 566 } // namespace api
546 } // namespace extensions 567 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698