Bug 1688832: part 5) Add `static` `AccessibleCaretManager::GetSelection`, `::GetFrame...
[gecko.git] / netwerk / cache / nsCache.cpp
blob73b98dee1c769a405cbc096b482a73160b127160
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 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/. */
7 #include "nsCache.h"
8 #include "nsReadableUtils.h"
9 #include "nsDependentSubstring.h"
10 #include "nsString.h"
11 #include "mozilla/IntegerPrintfMacros.h"
13 /**
14 * Cache Service Utility Functions
17 mozilla::LazyLogModule gCacheLog("cache");
19 void CacheLogPrintPath(mozilla::LogLevel level, const char* format,
20 nsIFile* item) {
21 MOZ_LOG(gCacheLog, level, (format, item->HumanReadablePath().get()));
24 uint32_t SecondsFromPRTime(PRTime prTime) {
25 int64_t microSecondsPerSecond = PR_USEC_PER_SEC;
26 return uint32_t(prTime / microSecondsPerSecond);
29 PRTime PRTimeFromSeconds(uint32_t seconds) {
30 int64_t intermediateResult = seconds;
31 PRTime prTime = intermediateResult * PR_USEC_PER_SEC;
32 return prTime;
35 nsresult ClientIDFromCacheKey(const nsACString& key, nsACString& result) {
36 nsReadingIterator<char> colon;
37 key.BeginReading(colon);
39 nsReadingIterator<char> start;
40 key.BeginReading(start);
42 nsReadingIterator<char> end;
43 key.EndReading(end);
45 if (FindCharInReadable(':', colon, end)) {
46 result.Assign(Substring(start, colon));
47 return NS_OK;
50 NS_ASSERTION(false, "FindCharInRead failed to find ':'");
51 return NS_ERROR_UNEXPECTED;
54 nsresult ClientKeyFromCacheKey(const nsCString& key, nsACString& result) {
55 nsReadingIterator<char> start;
56 key.BeginReading(start);
58 nsReadingIterator<char> end;
59 key.EndReading(end);
61 if (FindCharInReadable(':', start, end)) {
62 ++start; // advance past clientID ':' delimiter
63 result.Assign(Substring(start, end));
64 return NS_OK;
67 NS_ASSERTION(false, "FindCharInRead failed to find ':'");
68 result.Truncate(0);
69 return NS_ERROR_UNEXPECTED;