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: #ifndef CHROME_COMMON_CHILD_PROCESS_INFO_H_ michael@0: #define CHROME_COMMON_CHILD_PROCESS_INFO_H_ michael@0: michael@0: #include michael@0: michael@0: #include "base/process.h" michael@0: michael@0: // Holds information about a child process. michael@0: class ChildProcessInfo { michael@0: public: michael@0: enum ProcessType { michael@0: BROWSER_PROCESS, michael@0: RENDER_PROCESS, michael@0: PLUGIN_PROCESS, michael@0: WORKER_PROCESS, michael@0: UNKNOWN_PROCESS michael@0: }; michael@0: michael@0: // Returns the type of the process. michael@0: ProcessType type() const { return type_; } michael@0: michael@0: // Returns the name of the process. i.e. for plugins it might be Flash, while michael@0: // for workers it might be the domain that it's from. michael@0: std::wstring name() const { return name_; } michael@0: michael@0: // Getter to the process handle. michael@0: base::ProcessHandle handle() const { return process_.handle(); } michael@0: michael@0: virtual int GetProcessId() const { michael@0: if (pid_ != -1) michael@0: return pid_; michael@0: michael@0: pid_ = process_.pid(); michael@0: return pid_; michael@0: } michael@0: void SetProcessBackgrounded() const { process_.SetProcessBackgrounded(true); } michael@0: michael@0: // Returns an English name of the process type, should only be used for non michael@0: // user-visible strings, or debugging pages like about:memory. michael@0: static std::wstring GetTypeNameInEnglish(ProcessType type); michael@0: michael@0: // Returns a localized title for the child process. For example, a plugin michael@0: // process would be "Plug-in: Flash" when name is "Flash". michael@0: std::wstring GetLocalizedTitle() const; michael@0: michael@0: ChildProcessInfo(const ChildProcessInfo& original) { michael@0: type_ = original.type_; michael@0: name_ = original.name_; michael@0: process_ = original.process_; michael@0: pid_ = original.pid_; michael@0: } michael@0: michael@0: ChildProcessInfo& operator=(const ChildProcessInfo& original) { michael@0: if (&original != this) { michael@0: type_ = original.type_; michael@0: name_ = original.name_; michael@0: process_ = original.process_; michael@0: pid_ = original.pid_; michael@0: } michael@0: return *this; michael@0: } michael@0: michael@0: virtual ~ChildProcessInfo(); michael@0: michael@0: // We define the < operator so that the ChildProcessInfo can be used as a key michael@0: // in a std::map. michael@0: bool operator <(const ChildProcessInfo& rhs) const { michael@0: if (process_.handle() != rhs.process_.handle()) michael@0: return process_ .handle() < rhs.process_.handle(); michael@0: return false; michael@0: } michael@0: michael@0: bool operator ==(const ChildProcessInfo& rhs) const { michael@0: return process_.handle() == rhs.process_.handle(); michael@0: } michael@0: michael@0: // Generates a unique channel name for a child renderer/plugin process. michael@0: // The "instance" pointer value is baked into the channel id. michael@0: static std::wstring GenerateRandomChannelID(void* instance); michael@0: michael@0: protected: michael@0: void set_type(ProcessType type) { type_ = type; } michael@0: void set_name(const std::wstring& name) { name_ = name; } michael@0: void set_handle(base::ProcessHandle handle) { michael@0: process_.set_handle(handle); michael@0: pid_ = -1; michael@0: } michael@0: michael@0: // Derived objects need to use this constructor so we know what type we are. michael@0: ChildProcessInfo(ProcessType type); michael@0: michael@0: private: michael@0: ProcessType type_; michael@0: std::wstring name_; michael@0: mutable int pid_; // Cache of the process id. michael@0: michael@0: // The handle to the process. michael@0: mutable base::Process process_; michael@0: }; michael@0: michael@0: #endif // CHROME_COMMON_CHILD_PROCESS_INFO_H_