1 // Copyright 2013 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_manager/browser_process_resource_provider.h"
7 #include "base/command_line.h"
8 #include "base/strings/string16.h"
9 #include "chrome/browser/task_manager/resource_provider.h"
10 #include "chrome/browser/task_manager/task_manager.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "grit/generated_resources.h"
13 #include "grit/theme_resources.h"
14 #include "net/proxy/proxy_resolver_v8.h"
15 #include "third_party/sqlite/sqlite3.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/image/image_skia.h"
20 #if defined(OS_MACOSX)
21 #include "ui/gfx/image/image_skia_util_mac.h"
22 #endif // defined(OS_MACOSX)
25 #include "chrome/browser/app_icon_win.h"
26 #include "ui/gfx/icon_util.h"
27 #endif // defined(OS_WIN)
29 namespace task_manager
{
31 gfx::ImageSkia
* BrowserProcessResource::default_icon_
= NULL
;
33 BrowserProcessResource::BrowserProcessResource()
35 int pid
= base::GetCurrentProcId();
36 bool success
= base::OpenPrivilegedProcessHandle(pid
, &process_
);
40 HICON icon
= GetAppIcon();
42 scoped_ptr
<SkBitmap
> bitmap(IconUtil::CreateSkBitmapFromHICON(icon
));
43 default_icon_
= new gfx::ImageSkia(
44 gfx::ImageSkiaRep(*bitmap
, ui::SCALE_FACTOR_100P
));
47 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
49 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
50 default_icon_
= rb
.GetImageSkiaNamed(IDR_PRODUCT_LOGO_16
);
52 #elif defined(OS_MACOSX)
54 // IDR_PRODUCT_LOGO_16 doesn't quite look like chrome/mac's icns icon. Load
55 // the real app icon (requires a nsimage->image_skia->nsimage
57 default_icon_
= new gfx::ImageSkia(gfx::ApplicationIconAtSize(16));
60 // TODO(port): Port icon code.
62 #endif // defined(OS_WIN)
63 default_icon_
->MakeThreadSafe();
66 BrowserProcessResource::~BrowserProcessResource() {
67 base::CloseProcessHandle(process_
);
71 string16
BrowserProcessResource::GetTitle() const {
73 title_
= l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT
);
78 string16
BrowserProcessResource::GetProfileName() const {
82 gfx::ImageSkia
BrowserProcessResource::GetIcon() const {
83 return *default_icon_
;
86 size_t BrowserProcessResource::SqliteMemoryUsedBytes() const {
87 return static_cast<size_t>(sqlite3_memory_used());
90 base::ProcessHandle
BrowserProcessResource::GetProcess() const {
91 return base::GetCurrentProcessHandle(); // process_;
94 int BrowserProcessResource::GetUniqueChildProcessId() const {
98 Resource::Type
BrowserProcessResource::GetType() const {
102 bool BrowserProcessResource::SupportNetworkUsage() const {
106 void BrowserProcessResource::SetSupportNetworkUsage() {
110 bool BrowserProcessResource::ReportsSqliteMemoryUsed() const {
114 // BrowserProcess uses v8 for proxy resolver in certain cases.
115 bool BrowserProcessResource::ReportsV8MemoryStats() const {
116 const CommandLine
* command_line
= CommandLine::ForCurrentProcess();
117 bool using_v8
= !command_line
->HasSwitch(switches::kWinHttpProxyResolver
);
118 if (using_v8
&& command_line
->HasSwitch(switches::kSingleProcess
)) {
124 size_t BrowserProcessResource::GetV8MemoryAllocated() const {
125 return net::ProxyResolverV8::GetTotalHeapSize();
128 size_t BrowserProcessResource::GetV8MemoryUsed() const {
129 return net::ProxyResolverV8::GetUsedHeapSize();
132 ////////////////////////////////////////////////////////////////////////////////
133 // BrowserProcessResourceProvider class
134 ////////////////////////////////////////////////////////////////////////////////
136 BrowserProcessResourceProvider::
137 BrowserProcessResourceProvider(TaskManager
* task_manager
)
139 task_manager_(task_manager
) {
142 BrowserProcessResourceProvider::~BrowserProcessResourceProvider() {
145 Resource
* BrowserProcessResourceProvider::GetResource(
147 int render_process_host_id
,
149 if (origin_pid
|| render_process_host_id
!= -1) {
156 void BrowserProcessResourceProvider::StartUpdating() {
157 task_manager_
->AddResource(&resource_
);
160 void BrowserProcessResourceProvider::StopUpdating() {
163 } // namespace task_manager