summaryrefslogtreecommitdiffstats
path: root/net/spdy
diff options
context:
space:
mode:
authorrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-09 01:17:04 +0000
committerrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-09 01:17:04 +0000
commita3ddb80e63d345035c0700518b4029d47e8ed2af (patch)
tree0e3893ab9b9b8e963ad11f87d0182347c194db9c /net/spdy
parent8dbca13f0485c7f18b4baf06e03508da593075ef (diff)
downloadchromium_src-a3ddb80e63d345035c0700518b4029d47e8ed2af.zip
chromium_src-a3ddb80e63d345035c0700518b4029d47e8ed2af.tar.gz
chromium_src-a3ddb80e63d345035c0700518b4029d47e8ed2af.tar.bz2
Add a GetSSLClientSocket helper method to SpdySession to eliminate the various calls to reinterpret_cast<>().
Review URL: http://codereview.chromium.org/9630017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125754 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r--net/spdy/spdy_session.cc70
-rw-r--r--net/spdy/spdy_session.h4
2 files changed, 34 insertions, 40 deletions
diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc
index 9a8063b..78b5993 100644
--- a/net/spdy/spdy_session.cc
+++ b/net/spdy/spdy_session.cc
@@ -382,9 +382,7 @@ net::Error SpdySession::InitializeWithSocket(
certificate_error_code_ = certificate_error_code;
if (is_secure_) {
- SSLClientSocket* ssl_socket =
- reinterpret_cast<SSLClientSocket*>(connection_->socket());
- DCHECK(ssl_socket);
+ SSLClientSocket* ssl_socket = GetSSLClientSocket();
SSLClientSocket::NextProto protocol_negotiated =
ssl_socket->protocol_negotiated();
@@ -575,8 +573,7 @@ int SpdySession::CreateStreamImpl(
bool SpdySession::NeedsCredentials(const HostPortPair& origin) const {
if (!is_secure_)
return false;
- SSLClientSocket* ssl_socket =
- reinterpret_cast<SSLClientSocket*>(connection_->socket());
+ SSLClientSocket* ssl_socket = GetSSLClientSocket();
if (ssl_socket->protocol_negotiated() < SSLClientSocket::kProtoSPDY3)
return false;
if (!ssl_socket->WasOriginBoundCertSent())
@@ -632,12 +629,10 @@ int SpdySession::WriteCredentialFrame(const std::string& origin,
const std::string& cert,
RequestPriority priority) {
DCHECK(is_secure_);
- SSLClientSocket* ssl_socket =
- reinterpret_cast<SSLClientSocket*>(connection_->socket());
unsigned char secret[32]; // 32 bytes from the spec
- ssl_socket->ExportKeyingMaterial("SPDY certificate proof",
- origin,
- secret, arraysize(secret));
+ GetSSLClientSocket()->ExportKeyingMaterial("SPDY certificate proof",
+ origin,
+ secret, arraysize(secret));
// Convert the key string into a vector<unit8>
std::vector<uint8> key_data;
@@ -1116,10 +1111,7 @@ Value* SpdySession::GetInfoAsValue() const {
SSLClientSocket::NextProto proto = SSLClientSocket::kProtoUnknown;
if (is_secure_) {
- SSLClientSocket* ssl_socket =
- reinterpret_cast<SSLClientSocket*>(connection_->socket());
- DCHECK(ssl_socket);
- proto = ssl_socket->protocol_negotiated();
+ proto = GetSSLClientSocket()->protocol_negotiated();
}
dict->SetString("protocol_negotiated",
SSLClientSocket::NextProtoToString(proto));
@@ -1220,46 +1212,35 @@ scoped_refptr<SpdyStream> SpdySession::GetActivePushStream(
bool SpdySession::GetSSLInfo(SSLInfo* ssl_info,
bool* was_npn_negotiated,
SSLClientSocket::NextProto* protocol_negotiated) {
- if (is_secure_) {
- SSLClientSocket* ssl_socket =
- reinterpret_cast<SSLClientSocket*>(connection_->socket());
- ssl_socket->GetSSLInfo(ssl_info);
- *was_npn_negotiated = ssl_socket->was_npn_negotiated();
- *protocol_negotiated = ssl_socket->protocol_negotiated();
- return true;
- } else {
+ if (!is_secure_) {
*protocol_negotiated = SSLClientSocket::kProtoUnknown;
+ return false;
}
- return false;
+ SSLClientSocket* ssl_socket = GetSSLClientSocket();
+ ssl_socket->GetSSLInfo(ssl_info);
+ *was_npn_negotiated = ssl_socket->was_npn_negotiated();
+ *protocol_negotiated = ssl_socket->protocol_negotiated();
+ return true;
}
bool SpdySession::GetSSLCertRequestInfo(
SSLCertRequestInfo* cert_request_info) {
- if (is_secure_) {
- SSLClientSocket* ssl_socket =
- reinterpret_cast<SSLClientSocket*>(connection_->socket());
- ssl_socket->GetSSLCertRequestInfo(cert_request_info);
- return true;
- }
- return false;
+ if (!is_secure_)
+ return false;
+ GetSSLClientSocket()->GetSSLCertRequestInfo(cert_request_info);
+ return true;
}
OriginBoundCertService* SpdySession::GetOriginBoundCertService() const {
- if (!is_secure_) {
+ if (!is_secure_)
return NULL;
- }
- SSLClientSocket* ssl_socket =
- reinterpret_cast<SSLClientSocket*>(connection_->socket());
- return ssl_socket->GetOriginBoundCertService();
+ return GetSSLClientSocket()->GetOriginBoundCertService();
}
SSLClientCertType SpdySession::GetOriginBoundCertType() const {
- if (!is_secure_) {
+ if (!is_secure_)
return CLIENT_CERT_INVALID_TYPE;
- }
- SSLClientSocket* ssl_socket =
- reinterpret_cast<SSLClientSocket*>(connection_->socket());
- return ssl_socket->origin_bound_cert_type();
+ return GetSSLClientSocket()->origin_bound_cert_type();
}
void SpdySession::OnError(int error_code) {
@@ -1907,4 +1888,13 @@ void SpdySession::InvokeUserStreamCreationCallback(
callback.Run(result);
}
+SSLClientSocket* SpdySession::GetSSLClientSocket() const {
+ if (!is_secure_)
+ return NULL;
+ SSLClientSocket* ssl_socket =
+ reinterpret_cast<SSLClientSocket*>(connection_->socket());
+ DCHECK(ssl_socket);
+ return ssl_socket;
+}
+
} // namespace net
diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h
index b3208d6..6f33dfc 100644
--- a/net/spdy/spdy_session.h
+++ b/net/spdy/spdy_session.h
@@ -487,6 +487,10 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>,
bool check_ping_status_pending() const { return check_ping_status_pending_; }
+ // Returns the SSLClientSocket that this SPDY session sits on top of,
+ // or NULL, if the transport is not SSL.
+ SSLClientSocket* GetSSLClientSocket() const;
+
// Used for posting asynchronous IO tasks. We use this even though
// SpdySession is refcounted because we don't need to keep the SpdySession
// alive if the last reference is within a RunnableMethod. Just revoke the