| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/singleton.h" |
| 9 #include "chrome/browser/chrome_thread.h" |
| 8 #include "chrome/common/l10n_util.h" | 10 #include "chrome/common/l10n_util.h" |
| 9 | 11 |
| 10 #include "generated_resources.h" | 12 #include "generated_resources.h" |
| 11 | 13 |
| 14 typedef std::list<ChildProcessInfo*> ChildProcessList; |
| 15 |
| 16 |
| 12 std::wstring ChildProcessInfo::GetTypeNameInEnglish( | 17 std::wstring ChildProcessInfo::GetTypeNameInEnglish( |
| 13 ChildProcessInfo::ProcessType type) { | 18 ChildProcessInfo::ProcessType type) { |
| 14 switch (type) { | 19 switch (type) { |
| 15 case BROWSER_PROCESS: | 20 case BROWSER_PROCESS: |
| 16 return L"Browser"; | 21 return L"Browser"; |
| 17 case RENDER_PROCESS: | 22 case RENDER_PROCESS: |
| 18 return L"Tab"; | 23 return L"Tab"; |
| 19 case PLUGIN_PROCESS: | 24 case PLUGIN_PROCESS: |
| 20 return L"Plug-in"; | 25 return L"Plug-in"; |
| 21 case WORKER_PROCESS: | 26 case WORKER_PROCESS: |
| 22 return L"Web Worker"; | 27 return L"Web Worker"; |
| 23 case UNKNOWN_PROCESS: | 28 case UNKNOWN_PROCESS: |
| 24 default: | 29 default: |
| 25 DCHECK(false) << "Unknown child process type!"; | 30 DCHECK(false) << "Unknown child process type!"; |
| 26 return L"Unknown"; | 31 return L"Unknown"; |
| 27 } | 32 } |
| 28 } | 33 } |
| 29 | 34 |
| 30 std::wstring ChildProcessInfo::GetLocalizedTitle() const { | 35 std::wstring ChildProcessInfo::GetLocalizedTitle() const { |
| 31 std::wstring title = name_; | 36 std::wstring title = name_; |
| 32 if (type_ == ChildProcessInfo::PLUGIN_PROCESS && title.empty()) | 37 if (type_ == ChildProcessInfo::PLUGIN_PROCESS && title.empty()) |
| 33 title = l10n_util::GetString(IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME); | 38 title = l10n_util::GetString(IDS_TASK_MANAGER_UNKNOWN_PLUGIN_NAME); |
| 34 | 39 |
| 35 int message_id; | 40 int message_id; |
| 36 if (type_ == ChildProcessInfo::PLUGIN_PROCESS) { | 41 if (type_ == ChildProcessInfo::PLUGIN_PROCESS) { |
| 37 message_id = IDS_TASK_MANAGER_PLUGIN_PREFIX; | 42 message_id = IDS_TASK_MANAGER_PLUGIN_PREFIX; |
| 38 } else if (type_ == ChildProcessInfo::WORKER_PROCESS) { | 43 } else if (type_ == ChildProcessInfo::WORKER_PROCESS) { |
| 39 message_id = IDS_TASK_MANAGER_WORKER_PREFIX; | 44 message_id = IDS_TASK_MANAGER_WORKER_PREFIX; |
| 40 } else { | 45 } else { |
| 41 DCHECK(false) << "Need localized name for child process type."; | 46 DCHECK(false) << "Need localized name for child process type."; |
| 42 return title; | 47 return title; |
| 43 } | 48 } |
| 44 | 49 |
| 45 // Explicitly mark name as LTR if there is no strong RTL character, | 50 // Explicitly mark name as LTR if there is no strong RTL character, |
| 46 // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the | 51 // to avoid the wrong concatenation result similar to "!Yahoo! Mail: the |
| 47 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew | 52 // best web-based Email: NIGULP", in which "NIGULP" stands for the Hebrew |
| 48 // or Arabic word for "plugin". | 53 // or Arabic word for "plugin". |
| 49 l10n_util::AdjustStringForLocaleDirection(title, &title); | 54 l10n_util::AdjustStringForLocaleDirection(title, &title); |
| 50 return l10n_util::GetStringF(message_id, title); | 55 return l10n_util::GetStringF(message_id, title); |
| 51 } | 56 } |
| 57 |
| 58 ChildProcessInfo::ChildProcessInfo(ProcessType type) { |
| 59 // This constructor is only used by objects which derive from this class, |
| 60 // which means *this* is a real object that refers to a child process, and not |
| 61 // just a simple object that contains information about it. So add it to our |
| 62 // list of running processes. |
| 63 type_ = type; |
| 64 Singleton<ChildProcessList>::get()->push_back(this); |
| 65 } |
| 66 |
| 67 |
| 68 ChildProcessInfo::~ChildProcessInfo() { |
| 69 Singleton<ChildProcessList>::get()->remove(this); |
| 70 } |
| 71 |
| 72 |
| 73 ChildProcessInfo::Iterator::Iterator() : all_(true) { |
| 74 iterator_ = Singleton<ChildProcessList>::get()->begin(); |
| 75 DCHECK(MessageLoop::current() == |
| 76 ChromeThread::GetMessageLoop(ChromeThread::IO)) << |
| 77 "ChildProcessInfo::Iterator must be used on the IO thread."; |
| 78 } |
| 79 |
| 80 ChildProcessInfo::Iterator::Iterator(ProcessType type) |
| 81 : all_(false), type_(type) { |
| 82 iterator_ = Singleton<ChildProcessList>::get()->begin(); |
| 83 DCHECK(MessageLoop::current() == |
| 84 ChromeThread::GetMessageLoop(ChromeThread::IO)) << |
| 85 "ChildProcessInfo::Iterator must be used on the IO thread."; |
| 86 } |
| 87 |
| 88 ChildProcessInfo* ChildProcessInfo::Iterator::operator++() { |
| 89 do { |
| 90 ++iterator_; |
| 91 if (Done()) |
| 92 break; |
| 93 |
| 94 if (!all_ && (*iterator_)->type() != type_) |
| 95 continue; |
| 96 |
| 97 return *iterator_; |
| 98 } while (true); |
| 99 |
| 100 return NULL; |
| 101 } |
| 102 |
| 103 bool ChildProcessInfo::Iterator::Done() { |
| 104 return iterator_ == Singleton<ChildProcessList>::get()->end(); |
| 105 } |
| OLD | NEW |