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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
     2 // Use of this source code is governed by a BSD-style license that can be
     3 // found in the LICENSE file.
     5 #include "chrome/common/child_process_info.h"
     7 #include <limits>
     9 #include "base/logging.h"
    10 #include "base/process_util.h"
    11 #include "base/rand_util.h"
    12 #include "base/string_util.h"
    14 std::wstring ChildProcessInfo::GetTypeNameInEnglish(
    15     ChildProcessInfo::ProcessType type) {
    16   switch (type) {
    17     case BROWSER_PROCESS:
    18       return L"Browser";
    19     case RENDER_PROCESS:
    20       return L"Tab";
    21     case PLUGIN_PROCESS:
    22       return L"Plug-in";
    23     case WORKER_PROCESS:
    24       return L"Web Worker";
    25     case UNKNOWN_PROCESS:
    26       default:
    27       DCHECK(false) << "Unknown child process type!";
    28       return L"Unknown";
    29     }
    30 }
    32 std::wstring ChildProcessInfo::GetLocalizedTitle() const {
    33   return name_;
    34 }
    36 ChildProcessInfo::ChildProcessInfo(ProcessType type) {
    37   // This constructor is only used by objects which derive from this class,
    38   // which means *this* is a real object that refers to a child process, and not
    39   // just a simple object that contains information about it.  So add it to our
    40   // list of running processes.
    41   type_ = type;
    42   pid_ = -1;
    43 }
    46 ChildProcessInfo::~ChildProcessInfo() {
    47 }
    49 std::wstring ChildProcessInfo::GenerateRandomChannelID(void* instance) {
    50   // Note: the string must start with the current process id, this is how
    51   // child processes determine the pid of the parent.
    52   // Build the channel ID.  This is composed of a unique identifier for the
    53   // parent browser process, an identifier for the child instance, and a random
    54   // component. We use a random component so that a hacked child process can't
    55   // cause denial of service by causing future named pipe creation to fail.
    56   return StringPrintf(L"%d.%x.%d",
    57                       base::GetCurrentProcId(), instance,
    58                       base::RandInt(0, std::numeric_limits<int>::max()));
    59 }

mercurial