LCOV - code coverage report
Current view: top level - netwerk/protocol/about - nsAboutProtocolUtils.h (source / functions) Hit Total Coverage
Test: output.info Lines: 15 25 60.0 %
Date: 2017-07-14 16:53:18 Functions: 2 4 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* This Source Code Form is subject to the terms of the Mozilla Public
       2             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       3             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       4             : 
       5             : #ifndef nsAboutProtocolUtils_h
       6             : #define nsAboutProtocolUtils_h
       7             : 
       8             : #include "nsIURI.h"
       9             : #include "nsString.h"
      10             : #include "nsReadableUtils.h"
      11             : #include "nsIAboutModule.h"
      12             : #include "nsServiceManagerUtils.h"
      13             : #include "prtime.h"
      14             : 
      15             : inline MOZ_MUST_USE nsresult
      16          79 : NS_GetAboutModuleName(nsIURI *aAboutURI, nsCString& aModule)
      17             : {
      18             : #ifdef DEBUG
      19             :     {
      20             :         bool isAbout;
      21          79 :         NS_ASSERTION(NS_SUCCEEDED(aAboutURI->SchemeIs("about", &isAbout)) &&
      22             :                      isAbout,
      23             :                      "should be used only on about: URIs");
      24             :     }
      25             : #endif
      26             : 
      27          79 :     nsresult rv = aAboutURI->GetPath(aModule);
      28          79 :     NS_ENSURE_SUCCESS(rv, rv);
      29             : 
      30          79 :     int32_t f = aModule.FindCharInSet(NS_LITERAL_CSTRING("#?"));
      31          79 :     if (f != kNotFound) {
      32           0 :         aModule.Truncate(f);
      33             :     }
      34             : 
      35             :     // convert to lowercase, as all about: modules are lowercase
      36          79 :     ToLowerCase(aModule);
      37          79 :     return NS_OK;
      38             : }
      39             : 
      40             : inline nsresult
      41          75 : NS_GetAboutModule(nsIURI *aAboutURI, nsIAboutModule** aModule)
      42             : {
      43          75 :   NS_PRECONDITION(aAboutURI, "Must have URI");
      44             : 
      45         150 :   nsAutoCString contractID;
      46          75 :   nsresult rv = NS_GetAboutModuleName(aAboutURI, contractID);
      47          75 :   if (NS_FAILED(rv)) return rv;
      48             : 
      49             :   // look up a handler to deal with "what"
      50          75 :   contractID.Insert(NS_LITERAL_CSTRING(NS_ABOUT_MODULE_CONTRACTID_PREFIX), 0);
      51             : 
      52          75 :   return CallGetService(contractID.get(), aModule);
      53             : }
      54             : 
      55           0 : inline PRTime SecondsToPRTime(uint32_t t_sec)
      56             : {
      57             :     PRTime t_usec, usec_per_sec;
      58           0 :     t_usec = t_sec;
      59           0 :     usec_per_sec = PR_USEC_PER_SEC;
      60           0 :     return t_usec *= usec_per_sec;
      61             : }
      62           0 : inline void PrintTimeString(char *buf, uint32_t bufsize, uint32_t t_sec)
      63             : {
      64             :     PRExplodedTime et;
      65           0 :     PRTime t_usec = SecondsToPRTime(t_sec);
      66           0 :     PR_ExplodeTime(t_usec, PR_LocalTimeParameters, &et);
      67           0 :     PR_FormatTime(buf, bufsize, "%Y-%m-%d %H:%M:%S", &et);
      68           0 : }
      69             : 
      70             : 
      71             : #endif

Generated by: LCOV version 1.13