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/profiler/scoped_tracker.h"
9 #include "base/strings/string16.h"
10 #include "chrome/browser/task_manager/resource_provider.h"
11 #include "chrome/browser/task_manager/task_manager.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "grit/theme_resources.h"
15 #include "net/proxy/proxy_resolver_v8.h"
16 #include "third_party/sqlite/sqlite3.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/image/image_skia.h"
21 #if defined(OS_MACOSX)
22 #include "ui/gfx/image/image_skia_util_mac.h"
23 #endif // defined(OS_MACOSX)
26 #include "chrome/browser/app_icon_win.h"
27 #include "ui/gfx/icon_util.h"
28 #endif // defined(OS_WIN)
30 namespace task_manager
{
32 gfx::ImageSkia
* BrowserProcessResource::default_icon_
= NULL
;
34 BrowserProcessResource::BrowserProcessResource()
36 // TODO(vadimt): Remove ScopedTracker below once crbug.com/437890 is fixed.
37 tracked_objects::ScopedTracker
tracking_profile1(
38 FROM_HERE_WITH_EXPLICIT_FUNCTION(
39 "437890 BrowserProcessResource::BrowserProcessResource1"));
41 int pid
= base::GetCurrentProcId();
42 bool success
= base::OpenPrivilegedProcessHandle(pid
, &process_
);
46 // TODO(vadimt): Remove ScopedTracker below once crbug.com/437890 is fixed.
47 tracked_objects::ScopedTracker
tracking_profile2(
48 FROM_HERE_WITH_EXPLICIT_FUNCTION(
49 "437890 BrowserProcessResource::BrowserProcessResource2"));
51 HICON icon
= GetAppIcon();
53 // TODO(vadimt): Remove ScopedTracker below once crbug.com/437890 is
55 tracked_objects::ScopedTracker
tracking_profile3(
56 FROM_HERE_WITH_EXPLICIT_FUNCTION(
57 "437890 BrowserProcessResource::BrowserProcessResource3"));
59 scoped_ptr
<SkBitmap
> bitmap(IconUtil::CreateSkBitmapFromHICON(icon
));
60 default_icon_
= new gfx::ImageSkia(gfx::ImageSkiaRep(*bitmap
, 1.0f
));
63 #elif defined(OS_POSIX)
65 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
66 default_icon_
= rb
.GetImageSkiaNamed(IDR_PRODUCT_LOGO_16
);
69 // TODO(port): Port icon code.
71 #endif // defined(OS_WIN)
73 // TODO(vadimt): Remove ScopedTracker below once crbug.com/437890 is
75 tracked_objects::ScopedTracker
tracking_profile4(
76 FROM_HERE_WITH_EXPLICIT_FUNCTION(
77 "437890 BrowserProcessResource::BrowserProcessResource4"));
79 default_icon_
->MakeThreadSafe();
82 BrowserProcessResource::~BrowserProcessResource() {
83 base::CloseProcessHandle(process_
);
87 base::string16
BrowserProcessResource::GetTitle() const {
89 title_
= l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT
);
94 base::string16
BrowserProcessResource::GetProfileName() const {
95 return base::string16();
98 gfx::ImageSkia
BrowserProcessResource::GetIcon() const {
99 return *default_icon_
;
102 size_t BrowserProcessResource::SqliteMemoryUsedBytes() const {
103 return static_cast<size_t>(sqlite3_memory_used());
106 base::ProcessHandle
BrowserProcessResource::GetProcess() const {
107 return base::GetCurrentProcessHandle(); // process_;
110 int BrowserProcessResource::GetUniqueChildProcessId() const {
114 Resource::Type
BrowserProcessResource::GetType() const {
118 bool BrowserProcessResource::SupportNetworkUsage() const {
122 void BrowserProcessResource::SetSupportNetworkUsage() {
126 bool BrowserProcessResource::ReportsSqliteMemoryUsed() const {
130 // BrowserProcess uses v8 for proxy resolver in certain cases.
131 bool BrowserProcessResource::ReportsV8MemoryStats() const {
132 const CommandLine
* command_line
= CommandLine::ForCurrentProcess();
133 bool using_v8
= !command_line
->HasSwitch(switches::kWinHttpProxyResolver
);
134 if (using_v8
&& command_line
->HasSwitch(switches::kSingleProcess
)) {
140 size_t BrowserProcessResource::GetV8MemoryAllocated() const {
141 return net::ProxyResolverV8::GetTotalHeapSize();
144 size_t BrowserProcessResource::GetV8MemoryUsed() const {
145 return net::ProxyResolverV8::GetUsedHeapSize();
148 ////////////////////////////////////////////////////////////////////////////////
149 // BrowserProcessResourceProvider class
150 ////////////////////////////////////////////////////////////////////////////////
152 BrowserProcessResourceProvider::
153 BrowserProcessResourceProvider(TaskManager
* task_manager
)
155 task_manager_(task_manager
) {
158 BrowserProcessResourceProvider::~BrowserProcessResourceProvider() {
161 Resource
* BrowserProcessResourceProvider::GetResource(
165 if (origin_pid
|| child_id
!= -1) {
172 void BrowserProcessResourceProvider::StartUpdating() {
173 task_manager_
->AddResource(&resource_
);
176 void BrowserProcessResourceProvider::StopUpdating() {
179 } // namespace task_manager