Chromium Code Reviews| Index: chrome/browser/task_management/private/tasks_providers/browser_process/browser_process_task.cc |
| diff --git a/chrome/browser/task_management/private/tasks_providers/browser_process/browser_process_task.cc b/chrome/browser/task_management/private/tasks_providers/browser_process/browser_process_task.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ed731693ef0cec65ad59ddf9221e4ebad1e73115 |
| --- /dev/null |
| +++ b/chrome/browser/task_management/private/tasks_providers/browser_process/browser_process_task.cc |
| @@ -0,0 +1,120 @@ |
| +// Copyright 2015 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/browser/task_management/private/tasks_providers/browser_process/browser_process_task.h" |
| + |
| +#include "base/command_line.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "chrome/grit/generated_resources.h" |
| +#include "grit/theme_resources.h" |
| +#include "net/proxy/proxy_resolver_v8.h" |
| +#include "third_party/sqlite/sqlite3.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| + |
| +#if defined(OS_MACOSX) |
| +#include "ui/gfx/image/image_skia_util_mac.h" |
| +#endif // defined(OS_MACOSX) |
| + |
| +#if defined(OS_WIN) |
| +#include "chrome/browser/app_icon_win.h" |
| +#include "ui/gfx/icon_util.h" |
| +#endif // defined(OS_WIN) |
| + |
| +namespace task_management { |
| + |
| +namespace { |
| + |
| +gfx::ImageSkia* default_icon = nullptr; |
| + |
| +gfx::ImageSkia* GetDefaultIcon() { |
| + if (!default_icon) { |
| +#if defined(OS_WIN) |
| + HICON icon = GetAppIcon(); |
| + if (icon) { |
| + scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon)); |
| + default_icon_ = new gfx::ImageSkia(gfx::ImageSkiaRep(*bitmap, 1.0f)); |
| + } |
| +#elif defined(OS_POSIX) |
| + if (ResourceBundle::HasSharedInstance()) { |
|
ncarter (slow)
2015/03/27 18:16:20
Seems like there's no closing bracket for this (or
afakhry
2015/03/31 00:19:19
Good catch! :)
|
| + default_icon = ResourceBundle::GetSharedInstance(). |
| + GetImageSkiaNamed(IDR_PRODUCT_LOGO_16); |
| +#else |
| + // TODO(port): Port icon code. |
| + NOTIMPLEMENTED(); |
| +#endif // defined(OS_WIN) |
| + if (default_icon) |
| + default_icon->MakeThreadSafe(); |
|
ncarter (slow)
2015/03/27 18:16:20
The indentation here seems off.
afakhry
2015/03/31 00:19:19
Done.
|
| + } |
| + } |
| + |
| + return default_icon; |
| +} |
| + |
| +bool ReportsV8Stats() { |
| + const base::CommandLine* command_line = |
| + base::CommandLine::ForCurrentProcess(); |
| + return command_line && |
| + !command_line->HasSwitch(switches::kWinHttpProxyResolver) && |
| + !command_line->HasSwitch(switches::kSingleProcess); |
| +} |
| + |
| +} // namespace |
| + |
| +// ---------------------------------------------------------------------- |
| +// Public Members: |
| +// ---------------------------------------------------------------------- |
|
ncarter (slow)
2015/03/27 18:16:20
Not needed.
|
| + |
| +BrowserProcessTask::BrowserProcessTask() |
| + : Task(l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT), |
| + *GetDefaultIcon(), |
| + base::GetCurrentProcessHandle()), |
| + allocated_v8_memory_(-1U), |
| + used_v8_memory_(-1U), |
| + used_sqlite_memory_(-1U), |
| + reports_v8_stats_(ReportsV8Stats()){ |
| +} |
| + |
| +BrowserProcessTask::~BrowserProcessTask() { |
| +} |
| + |
| +// ---------------------------------------------------------------------- |
| +// Private Members: |
| +// ---------------------------------------------------------------------- |
|
ncarter (slow)
2015/03/27 18:16:20
Not needed.
|
| + |
| +Task::Type BrowserProcessTask::GetType() const { |
| + return Task::BROWSER; |
| +} |
| + |
| +int BrowserProcessTask::GetChildProcessUniqueID() const { |
| + return 0; |
| +} |
| + |
| +size_t BrowserProcessTask::GetSqliteMemoryUsed() const { |
| + return used_sqlite_memory_; |
| +} |
| + |
| +size_t BrowserProcessTask::GetV8MemoryAllocated() const { |
| + return allocated_v8_memory_; |
| +} |
| + |
| +size_t BrowserProcessTask::GetV8MemoryUsed() const { |
| + return used_v8_memory_; |
| +} |
| + |
| +void BrowserProcessTask::Refresh(const base::TimeDelta& update_time) { |
| + Task::Refresh(update_time); |
| + |
| + // TODO(afakhry): Add code to skip v8 and sqlite stats update if they have |
| + // never been requested. |
| + if (reports_v8_stats_) { |
| + allocated_v8_memory_ = net::ProxyResolverV8::GetTotalHeapSize(); |
| + used_v8_memory_ = net::ProxyResolverV8::GetUsedHeapSize(); |
| + } |
| + |
| + used_sqlite_memory_ = static_cast<size_t>(sqlite3_memory_used()); |
| +} |
| + |
| +} // namespace task_management |
| + |