Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: chrome/common/child_process_info.cc

Issue 5981007: fix about:memory and memory histograms to show extensions more clearly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 9 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/child_process_info.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/child_process_info.h" 5 #include "chrome/common/child_process_info.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/atomicops.h" 10 #include "base/atomicops.h"
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/process_util.h" 13 #include "base/process_util.h"
14 #include "base/rand_util.h" 14 #include "base/rand_util.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
18 18
19 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) :
20 type_(type),
21 renderer_type_(RENDERER_UNKNOWN) {
22 if (id == -1)
23 id_ = GenerateChildProcessUniqueId();
24 else
25 id_ = id;
26 }
27
19 ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original) 28 ChildProcessInfo::ChildProcessInfo(const ChildProcessInfo& original)
20 : type_(original.type_), 29 : type_(original.type_),
30 renderer_type_(original.renderer_type_),
21 name_(original.name_), 31 name_(original.name_),
22 version_(original.version_), 32 version_(original.version_),
23 id_(original.id_), 33 id_(original.id_),
24 process_(original.process_) { 34 process_(original.process_) {
25 } 35 }
26 36
27 ChildProcessInfo::~ChildProcessInfo() { 37 ChildProcessInfo::~ChildProcessInfo() {
28 } 38 }
29 39
30 ChildProcessInfo& ChildProcessInfo::operator=( 40 ChildProcessInfo& ChildProcessInfo::operator=(
31 const ChildProcessInfo& original) { 41 const ChildProcessInfo& original) {
32 if (&original != this) { 42 if (&original != this) {
33 type_ = original.type_; 43 type_ = original.type_;
44 renderer_type_ = original.renderer_type_;
34 name_ = original.name_; 45 name_ = original.name_;
35 version_ = original.version_; 46 version_ = original.version_;
36 id_ = original.id_; 47 id_ = original.id_;
37 process_ = original.process_; 48 process_ = original.process_;
38 } 49 }
39 return *this; 50 return *this;
40 } 51 }
41 52
53 // static
42 std::string ChildProcessInfo::GetTypeNameInEnglish( 54 std::string ChildProcessInfo::GetTypeNameInEnglish(
43 ChildProcessInfo::ProcessType type) { 55 ChildProcessInfo::ProcessType type) {
44 switch (type) { 56 switch (type) {
45 case BROWSER_PROCESS: 57 case BROWSER_PROCESS:
46 return "Browser"; 58 return "Browser";
47 case RENDER_PROCESS: 59 case RENDER_PROCESS:
48 return "Tab"; 60 return "Tab";
49 case PLUGIN_PROCESS: 61 case PLUGIN_PROCESS:
50 return "Plug-in"; 62 return "Plug-in";
51 case WORKER_PROCESS: 63 case WORKER_PROCESS:
(...skipping 14 matching lines...) Expand all
66 return "GPU"; 78 return "GPU";
67 case PPAPI_PLUGIN_PROCESS: 79 case PPAPI_PLUGIN_PROCESS:
68 return "Pepper Plugin"; 80 return "Pepper Plugin";
69 case UNKNOWN_PROCESS: 81 case UNKNOWN_PROCESS:
70 default: 82 default:
71 DCHECK(false) << "Unknown child process type!"; 83 DCHECK(false) << "Unknown child process type!";
72 return "Unknown"; 84 return "Unknown";
73 } 85 }
74 } 86 }
75 87
88 // static
89 std::string ChildProcessInfo::GetRendererTypeNameInEnglish(
90 ChildProcessInfo::RendererProcessType type) {
91 switch (type) {
92 case RENDERER_NORMAL:
93 return "Tab";
94 case RENDERER_CHROME:
95 return "Tab (Chrome)";
96 case RENDERER_EXTENSION:
97 return "Extension";
98 case RENDERER_DEVTOOLS:
99 return "Devtools";
100 case RENDERER_INTERSTITIAL:
101 return "Interstitial";
102 case RENDERER_NOTIFICATION:
103 return "Notification";
104 case RENDERER_BACKGROUND_APP:
105 return "Background App";
106 case RENDERER_UNKNOWN:
107 default:
108 NOTREACHED() << "Unknown renderer process type!";
109 return "Unknown";
110 }
111 }
112
113 // static
114 std::string ChildProcessInfo::GetFullTypeNameInEnglish(
115 ChildProcessInfo::ProcessType type,
116 ChildProcessInfo::RendererProcessType rtype) {
117 if (type == RENDER_PROCESS)
118 return GetRendererTypeNameInEnglish(rtype);
119 return GetTypeNameInEnglish(type);
120 }
121
122
76 string16 ChildProcessInfo::GetLocalizedTitle() const { 123 string16 ChildProcessInfo::GetLocalizedTitle() const {
77 string16 title = WideToUTF16Hack(name_); 124 string16 title = WideToUTF16Hack(name_);
78 if (type_ == ChildProcessInfo::PLUGIN_PROCESS && title.empty()) 125 if (type_ == ChildProcessInfo::PLUGIN_PROCESS && title.empty())
79 title = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME); 126 title = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME);
80 127
81 // Explicitly mark name as LTR if there is no strong RTL character, 128 // Explicitly mark name as LTR if there is no strong RTL character,
82 // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the 129 // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the
83 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew 130 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew
84 // or Arabic word for "plugin". 131 // or Arabic word for "plugin".
85 base::i18n::AdjustStringForLocaleDirection(&title); 132 base::i18n::AdjustStringForLocaleDirection(&title);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 NOTREACHED(); 164 NOTREACHED();
118 break; 165 break;
119 166
120 case UNKNOWN_PROCESS: 167 case UNKNOWN_PROCESS:
121 NOTREACHED() << "Need localized name for child process type."; 168 NOTREACHED() << "Need localized name for child process type.";
122 } 169 }
123 170
124 return title; 171 return title;
125 } 172 }
126 173
127 ChildProcessInfo::ChildProcessInfo(ProcessType type, int id) : type_(type) {
128 if (id == -1)
129 id_ = GenerateChildProcessUniqueId();
130 else
131 id_ = id;
132 }
133
134 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) { 174 std::string ChildProcessInfo::GenerateRandomChannelID(void* instance) {
135 // Note: the string must start with the current process id, this is how 175 // Note: the string must start with the current process id, this is how
136 // child processes determine the pid of the parent. 176 // child processes determine the pid of the parent.
137 // Build the channel ID. This is composed of a unique identifier for the 177 // Build the channel ID. This is composed of a unique identifier for the
138 // parent browser process, an identifier for the child instance, and a random 178 // parent browser process, an identifier for the child instance, and a random
139 // component. We use a random component so that a hacked child process can't 179 // component. We use a random component so that a hacked child process can't
140 // cause denial of service by causing future named pipe creation to fail. 180 // cause denial of service by causing future named pipe creation to fail.
141 return base::StringPrintf("%d.%p.%d", 181 return base::StringPrintf("%d.%p.%d",
142 base::GetCurrentProcId(), instance, 182 base::GetCurrentProcId(), instance,
143 base::RandInt(0, std::numeric_limits<int>::max())); 183 base::RandInt(0, std::numeric_limits<int>::max()));
144 } 184 }
145 185
146 // static 186 // static
147 int ChildProcessInfo::GenerateChildProcessUniqueId() { 187 int ChildProcessInfo::GenerateChildProcessUniqueId() {
148 // This function must be threadsafe. 188 // This function must be threadsafe.
149 static base::subtle::Atomic32 last_unique_child_id = 0; 189 static base::subtle::Atomic32 last_unique_child_id = 0;
150 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1); 190 return base::subtle::NoBarrier_AtomicIncrement(&last_unique_child_id, 1);
151 } 191 }
OLDNEW
« no previous file with comments | « chrome/common/child_process_info.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698