HeapSnapshotTempFileHelperParent.cpp (1725B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set sw=2 ts=8 et 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/devtools/HeapSnapshot.h" 8 #include "mozilla/devtools/HeapSnapshotTempFileHelperParent.h" 9 #include "mozilla/ErrorResult.h" 10 #include "private/pprio.h" 11 12 #include "nsIFile.h" 13 14 namespace mozilla { 15 namespace devtools { 16 17 static bool openFileFailure(ErrorResult& rv, 18 OpenHeapSnapshotTempFileResponse* outResponse) { 19 *outResponse = rv.StealNSResult(); 20 return true; 21 } 22 23 mozilla::ipc::IPCResult 24 HeapSnapshotTempFileHelperParent::RecvOpenHeapSnapshotTempFile( 25 OpenHeapSnapshotTempFileResponse* outResponse) { 26 auto start = TimeStamp::Now(); 27 ErrorResult rv; 28 nsAutoString filePath; 29 nsAutoString snapshotId; 30 nsCOMPtr<nsIFile> file = 31 HeapSnapshot::CreateUniqueCoreDumpFile(rv, start, filePath, snapshotId); 32 if (NS_WARN_IF(rv.Failed())) { 33 if (!openFileFailure(rv, outResponse)) { 34 return IPC_FAIL_NO_REASON(this); 35 } 36 return IPC_OK(); 37 } 38 39 PRFileDesc* prfd; 40 rv = file->OpenNSPRFileDesc(PR_WRONLY, 0, &prfd); 41 if (NS_WARN_IF(rv.Failed())) { 42 if (!openFileFailure(rv, outResponse)) { 43 return IPC_FAIL_NO_REASON(this); 44 } 45 return IPC_OK(); 46 } 47 48 FileDescriptor::PlatformHandleType handle = 49 FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(prfd)); 50 FileDescriptor fd(handle); 51 *outResponse = OpenedFile(filePath, snapshotId, fd); 52 return IPC_OK(); 53 } 54 55 } // namespace devtools 56 } // namespace mozilla