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

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.

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 #ifndef CHROME_COMMON_CHILD_PROCESS_INFO_H_
michael@0 6 #define CHROME_COMMON_CHILD_PROCESS_INFO_H_
michael@0 7
michael@0 8 #include <string>
michael@0 9
michael@0 10 #include "base/process.h"
michael@0 11
michael@0 12 // Holds information about a child process.
michael@0 13 class ChildProcessInfo {
michael@0 14 public:
michael@0 15 enum ProcessType {
michael@0 16 BROWSER_PROCESS,
michael@0 17 RENDER_PROCESS,
michael@0 18 PLUGIN_PROCESS,
michael@0 19 WORKER_PROCESS,
michael@0 20 UNKNOWN_PROCESS
michael@0 21 };
michael@0 22
michael@0 23 // Returns the type of the process.
michael@0 24 ProcessType type() const { return type_; }
michael@0 25
michael@0 26 // Returns the name of the process. i.e. for plugins it might be Flash, while
michael@0 27 // for workers it might be the domain that it's from.
michael@0 28 std::wstring name() const { return name_; }
michael@0 29
michael@0 30 // Getter to the process handle.
michael@0 31 base::ProcessHandle handle() const { return process_.handle(); }
michael@0 32
michael@0 33 virtual int GetProcessId() const {
michael@0 34 if (pid_ != -1)
michael@0 35 return pid_;
michael@0 36
michael@0 37 pid_ = process_.pid();
michael@0 38 return pid_;
michael@0 39 }
michael@0 40 void SetProcessBackgrounded() const { process_.SetProcessBackgrounded(true); }
michael@0 41
michael@0 42 // Returns an English name of the process type, should only be used for non
michael@0 43 // user-visible strings, or debugging pages like about:memory.
michael@0 44 static std::wstring GetTypeNameInEnglish(ProcessType type);
michael@0 45
michael@0 46 // Returns a localized title for the child process. For example, a plugin
michael@0 47 // process would be "Plug-in: Flash" when name is "Flash".
michael@0 48 std::wstring GetLocalizedTitle() const;
michael@0 49
michael@0 50 ChildProcessInfo(const ChildProcessInfo& original) {
michael@0 51 type_ = original.type_;
michael@0 52 name_ = original.name_;
michael@0 53 process_ = original.process_;
michael@0 54 pid_ = original.pid_;
michael@0 55 }
michael@0 56
michael@0 57 ChildProcessInfo& operator=(const ChildProcessInfo& original) {
michael@0 58 if (&original != this) {
michael@0 59 type_ = original.type_;
michael@0 60 name_ = original.name_;
michael@0 61 process_ = original.process_;
michael@0 62 pid_ = original.pid_;
michael@0 63 }
michael@0 64 return *this;
michael@0 65 }
michael@0 66
michael@0 67 virtual ~ChildProcessInfo();
michael@0 68
michael@0 69 // We define the < operator so that the ChildProcessInfo can be used as a key
michael@0 70 // in a std::map.
michael@0 71 bool operator <(const ChildProcessInfo& rhs) const {
michael@0 72 if (process_.handle() != rhs.process_.handle())
michael@0 73 return process_ .handle() < rhs.process_.handle();
michael@0 74 return false;
michael@0 75 }
michael@0 76
michael@0 77 bool operator ==(const ChildProcessInfo& rhs) const {
michael@0 78 return process_.handle() == rhs.process_.handle();
michael@0 79 }
michael@0 80
michael@0 81 // Generates a unique channel name for a child renderer/plugin process.
michael@0 82 // The "instance" pointer value is baked into the channel id.
michael@0 83 static std::wstring GenerateRandomChannelID(void* instance);
michael@0 84
michael@0 85 protected:
michael@0 86 void set_type(ProcessType type) { type_ = type; }
michael@0 87 void set_name(const std::wstring& name) { name_ = name; }
michael@0 88 void set_handle(base::ProcessHandle handle) {
michael@0 89 process_.set_handle(handle);
michael@0 90 pid_ = -1;
michael@0 91 }
michael@0 92
michael@0 93 // Derived objects need to use this constructor so we know what type we are.
michael@0 94 ChildProcessInfo(ProcessType type);
michael@0 95
michael@0 96 private:
michael@0 97 ProcessType type_;
michael@0 98 std::wstring name_;
michael@0 99 mutable int pid_; // Cache of the process id.
michael@0 100
michael@0 101 // The handle to the process.
michael@0 102 mutable base::Process process_;
michael@0 103 };
michael@0 104
michael@0 105 #endif // CHROME_COMMON_CHILD_PROCESS_INFO_H_

mercurial