ipc/chromium/src/chrome/common/child_process_info.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/chrome/common/child_process_info.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +// Copyright (c) 2009 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "chrome/common/child_process_info.h"
     1.9 +
    1.10 +#include <limits>
    1.11 +
    1.12 +#include "base/logging.h"
    1.13 +#include "base/process_util.h"
    1.14 +#include "base/rand_util.h"
    1.15 +#include "base/string_util.h"
    1.16 +
    1.17 +std::wstring ChildProcessInfo::GetTypeNameInEnglish(
    1.18 +    ChildProcessInfo::ProcessType type) {
    1.19 +  switch (type) {
    1.20 +    case BROWSER_PROCESS:
    1.21 +      return L"Browser";
    1.22 +    case RENDER_PROCESS:
    1.23 +      return L"Tab";
    1.24 +    case PLUGIN_PROCESS:
    1.25 +      return L"Plug-in";
    1.26 +    case WORKER_PROCESS:
    1.27 +      return L"Web Worker";
    1.28 +    case UNKNOWN_PROCESS:
    1.29 +      default:
    1.30 +      DCHECK(false) << "Unknown child process type!";
    1.31 +      return L"Unknown";
    1.32 +    }
    1.33 +}
    1.34 +
    1.35 +std::wstring ChildProcessInfo::GetLocalizedTitle() const {
    1.36 +  return name_;
    1.37 +}
    1.38 +
    1.39 +ChildProcessInfo::ChildProcessInfo(ProcessType type) {
    1.40 +  // This constructor is only used by objects which derive from this class,
    1.41 +  // which means *this* is a real object that refers to a child process, and not
    1.42 +  // just a simple object that contains information about it.  So add it to our
    1.43 +  // list of running processes.
    1.44 +  type_ = type;
    1.45 +  pid_ = -1;
    1.46 +}
    1.47 +
    1.48 +
    1.49 +ChildProcessInfo::~ChildProcessInfo() {
    1.50 +}
    1.51 +
    1.52 +std::wstring ChildProcessInfo::GenerateRandomChannelID(void* instance) {
    1.53 +  // Note: the string must start with the current process id, this is how
    1.54 +  // child processes determine the pid of the parent.
    1.55 +  // Build the channel ID.  This is composed of a unique identifier for the
    1.56 +  // parent browser process, an identifier for the child instance, and a random
    1.57 +  // component. We use a random component so that a hacked child process can't
    1.58 +  // cause denial of service by causing future named pipe creation to fail.
    1.59 +  return StringPrintf(L"%d.%x.%d",
    1.60 +                      base::GetCurrentProcId(), instance,
    1.61 +                      base::RandInt(0, std::numeric_limits<int>::max()));
    1.62 +}

mercurial