Backed out changeset b06f19b95b94 (bug 1784438) for causing build bustages CLOSED...
[gecko.git] / toolkit / components / bitsdownload / Bits.cpp
blobda16e40497ccb39da147f9309a935becdfc036da
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 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 #include "mozilla/ClearOnShutdown.h"
7 #include "mozilla/StaticPtr.h"
8 #include "nsCOMPtr.h"
9 #include "Bits.h"
11 // This anonymous namespace prevents outside C++ code from improperly accessing
12 // these implementation details.
13 namespace {
14 extern "C" {
15 // Implemented in Rust.
16 void new_bits_service(nsIBits** result);
19 static mozilla::StaticRefPtr<nsIBits> sBitsService;
20 } // namespace
22 already_AddRefed<nsIBits> GetBitsService() {
23 nsCOMPtr<nsIBits> bitsService;
25 if (sBitsService) {
26 bitsService = sBitsService;
27 } else {
28 new_bits_service(getter_AddRefs(bitsService));
29 sBitsService = bitsService;
30 mozilla::ClearOnShutdown(&sBitsService);
33 return bitsService.forget();