OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/task_manager/task_manager_browser_process_resource_prov
ider.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/string16.h" | |
9 #include "chrome/common/chrome_switches.h" | |
10 #include "grit/generated_resources.h" | |
11 #include "grit/theme_resources.h" | |
12 #include "net/proxy/proxy_resolver_v8.h" | |
13 #include "third_party/sqlite/sqlite3.h" | |
14 #include "ui/base/l10n/l10n_util.h" | |
15 #include "ui/base/resource/resource_bundle.h" | |
16 #include "ui/gfx/image/image_skia.h" | |
17 | |
18 #if defined(OS_MACOSX) | |
19 #include "ui/gfx/image/image_skia_util_mac.h" | |
20 #endif // defined(OS_MACOSX) | |
21 | |
22 #if defined(OS_WIN) | |
23 #include "chrome/browser/app_icon_win.h" | |
24 #include "ui/gfx/icon_util.h" | |
25 #endif // defined(OS_WIN) | |
26 | |
27 //////////////////////////////////////////////////////////////////////////////// | |
28 // TaskManagerBrowserProcessResource class | |
29 //////////////////////////////////////////////////////////////////////////////// | |
30 | |
31 gfx::ImageSkia* TaskManagerBrowserProcessResource::default_icon_ = NULL; | |
32 | |
33 TaskManagerBrowserProcessResource::TaskManagerBrowserProcessResource() | |
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( | |
44 gfx::ImageSkiaRep(*bitmap, ui::SCALE_FACTOR_100P)); | |
45 } | |
46 } | |
47 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | |
48 if (!default_icon_) { | |
49 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
50 default_icon_ = rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_16); | |
51 } | |
52 #elif defined(OS_MACOSX) | |
53 if (!default_icon_) { | |
54 // IDR_PRODUCT_LOGO_16 doesn't quite look like chrome/mac's icns icon. Load | |
55 // the real app icon (requires a nsimage->image_skia->nsimage | |
56 // conversion :-(). | |
57 default_icon_ = new gfx::ImageSkia(gfx::ApplicationIconAtSize(16)); | |
58 } | |
59 #else | |
60 // TODO(port): Port icon code. | |
61 NOTIMPLEMENTED(); | |
62 #endif // defined(OS_WIN) | |
63 default_icon_->MakeThreadSafe(); | |
64 } | |
65 | |
66 TaskManagerBrowserProcessResource::~TaskManagerBrowserProcessResource() { | |
67 base::CloseProcessHandle(process_); | |
68 } | |
69 | |
70 // TaskManagerResource methods: | |
71 string16 TaskManagerBrowserProcessResource::GetTitle() const { | |
72 if (title_.empty()) { | |
73 title_ = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT); | |
74 } | |
75 return title_; | |
76 } | |
77 | |
78 string16 TaskManagerBrowserProcessResource::GetProfileName() const { | |
79 return string16(); | |
80 } | |
81 | |
82 gfx::ImageSkia TaskManagerBrowserProcessResource::GetIcon() const { | |
83 return *default_icon_; | |
84 } | |
85 | |
86 size_t TaskManagerBrowserProcessResource::SqliteMemoryUsedBytes() const { | |
87 return static_cast<size_t>(sqlite3_memory_used()); | |
88 } | |
89 | |
90 base::ProcessHandle TaskManagerBrowserProcessResource::GetProcess() const { | |
91 return base::GetCurrentProcessHandle(); // process_; | |
92 } | |
93 | |
94 int TaskManagerBrowserProcessResource::GetUniqueChildProcessId() const { | |
95 return 0; | |
96 } | |
97 | |
98 TaskManager::Resource::Type TaskManagerBrowserProcessResource::GetType() const { | |
99 return BROWSER; | |
100 } | |
101 | |
102 bool TaskManagerBrowserProcessResource::SupportNetworkUsage() const { | |
103 return true; | |
104 } | |
105 | |
106 void TaskManagerBrowserProcessResource::SetSupportNetworkUsage() { | |
107 NOTREACHED(); | |
108 } | |
109 | |
110 bool TaskManagerBrowserProcessResource::ReportsSqliteMemoryUsed() const { | |
111 return true; | |
112 } | |
113 | |
114 // BrowserProcess uses v8 for proxy resolver in certain cases. | |
115 bool TaskManagerBrowserProcessResource::ReportsV8MemoryStats() const { | |
116 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
117 bool using_v8 = !command_line->HasSwitch(switches::kWinHttpProxyResolver); | |
118 if (using_v8 && command_line->HasSwitch(switches::kSingleProcess)) { | |
119 using_v8 = false; | |
120 } | |
121 return using_v8; | |
122 } | |
123 | |
124 size_t TaskManagerBrowserProcessResource::GetV8MemoryAllocated() const { | |
125 return net::ProxyResolverV8::GetTotalHeapSize(); | |
126 } | |
127 | |
128 size_t TaskManagerBrowserProcessResource::GetV8MemoryUsed() const { | |
129 return net::ProxyResolverV8::GetUsedHeapSize(); | |
130 } | |
131 | |
132 //////////////////////////////////////////////////////////////////////////////// | |
133 // TaskManagerBrowserProcessResourceProvider class | |
134 //////////////////////////////////////////////////////////////////////////////// | |
135 | |
136 TaskManagerBrowserProcessResourceProvider:: | |
137 TaskManagerBrowserProcessResourceProvider(TaskManager* task_manager) | |
138 : updating_(false), | |
139 task_manager_(task_manager) { | |
140 } | |
141 | |
142 TaskManagerBrowserProcessResourceProvider:: | |
143 ~TaskManagerBrowserProcessResourceProvider() { | |
144 } | |
145 | |
146 TaskManager::Resource* TaskManagerBrowserProcessResourceProvider::GetResource( | |
147 int origin_pid, | |
148 int render_process_host_id, | |
149 int routing_id) { | |
150 if (origin_pid || render_process_host_id != -1) { | |
151 return NULL; | |
152 } | |
153 | |
154 return &resource_; | |
155 } | |
156 | |
157 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | |
158 task_manager_->AddResource(&resource_); | |
159 } | |
160 | |
161 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | |
162 } | |
OLD | NEW |