Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / task_management / providers / task.cc
blob849fafd5f67b783eb54d0d4c110039678c257726
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 #include "chrome/browser/task_management/task_manager_observer.h"
9 namespace task_management {
11 namespace {
13 // The last ID given to the previously created task.
14 int64 g_last_id = 0;
16 } // namespace
19 Task::Task(const base::string16& title,
20 const gfx::ImageSkia* icon,
21 base::ProcessHandle handle)
22 : task_id_(g_last_id++),
23 network_usage_(-1),
24 current_byte_count_(-1),
25 title_(title),
26 icon_(icon ? *icon : gfx::ImageSkia()),
27 process_handle_(handle),
28 process_id_(base::GetProcId(handle)) {
31 Task::~Task() {
34 void Task::Activate() {
37 void Task::Refresh(const base::TimeDelta& update_interval,
38 int64 refresh_flags) {
39 if ((refresh_flags & REFRESH_TYPE_NETWORK_USAGE) == 0)
40 return;
42 if (current_byte_count_ == -1)
43 return;
45 network_usage_ =
46 (current_byte_count_ * base::TimeDelta::FromSeconds(1)) / update_interval;
48 // Reset the current byte count for this task.
49 current_byte_count_ = 0;
52 void Task::OnNetworkBytesRead(int64 bytes_read) {
53 if (current_byte_count_ == -1)
54 current_byte_count_ = 0;
56 current_byte_count_ += bytes_read;
59 base::string16 Task::GetProfileName() const {
60 return base::string16();
63 bool Task::ReportsSqliteMemory() const {
64 return GetSqliteMemoryUsed() != -1;
67 int64 Task::GetSqliteMemoryUsed() const {
68 return -1;
71 bool Task::ReportsV8Memory() const {
72 return GetV8MemoryAllocated() != -1;
75 int64 Task::GetV8MemoryAllocated() const {
76 return -1;
79 int64 Task::GetV8MemoryUsed() const {
80 return -1;
83 bool Task::ReportsWebCacheStats() const {
84 return false;
87 blink::WebCache::ResourceTypeStats Task::GetWebCacheStats() const {
88 return blink::WebCache::ResourceTypeStats();
91 bool Task::ReportsNetworkUsage() const {
92 return network_usage_ != -1;
95 } // namespace task_management