New Task Manager - Phase 1.1: Implement Browser Process Task Providing
[chromium-blink-merge.git] / chrome / browser / task_management / providers / task.cc
blob2f3a1b982177f93391d5acdf43e5b9d190624982
1 // Copyright 2015 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.
5 #include "chrome/browser/task_management/providers/task.h"
7 namespace task_management {
9 namespace {
11 // The last ID given to the previously created task.
12 int64 g_last_id = 0;
14 } // namespace
17 Task::Task(const base::string16& title,
18 const gfx::ImageSkia& icon,
19 base::ProcessHandle handle)
20 : task_id_(g_last_id++),
21 network_usage_(-1),
22 current_byte_count_(-1),
23 title_(title),
24 icon_(icon),
25 process_handle_(handle) {
28 Task::~Task() {
31 void Task::Refresh(const base::TimeDelta& update_interval) {
32 // TODO(afakhry): Add code here to skip this when network usage refresh has
33 // never been requested.
35 if (current_byte_count_ == -1)
36 return;
38 network_usage_ =
39 (current_byte_count_ * base::TimeDelta::FromSeconds(1)) / update_interval;
41 // Reset the current byte count for this task.
42 current_byte_count_ = 0;
45 void Task::OnNetworkBytesRead(int64 bytes_read) {
46 if (current_byte_count_ == -1)
47 current_byte_count_ = 0;
49 current_byte_count_ += bytes_read;
52 base::string16 Task::GetProfileName() const {
53 return base::string16();
56 int Task::GetRoutingID() const {
57 return 0;
60 bool Task::ReportsSqliteMemory() const {
61 return GetSqliteMemoryUsed() != -1;
64 int64 Task::GetSqliteMemoryUsed() const {
65 return -1;
68 bool Task::ReportsV8Memory() const {
69 return GetV8MemoryAllocated() != -1;
72 int64 Task::GetV8MemoryAllocated() const {
73 return -1;
76 int64 Task::GetV8MemoryUsed() const {
77 return -1;
80 bool Task::ReportsWebCacheStats() const {
81 return false;
84 blink::WebCache::ResourceTypeStats Task::GetWebCacheStats() const {
85 return blink::WebCache::ResourceTypeStats();
88 bool Task::ReportsNetworkUsage() const {
89 return network_usage_ != -1;
92 } // namespace task_management