summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-11 23:55:10 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-11 23:55:10 +0000
commita27a938d8511abfaf89d6e2d0e4d4242c76dffed (patch)
tree98b133536459106b96a0ee09e0deb94b8d92c4b3 /chrome/common
parent342c2c40bd1729fe985d5a6ee06f6eb28bbcdc22 (diff)
downloadchromium_src-a27a938d8511abfaf89d6e2d0e4d4242c76dffed.zip
chromium_src-a27a938d8511abfaf89d6e2d0e4d4242c76dffed.tar.gz
chromium_src-a27a938d8511abfaf89d6e2d0e4d4242c76dffed.tar.bz2
Refactor plugin process code in the browser process so that the browser/about:memory/task manager/metrics code doesn't depend on PluginProcessHost pointers. In a future changelist I'll add one central child process registry in the browser process.
Review URL: http://codereview.chromium.org/20196 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9621 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/child_process_info.cc51
-rw-r--r--chrome/common/child_process_info.h66
-rw-r--r--chrome/common/common.scons2
-rw-r--r--chrome/common/common.vcproj10
-rw-r--r--chrome/common/notification_type.h46
-rw-r--r--chrome/common/pref_names.cc4
-rw-r--r--chrome/common/pref_names.h2
7 files changed, 148 insertions, 33 deletions
diff --git a/chrome/common/child_process_info.cc b/chrome/common/child_process_info.cc
new file mode 100644
index 0000000..ca777bd
--- /dev/null
+++ b/chrome/common/child_process_info.cc
@@ -0,0 +1,51 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/child_process_info.h"
+
+#include "base/logging.h"
+#include "chrome/common/l10n_util.h"
+
+#include "generated_resources.h"
+
+std::wstring ChildProcessInfo::GetTypeNameInEnglish(
+ ChildProcessInfo::ProcessType type) {
+ switch (type) {
+ case BROWSER_PROCESS:
+ return L"Browser";
+ case RENDER_PROCESS:
+ return L"Tab";
+ case PLUGIN_PROCESS:
+ return L"Plug-in";
+ case WORKER_PROCESS:
+ return L"Web Worker";
+ case UNKNOWN_PROCESS:
+ default:
+ DCHECK(false) << "Unknown child process type!";
+ return L"Unknown";
+ }
+}
+
+std::wstring ChildProcessInfo::GetLocalizedTitle() const {
+ std::wstring title = name_;
+ if (type_ == ChildProcessInfo::PLUGIN_PROCESS && title.empty())
+ title = l10n_util::GetString(IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME);
+
+ int message_id;
+ if (type_ == ChildProcessInfo::PLUGIN_PROCESS) {
+ message_id = IDS_TASK_MANAGER_PLUGIN_PREFIX;
+ } else if (type_ == ChildProcessInfo::WORKER_PROCESS) {
+ message_id = IDS_TASK_MANAGER_WORKER_PREFIX;
+ } else {
+ DCHECK(false) << "Need localized name for child process type.";
+ return title;
+ }
+
+ // Explicitly mark name as LTR if there is no strong RTL character,
+ // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the
+ // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew
+ // or Arabic word for "plugin".
+ l10n_util::AdjustStringForLocaleDirection(title, &title);
+ return l10n_util::GetStringF(message_id, title);
+}
diff --git a/chrome/common/child_process_info.h b/chrome/common/child_process_info.h
new file mode 100644
index 0000000..2007bcb
--- /dev/null
+++ b/chrome/common/child_process_info.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_CHILD_PROCESS_INFO_H_
+#define CHROME_COMMON_CHILD_PROCESS_INFO_H_
+
+#include <string>
+#include "base/basictypes.h"
+#include "base/process.h"
+
+// Holds information about a child process.
+class ChildProcessInfo {
+ public:
+ enum ProcessType {
+ BROWSER_PROCESS,
+ RENDER_PROCESS,
+ PLUGIN_PROCESS,
+ WORKER_PROCESS,
+ UNKNOWN_PROCESS,
+ };
+
+ // Returns the type of the process.
+ ProcessType type() const { return type_; }
+
+ // Returns the name of the process. i.e. for plugins it might be Flash, while
+ // for workers it might be the domain that it's from.
+ std::wstring name() const { return name_; }
+
+ // Getter to the process.
+ base::Process& process() { return process_; }
+
+ // Returns an English name of the process type, should only be used for non
+ // user-visible strings, or debugging pages like about:memory.
+ static std::wstring GetTypeNameInEnglish(ProcessType type);
+
+ // Returns a localized title for the child process. For example, a plugin
+ // process would be "Plug-in: Flash" when name is "Flash".
+ std::wstring GetLocalizedTitle() const;
+
+ // We define the < operator so that the ChildProcessInfo can be used as a key
+ // in a std::map.
+ bool operator <(const ChildProcessInfo& rhs) const {
+ if (process_.handle() != rhs.process_.handle())
+ return process_ .handle() < rhs.process_.handle();
+ return name_ < rhs.name_;
+ }
+
+ bool operator ==(const ChildProcessInfo& rhs) const {
+ return (process_.handle() == rhs.process_.handle()) && (name_ == rhs.name_);
+ }
+
+ protected:
+ void set_type(ProcessType type) { type_ = type; }
+ void set_name(const std::wstring& name) { name_ = name; }
+
+ private:
+ ProcessType type_;
+ std::wstring name_;
+
+ // The handle to the process.
+ base::Process process_;
+};
+
+#endif // CHROME_COMMON_CHILD_PROCESS_INFO_H_
+
diff --git a/chrome/common/common.scons b/chrome/common/common.scons
index 829da06..832485f 100644
--- a/chrome/common/common.scons
+++ b/chrome/common/common.scons
@@ -106,6 +106,8 @@ input_files = ChromeFileList([
'animation.h',
'child_process.cc',
'child_process.h',
+ 'child_process_info.cc',
+ 'child_process_info.h',
'chrome_constants.cc',
'chrome_constants.h',
'chrome_counters.cc',
diff --git a/chrome/common/common.vcproj b/chrome/common/common.vcproj
index 44c9962..00282224 100644
--- a/chrome/common/common.vcproj
+++ b/chrome/common/common.vcproj
@@ -342,6 +342,14 @@
>
</File>
<File
+ RelativePath=".\child_process_info.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\child_process_info.h"
+ >
+ </File>
+ <File
RelativePath=".\chrome_constants.cc"
>
</File>
@@ -525,7 +533,7 @@
RelativePath=".\notification_details.h"
>
</File>
- <File
+ <File
RelativePath=".\notification_observer.h"
>
</File>
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index 7924866..5e59742 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -319,47 +319,35 @@ class NotificationType {
// guaranteed to be valid after the notification.
WEB_CACHE_STATS_OBSERVED,
- // Plugins -----------------------------------------------------------------
+ // Child Processes ---------------------------------------------------------
- // This notification is sent when a plugin process host has connected to a
- // plugin process. There is no usable source, since it is sent from an
+ // This notification is sent when a child process host has connected to a
+ // child process. There is no usable source, since it is sent from an
// ephemeral task; register for AllSources() to receive this notification.
- // The details are in a Details<PluginProcessInfo> with a pointer to a
- // plug-in process info for the plugin, that is only valid for the time of
- // the notification (don't keep this pointer around, make a copy of the
- // object if you need to keep it).
- PLUGIN_PROCESS_HOST_CONNECTED,
-
- // This message is sent after a PluginProcessHost is disconnected from the
- // plugin process. There is no usable source, since it is sent from an
+ // The details are in a Details<ChildProcessInfo>.
+ CHILD_PROCESS_HOST_CONNECTED,
+
+ // This message is sent after a ChildProcessHost is disconnected from the
+ // child process. There is no usable source, since it is sent from an
// ephemeral task; register for AllSources() to receive this notification.
- // The details are in a Details<PluginProcessInfo> with a pointer to a
- // plug-in process info for the plugin, that is only valid for the time of
- // the notification (don't keep this pointer around, make a copy of the
- // object if you need to keep it).
- PLUGIN_PROCESS_HOST_DISCONNECTED,
+ // The details are in a Details<ChildProcessInfo>.
+ CHILD_PROCESS_HOST_DISCONNECTED,
- // This message is sent when a plugin process disappears unexpectedly.
+ // This message is sent when a child process disappears unexpectedly.
// There is no usable source, since it is sent from an ephemeral task;
// register for AllSources() to receive this notification. The details are
- // in a Details<PluginProcessInfo> with a pointer to a plug-in process info
- // for the plugin, that is only valid for the time of the notification
- // (don't keep this pointer around, make a copy of the object if you need
- // to keep it).
- PLUGIN_PROCESS_CRASHED,
+ // in a Details<ChildProcessInfo>.
+ CHILD_PROCESS_CRASHED,
- // This message indicates that an instance of a particular plugin was
+ // This message indicates that an instance of a particular child was
// created in a page. (If one page contains several regions rendered by
- // the same plugin, this notification will occur once for each region
+ // the same child, this notification will occur once for each region
// during the page load.)
//
// There is no usable source, since it is sent from an ephemeral task;
// register for AllSources() to receive this notification. The details are
- // in a Details<PluginProcessInfo> with a pointer to a plug-in process info
- // for the plugin, that is only valid for the time of the notification
- // (don't keep this pointer around, make a copy of the object if you need
- // to keep it).
- PLUGIN_INSTANCE_CREATED,
+ // in a Details<ChildProcessInfo>.
+ CHILD_INSTANCE_CREATED,
// This is sent when network interception is disabled for a plugin, or the
// plugin is unloaded. This should only be sent/received on the browser IO
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index f00406d..8c8dc76 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -328,7 +328,7 @@ const wchar_t kStabilityUptimeSec[] =
// This is the location of a list of dictionaries of plugin stability stats.
const wchar_t kStabilityPluginStats[] =
- L"user_experience_metrics.stability.plugin_stats";
+ L"user_experience_metrics.stability.plugin_stats2";
// Number of times the renderer has become non-responsive since the last
// report.
@@ -353,7 +353,7 @@ const wchar_t kStabilityDebuggerNotPresent[] =
// The keys below are used for the dictionaries in the
// kStabilityPluginStats list.
-const wchar_t kStabilityPluginPath[] = L"path";
+const wchar_t kStabilityPluginName[] = L"name";
const wchar_t kStabilityPluginLaunches[] = L"launches";
const wchar_t kStabilityPluginInstances[] = L"instances";
const wchar_t kStabilityPluginCrashes[] = L"crashes";
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 6e09d74..501b3e0 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -116,7 +116,7 @@ extern const wchar_t kSecurityRendererOnSboxDesktop[];
extern const wchar_t kSecurityRendererOnDefaultDesktop[];
extern const wchar_t kStabilityPluginStats[];
-extern const wchar_t kStabilityPluginPath[];
+extern const wchar_t kStabilityPluginName[];
extern const wchar_t kStabilityPluginLaunches[];
extern const wchar_t kStabilityPluginInstances[];
extern const wchar_t kStabilityPluginCrashes[];