Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: chrome/browser/power/process_power_collector.cc

Issue 519883002: Update the Website Settings page when the power consumption is updated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a bug where the Origin Map may not exist in tests. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/webui/options/website_settings_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DCHECK(origin_power_map);
175 origin_power_map->AddPowerForOrigin(origin, last_process_power_usage); 175 origin_power_map->AddPowerForOrigin(origin, last_process_power_usage);
176 } 176 }
177
178 // Iterate over all profiles to let them know we've finished updating.
179 ProfileManager* pm = g_browser_process->profile_manager();
180 std::vector<Profile*> open_profiles = pm->GetLoadedProfiles();
181 for (std::vector<Profile*>::const_iterator it = open_profiles.begin();
182 it != open_profiles.end();
183 ++it) {
184 power::OriginPowerMap* origin_power_map =
185 power::OriginPowerMapFactory::GetForBrowserContext(*it);
186 origin_power_map->OnAllOriginsUpdated();
187 }
177 } 188 }
178 189
179 void ProcessPowerCollector::UpdateProcessInMap( 190 void ProcessPowerCollector::UpdateProcessInMap(
180 const content::RenderProcessHost* rph, 191 const content::RenderProcessHost* rph,
181 const GURL& origin) { 192 const GURL& origin) {
182 base::ProcessHandle handle = rph->GetHandle(); 193 base::ProcessHandle handle = rph->GetHandle();
183 if (metrics_map_.find(handle) == metrics_map_.end()) { 194 if (metrics_map_.find(handle) == metrics_map_.end()) {
184 metrics_map_[handle] = linked_ptr<PerProcessData>(new PerProcessData( 195 metrics_map_[handle] = linked_ptr<PerProcessData>(new PerProcessData(
185 #if defined(OS_MACOSX) 196 #if defined(OS_MACOSX)
186 scoped_ptr<base::ProcessMetrics>( 197 scoped_ptr<base::ProcessMetrics>(
187 base::ProcessMetrics::CreateProcessMetrics(handle, NULL)), 198 base::ProcessMetrics::CreateProcessMetrics(handle, NULL)),
188 #else 199 #else
189 scoped_ptr<base::ProcessMetrics>( 200 scoped_ptr<base::ProcessMetrics>(
190 base::ProcessMetrics::CreateProcessMetrics(handle)), 201 base::ProcessMetrics::CreateProcessMetrics(handle)),
191 #endif 202 #endif
192 origin, 203 origin,
193 Profile::FromBrowserContext(rph->GetBrowserContext()))); 204 Profile::FromBrowserContext(rph->GetBrowserContext())));
194 } 205 }
195 206
196 linked_ptr<PerProcessData>& process_data = metrics_map_[handle]; 207 linked_ptr<PerProcessData>& process_data = metrics_map_[handle];
197 process_data->set_last_cpu_percent(std::max(0.0, 208 process_data->set_last_cpu_percent(std::max(0.0,
198 cpu_usage_callback_.is_null() ? process_data->metrics()->GetCPUUsage() 209 cpu_usage_callback_.is_null() ? process_data->metrics()->GetCPUUsage()
199 : cpu_usage_callback_.Run(handle))); 210 : cpu_usage_callback_.Run(handle)));
200 process_data->set_seen_this_cycle(true); 211 process_data->set_seen_this_cycle(true);
201 } 212 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/options/website_settings_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698