| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_ |
| 6 #define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_ | 6 #define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // This class is a singleton. | 36 // This class is a singleton. |
| 37 class TaskManager { | 37 class TaskManager { |
| 38 public: | 38 public: |
| 39 // A resource represents one row in the task manager. | 39 // A resource represents one row in the task manager. |
| 40 // Resources from similar processes are grouped together by the task manager. | 40 // Resources from similar processes are grouped together by the task manager. |
| 41 class Resource { | 41 class Resource { |
| 42 public: | 42 public: |
| 43 virtual ~Resource() {} | 43 virtual ~Resource() {} |
| 44 | 44 |
| 45 enum Type { |
| 46 UNKNOWN = 0, // An unknown process type. |
| 47 BROWSER, // The main browser process. |
| 48 RENDERER, // A normal TabContents renderer process. |
| 49 EXTENSION, // An extension or app process. |
| 50 NOTIFICATION, // A notification process. |
| 51 PLUGIN, // A plugin process. |
| 52 WORKER, // A web worker process. |
| 53 NACL, // A NativeClient loader or broker process. |
| 54 UTILITY, // A browser utility process. |
| 55 PROFILE_IMPORT, // A profile import process. |
| 56 ZYGOTE, // A Linux zygote process. |
| 57 SANDBOX_HELPER, // A sandbox helper process. |
| 58 GPU // A graphics process. |
| 59 }; |
| 60 |
| 45 virtual std::wstring GetTitle() const = 0; | 61 virtual std::wstring GetTitle() const = 0; |
| 46 virtual SkBitmap GetIcon() const = 0; | 62 virtual SkBitmap GetIcon() const = 0; |
| 47 virtual base::ProcessHandle GetProcess() const = 0; | 63 virtual base::ProcessHandle GetProcess() const = 0; |
| 64 virtual Type GetType() const = 0; |
| 48 | 65 |
| 49 virtual bool ReportsCacheStats() const { return false; } | 66 virtual bool ReportsCacheStats() const { return false; } |
| 50 virtual WebKit::WebCache::ResourceTypeStats GetWebCoreCacheStats() const { | 67 virtual WebKit::WebCache::ResourceTypeStats GetWebCoreCacheStats() const { |
| 51 return WebKit::WebCache::ResourceTypeStats(); | 68 return WebKit::WebCache::ResourceTypeStats(); |
| 52 } | 69 } |
| 53 | 70 |
| 54 virtual bool ReportsSqliteMemoryUsed() const { return false; } | 71 virtual bool ReportsSqliteMemoryUsed() const { return false; } |
| 55 virtual size_t SqliteMemoryUsedBytes() const { return 0; } | 72 virtual size_t SqliteMemoryUsedBytes() const { return 0; } |
| 56 | 73 |
| 57 // Return extension associated with the resource, or NULL | 74 // Return extension associated with the resource, or NULL |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 public base::RefCountedThreadSafe<TaskManagerModel> { | 207 public base::RefCountedThreadSafe<TaskManagerModel> { |
| 191 public: | 208 public: |
| 192 explicit TaskManagerModel(TaskManager* task_manager); | 209 explicit TaskManagerModel(TaskManager* task_manager); |
| 193 | 210 |
| 194 void AddObserver(TaskManagerModelObserver* observer); | 211 void AddObserver(TaskManagerModelObserver* observer); |
| 195 void RemoveObserver(TaskManagerModelObserver* observer); | 212 void RemoveObserver(TaskManagerModelObserver* observer); |
| 196 | 213 |
| 197 // Returns number of registered resources. | 214 // Returns number of registered resources. |
| 198 int ResourceCount() const; | 215 int ResourceCount() const; |
| 199 | 216 |
| 217 // Methods to return raw resource information. |
| 218 int64 GetNetworkUsage(int index) const; |
| 219 double GetCPUUsage(int index) const; |
| 220 int GetProcessId(int index) const; |
| 221 |
| 200 // Methods to return formatted resource information. | 222 // Methods to return formatted resource information. |
| 201 string16 GetResourceTitle(int index) const; | 223 string16 GetResourceTitle(int index) const; |
| 202 string16 GetResourceNetworkUsage(int index) const; | 224 string16 GetResourceNetworkUsage(int index) const; |
| 203 string16 GetResourceCPUUsage(int index) const; | 225 string16 GetResourceCPUUsage(int index) const; |
| 204 string16 GetResourcePrivateMemory(int index) const; | 226 string16 GetResourcePrivateMemory(int index) const; |
| 205 string16 GetResourceSharedMemory(int index) const; | 227 string16 GetResourceSharedMemory(int index) const; |
| 206 string16 GetResourcePhysicalMemory(int index) const; | 228 string16 GetResourcePhysicalMemory(int index) const; |
| 207 string16 GetResourceProcessId(int index) const; | 229 string16 GetResourceProcessId(int index) const; |
| 208 string16 GetResourceWebCoreImageCacheSize(int index) const; | 230 string16 GetResourceWebCoreImageCacheSize(int index) const; |
| 209 string16 GetResourceWebCoreScriptsCacheSize(int index) const; | 231 string16 GetResourceWebCoreScriptsCacheSize(int index) const; |
| 210 string16 GetResourceWebCoreCSSCacheSize(int index) const; | 232 string16 GetResourceWebCoreCSSCacheSize(int index) const; |
| 211 string16 GetResourceSqliteMemoryUsed(int index) const; | 233 string16 GetResourceSqliteMemoryUsed(int index) const; |
| 212 string16 GetResourceGoatsTeleported(int index) const; | 234 string16 GetResourceGoatsTeleported(int index) const; |
| 213 string16 GetResourceV8MemoryAllocatedSize(int index) const; | 235 string16 GetResourceV8MemoryAllocatedSize(int index) const; |
| 214 | 236 |
| 237 // Gets the private memory (in bytes) that should be displayed for the passed |
| 238 // resource index. Caches the result since this calculation can take time on |
| 239 // some platforms. |
| 240 bool GetPrivateMemory(int index, size_t* result) const; |
| 241 |
| 242 // Gets the shared memory (in bytes) that should be displayed for the passed |
| 243 // resource index. Caches the result since this calculation can take time on |
| 244 // some platforms. |
| 245 bool GetSharedMemory(int index, size_t* result) const; |
| 246 |
| 247 // Gets the physical memory (in bytes) that should be displayed for the passed |
| 248 // resource index. |
| 249 bool GetPhysicalMemory(int index, size_t* result) const; |
| 250 |
| 251 // Gets the amount of memory allocated for javascript. Returns false if the |
| 252 // resource for the given row isn't a renderer. |
| 253 bool GetV8Memory(int index, size_t* result) const; |
| 254 |
| 255 // See design doc at http://go/at-teleporter for more information. |
| 256 int GetGoatsTeleported(int index) const; |
| 257 |
| 215 // Returns true if the resource is first in its group (resources | 258 // Returns true if the resource is first in its group (resources |
| 216 // rendered by the same process are groupped together). | 259 // rendered by the same process are groupped together). |
| 217 bool IsResourceFirstInGroup(int index) const; | 260 bool IsResourceFirstInGroup(int index) const; |
| 218 | 261 |
| 219 // Returns icon to be used for resource (for example a favicon). | 262 // Returns icon to be used for resource (for example a favicon). |
| 220 SkBitmap GetResourceIcon(int index) const; | 263 SkBitmap GetResourceIcon(int index) const; |
| 221 | 264 |
| 222 // Returns a pair (start, length) of the group range of resource. | 265 // Returns a pair (start, length) of the group range of resource. |
| 223 std::pair<int, int> GetGroupRangeForResource(int index) const; | 266 std::pair<int, int> GetGroupRangeForResource(int index) const; |
| 224 | 267 |
| 225 // Compares values in column |col_id| and rows |row1|, |row2|. | 268 // Compares values in column |col_id| and rows |row1|, |row2|. |
| 226 // Returns -1 if value in |row1| is less than value in |row2|, | 269 // Returns -1 if value in |row1| is less than value in |row2|, |
| 227 // 0 if they are equal, and 1 otherwise. | 270 // 0 if they are equal, and 1 otherwise. |
| 228 int CompareValues(int row1, int row2, int col_id) const; | 271 int CompareValues(int row1, int row2, int col_id) const; |
| 229 | 272 |
| 230 // Returns process handle for given resource. | 273 // Returns process handle for given resource. |
| 231 base::ProcessHandle GetResourceProcessHandle(int index) const; | 274 base::ProcessHandle GetResourceProcessHandle(int index) const; |
| 232 | 275 |
| 276 // Returns the type of the given resource. |
| 277 TaskManager::Resource::Type GetResourceType(int index) const; |
| 278 |
| 233 // Returns TabContents of given resource or NULL if not applicable. | 279 // Returns TabContents of given resource or NULL if not applicable. |
| 234 TabContents* GetResourceTabContents(int index) const; | 280 TabContents* GetResourceTabContents(int index) const; |
| 235 | 281 |
| 236 // Returns Extension of given resource or NULL if not applicable. | 282 // Returns Extension of given resource or NULL if not applicable. |
| 237 const Extension* GetResourceExtension(int index) const; | 283 const Extension* GetResourceExtension(int index) const; |
| 238 | 284 |
| 239 // JobObserver methods: | 285 // JobObserver methods: |
| 240 void OnJobAdded(URLRequestJob* job); | 286 void OnJobAdded(URLRequestJob* job); |
| 241 void OnJobRemoved(URLRequestJob* job); | 287 void OnJobRemoved(URLRequestJob* job); |
| 242 void OnJobDone(URLRequestJob* job, const URLRequestStatus& status); | 288 void OnJobDone(URLRequestJob* job, const URLRequestStatus& status); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 258 base::ProcessId renderer_id, | 304 base::ProcessId renderer_id, |
| 259 const WebKit::WebCache::ResourceTypeStats& stats); | 305 const WebKit::WebCache::ResourceTypeStats& stats); |
| 260 | 306 |
| 261 void NotifyV8HeapStats(base::ProcessId renderer_id, | 307 void NotifyV8HeapStats(base::ProcessId renderer_id, |
| 262 size_t v8_memory_allocated, | 308 size_t v8_memory_allocated, |
| 263 size_t v8_memory_used); | 309 size_t v8_memory_used); |
| 264 | 310 |
| 265 private: | 311 private: |
| 266 friend class base::RefCountedThreadSafe<TaskManagerModel>; | 312 friend class base::RefCountedThreadSafe<TaskManagerModel>; |
| 267 FRIEND_TEST_ALL_PREFIXES(TaskManagerTest, RefreshCalled); | 313 FRIEND_TEST_ALL_PREFIXES(TaskManagerTest, RefreshCalled); |
| 314 FRIEND_TEST_ALL_PREFIXES(ExtensionApiTest, ProcessesVsTaskManager); |
| 268 | 315 |
| 269 ~TaskManagerModel(); | 316 ~TaskManagerModel(); |
| 270 | 317 |
| 271 enum UpdateState { | 318 enum UpdateState { |
| 272 IDLE = 0, // Currently not updating. | 319 IDLE = 0, // Currently not updating. |
| 273 TASK_PENDING, // An update task is pending. | 320 TASK_PENDING, // An update task is pending. |
| 274 STOPPING // A update task is pending and it should stop the update. | 321 STOPPING // A update task is pending and it should stop the update. |
| 275 }; | 322 }; |
| 276 | 323 |
| 277 // This struct is used to exchange information between the io and ui threads. | 324 // This struct is used to exchange information between the io and ui threads. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 372 |
| 326 // Returns the network usage (in byte per second) that should be displayed for | 373 // Returns the network usage (in byte per second) that should be displayed for |
| 327 // the passed |resource|. -1 means the information is not available for that | 374 // the passed |resource|. -1 means the information is not available for that |
| 328 // resource. | 375 // resource. |
| 329 int64 GetNetworkUsage(TaskManager::Resource* resource) const; | 376 int64 GetNetworkUsage(TaskManager::Resource* resource) const; |
| 330 | 377 |
| 331 // Returns the CPU usage (in %) that should be displayed for the passed | 378 // Returns the CPU usage (in %) that should be displayed for the passed |
| 332 // |resource|. | 379 // |resource|. |
| 333 double GetCPUUsage(TaskManager::Resource* resource) const; | 380 double GetCPUUsage(TaskManager::Resource* resource) const; |
| 334 | 381 |
| 335 // Gets the private memory (in bytes) that should be displayed for the passed | |
| 336 // resource index. Caches the result since this calculation can take time on | |
| 337 // some platforms. | |
| 338 bool GetPrivateMemory(int index, size_t* result) const; | |
| 339 | |
| 340 // Gets the shared memory (in bytes) that should be displayed for the passed | |
| 341 // resource index. Caches the result since this calculation can take time on | |
| 342 // some platforms. | |
| 343 bool GetSharedMemory(int index, size_t* result) const; | |
| 344 | |
| 345 // Gets the physical memory (in bytes) that should be displayed for the passed | |
| 346 // resource index. | |
| 347 bool GetPhysicalMemory(int index, size_t* result) const; | |
| 348 | |
| 349 // Gets the amount of memory allocated for javascript. Returns false if the | |
| 350 // resource for the given row isn't a renderer. | |
| 351 bool GetV8Memory(int index, size_t* result) const; | |
| 352 | |
| 353 // See design doc at http://go/at-teleporter for more information. | |
| 354 int GetGoatsTeleported(int index) const; | |
| 355 | |
| 356 // Retrieves the ProcessMetrics for the resources at the specified row. | 382 // Retrieves the ProcessMetrics for the resources at the specified row. |
| 357 // Returns true if there was a ProcessMetrics available. | 383 // Returns true if there was a ProcessMetrics available. |
| 358 bool GetProcessMetricsForRow(int row, | 384 bool GetProcessMetricsForRow(int row, |
| 359 base::ProcessMetrics** proc_metrics) const; | 385 base::ProcessMetrics** proc_metrics) const; |
| 360 | 386 |
| 361 // Given a number, this function returns the formatted string that should be | 387 // Given a number, this function returns the formatted string that should be |
| 362 // displayed in the task manager's memory cell. | 388 // displayed in the task manager's memory cell. |
| 363 string16 GetMemCellText(int64 number) const; | 389 string16 GetMemCellText(int64 number) const; |
| 364 | 390 |
| 365 // Looks up the data for |handle| and puts it in the mutable cache | 391 // Looks up the data for |handle| and puts it in the mutable cache |
| (...skipping 30 matching lines...) Expand all Loading... |
| 396 CPUUsageMap cpu_usage_map_; | 422 CPUUsageMap cpu_usage_map_; |
| 397 | 423 |
| 398 // A map that contains the private/shared memory usage of the process. We | 424 // A map that contains the private/shared memory usage of the process. We |
| 399 // cache this because the same APIs are called on linux and windows, and | 425 // cache this because the same APIs are called on linux and windows, and |
| 400 // because the linux call takes >10ms to complete. This cache is cleared on | 426 // because the linux call takes >10ms to complete. This cache is cleared on |
| 401 // every Refresh(). | 427 // every Refresh(). |
| 402 mutable MemoryUsageMap memory_usage_map_; | 428 mutable MemoryUsageMap memory_usage_map_; |
| 403 | 429 |
| 404 ObserverList<TaskManagerModelObserver> observer_list_; | 430 ObserverList<TaskManagerModelObserver> observer_list_; |
| 405 | 431 |
| 432 // How many calls to StartUpdating have been made without matching calls to |
| 433 // StopUpdating. |
| 434 int update_requests_; |
| 435 |
| 406 // Whether we are currently in the process of updating. | 436 // Whether we are currently in the process of updating. |
| 407 UpdateState update_state_; | 437 UpdateState update_state_; |
| 408 | 438 |
| 409 // A salt lick for the goats. | 439 // A salt lick for the goats. |
| 410 int goat_salt_; | 440 int goat_salt_; |
| 411 | 441 |
| 412 DISALLOW_COPY_AND_ASSIGN(TaskManagerModel); | 442 DISALLOW_COPY_AND_ASSIGN(TaskManagerModel); |
| 413 }; | 443 }; |
| 414 | 444 |
| 415 #endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_ | 445 #endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_ |
| OLD | NEW |