OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/task_manager/task_manager_browser_process_resource_prov
ider.h" | 5 #include "chrome/browser/task_manager/browser_process_resource_provider.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
11 #include "grit/theme_resources.h" | 11 #include "grit/theme_resources.h" |
12 #include "net/proxy/proxy_resolver_v8.h" | 12 #include "net/proxy/proxy_resolver_v8.h" |
13 #include "third_party/sqlite/sqlite3.h" | 13 #include "third_party/sqlite/sqlite3.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/image/image_skia.h" | 16 #include "ui/gfx/image/image_skia.h" |
17 | 17 |
18 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
19 #include "ui/gfx/image/image_skia_util_mac.h" | 19 #include "ui/gfx/image/image_skia_util_mac.h" |
20 #endif // defined(OS_MACOSX) | 20 #endif // defined(OS_MACOSX) |
21 | 21 |
22 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
23 #include "chrome/browser/app_icon_win.h" | 23 #include "chrome/browser/app_icon_win.h" |
24 #include "ui/gfx/icon_util.h" | 24 #include "ui/gfx/icon_util.h" |
25 #endif // defined(OS_WIN) | 25 #endif // defined(OS_WIN) |
26 | 26 |
27 //////////////////////////////////////////////////////////////////////////////// | 27 namespace task_manager { |
28 // TaskManagerBrowserProcessResource class | |
29 //////////////////////////////////////////////////////////////////////////////// | |
30 | 28 |
31 gfx::ImageSkia* TaskManagerBrowserProcessResource::default_icon_ = NULL; | 29 gfx::ImageSkia* BrowserProcessResource::default_icon_ = NULL; |
32 | 30 |
33 TaskManagerBrowserProcessResource::TaskManagerBrowserProcessResource() | 31 BrowserProcessResource::BrowserProcessResource() |
34 : title_() { | 32 : title_() { |
35 int pid = base::GetCurrentProcId(); | 33 int pid = base::GetCurrentProcId(); |
36 bool success = base::OpenPrivilegedProcessHandle(pid, &process_); | 34 bool success = base::OpenPrivilegedProcessHandle(pid, &process_); |
37 DCHECK(success); | 35 DCHECK(success); |
38 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
39 if (!default_icon_) { | 37 if (!default_icon_) { |
40 HICON icon = GetAppIcon(); | 38 HICON icon = GetAppIcon(); |
41 if (icon) { | 39 if (icon) { |
42 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon)); | 40 scoped_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon)); |
43 default_icon_ = new gfx::ImageSkia( | 41 default_icon_ = new gfx::ImageSkia( |
(...skipping 12 matching lines...) Expand all Loading... |
56 // conversion :-(). | 54 // conversion :-(). |
57 default_icon_ = new gfx::ImageSkia(gfx::ApplicationIconAtSize(16)); | 55 default_icon_ = new gfx::ImageSkia(gfx::ApplicationIconAtSize(16)); |
58 } | 56 } |
59 #else | 57 #else |
60 // TODO(port): Port icon code. | 58 // TODO(port): Port icon code. |
61 NOTIMPLEMENTED(); | 59 NOTIMPLEMENTED(); |
62 #endif // defined(OS_WIN) | 60 #endif // defined(OS_WIN) |
63 default_icon_->MakeThreadSafe(); | 61 default_icon_->MakeThreadSafe(); |
64 } | 62 } |
65 | 63 |
66 TaskManagerBrowserProcessResource::~TaskManagerBrowserProcessResource() { | 64 BrowserProcessResource::~BrowserProcessResource() { |
67 base::CloseProcessHandle(process_); | 65 base::CloseProcessHandle(process_); |
68 } | 66 } |
69 | 67 |
70 // TaskManagerResource methods: | 68 // TaskManagerResource methods: |
71 string16 TaskManagerBrowserProcessResource::GetTitle() const { | 69 string16 BrowserProcessResource::GetTitle() const { |
72 if (title_.empty()) { | 70 if (title_.empty()) { |
73 title_ = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT); | 71 title_ = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT); |
74 } | 72 } |
75 return title_; | 73 return title_; |
76 } | 74 } |
77 | 75 |
78 string16 TaskManagerBrowserProcessResource::GetProfileName() const { | 76 string16 BrowserProcessResource::GetProfileName() const { |
79 return string16(); | 77 return string16(); |
80 } | 78 } |
81 | 79 |
82 gfx::ImageSkia TaskManagerBrowserProcessResource::GetIcon() const { | 80 gfx::ImageSkia BrowserProcessResource::GetIcon() const { |
83 return *default_icon_; | 81 return *default_icon_; |
84 } | 82 } |
85 | 83 |
86 size_t TaskManagerBrowserProcessResource::SqliteMemoryUsedBytes() const { | 84 size_t BrowserProcessResource::SqliteMemoryUsedBytes() const { |
87 return static_cast<size_t>(sqlite3_memory_used()); | 85 return static_cast<size_t>(sqlite3_memory_used()); |
88 } | 86 } |
89 | 87 |
90 base::ProcessHandle TaskManagerBrowserProcessResource::GetProcess() const { | 88 base::ProcessHandle BrowserProcessResource::GetProcess() const { |
91 return base::GetCurrentProcessHandle(); // process_; | 89 return base::GetCurrentProcessHandle(); // process_; |
92 } | 90 } |
93 | 91 |
94 int TaskManagerBrowserProcessResource::GetUniqueChildProcessId() const { | 92 int BrowserProcessResource::GetUniqueChildProcessId() const { |
95 return 0; | 93 return 0; |
96 } | 94 } |
97 | 95 |
98 TaskManager::Resource::Type TaskManagerBrowserProcessResource::GetType() const { | 96 TaskManager::Resource::Type BrowserProcessResource::GetType() const { |
99 return BROWSER; | 97 return BROWSER; |
100 } | 98 } |
101 | 99 |
102 bool TaskManagerBrowserProcessResource::SupportNetworkUsage() const { | 100 bool BrowserProcessResource::SupportNetworkUsage() const { |
103 return true; | 101 return true; |
104 } | 102 } |
105 | 103 |
106 void TaskManagerBrowserProcessResource::SetSupportNetworkUsage() { | 104 void BrowserProcessResource::SetSupportNetworkUsage() { |
107 NOTREACHED(); | 105 NOTREACHED(); |
108 } | 106 } |
109 | 107 |
110 bool TaskManagerBrowserProcessResource::ReportsSqliteMemoryUsed() const { | 108 bool BrowserProcessResource::ReportsSqliteMemoryUsed() const { |
111 return true; | 109 return true; |
112 } | 110 } |
113 | 111 |
114 // BrowserProcess uses v8 for proxy resolver in certain cases. | 112 // BrowserProcess uses v8 for proxy resolver in certain cases. |
115 bool TaskManagerBrowserProcessResource::ReportsV8MemoryStats() const { | 113 bool BrowserProcessResource::ReportsV8MemoryStats() const { |
116 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 114 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
117 bool using_v8 = !command_line->HasSwitch(switches::kWinHttpProxyResolver); | 115 bool using_v8 = !command_line->HasSwitch(switches::kWinHttpProxyResolver); |
118 if (using_v8 && command_line->HasSwitch(switches::kSingleProcess)) { | 116 if (using_v8 && command_line->HasSwitch(switches::kSingleProcess)) { |
119 using_v8 = false; | 117 using_v8 = false; |
120 } | 118 } |
121 return using_v8; | 119 return using_v8; |
122 } | 120 } |
123 | 121 |
124 size_t TaskManagerBrowserProcessResource::GetV8MemoryAllocated() const { | 122 size_t BrowserProcessResource::GetV8MemoryAllocated() const { |
125 return net::ProxyResolverV8::GetTotalHeapSize(); | 123 return net::ProxyResolverV8::GetTotalHeapSize(); |
126 } | 124 } |
127 | 125 |
128 size_t TaskManagerBrowserProcessResource::GetV8MemoryUsed() const { | 126 size_t BrowserProcessResource::GetV8MemoryUsed() const { |
129 return net::ProxyResolverV8::GetUsedHeapSize(); | 127 return net::ProxyResolverV8::GetUsedHeapSize(); |
130 } | 128 } |
131 | 129 |
132 //////////////////////////////////////////////////////////////////////////////// | 130 //////////////////////////////////////////////////////////////////////////////// |
133 // TaskManagerBrowserProcessResourceProvider class | 131 // BrowserProcessResourceProvider class |
134 //////////////////////////////////////////////////////////////////////////////// | 132 //////////////////////////////////////////////////////////////////////////////// |
135 | 133 |
136 TaskManagerBrowserProcessResourceProvider:: | 134 BrowserProcessResourceProvider:: |
137 TaskManagerBrowserProcessResourceProvider(TaskManager* task_manager) | 135 BrowserProcessResourceProvider(TaskManager* task_manager) |
138 : updating_(false), | 136 : updating_(false), |
139 task_manager_(task_manager) { | 137 task_manager_(task_manager) { |
140 } | 138 } |
141 | 139 |
142 TaskManagerBrowserProcessResourceProvider:: | 140 BrowserProcessResourceProvider::~BrowserProcessResourceProvider() { |
143 ~TaskManagerBrowserProcessResourceProvider() { | |
144 } | 141 } |
145 | 142 |
146 TaskManager::Resource* TaskManagerBrowserProcessResourceProvider::GetResource( | 143 TaskManager::Resource* BrowserProcessResourceProvider::GetResource( |
147 int origin_pid, | 144 int origin_pid, |
148 int render_process_host_id, | 145 int render_process_host_id, |
149 int routing_id) { | 146 int routing_id) { |
150 if (origin_pid || render_process_host_id != -1) { | 147 if (origin_pid || render_process_host_id != -1) { |
151 return NULL; | 148 return NULL; |
152 } | 149 } |
153 | 150 |
154 return &resource_; | 151 return &resource_; |
155 } | 152 } |
156 | 153 |
157 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 154 void BrowserProcessResourceProvider::StartUpdating() { |
158 task_manager_->AddResource(&resource_); | 155 task_manager_->AddResource(&resource_); |
159 } | 156 } |
160 | 157 |
161 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 158 void BrowserProcessResourceProvider::StopUpdating() { |
162 } | 159 } |
| 160 |
| 161 } // namespace task_manager |
OLD | NEW |