| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/task_manager/providers/task.h" | 5 #include "chrome/browser/task_manager/providers/task.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/process/process.h" | 9 #include "base/process/process.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/profiles/profile_attributes_entry.h" | 12 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 13 #include "chrome/browser/profiles/profile_attributes_storage.h" | 13 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/task_manager/providers/task_provider_observer.h" |
| 15 #include "chrome/browser/task_manager/task_manager_observer.h" | 16 #include "chrome/browser/task_manager/task_manager_observer.h" |
| 16 #include "content/public/common/result_codes.h" | 17 #include "content/public/common/result_codes.h" |
| 17 | 18 |
| 18 namespace task_manager { | 19 namespace task_manager { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // The last ID given to the previously created task. | 23 // The last ID given to the previously created task. |
| 23 int64_t g_last_id = 0; | 24 int64_t g_last_id = 0; |
| 24 | 25 |
| 26 base::ProcessId DetermineProcessId(base::ProcessHandle handle, |
| 27 base::ProcessId process_id) { |
| 28 if (process_id != base::kNullProcessId) |
| 29 return process_id; |
| 30 return base::GetProcId(handle); |
| 31 } |
| 32 |
| 25 } // namespace | 33 } // namespace |
| 26 | 34 |
| 27 Task::Task(const base::string16& title, | 35 Task::Task(const base::string16& title, |
| 28 const std::string& rappor_sample, | 36 const std::string& rappor_sample, |
| 29 const gfx::ImageSkia* icon, | 37 const gfx::ImageSkia* icon, |
| 30 base::ProcessHandle handle, | 38 base::ProcessHandle handle, |
| 31 base::ProcessId process_id) | 39 base::ProcessId process_id) |
| 32 : task_id_(g_last_id++), | 40 : task_id_(g_last_id++), |
| 33 network_usage_(-1), | 41 network_usage_(-1), |
| 34 current_byte_count_(-1), | 42 current_byte_count_(-1), |
| 35 title_(title), | 43 title_(title), |
| 36 rappor_sample_name_(rappor_sample), | 44 rappor_sample_name_(rappor_sample), |
| 37 icon_(icon ? *icon : gfx::ImageSkia()), | 45 icon_(icon ? *icon : gfx::ImageSkia()), |
| 38 process_handle_(handle), | 46 process_handle_(handle), |
| 39 process_id_(process_id != base::kNullProcessId | 47 process_id_(DetermineProcessId(handle, process_id)) {} |
| 40 ? process_id | |
| 41 : base::GetProcId(handle)) {} | |
| 42 | 48 |
| 43 Task::~Task() {} | 49 Task::~Task() {} |
| 44 | 50 |
| 45 // static | 51 // static |
| 46 base::string16 Task::GetProfileNameFromProfile(Profile* profile) { | 52 base::string16 Task::GetProfileNameFromProfile(Profile* profile) { |
| 47 DCHECK(profile); | 53 DCHECK(profile); |
| 48 ProfileAttributesEntry* entry; | 54 ProfileAttributesEntry* entry; |
| 49 if (g_browser_process->profile_manager()->GetProfileAttributesStorage(). | 55 if (g_browser_process->profile_manager()->GetProfileAttributesStorage(). |
| 50 GetProfileAttributesWithPath(profile->GetOriginalProfile()->GetPath(), | 56 GetProfileAttributesWithPath(profile->GetOriginalProfile()->GetPath(), |
| 51 &entry)) { | 57 &entry)) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 76 if (current_byte_count_ == -1) | 82 if (current_byte_count_ == -1) |
| 77 return; | 83 return; |
| 78 | 84 |
| 79 network_usage_ = | 85 network_usage_ = |
| 80 (current_byte_count_ * base::TimeDelta::FromSeconds(1)) / update_interval; | 86 (current_byte_count_ * base::TimeDelta::FromSeconds(1)) / update_interval; |
| 81 | 87 |
| 82 // Reset the current byte count for this task. | 88 // Reset the current byte count for this task. |
| 83 current_byte_count_ = 0; | 89 current_byte_count_ = 0; |
| 84 } | 90 } |
| 85 | 91 |
| 92 void Task::UpdateProcessInfo(base::ProcessHandle handle, |
| 93 base::ProcessId process_id, |
| 94 TaskProviderObserver* observer) { |
| 95 process_id = DetermineProcessId(handle, process_id); |
| 96 |
| 97 // Don't remove the task if there is no change to the process ID. |
| 98 if (process_id == process_id_) |
| 99 return; |
| 100 |
| 101 // TaskManagerImpl and TaskGroup implementations assume that a process ID is |
| 102 // consistent for the lifetime of a Task. So to change the process ID, |
| 103 // temporarily unregister this Task. |
| 104 observer->TaskRemoved(this); |
| 105 process_handle_ = handle; |
| 106 process_id_ = process_id; |
| 107 observer->TaskAdded(this); |
| 108 } |
| 109 |
| 86 void Task::OnNetworkBytesRead(int64_t bytes_read) { | 110 void Task::OnNetworkBytesRead(int64_t bytes_read) { |
| 87 if (current_byte_count_ == -1) | 111 if (current_byte_count_ == -1) |
| 88 current_byte_count_ = 0; | 112 current_byte_count_ = 0; |
| 89 | 113 |
| 90 current_byte_count_ += bytes_read; | 114 current_byte_count_ += bytes_read; |
| 91 } | 115 } |
| 92 | 116 |
| 93 void Task::GetTerminationStatus(base::TerminationStatus* out_status, | 117 void Task::GetTerminationStatus(base::TerminationStatus* out_status, |
| 94 int* out_error_code) const { | 118 int* out_error_code) const { |
| 95 DCHECK(out_status); | 119 DCHECK(out_status); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 169 |
| 146 int Task::GetKeepaliveCount() const { | 170 int Task::GetKeepaliveCount() const { |
| 147 return -1; | 171 return -1; |
| 148 } | 172 } |
| 149 | 173 |
| 150 bool Task::ReportsNetworkUsage() const { | 174 bool Task::ReportsNetworkUsage() const { |
| 151 return network_usage_ != -1; | 175 return network_usage_ != -1; |
| 152 } | 176 } |
| 153 | 177 |
| 154 } // namespace task_manager | 178 } // namespace task_manager |
| OLD | NEW |