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

Side by Side Diff: net/websockets/websocket_job.cc

Issue 18932005: Reduce the complexity of WebSocketThrottle's wakeup code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android_dbg build fix Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/net_error_list.h ('k') | net/websockets/websocket_job_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/websockets/websocket_job.h" 5 #include "net/websockets/websocket_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 141 }
142 142
143 void WebSocketJob::RestartWithAuth(const AuthCredentials& credentials) { 143 void WebSocketJob::RestartWithAuth(const AuthCredentials& credentials) {
144 state_ = CONNECTING; 144 state_ = CONNECTING;
145 socket_->RestartWithAuth(credentials); 145 socket_->RestartWithAuth(credentials);
146 } 146 }
147 147
148 void WebSocketJob::DetachDelegate() { 148 void WebSocketJob::DetachDelegate() {
149 state_ = CLOSED; 149 state_ = CLOSED;
150 WebSocketThrottle::GetInstance()->RemoveFromQueue(this); 150 WebSocketThrottle::GetInstance()->RemoveFromQueue(this);
151 WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary();
152 151
153 scoped_refptr<WebSocketJob> protect(this); 152 scoped_refptr<WebSocketJob> protect(this);
154 weak_ptr_factory_.InvalidateWeakPtrs(); 153 weak_ptr_factory_.InvalidateWeakPtrs();
155 weak_ptr_factory_for_send_pending_.InvalidateWeakPtrs(); 154 weak_ptr_factory_for_send_pending_.InvalidateWeakPtrs();
156 155
157 delegate_ = NULL; 156 delegate_ = NULL;
158 if (socket_.get()) 157 if (socket_.get())
159 socket_->DetachDelegate(); 158 socket_->DetachDelegate();
160 socket_ = NULL; 159 socket_ = NULL;
161 if (!callback_.is_null()) { 160 if (!callback_.is_null()) {
162 waiting_ = false; 161 waiting_ = false;
163 callback_.Reset(); 162 callback_.Reset();
164 Release(); // Balanced with OnStartOpenConnection(). 163 Release(); // Balanced with OnStartOpenConnection().
165 } 164 }
166 } 165 }
167 166
168 int WebSocketJob::OnStartOpenConnection( 167 int WebSocketJob::OnStartOpenConnection(
169 SocketStream* socket, const CompletionCallback& callback) { 168 SocketStream* socket, const CompletionCallback& callback) {
170 DCHECK(callback_.is_null()); 169 DCHECK(callback_.is_null());
171 state_ = CONNECTING; 170 state_ = CONNECTING;
171
172 addresses_ = socket->address_list(); 172 addresses_ = socket->address_list();
173 WebSocketThrottle::GetInstance()->PutInQueue(this); 173 if (!WebSocketThrottle::GetInstance()->PutInQueue(this)) {
174 return ERR_WS_THROTTLE_QUEUE_TOO_LARGE;
175 }
176
174 if (delegate_) { 177 if (delegate_) {
175 int result = delegate_->OnStartOpenConnection(socket, callback); 178 int result = delegate_->OnStartOpenConnection(socket, callback);
176 DCHECK_EQ(OK, result); 179 DCHECK_EQ(OK, result);
177 } 180 }
178 if (waiting_) { 181 if (waiting_) {
179 // PutInQueue() may set |waiting_| true for throttling. In this case, 182 // PutInQueue() may set |waiting_| true for throttling. In this case,
180 // Wakeup() will be called later. 183 // Wakeup() will be called later.
181 callback_ = callback; 184 callback_ = callback;
182 AddRef(); // Balanced when callback_ is cleared. 185 AddRef(); // Balanced when callback_ is cleared.
183 return ERR_IO_PENDING; 186 return ERR_IO_PENDING;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 return; 242 return;
240 } 243 }
241 DCHECK(state_ == OPEN || state_ == CLOSING); 244 DCHECK(state_ == OPEN || state_ == CLOSING);
242 if (delegate_ && len > 0) 245 if (delegate_ && len > 0)
243 delegate_->OnReceivedData(socket, data, len); 246 delegate_->OnReceivedData(socket, data, len);
244 } 247 }
245 248
246 void WebSocketJob::OnClose(SocketStream* socket) { 249 void WebSocketJob::OnClose(SocketStream* socket) {
247 state_ = CLOSED; 250 state_ = CLOSED;
248 WebSocketThrottle::GetInstance()->RemoveFromQueue(this); 251 WebSocketThrottle::GetInstance()->RemoveFromQueue(this);
249 WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary();
250 252
251 scoped_refptr<WebSocketJob> protect(this); 253 scoped_refptr<WebSocketJob> protect(this);
252 weak_ptr_factory_.InvalidateWeakPtrs(); 254 weak_ptr_factory_.InvalidateWeakPtrs();
253 255
254 SocketStream::Delegate* delegate = delegate_; 256 SocketStream::Delegate* delegate = delegate_;
255 delegate_ = NULL; 257 delegate_ = NULL;
256 socket_ = NULL; 258 socket_ = NULL;
257 if (!callback_.is_null()) { 259 if (!callback_.is_null()) {
258 waiting_ = false; 260 waiting_ = false;
259 callback_.Reset(); 261 callback_.Reset();
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 received_data_after_handshake_.clear(); 492 received_data_after_handshake_.clear();
491 493
492 state_ = OPEN; 494 state_ = OPEN;
493 495
494 DCHECK(!received_data.empty()); 496 DCHECK(!received_data.empty());
495 if (delegate_) 497 if (delegate_)
496 delegate_->OnReceivedData( 498 delegate_->OnReceivedData(
497 socket_.get(), &received_data.front(), received_data.size()); 499 socket_.get(), &received_data.front(), received_data.size());
498 500
499 WebSocketThrottle::GetInstance()->RemoveFromQueue(this); 501 WebSocketThrottle::GetInstance()->RemoveFromQueue(this);
500 WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary();
501 } 502 }
502 503
503 void WebSocketJob::SaveNextCookie() { 504 void WebSocketJob::SaveNextCookie() {
504 if (!socket_.get() || !delegate_ || state_ != CONNECTING) 505 if (!socket_.get() || !delegate_ || state_ != CONNECTING)
505 return; 506 return;
506 507
507 callback_pending_ = false; 508 callback_pending_ = false;
508 save_next_cookie_running_ = true; 509 save_next_cookie_running_ = true;
509 510
510 if (socket_->context()->cookie_store()) { 511 if (socket_->context()->cookie_store()) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 696
696 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front(); 697 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front();
697 send_buffer_queue_.pop_front(); 698 send_buffer_queue_.pop_front();
698 current_send_buffer_ = 699 current_send_buffer_ =
699 new DrainableIOBuffer(next_buffer.get(), next_buffer->size()); 700 new DrainableIOBuffer(next_buffer.get(), next_buffer->size());
700 SendDataInternal(current_send_buffer_->data(), 701 SendDataInternal(current_send_buffer_->data(),
701 current_send_buffer_->BytesRemaining()); 702 current_send_buffer_->BytesRemaining());
702 } 703 }
703 704
704 } // namespace net 705 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_error_list.h ('k') | net/websockets/websocket_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698