blob: af69e102436da5dd860b8106ca19a28e6c7d9af8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
// 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 "base/singleton.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/common/l10n_util.h"
#include "generated_resources.h"
typedef std::list<ChildProcessInfo*> ChildProcessList;
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);
}
ChildProcessInfo::ChildProcessInfo(ProcessType type) {
// This constructor is only used by objects which derive from this class,
// which means *this* is a real object that refers to a child process, and not
// just a simple object that contains information about it. So add it to our
// list of running processes.
type_ = type;
Singleton<ChildProcessList>::get()->push_back(this);
}
ChildProcessInfo::~ChildProcessInfo() {
Singleton<ChildProcessList>::get()->remove(this);
}
ChildProcessInfo::Iterator::Iterator() : all_(true) {
iterator_ = Singleton<ChildProcessList>::get()->begin();
DCHECK(MessageLoop::current() ==
ChromeThread::GetMessageLoop(ChromeThread::IO)) <<
"ChildProcessInfo::Iterator must be used on the IO thread.";
}
ChildProcessInfo::Iterator::Iterator(ProcessType type)
: all_(false), type_(type) {
iterator_ = Singleton<ChildProcessList>::get()->begin();
DCHECK(MessageLoop::current() ==
ChromeThread::GetMessageLoop(ChromeThread::IO)) <<
"ChildProcessInfo::Iterator must be used on the IO thread.";
}
ChildProcessInfo* ChildProcessInfo::Iterator::operator++() {
do {
++iterator_;
if (Done())
break;
if (!all_ && (*iterator_)->type() != type_)
continue;
return *iterator_;
} while (true);
return NULL;
}
bool ChildProcessInfo::Iterator::Done() {
return iterator_ == Singleton<ChildProcessList>::get()->end();
}
|