Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/cache/nsCache.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
 *
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
#include "nsCache.h"
8
#include "nsReadableUtils.h"
9
#include "nsDependentSubstring.h"
10
#include "nsString.h"
11
#include "mozilla/IntegerPrintfMacros.h"
12
13
14
/**
15
 * Cache Service Utility Functions
16
 */
17
18
mozilla::LazyLogModule gCacheLog("cache");
19
20
void
21
CacheLogPrintPath(mozilla::LogLevel level, const char * format, nsIFile * item)
22
0
{
23
0
    MOZ_LOG(gCacheLog, level, (format, item->HumanReadablePath().get()));
24
0
}
25
26
27
uint32_t
28
SecondsFromPRTime(PRTime prTime)
29
0
{
30
0
  int64_t  microSecondsPerSecond = PR_USEC_PER_SEC;
31
0
  return uint32_t(prTime / microSecondsPerSecond);
32
0
}
33
34
35
PRTime
36
PRTimeFromSeconds(uint32_t seconds)
37
0
{
38
0
  int64_t intermediateResult = seconds;
39
0
  PRTime prTime = intermediateResult * PR_USEC_PER_SEC;
40
0
  return prTime;
41
0
}
42
43
44
nsresult
45
ClientIDFromCacheKey(const nsACString& key, nsACString& result)
46
0
{
47
0
    nsReadingIterator<char> colon;
48
0
    key.BeginReading(colon);
49
0
50
0
    nsReadingIterator<char> start;
51
0
    key.BeginReading(start);
52
0
53
0
    nsReadingIterator<char> end;
54
0
    key.EndReading(end);
55
0
56
0
    if (FindCharInReadable(':', colon, end)) {
57
0
        result.Assign(Substring(start, colon));
58
0
        return NS_OK;
59
0
    }
60
0
61
0
    NS_ASSERTION(false, "FindCharInRead failed to find ':'");
62
0
    return NS_ERROR_UNEXPECTED;
63
0
}
64
65
66
nsresult
67
ClientKeyFromCacheKey(const nsCString& key, nsACString &result)
68
0
{
69
0
    nsReadingIterator<char> start;
70
0
    key.BeginReading(start);
71
0
72
0
    nsReadingIterator<char> end;
73
0
    key.EndReading(end);
74
0
75
0
    if (FindCharInReadable(':', start, end)) {
76
0
        ++start;  // advance past clientID ':' delimiter
77
0
        result.Assign(Substring(start, end));
78
0
        return NS_OK;
79
0
    }
80
0
81
0
    NS_ASSERTION(false, "FindCharInRead failed to find ':'");
82
0
    result.Truncate(0);
83
0
    return NS_ERROR_UNEXPECTED;
84
0
}