SFVService.cpp (1064B)
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 7 #include "mozilla/ClearOnShutdown.h" 8 #include "mozilla/StaticPtr.h" 9 #include "nsCOMPtr.h" 10 #include "SFVService.h" 11 12 // This anonymous namespace prevents outside C++ code from improperly accessing 13 // these implementation details. 14 namespace { 15 extern "C" { 16 // Implemented in Rust. 17 void new_sfv_service(nsISFVService** result); 18 } 19 20 static mozilla::StaticRefPtr<nsISFVService> sService; 21 } // namespace 22 23 namespace mozilla::net { 24 25 already_AddRefed<nsISFVService> GetSFVService() { 26 nsCOMPtr<nsISFVService> service; 27 28 if (sService) { 29 service = sService; 30 } else { 31 new_sfv_service(getter_AddRefs(service)); 32 sService = service; 33 mozilla::ClearOnShutdown(&sService); 34 } 35 36 return service.forget(); 37 } 38 39 } // namespace mozilla::net