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 "chrome/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 namespace task_manager
{
24 gfx::ImageSkia
* g_default_icon
= nullptr;
26 gfx::ImageSkia
* GetDefaultIcon() {
27 if (!g_default_icon
&& ResourceBundle::HasSharedInstance()) {
28 g_default_icon
= ResourceBundle::GetSharedInstance().
29 GetImageSkiaNamed(IDR_PRODUCT_LOGO_16
);
31 g_default_icon
->MakeThreadSafe();
34 return g_default_icon
;
39 BrowserProcessResource::BrowserProcessResource()
43 BrowserProcessResource::~BrowserProcessResource() {
47 base::string16
BrowserProcessResource::GetTitle() const {
49 title_
= l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT
);
54 base::string16
BrowserProcessResource::GetProfileName() const {
55 return base::string16();
58 gfx::ImageSkia
BrowserProcessResource::GetIcon() const {
59 gfx::ImageSkia
* image
= GetDefaultIcon();
60 return image
? *image
: gfx::ImageSkia();
63 size_t BrowserProcessResource::SqliteMemoryUsedBytes() const {
64 return static_cast<size_t>(sqlite3_memory_used());
67 base::ProcessHandle
BrowserProcessResource::GetProcess() const {
68 return base::GetCurrentProcessHandle();
71 int BrowserProcessResource::GetUniqueChildProcessId() const {
75 Resource::Type
BrowserProcessResource::GetType() const {
79 bool BrowserProcessResource::SupportNetworkUsage() const {
83 void BrowserProcessResource::SetSupportNetworkUsage() {
87 bool BrowserProcessResource::ReportsSqliteMemoryUsed() const {
91 // BrowserProcess uses v8 for proxy resolver in certain cases.
92 bool BrowserProcessResource::ReportsV8MemoryStats() const {
93 const base::CommandLine
* command_line
=
94 base::CommandLine::ForCurrentProcess();
95 bool using_v8
= !command_line
->HasSwitch(switches::kWinHttpProxyResolver
);
96 if (using_v8
&& command_line
->HasSwitch(switches::kSingleProcess
)) {
102 size_t BrowserProcessResource::GetV8MemoryAllocated() const {
103 return net::ProxyResolverV8::GetTotalHeapSize();
106 size_t BrowserProcessResource::GetV8MemoryUsed() const {
107 return net::ProxyResolverV8::GetUsedHeapSize();
110 ////////////////////////////////////////////////////////////////////////////////
111 // BrowserProcessResourceProvider class
112 ////////////////////////////////////////////////////////////////////////////////
114 BrowserProcessResourceProvider::
115 BrowserProcessResourceProvider(TaskManager
* task_manager
)
117 task_manager_(task_manager
) {
120 BrowserProcessResourceProvider::~BrowserProcessResourceProvider() {
123 Resource
* BrowserProcessResourceProvider::GetResource(
127 if (origin_pid
|| child_id
!= -1) {
134 void BrowserProcessResourceProvider::StartUpdating() {
135 task_manager_
->AddResource(&resource_
);
138 void BrowserProcessResourceProvider::StopUpdating() {
141 } // namespace task_manager