LCOV - code coverage report
Current view: top level - netwerk/protocol/http - ASpdySession.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 5 47 10.6 %
Date: 2017-07-14 16:53:18 Functions: 1 11 9.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set sw=2 ts=8 et tw=80 : */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : // HttpLog.h should generally be included first
       8             : #include "HttpLog.h"
       9             : 
      10             : /*
      11             :   Currently supported is h2
      12             : */
      13             : 
      14             : #include "nsHttp.h"
      15             : #include "nsHttpHandler.h"
      16             : 
      17             : #include "ASpdySession.h"
      18             : #include "PSpdyPush.h"
      19             : #include "Http2Push.h"
      20             : #include "Http2Session.h"
      21             : 
      22             : #include "mozilla/Telemetry.h"
      23             : 
      24             : namespace mozilla {
      25             : namespace net {
      26             : 
      27           0 : ASpdySession::ASpdySession()
      28             : {
      29           0 : }
      30             : 
      31             : ASpdySession::~ASpdySession() = default;
      32             : 
      33             : ASpdySession *
      34           0 : ASpdySession::NewSpdySession(uint32_t version,
      35             :                              nsISocketTransport *aTransport,
      36             :                              bool attemptingEarlyData)
      37             : {
      38             :   // This is a necko only interface, so we can enforce version
      39             :   // requests as a precondition
      40           0 :   MOZ_ASSERT(version == HTTP_VERSION_2,
      41             :              "Unsupported spdy version");
      42             : 
      43             :   // Don't do a runtime check of IsSpdyV?Enabled() here because pref value
      44             :   // may have changed since starting negotiation. The selected protocol comes
      45             :   // from a list provided in the SERVER HELLO filtered by our acceptable
      46             :   // versions, so there is no risk of the server ignoring our prefs.
      47             : 
      48           0 :   Telemetry::Accumulate(Telemetry::SPDY_VERSION2, version);
      49             : 
      50           0 :   return new Http2Session(aTransport, version, attemptingEarlyData);
      51             : }
      52             : 
      53           2 : SpdyInformation::SpdyInformation()
      54             : {
      55             :   // highest index of enabled protocols is the
      56             :   // most preferred for ALPN negotiaton
      57           2 :   Version[0] = HTTP_VERSION_2;
      58           2 :   VersionString[0] = NS_LITERAL_CSTRING("h2");
      59           2 :   ALPNCallbacks[0] = Http2Session::ALPNCallback;
      60           2 : }
      61             : 
      62             : bool
      63           0 : SpdyInformation::ProtocolEnabled(uint32_t index) const
      64             : {
      65           0 :   MOZ_ASSERT(index < kCount, "index out of range");
      66             : 
      67           0 :   return gHttpHandler->IsHttp2Enabled();
      68             : }
      69             : 
      70             : nsresult
      71           0 : SpdyInformation::GetNPNIndex(const nsACString &npnString,
      72             :                              uint32_t *result) const
      73             : {
      74           0 :   if (npnString.IsEmpty())
      75           0 :     return NS_ERROR_FAILURE;
      76             : 
      77           0 :   for (uint32_t index = 0; index < kCount; ++index) {
      78           0 :     if (npnString.Equals(VersionString[index])) {
      79           0 :       *result = index;
      80           0 :       return NS_OK;
      81             :     }
      82             :   }
      83             : 
      84           0 :   return NS_ERROR_FAILURE;
      85             : }
      86             : 
      87             : //////////////////////////////////////////
      88             : // SpdyPushCache
      89             : //////////////////////////////////////////
      90             : 
      91           0 : SpdyPushCache::SpdyPushCache()
      92             : {
      93           0 : }
      94             : 
      95           0 : SpdyPushCache::~SpdyPushCache()
      96             : {
      97           0 :   mHashHttp2.Clear();
      98           0 : }
      99             : 
     100             : bool
     101           0 : SpdyPushCache::RegisterPushedStreamHttp2(const nsCString& key,
     102             :                                          Http2PushedStream *stream)
     103             : {
     104           0 :   LOG3(("SpdyPushCache::RegisterPushedStreamHttp2 %s 0x%X\n",
     105             :         key.get(), stream->StreamID()));
     106           0 :   if(mHashHttp2.Get(key)) {
     107           0 :     LOG3(("SpdyPushCache::RegisterPushedStreamHttp2 %s 0x%X duplicate key\n",
     108             :           key.get(), stream->StreamID()));
     109           0 :     return false;
     110             :   }
     111           0 :   mHashHttp2.Put(key, stream);
     112           0 :   return true;
     113             : }
     114             : 
     115             : Http2PushedStream *
     116           0 : SpdyPushCache::RemovePushedStreamHttp2(const nsCString& key)
     117             : {
     118           0 :   Http2PushedStream *rv = mHashHttp2.Get(key);
     119           0 :   LOG3(("SpdyPushCache::RemovePushedStreamHttp2 %s 0x%X\n",
     120             :         key.get(), rv ? rv->StreamID() : 0));
     121           0 :   if (rv)
     122           0 :     mHashHttp2.Remove(key);
     123           0 :   return rv;
     124             : }
     125             : 
     126             : Http2PushedStream *
     127           0 : SpdyPushCache::RemovePushedStreamHttp2ByID(const nsCString& key, const uint32_t& streamID)
     128             : {
     129           0 :   Http2PushedStream *rv = mHashHttp2.Get(key);
     130           0 :   LOG3(("SpdyPushCache::RemovePushedStreamHttp2ByID %s 0x%X 0x%X",
     131             :         key.get(), rv ? rv->StreamID() : 0, streamID));
     132           0 :   if (rv && streamID == rv->StreamID()) {
     133           0 :     mHashHttp2.Remove(key);
     134             :   } else {
     135             :     // Ensure we overwrite our rv with null in case the stream IDs don't match
     136           0 :     rv = nullptr;
     137             :   }
     138           0 :   return rv;
     139             : }
     140             : 
     141             : } // namespace net
     142             : } // namespace mozilla
     143             : 

Generated by: LCOV version 1.13