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

Side by Side Diff: net/socket_stream/socket_stream.cc

Issue 15989003: Support delegate deleting itself from OnError (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 7 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
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 // TODO(ukai): code is similar with http_network_transaction.cc. We should 5 // TODO(ukai): code is similar with http_network_transaction.cc. We should
6 // think about ways to share code, if possible. 6 // think about ways to share code, if possible.
7 7
8 #include "net/socket_stream/socket_stream.h" 8 #include "net/socket_stream/socket_stream.h"
9 9
10 #include <set> 10 #include <set>
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 285
286 MessageLoop::current()->PostTask( 286 MessageLoop::current()->PostTask(
287 FROM_HERE, 287 FROM_HERE,
288 base::Bind(&SocketStream::DoRestartWithAuth, this)); 288 base::Bind(&SocketStream::DoRestartWithAuth, this));
289 } 289 }
290 290
291 void SocketStream::DetachDelegate() { 291 void SocketStream::DetachDelegate() {
292 if (!delegate_) 292 if (!delegate_)
293 return; 293 return;
294 delegate_ = NULL; 294 delegate_ = NULL;
295 if (next_state_ == STATE_NONE)
296 return;
tyoshino (SeeGerritForStatus) 2013/05/27 05:55:36 what is this change for?
Adam Rice 2013/05/27 07:16:33 Previously, Finish() would set delegate_ to NULL,
tyoshino (SeeGerritForStatus) 2013/05/27 08:09:13 I see. Thanks
295 net_log_.AddEvent(NetLog::TYPE_CANCELLED); 297 net_log_.AddEvent(NetLog::TYPE_CANCELLED);
296 // We don't need to send pending data when client detach the delegate. 298 // We don't need to send pending data when client detach the delegate.
297 pending_write_bufs_.clear(); 299 pending_write_bufs_.clear();
298 Close(); 300 Close();
299 } 301 }
300 302
301 const ProxyServer& SocketStream::proxy_server() const { 303 const ProxyServer& SocketStream::proxy_server() const {
302 return proxy_info_.proxy_server(); 304 return proxy_info_.proxy_server();
303 } 305 }
304 306
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 "The current MessageLoop must exist"; 364 "The current MessageLoop must exist";
363 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << 365 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) <<
364 "The current MessageLoop must be TYPE_IO"; 366 "The current MessageLoop must be TYPE_IO";
365 DCHECK_LE(result, OK); 367 DCHECK_LE(result, OK);
366 if (result == OK) 368 if (result == OK)
367 result = ERR_CONNECTION_CLOSED; 369 result = ERR_CONNECTION_CLOSED;
368 DCHECK_EQ(next_state_, STATE_NONE); 370 DCHECK_EQ(next_state_, STATE_NONE);
369 DVLOG(1) << "Finish result=" << ErrorToString(result); 371 DVLOG(1) << "Finish result=" << ErrorToString(result);
370 372
371 metrics_->OnClose(); 373 metrics_->OnClose();
372 Delegate* delegate = delegate_; 374
375 if (result != ERR_CONNECTION_CLOSED && delegate_)
376 delegate_->OnError(this, result);
377 if (result != ERR_PROTOCOL_SWITCHED && delegate_)
378 delegate_->OnClose(this);
373 delegate_ = NULL; 379 delegate_ = NULL;
374 if (delegate) { 380
375 if (result != ERR_CONNECTION_CLOSED)
376 delegate->OnError(this, result);
377 if (result != ERR_PROTOCOL_SWITCHED)
378 delegate->OnClose(this);
379 }
380 Release(); 381 Release();
381 } 382 }
382 383
383 int SocketStream::DidEstablishConnection() { 384 int SocketStream::DidEstablishConnection() {
384 if (!socket_.get() || !socket_->IsConnected()) { 385 if (!socket_.get() || !socket_->IsConnected()) {
385 next_state_ = STATE_CLOSE; 386 next_state_ = STATE_CLOSE;
386 return ERR_CONNECTION_FAILED; 387 return ERR_CONNECTION_FAILED;
387 } 388 }
388 next_state_ = STATE_READ_WRITE; 389 next_state_ = STATE_READ_WRITE;
389 metrics_->OnConnected(); 390 metrics_->OnConnected();
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 1322
1322 SSLConfigService* SocketStream::ssl_config_service() const { 1323 SSLConfigService* SocketStream::ssl_config_service() const {
1323 return context_->ssl_config_service(); 1324 return context_->ssl_config_service();
1324 } 1325 }
1325 1326
1326 ProxyService* SocketStream::proxy_service() const { 1327 ProxyService* SocketStream::proxy_service() const {
1327 return context_->proxy_service(); 1328 return context_->proxy_service();
1328 } 1329 }
1329 1330
1330 } // namespace net 1331 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/socket_stream/socket_stream_unittest.cc » ('j') | net/socket_stream/socket_stream_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698