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