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

Unified Diff: net/socket_stream/socket_stream.cc

Issue 10541046: Adds NetworkDelegate::NotifyBeforeSocketStreamConnect() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix compile error Created 8 years, 6 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
Index: net/socket_stream/socket_stream.cc
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc
index 46cb1e5bd0b68cab6c3ec695638d24140a0f3e97..3bc6da4ac28b39b73dedfc5d47e08fd491f3454a 100644
--- a/net/socket_stream/socket_stream.cc
+++ b/net/socket_stream/socket_stream.cc
@@ -63,6 +63,9 @@ SocketStream::SocketStream(const GURL& url, Delegate* delegate)
server_bound_cert_service_(NULL),
http_auth_handler_factory_(NULL),
factory_(ClientSocketFactory::GetDefaultFactory()),
+ ALLOW_THIS_IN_INITIALIZER_LIST(before_connect_callback_(
+ base::Bind(&SocketStream::BeforeConnectComplete,
+ base::Unretained(this)))),
proxy_mode_(kDirectConnection),
proxy_url_(url),
pac_request_(NULL),
@@ -147,7 +150,7 @@ void SocketStream::Connect() {
AddRef(); // Released in Finish()
// Open a connection asynchronously, so that delegate won't be called
// back before returning Connect().
- next_state_ = STATE_RESOLVE_PROXY;
+ next_state_ = STATE_BEFORE_CONNECT;
net_log_.BeginEvent(
NetLog::TYPE_SOCKET_STREAM_CONNECT,
make_scoped_refptr(
@@ -410,6 +413,10 @@ void SocketStream::DoLoop(int result) {
State state = next_state_;
next_state_ = STATE_NONE;
switch (state) {
+ case STATE_BEFORE_CONNECT:
+ DCHECK_EQ(OK, result);
+ result = DoBeforeConnect();
+ break;
case STATE_RESOLVE_PROXY:
DCHECK_EQ(OK, result);
result = DoResolveProxy();
@@ -511,6 +518,19 @@ void SocketStream::DoLoop(int result) {
} while (result != ERR_IO_PENDING);
}
+int SocketStream::DoBeforeConnect() {
+ next_state_ = STATE_RESOLVE_PROXY;
+ if (!context_ || !context_->network_delegate())
+ return OK;
+
+ int result = context_->network_delegate()->NotifyBeforeSocketStreamConnect(
+ this, before_connect_callback_);
+ if (result != OK && result != ERR_IO_PENDING)
+ next_state_ = STATE_CLOSE;
+
+ return result;
+}
+
int SocketStream::DoResolveProxy() {
DCHECK(!pac_request_);
next_state_ = STATE_RESOLVE_PROXY_COMPLETE;
@@ -1072,6 +1092,16 @@ int SocketStream::DoReadWrite(int result) {
return ERR_IO_PENDING;
}
+void SocketStream::BeforeConnectComplete(int result) {
+ DCHECK_NE(ERR_IO_PENDING, result);
+
+ if (result == OK)
+ next_state_ = STATE_RESOLVE_PROXY;
+ else
+ next_state_ = STATE_CLOSE;
+ DoLoop(result);
+}
+
GURL SocketStream::ProxyAuthOrigin() const {
DCHECK(!proxy_info_.is_empty());
return GURL("http://" +

Powered by Google App Engine
This is Rietveld 408576698