Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/devtools/shared/heapsnapshot/HeapSnapshotTempFileHelperParent.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* vim: set sw=4 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
using ipc::FileDescriptor;
18
19
static bool
20
openFileFailure(ErrorResult& rv,
21
                OpenHeapSnapshotTempFileResponse* outResponse)
22
0
{
23
0
    *outResponse = rv.StealNSResult();
24
0
    return true;
25
0
}
26
27
mozilla::ipc::IPCResult
28
HeapSnapshotTempFileHelperParent::RecvOpenHeapSnapshotTempFile(
29
    OpenHeapSnapshotTempFileResponse* outResponse)
30
0
{
31
0
    auto start = TimeStamp::Now();
32
0
    ErrorResult rv;
33
0
    nsAutoString filePath;
34
0
    nsAutoString snapshotId;
35
0
    nsCOMPtr<nsIFile> file = HeapSnapshot::CreateUniqueCoreDumpFile(rv,
36
0
                                                                    start,
37
0
                                                                    filePath,
38
0
                                                                    snapshotId);
39
0
    if (NS_WARN_IF(rv.Failed())) {
40
0
        if (!openFileFailure(rv, outResponse)) {
41
0
          return IPC_FAIL_NO_REASON(this);
42
0
        }
43
0
        return IPC_OK();
44
0
    }
45
0
46
0
    PRFileDesc* prfd;
47
0
    rv = file->OpenNSPRFileDesc(PR_WRONLY, 0, &prfd);
48
0
    if (NS_WARN_IF(rv.Failed())) {
49
0
        if (!openFileFailure(rv, outResponse)) {
50
0
          return IPC_FAIL_NO_REASON(this);
51
0
        }
52
0
        return IPC_OK();
53
0
    }
54
0
55
0
    FileDescriptor::PlatformHandleType handle =
56
0
        FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(prfd));
57
0
    FileDescriptor fd(handle);
58
0
    *outResponse = OpenedFile(filePath, snapshotId, fd);
59
0
    return IPC_OK();
60
0
}
61
62
} // namespace devtools
63
} // namespace mozilla