michael@0: // Copyright (c) 2009 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "chrome/common/child_process_info.h" michael@0: michael@0: #include michael@0: michael@0: #include "base/logging.h" michael@0: #include "base/process_util.h" michael@0: #include "base/rand_util.h" michael@0: #include "base/string_util.h" michael@0: michael@0: std::wstring ChildProcessInfo::GetTypeNameInEnglish( michael@0: ChildProcessInfo::ProcessType type) { michael@0: switch (type) { michael@0: case BROWSER_PROCESS: michael@0: return L"Browser"; michael@0: case RENDER_PROCESS: michael@0: return L"Tab"; michael@0: case PLUGIN_PROCESS: michael@0: return L"Plug-in"; michael@0: case WORKER_PROCESS: michael@0: return L"Web Worker"; michael@0: case UNKNOWN_PROCESS: michael@0: default: michael@0: DCHECK(false) << "Unknown child process type!"; michael@0: return L"Unknown"; michael@0: } michael@0: } michael@0: michael@0: std::wstring ChildProcessInfo::GetLocalizedTitle() const { michael@0: return name_; michael@0: } michael@0: michael@0: ChildProcessInfo::ChildProcessInfo(ProcessType type) { michael@0: // This constructor is only used by objects which derive from this class, michael@0: // which means *this* is a real object that refers to a child process, and not michael@0: // just a simple object that contains information about it. So add it to our michael@0: // list of running processes. michael@0: type_ = type; michael@0: pid_ = -1; michael@0: } michael@0: michael@0: michael@0: ChildProcessInfo::~ChildProcessInfo() { michael@0: } michael@0: michael@0: std::wstring ChildProcessInfo::GenerateRandomChannelID(void* instance) { michael@0: // Note: the string must start with the current process id, this is how michael@0: // child processes determine the pid of the parent. michael@0: // Build the channel ID. This is composed of a unique identifier for the michael@0: // parent browser process, an identifier for the child instance, and a random michael@0: // component. We use a random component so that a hacked child process can't michael@0: // cause denial of service by causing future named pipe creation to fail. michael@0: return StringPrintf(L"%d.%x.%d", michael@0: base::GetCurrentProcId(), instance, michael@0: base::RandInt(0, std::numeric_limits::max())); michael@0: }