Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / task_management / providers / browser_process_task.cc
blobc4589faa154d8bf210b5f2aec337d5efdf939a78
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/task_management/providers/browser_process_task.h"
7 #include "base/command_line.h"
8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "grit/theme_resources.h"
11 #include "net/proxy/proxy_resolver_v8.h"
12 #include "third_party/sqlite/sqlite3.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
16 #if defined(OS_MACOSX)
17 #include "ui/gfx/image/image_skia_util_mac.h"
18 #endif // defined(OS_MACOSX)
20 #if defined(OS_WIN)
21 #include "chrome/browser/app_icon_win.h"
22 #include "ui/gfx/icon_util.h"
23 #endif // defined(OS_WIN)
25 namespace task_management {
27 namespace {
29 gfx::ImageSkia* g_default_icon = nullptr;
31 gfx::ImageSkia* GetDefaultIcon() {
32 if (!g_default_icon) {
33 #if defined(OS_WIN)
34 HICON icon = GetAppIcon();
35 if (icon) {
36 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon));
37 g_default_icon = new gfx::ImageSkia(gfx::ImageSkiaRep(*bitmap, 1.0f));
39 #elif defined(OS_POSIX)
40 if (ResourceBundle::HasSharedInstance()) {
41 g_default_icon = ResourceBundle::GetSharedInstance().
42 GetImageSkiaNamed(IDR_PRODUCT_LOGO_16);
44 #else
45 // TODO(port): Port icon code.
46 NOTIMPLEMENTED();
47 #endif // defined(OS_WIN)
48 if (g_default_icon)
49 g_default_icon->MakeThreadSafe();
52 return g_default_icon;
55 bool ReportsV8Stats() {
56 const base::CommandLine* command_line =
57 base::CommandLine::ForCurrentProcess();
58 return !command_line->HasSwitch(switches::kWinHttpProxyResolver) &&
59 !command_line->HasSwitch(switches::kSingleProcess);
62 } // namespace
64 BrowserProcessTask::BrowserProcessTask()
65 : Task(l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT),
66 *GetDefaultIcon(),
67 base::GetCurrentProcessHandle()),
68 allocated_v8_memory_(-1),
69 used_v8_memory_(-1),
70 used_sqlite_memory_(-1),
71 reports_v8_stats_(ReportsV8Stats()){
74 BrowserProcessTask::~BrowserProcessTask() {
77 void BrowserProcessTask::Refresh(const base::TimeDelta& update_interval) {
78 Task::Refresh(update_interval);
80 // TODO(afakhry): Add code to skip v8 and sqlite stats update if they have
81 // never been requested.
82 if (reports_v8_stats_) {
83 allocated_v8_memory_ =
84 static_cast<int64>(net::ProxyResolverV8::GetTotalHeapSize());
85 used_v8_memory_ =
86 static_cast<int64>(net::ProxyResolverV8::GetUsedHeapSize());
89 used_sqlite_memory_ = static_cast<int64>(sqlite3_memory_used());
92 Task::Type BrowserProcessTask::GetType() const {
93 return Task::BROWSER;
96 int BrowserProcessTask::GetChildProcessUniqueID() const {
97 return 0;
100 int64 BrowserProcessTask::GetSqliteMemoryUsed() const {
101 return used_sqlite_memory_;
104 int64 BrowserProcessTask::GetV8MemoryAllocated() const {
105 return allocated_v8_memory_;
108 int64 BrowserProcessTask::GetV8MemoryUsed() const {
109 return used_v8_memory_;
112 } // namespace task_management