FileSystemQuotaClientFactory.cpp (1353B)
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 "FileSystemQuotaClientFactory.h" 8 9 #include "FileSystemQuotaClient.h" 10 #include "mozilla/RefPtr.h" 11 #include "mozilla/ipc/BackgroundParent.h" 12 13 namespace mozilla::dom::fs { 14 15 namespace { 16 17 StaticRefPtr<FileSystemQuotaClientFactory> gCustomFactory; 18 19 } // namespace 20 21 // static 22 void FileSystemQuotaClientFactory::SetCustomFactory( 23 RefPtr<FileSystemQuotaClientFactory> aCustomFactory) { 24 gCustomFactory = std::move(aCustomFactory); 25 } 26 27 // static 28 already_AddRefed<quota::Client> 29 FileSystemQuotaClientFactory::CreateQuotaClient() { 30 ::mozilla::ipc::AssertIsOnBackgroundThread(); 31 32 if (gCustomFactory) { 33 return gCustomFactory->AllocQuotaClient(); 34 } 35 36 auto factory = MakeRefPtr<FileSystemQuotaClientFactory>(); 37 38 return factory->AllocQuotaClient(); 39 } 40 41 already_AddRefed<quota::Client> 42 FileSystemQuotaClientFactory::AllocQuotaClient() { 43 ::mozilla::ipc::AssertIsOnBackgroundThread(); 44 45 RefPtr<FileSystemQuotaClient> result = new FileSystemQuotaClient(); 46 return result.forget(); 47 } 48 49 } // namespace mozilla::dom::fs