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