| 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/browser_process_resource_provider.h" | |
| 6 | |
| 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 "chrome/grit/generated_resources.h" | |
| 13 #include "content/public/common/content_switches.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" | |
| 20 | |
| 21 namespace task_manager { | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 gfx::ImageSkia* g_default_icon = nullptr; | |
| 26 | |
| 27 gfx::ImageSkia* GetDefaultIcon() { | |
| 28 if (!g_default_icon && ResourceBundle::HasSharedInstance()) { | |
| 29 g_default_icon = ResourceBundle::GetSharedInstance(). | |
| 30 GetImageSkiaNamed(IDR_PRODUCT_LOGO_16); | |
| 31 if (g_default_icon) | |
| 32 g_default_icon->MakeThreadSafe(); | |
| 33 } | |
| 34 | |
| 35 return g_default_icon; | |
| 36 } | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 40 BrowserProcessResource::BrowserProcessResource() | |
| 41 : title_() { | |
| 42 } | |
| 43 | |
| 44 BrowserProcessResource::~BrowserProcessResource() { | |
| 45 } | |
| 46 | |
| 47 // Resource methods: | |
| 48 base::string16 BrowserProcessResource::GetTitle() const { | |
| 49 if (title_.empty()) { | |
| 50 title_ = l10n_util::GetStringUTF16(IDS_TASK_MANAGER_WEB_BROWSER_CELL_TEXT); | |
| 51 } | |
| 52 return title_; | |
| 53 } | |
| 54 | |
| 55 base::string16 BrowserProcessResource::GetProfileName() const { | |
| 56 return base::string16(); | |
| 57 } | |
| 58 | |
| 59 gfx::ImageSkia BrowserProcessResource::GetIcon() const { | |
| 60 gfx::ImageSkia* image = GetDefaultIcon(); | |
| 61 return image? *image : gfx::ImageSkia(); | |
| 62 } | |
| 63 | |
| 64 size_t BrowserProcessResource::SqliteMemoryUsedBytes() const { | |
| 65 return static_cast<size_t>(sqlite3_memory_used()); | |
| 66 } | |
| 67 | |
| 68 base::ProcessHandle BrowserProcessResource::GetProcess() const { | |
| 69 return base::GetCurrentProcessHandle(); | |
| 70 } | |
| 71 | |
| 72 int BrowserProcessResource::GetUniqueChildProcessId() const { | |
| 73 return 0; | |
| 74 } | |
| 75 | |
| 76 Resource::Type BrowserProcessResource::GetType() const { | |
| 77 return BROWSER; | |
| 78 } | |
| 79 | |
| 80 bool BrowserProcessResource::SupportNetworkUsage() const { | |
| 81 return true; | |
| 82 } | |
| 83 | |
| 84 void BrowserProcessResource::SetSupportNetworkUsage() { | |
| 85 NOTREACHED(); | |
| 86 } | |
| 87 | |
| 88 bool BrowserProcessResource::ReportsSqliteMemoryUsed() const { | |
| 89 return true; | |
| 90 } | |
| 91 | |
| 92 // BrowserProcess uses v8 for proxy resolver in certain cases. | |
| 93 bool BrowserProcessResource::ReportsV8MemoryStats() const { | |
| 94 const base::CommandLine* command_line = | |
| 95 base::CommandLine::ForCurrentProcess(); | |
| 96 bool using_v8 = !command_line->HasSwitch(switches::kWinHttpProxyResolver); | |
| 97 if (using_v8 && command_line->HasSwitch(switches::kSingleProcess)) { | |
| 98 using_v8 = false; | |
| 99 } | |
| 100 return using_v8; | |
| 101 } | |
| 102 | |
| 103 size_t BrowserProcessResource::GetV8MemoryAllocated() const { | |
| 104 return net::ProxyResolverV8::GetTotalHeapSize(); | |
| 105 } | |
| 106 | |
| 107 size_t BrowserProcessResource::GetV8MemoryUsed() const { | |
| 108 return net::ProxyResolverV8::GetUsedHeapSize(); | |
| 109 } | |
| 110 | |
| 111 //////////////////////////////////////////////////////////////////////////////// | |
| 112 // BrowserProcessResourceProvider class | |
| 113 //////////////////////////////////////////////////////////////////////////////// | |
| 114 | |
| 115 BrowserProcessResourceProvider:: | |
| 116 BrowserProcessResourceProvider(TaskManager* task_manager) | |
| 117 : updating_(false), | |
| 118 task_manager_(task_manager) { | |
| 119 } | |
| 120 | |
| 121 BrowserProcessResourceProvider::~BrowserProcessResourceProvider() { | |
| 122 } | |
| 123 | |
| 124 Resource* BrowserProcessResourceProvider::GetResource( | |
| 125 int origin_pid, | |
| 126 int child_id, | |
| 127 int route_id) { | |
| 128 if (origin_pid || child_id != -1) { | |
| 129 return NULL; | |
| 130 } | |
| 131 | |
| 132 return &resource_; | |
| 133 } | |
| 134 | |
| 135 void BrowserProcessResourceProvider::StartUpdating() { | |
| 136 task_manager_->AddResource(&resource_); | |
| 137 } | |
| 138 | |
| 139 void BrowserProcessResourceProvider::StopUpdating() { | |
| 140 } | |
| 141 | |
| 142 } // namespace task_manager | |
| OLD | NEW |