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

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

Issue 582983002: Fix a bug where Guest Profiles in CrOS could cause crashes when collecting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: No colon. 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // |origin_power_map| can be NULL, if the profile is a guest profile in
175 // Chrome OS.
176 if (!origin_power_map)
177 continue;
175 origin_power_map->AddPowerForOrigin(origin, last_process_power_usage); 178 origin_power_map->AddPowerForOrigin(origin, last_process_power_usage);
176 } 179 }
177 180
178 // Iterate over all profiles to let them know we've finished updating. 181 // Iterate over all profiles to let them know we've finished updating.
179 ProfileManager* pm = g_browser_process->profile_manager(); 182 ProfileManager* pm = g_browser_process->profile_manager();
180 std::vector<Profile*> open_profiles = pm->GetLoadedProfiles(); 183 std::vector<Profile*> open_profiles = pm->GetLoadedProfiles();
181 for (std::vector<Profile*>::const_iterator it = open_profiles.begin(); 184 for (std::vector<Profile*>::const_iterator it = open_profiles.begin();
182 it != open_profiles.end(); 185 it != open_profiles.end();
183 ++it) { 186 ++it) {
184 power::OriginPowerMap* origin_power_map = 187 power::OriginPowerMap* origin_power_map =
185 power::OriginPowerMapFactory::GetForBrowserContext(*it); 188 power::OriginPowerMapFactory::GetForBrowserContext(*it);
189 if (!origin_power_map)
190 continue;
186 origin_power_map->OnAllOriginsUpdated(); 191 origin_power_map->OnAllOriginsUpdated();
187 } 192 }
188 } 193 }
189 194
190 void ProcessPowerCollector::UpdateProcessInMap( 195 void ProcessPowerCollector::UpdateProcessInMap(
191 const content::RenderProcessHost* rph, 196 const content::RenderProcessHost* rph,
192 const GURL& origin) { 197 const GURL& origin) {
193 base::ProcessHandle handle = rph->GetHandle(); 198 base::ProcessHandle handle = rph->GetHandle();
194 if (metrics_map_.find(handle) == metrics_map_.end()) { 199 if (metrics_map_.find(handle) == metrics_map_.end()) {
195 metrics_map_[handle] = linked_ptr<PerProcessData>(new PerProcessData( 200 metrics_map_[handle] = linked_ptr<PerProcessData>(new PerProcessData(
196 #if defined(OS_MACOSX) 201 #if defined(OS_MACOSX)
197 scoped_ptr<base::ProcessMetrics>( 202 scoped_ptr<base::ProcessMetrics>(
198 base::ProcessMetrics::CreateProcessMetrics(handle, NULL)), 203 base::ProcessMetrics::CreateProcessMetrics(handle, NULL)),
199 #else 204 #else
200 scoped_ptr<base::ProcessMetrics>( 205 scoped_ptr<base::ProcessMetrics>(
201 base::ProcessMetrics::CreateProcessMetrics(handle)), 206 base::ProcessMetrics::CreateProcessMetrics(handle)),
202 #endif 207 #endif
203 origin, 208 origin,
204 Profile::FromBrowserContext(rph->GetBrowserContext()))); 209 Profile::FromBrowserContext(rph->GetBrowserContext())));
205 } 210 }
206 211
207 linked_ptr<PerProcessData>& process_data = metrics_map_[handle]; 212 linked_ptr<PerProcessData>& process_data = metrics_map_[handle];
208 process_data->set_last_cpu_percent(std::max(0.0, 213 process_data->set_last_cpu_percent(std::max(0.0,
209 cpu_usage_callback_.is_null() ? process_data->metrics()->GetCPUUsage() 214 cpu_usage_callback_.is_null() ? process_data->metrics()->GetCPUUsage()
210 : cpu_usage_callback_.Run(handle))); 215 : cpu_usage_callback_.Run(handle)));
211 process_data->set_seen_this_cycle(true); 216 process_data->set_seen_this_cycle(true);
212 } 217 }
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