Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / task_manager / browser_process_resource_provider.cc
blobd2cbac44d808634294806a0d094e7bffe5cf359d
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 int pid = base::GetCurrentProcId();
42 bool success = base::OpenPrivilegedProcessHandle(pid, &process_);
43 DCHECK(success);
44 #if defined(OS_WIN)
45 if (!default_icon_) {
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();
52 if (icon) {
53 // TODO(vadimt): Remove ScopedTracker below once crbug.com/437890 is
54 // fixed.
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)
64 if (!default_icon_) {
65 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
66 default_icon_ = rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_16);
68 #else
69 // TODO(port): Port icon code.
70 NOTIMPLEMENTED();
71 #endif // defined(OS_WIN)
73 // TODO(vadimt): Remove ScopedTracker below once crbug.com/437890 is
74 // fixed.
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_);
86 // Resource methods:
87 base::string16 BrowserProcessResource::GetTitle() const {
88 if (title_.empty()) {
89 title_ = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT);
91 return title_;
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 {
111 return 0;
114 Resource::Type BrowserProcessResource::GetType() const {
115 return BROWSER;
118 bool BrowserProcessResource::SupportNetworkUsage() const {
119 return true;
122 void BrowserProcessResource::SetSupportNetworkUsage() {
123 NOTREACHED();
126 bool BrowserProcessResource::ReportsSqliteMemoryUsed() const {
127 return true;
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)) {
135 using_v8 = false;
137 return using_v8;
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)
154 : updating_(false),
155 task_manager_(task_manager) {
158 BrowserProcessResourceProvider::~BrowserProcessResourceProvider() {
161 Resource* BrowserProcessResourceProvider::GetResource(
162 int origin_pid,
163 int child_id,
164 int route_id) {
165 if (origin_pid || child_id != -1) {
166 return NULL;
169 return &resource_;
172 void BrowserProcessResourceProvider::StartUpdating() {
173 task_manager_->AddResource(&resource_);
176 void BrowserProcessResourceProvider::StopUpdating() {
179 } // namespace task_manager