Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / task_manager / browser_process_resource_provider.cc
blobf136bc2b66b0229b9e3d2e4491c541c4186ce4c5
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)
24 #if defined(OS_WIN)
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()
34 : title_() {
35 int pid = base::GetCurrentProcId();
36 bool success = base::OpenPrivilegedProcessHandle(pid, &process_);
37 DCHECK(success);
38 #if defined(OS_WIN)
39 if (!default_icon_) {
40 HICON icon = GetAppIcon();
41 if (icon) {
42 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon));
43 default_icon_ = new gfx::ImageSkia(gfx::ImageSkiaRep(*bitmap, 1.0f));
46 #elif defined(OS_POSIX)
47 if (!default_icon_) {
48 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
49 default_icon_ = rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_16);
51 #else
52 // TODO(port): Port icon code.
53 NOTIMPLEMENTED();
54 #endif // defined(OS_WIN)
55 default_icon_->MakeThreadSafe();
58 BrowserProcessResource::~BrowserProcessResource() {
59 base::CloseProcessHandle(process_);
62 // Resource methods:
63 base::string16 BrowserProcessResource::GetTitle() const {
64 if (title_.empty()) {
65 title_ = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT);
67 return title_;
70 base::string16 BrowserProcessResource::GetProfileName() const {
71 return base::string16();
74 gfx::ImageSkia BrowserProcessResource::GetIcon() const {
75 return *default_icon_;
78 size_t BrowserProcessResource::SqliteMemoryUsedBytes() const {
79 return static_cast<size_t>(sqlite3_memory_used());
82 base::ProcessHandle BrowserProcessResource::GetProcess() const {
83 return base::GetCurrentProcessHandle(); // process_;
86 int BrowserProcessResource::GetUniqueChildProcessId() const {
87 return 0;
90 Resource::Type BrowserProcessResource::GetType() const {
91 return BROWSER;
94 bool BrowserProcessResource::SupportNetworkUsage() const {
95 return true;
98 void BrowserProcessResource::SetSupportNetworkUsage() {
99 NOTREACHED();
102 bool BrowserProcessResource::ReportsSqliteMemoryUsed() const {
103 return true;
106 // BrowserProcess uses v8 for proxy resolver in certain cases.
107 bool BrowserProcessResource::ReportsV8MemoryStats() const {
108 const CommandLine* command_line = CommandLine::ForCurrentProcess();
109 bool using_v8 = !command_line->HasSwitch(switches::kWinHttpProxyResolver);
110 if (using_v8 && command_line->HasSwitch(switches::kSingleProcess)) {
111 using_v8 = false;
113 return using_v8;
116 size_t BrowserProcessResource::GetV8MemoryAllocated() const {
117 return net::ProxyResolverV8::GetTotalHeapSize();
120 size_t BrowserProcessResource::GetV8MemoryUsed() const {
121 return net::ProxyResolverV8::GetUsedHeapSize();
124 ////////////////////////////////////////////////////////////////////////////////
125 // BrowserProcessResourceProvider class
126 ////////////////////////////////////////////////////////////////////////////////
128 BrowserProcessResourceProvider::
129 BrowserProcessResourceProvider(TaskManager* task_manager)
130 : updating_(false),
131 task_manager_(task_manager) {
134 BrowserProcessResourceProvider::~BrowserProcessResourceProvider() {
137 Resource* BrowserProcessResourceProvider::GetResource(
138 int origin_pid,
139 int child_id,
140 int route_id) {
141 if (origin_pid || child_id != -1) {
142 return NULL;
145 return &resource_;
148 void BrowserProcessResourceProvider::StartUpdating() {
149 task_manager_->AddResource(&resource_);
152 void BrowserProcessResourceProvider::StopUpdating() {
155 } // namespace task_manager