Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / task_manager / browser_process_resource_provider.cc
blob72fcd1e9334a6f218f2594258e930e49335ef2fc
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)
25 #if defined(OS_WIN)
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()
35 : title_() {
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 #if defined(OS_WIN)
42 if (!default_icon_) {
43 // TODO(vadimt): Remove ScopedTracker below once crbug.com/437890 is fixed.
44 tracked_objects::ScopedTracker tracking_profile2(
45 FROM_HERE_WITH_EXPLICIT_FUNCTION(
46 "437890 BrowserProcessResource::BrowserProcessResource2"));
48 HICON icon = GetAppIcon();
49 if (icon) {
50 // TODO(vadimt): Remove ScopedTracker below once crbug.com/437890 is
51 // fixed.
52 tracked_objects::ScopedTracker tracking_profile3(
53 FROM_HERE_WITH_EXPLICIT_FUNCTION(
54 "437890 BrowserProcessResource::BrowserProcessResource3"));
56 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon));
57 default_icon_ = new gfx::ImageSkia(gfx::ImageSkiaRep(*bitmap, 1.0f));
60 #elif defined(OS_POSIX)
61 if (!default_icon_) {
62 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
63 default_icon_ = rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_16);
65 #else
66 // TODO(port): Port icon code.
67 NOTIMPLEMENTED();
68 #endif // defined(OS_WIN)
70 // TODO(vadimt): Remove ScopedTracker below once crbug.com/437890 is
71 // fixed.
72 tracked_objects::ScopedTracker tracking_profile4(
73 FROM_HERE_WITH_EXPLICIT_FUNCTION(
74 "437890 BrowserProcessResource::BrowserProcessResource4"));
76 default_icon_->MakeThreadSafe();
79 BrowserProcessResource::~BrowserProcessResource() {
82 // Resource methods:
83 base::string16 BrowserProcessResource::GetTitle() const {
84 if (title_.empty()) {
85 title_ = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT);
87 return title_;
90 base::string16 BrowserProcessResource::GetProfileName() const {
91 return base::string16();
94 gfx::ImageSkia BrowserProcessResource::GetIcon() const {
95 return *default_icon_;
98 size_t BrowserProcessResource::SqliteMemoryUsedBytes() const {
99 return static_cast<size_t>(sqlite3_memory_used());
102 base::ProcessHandle BrowserProcessResource::GetProcess() const {
103 return base::GetCurrentProcessHandle();
106 int BrowserProcessResource::GetUniqueChildProcessId() const {
107 return 0;
110 Resource::Type BrowserProcessResource::GetType() const {
111 return BROWSER;
114 bool BrowserProcessResource::SupportNetworkUsage() const {
115 return true;
118 void BrowserProcessResource::SetSupportNetworkUsage() {
119 NOTREACHED();
122 bool BrowserProcessResource::ReportsSqliteMemoryUsed() const {
123 return true;
126 // BrowserProcess uses v8 for proxy resolver in certain cases.
127 bool BrowserProcessResource::ReportsV8MemoryStats() const {
128 const base::CommandLine* command_line =
129 base::CommandLine::ForCurrentProcess();
130 bool using_v8 = !command_line->HasSwitch(switches::kWinHttpProxyResolver);
131 if (using_v8 && command_line->HasSwitch(switches::kSingleProcess)) {
132 using_v8 = false;
134 return using_v8;
137 size_t BrowserProcessResource::GetV8MemoryAllocated() const {
138 return net::ProxyResolverV8::GetTotalHeapSize();
141 size_t BrowserProcessResource::GetV8MemoryUsed() const {
142 return net::ProxyResolverV8::GetUsedHeapSize();
145 ////////////////////////////////////////////////////////////////////////////////
146 // BrowserProcessResourceProvider class
147 ////////////////////////////////////////////////////////////////////////////////
149 BrowserProcessResourceProvider::
150 BrowserProcessResourceProvider(TaskManager* task_manager)
151 : updating_(false),
152 task_manager_(task_manager) {
155 BrowserProcessResourceProvider::~BrowserProcessResourceProvider() {
158 Resource* BrowserProcessResourceProvider::GetResource(
159 int origin_pid,
160 int child_id,
161 int route_id) {
162 if (origin_pid || child_id != -1) {
163 return NULL;
166 return &resource_;
169 void BrowserProcessResourceProvider::StartUpdating() {
170 task_manager_->AddResource(&resource_);
173 void BrowserProcessResourceProvider::StopUpdating() {
176 } // namespace task_manager