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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/chrome/common/child_process_info.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,105 @@
     1.4 +// Copyright (c) 2009 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef CHROME_COMMON_CHILD_PROCESS_INFO_H_
     1.9 +#define CHROME_COMMON_CHILD_PROCESS_INFO_H_
    1.10 +
    1.11 +#include <string>
    1.12 +
    1.13 +#include "base/process.h"
    1.14 +
    1.15 +// Holds information about a child process.
    1.16 +class ChildProcessInfo {
    1.17 + public:
    1.18 +  enum ProcessType {
    1.19 +    BROWSER_PROCESS,
    1.20 +    RENDER_PROCESS,
    1.21 +    PLUGIN_PROCESS,
    1.22 +    WORKER_PROCESS,
    1.23 +    UNKNOWN_PROCESS
    1.24 +  };
    1.25 +
    1.26 +  // Returns the type of the process.
    1.27 +  ProcessType type() const { return type_; }
    1.28 +
    1.29 +  // Returns the name of the process.  i.e. for plugins it might be Flash, while
    1.30 +  // for workers it might be the domain that it's from.
    1.31 +  std::wstring name() const { return name_; }
    1.32 +
    1.33 +  // Getter to the process handle.
    1.34 +  base::ProcessHandle handle() const { return process_.handle(); }
    1.35 +
    1.36 +  virtual int GetProcessId() const {
    1.37 +    if (pid_ != -1)
    1.38 +      return pid_;
    1.39 +
    1.40 +    pid_ = process_.pid();
    1.41 +    return pid_;
    1.42 +  }
    1.43 +  void SetProcessBackgrounded() const { process_.SetProcessBackgrounded(true); }
    1.44 +
    1.45 +  // Returns an English name of the process type, should only be used for non
    1.46 +  // user-visible strings, or debugging pages like about:memory.
    1.47 +  static std::wstring GetTypeNameInEnglish(ProcessType type);
    1.48 +
    1.49 +  // Returns a localized title for the child process.  For example, a plugin
    1.50 +  // process would be "Plug-in: Flash" when name is "Flash".
    1.51 +  std::wstring GetLocalizedTitle() const;
    1.52 +
    1.53 +  ChildProcessInfo(const ChildProcessInfo& original) {
    1.54 +    type_ = original.type_;
    1.55 +    name_ = original.name_;
    1.56 +    process_ = original.process_;
    1.57 +    pid_ = original.pid_;
    1.58 +  }
    1.59 +
    1.60 +  ChildProcessInfo& operator=(const ChildProcessInfo& original) {
    1.61 +    if (&original != this) {
    1.62 +      type_ = original.type_;
    1.63 +      name_ = original.name_;
    1.64 +      process_ = original.process_;
    1.65 +      pid_ = original.pid_;
    1.66 +    }
    1.67 +    return *this;
    1.68 +  }
    1.69 +
    1.70 +  virtual ~ChildProcessInfo();
    1.71 +
    1.72 +  // We define the < operator so that the ChildProcessInfo can be used as a key
    1.73 +  // in a std::map.
    1.74 +  bool operator <(const ChildProcessInfo& rhs) const {
    1.75 +    if (process_.handle() != rhs.process_.handle())
    1.76 +      return process_ .handle() < rhs.process_.handle();
    1.77 +    return false;
    1.78 +  }
    1.79 +
    1.80 +  bool operator ==(const ChildProcessInfo& rhs) const {
    1.81 +    return process_.handle() == rhs.process_.handle();
    1.82 +  }
    1.83 +
    1.84 +  // Generates a unique channel name for a child renderer/plugin process.
    1.85 +  // The "instance" pointer value is baked into the channel id.
    1.86 +  static std::wstring GenerateRandomChannelID(void* instance);
    1.87 +
    1.88 + protected:
    1.89 +  void set_type(ProcessType type) { type_ = type; }
    1.90 +  void set_name(const std::wstring& name) { name_ = name; }
    1.91 +  void set_handle(base::ProcessHandle handle) {
    1.92 +    process_.set_handle(handle);
    1.93 +    pid_ = -1;
    1.94 +  }
    1.95 +
    1.96 +  // Derived objects need to use this constructor so we know what type we are.
    1.97 +  ChildProcessInfo(ProcessType type);
    1.98 +
    1.99 + private:
   1.100 +  ProcessType type_;
   1.101 +  std::wstring name_;
   1.102 +  mutable int pid_;  // Cache of the process id.
   1.103 +
   1.104 +  // The handle to the process.
   1.105 +  mutable base::Process process_;
   1.106 +};
   1.107 +
   1.108 +#endif  // CHROME_COMMON_CHILD_PROCESS_INFO_H_

mercurial