chromium/remoting/base/breakpad_utils.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "remoting/base/breakpad_utils.h"

#include <utility>

#include "base/base_paths.h"
#include "base/check.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "remoting/base/version.h"

#if BUILDFLAG(IS_WIN)
#include <windows.h>
#endif

namespace remoting {

// This class is allowlisted in thread_restrictions.h.
class ScopedAllowBlockingForCrashReporting : public base::ScopedAllowBlocking {};

namespace {

const base::BasePathKey kBasePathKey =// We can't use %TEMP% for Windows because our processes run as SYSTEM,
    // Local Service, and the user. SYSTEM processes will write to %WINDIR%\Temp
    // which we don't want to do and if a crash occurs before login, there isn't
    // a user temp env var to query. Because of these issues, we store the crash
    // dumps, which are usually < 100KB, in the install folder so they will get
    // cleaned up when the user uninstalls or we push an update.
    base::BasePathKey::DIR_ASSETS;
#else
    base::BasePathKey::DIR_TEMP;
#endif

const base::FilePath::CharType kMinidumpsPath[] =FILE_PATH_LITERAL("minidumps");
#else
    FILE_PATH_LITERAL("chromoting/minidumps");
#endif

const base::FilePath::CharType kTempExtension[] =);
const base::FilePath::CharType kJsonExtension[] =);

}  // namespace

const char kBreakpadProductVersionKey[] =;
const char kBreakpadProcessStartTimeKey[] =;
const char kBreakpadProcessIdKey[] =;
const char kBreakpadProcessNameKey[] =;
const char kBreakpadProcessUptimeKey[] =;

#if BUILDFLAG(IS_WIN)

const wchar_t kCrashServerPipeName[] =
    L"\\\\.\\pipe\\RemotingCrashService\\S-1-5-18";

base::win::ScopedHandle GetClientHandleForCrashServerPipe() {
  const ACCESS_MASK kPipeAccessMask = FILE_READ_ATTRIBUTES | FILE_READ_DATA |
                                      FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA |
                                      SYNCHRONIZE;
  const DWORD kPipeFlagsAndAttributes =
      SECURITY_IDENTIFICATION | SECURITY_SQOS_PRESENT;

  SECURITY_ATTRIBUTES security_attributes = {0};
  security_attributes.bInheritHandle = true;

  base::win::ScopedHandle handle(
      CreateFile(kCrashServerPipeName, kPipeAccessMask,
                 /*dwShareMode=*/0, &security_attributes, OPEN_EXISTING,
                 kPipeFlagsAndAttributes,
                 /*hTemplateFile=*/nullptr));
  if (!handle.get()) {
    PLOG(ERROR) << "Failed to open named pipe to crash server.";
  }

  return handle;
}

#endif  // BUILDFLAG(IS_WIN)

base::FilePath GetMinidumpDirectoryPath() {}

bool CreateMinidumpDirectoryIfNeeded(const base::FilePath& minidump_directory) {}

bool WriteMetadataForMinidump(const base::FilePath& minidump_file_path,
                              base::Value::Dict metadata) {}

BreakpadHelper::BreakpadHelper() = default;
BreakpadHelper::~BreakpadHelper() = default;

bool BreakpadHelper::Initialize(const base::FilePath& minidump_directory) {}

void BreakpadHelper::OnException() {}

bool BreakpadHelper::OnMinidumpGenerated(
    const base::FilePath& minidump_file_path) {}

}  // namespace remoting