Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/power/process_power_collector.h" | 5 #include "chrome/browser/power/process_power_collector.h" |
| 6 | 6 |
| 7 #include "base/process/process_handle.h" | 7 #include "base/process/process_handle.h" |
| 8 #include "base/process/process_metrics.h" | 8 #include "base/process/process_metrics.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 for (ProcessMetricsMap::iterator it = metrics_map_.begin(); | 164 for (ProcessMetricsMap::iterator it = metrics_map_.begin(); |
| 165 it != metrics_map_.end(); | 165 it != metrics_map_.end(); |
| 166 ++it) { | 166 ++it) { |
| 167 double last_process_power_usage = it->second->last_cpu_percent(); | 167 double last_process_power_usage = it->second->last_cpu_percent(); |
| 168 last_process_power_usage *= scale_factor_ / total_cpu_percent; | 168 last_process_power_usage *= scale_factor_ / total_cpu_percent; |
| 169 | 169 |
| 170 GURL origin = it->second->last_origin(); | 170 GURL origin = it->second->last_origin(); |
| 171 power::OriginPowerMap* origin_power_map = | 171 power::OriginPowerMap* origin_power_map = |
| 172 power::OriginPowerMapFactory::GetForBrowserContext( | 172 power::OriginPowerMapFactory::GetForBrowserContext( |
| 173 it->second->profile()); | 173 it->second->profile()); |
| 174 DCHECK(origin_power_map); | 174 if (!origin_power_map) |
|
Daniel Erat
2014/09/19 00:39:42
nit: add a comment documenting that this can happe
Daniel Nishi
2014/09/19 00:50:15
Done.
| |
| 175 continue; | |
| 175 origin_power_map->AddPowerForOrigin(origin, last_process_power_usage); | 176 origin_power_map->AddPowerForOrigin(origin, last_process_power_usage); |
| 176 } | 177 } |
| 177 | 178 |
| 178 // Iterate over all profiles to let them know we've finished updating. | 179 // Iterate over all profiles to let them know we've finished updating. |
| 179 ProfileManager* pm = g_browser_process->profile_manager(); | 180 ProfileManager* pm = g_browser_process->profile_manager(); |
| 180 std::vector<Profile*> open_profiles = pm->GetLoadedProfiles(); | 181 std::vector<Profile*> open_profiles = pm->GetLoadedProfiles(); |
| 181 for (std::vector<Profile*>::const_iterator it = open_profiles.begin(); | 182 for (std::vector<Profile*>::const_iterator it = open_profiles.begin(); |
| 182 it != open_profiles.end(); | 183 it != open_profiles.end(); |
| 183 ++it) { | 184 ++it) { |
| 184 power::OriginPowerMap* origin_power_map = | 185 power::OriginPowerMap* origin_power_map = |
| 185 power::OriginPowerMapFactory::GetForBrowserContext(*it); | 186 power::OriginPowerMapFactory::GetForBrowserContext(*it); |
| 187 if (!origin_power_map) | |
| 188 continue; | |
| 186 origin_power_map->OnAllOriginsUpdated(); | 189 origin_power_map->OnAllOriginsUpdated(); |
| 187 } | 190 } |
| 188 } | 191 } |
| 189 | 192 |
| 190 void ProcessPowerCollector::UpdateProcessInMap( | 193 void ProcessPowerCollector::UpdateProcessInMap( |
| 191 const content::RenderProcessHost* rph, | 194 const content::RenderProcessHost* rph, |
| 192 const GURL& origin) { | 195 const GURL& origin) { |
| 193 base::ProcessHandle handle = rph->GetHandle(); | 196 base::ProcessHandle handle = rph->GetHandle(); |
| 194 if (metrics_map_.find(handle) == metrics_map_.end()) { | 197 if (metrics_map_.find(handle) == metrics_map_.end()) { |
| 195 metrics_map_[handle] = linked_ptr<PerProcessData>(new PerProcessData( | 198 metrics_map_[handle] = linked_ptr<PerProcessData>(new PerProcessData( |
| 196 #if defined(OS_MACOSX) | 199 #if defined(OS_MACOSX) |
| 197 scoped_ptr<base::ProcessMetrics>( | 200 scoped_ptr<base::ProcessMetrics>( |
| 198 base::ProcessMetrics::CreateProcessMetrics(handle, NULL)), | 201 base::ProcessMetrics::CreateProcessMetrics(handle, NULL)), |
| 199 #else | 202 #else |
| 200 scoped_ptr<base::ProcessMetrics>( | 203 scoped_ptr<base::ProcessMetrics>( |
| 201 base::ProcessMetrics::CreateProcessMetrics(handle)), | 204 base::ProcessMetrics::CreateProcessMetrics(handle)), |
| 202 #endif | 205 #endif |
| 203 origin, | 206 origin, |
| 204 Profile::FromBrowserContext(rph->GetBrowserContext()))); | 207 Profile::FromBrowserContext(rph->GetBrowserContext()))); |
| 205 } | 208 } |
| 206 | 209 |
| 207 linked_ptr<PerProcessData>& process_data = metrics_map_[handle]; | 210 linked_ptr<PerProcessData>& process_data = metrics_map_[handle]; |
| 208 process_data->set_last_cpu_percent(std::max(0.0, | 211 process_data->set_last_cpu_percent(std::max(0.0, |
| 209 cpu_usage_callback_.is_null() ? process_data->metrics()->GetCPUUsage() | 212 cpu_usage_callback_.is_null() ? process_data->metrics()->GetCPUUsage() |
| 210 : cpu_usage_callback_.Run(handle))); | 213 : cpu_usage_callback_.Run(handle))); |
| 211 process_data->set_seen_this_cycle(true); | 214 process_data->set_seen_this_cycle(true); |
| 212 } | 215 } |
| OLD | NEW |