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

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector.cc

Issue 868543002: Move OpenProcessHandle to Process::Open. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/policy/device_status_collector.h" 5 #include "chrome/browser/chromeos/policy/device_status_collector.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <limits> 8 #include <limits>
9 #include <sys/statvfs.h> 9 #include <sys/statvfs.h>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/posix/eintr_wrapper.h" 16 #include "base/posix/eintr_wrapper.h"
17 #include "base/prefs/pref_registry_simple.h" 17 #include "base/prefs/pref_registry_simple.h"
18 #include "base/prefs/pref_service.h" 18 #include "base/prefs/pref_service.h"
19 #include "base/prefs/scoped_user_pref_update.h" 19 #include "base/prefs/scoped_user_pref_update.h"
20 #include "base/process/process_handle.h" 20 #include "base/process/process.h"
21 #include "base/process/process_iterator.h" 21 #include "base/process/process_iterator.h"
22 #include "base/process/process_metrics.h" 22 #include "base/process/process_metrics.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/sys_info.h" 24 #include "base/sys_info.h"
25 #include "base/task_runner_util.h" 25 #include "base/task_runner_util.h"
26 #include "base/values.h" 26 #include "base/values.h"
27 #include "chrome/browser/browser_process.h" 27 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
29 #include "chrome/browser/chromeos/settings/cros_settings.h" 29 #include "chrome/browser/chromeos/settings/cros_settings.h"
30 #include "chrome/common/chrome_version_info.h" 30 #include "chrome/common/chrome_version_info.h"
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 cpu_usage_percent_.pop_front(); 420 cpu_usage_percent_.pop_front();
421 } 421 }
422 422
423 std::vector<double> DeviceStatusCollector::GetPerProcessCPUUsage() { 423 std::vector<double> DeviceStatusCollector::GetPerProcessCPUUsage() {
424 std::vector<double> cpu_usage; 424 std::vector<double> cpu_usage;
425 base::ProcessIterator process_iter(nullptr); 425 base::ProcessIterator process_iter(nullptr);
426 426
427 const int num_processors = base::SysInfo::NumberOfProcessors(); 427 const int num_processors = base::SysInfo::NumberOfProcessors();
428 while (const base::ProcessEntry* process_entry = 428 while (const base::ProcessEntry* process_entry =
429 process_iter.NextProcessEntry()) { 429 process_iter.NextProcessEntry()) {
430 base::ProcessHandle process; 430 base::Process process = base::Process::Open(process_entry->pid());
431 if (!base::OpenProcessHandle(process_entry->pid(), &process)) { 431 if (!process.IsValid()) {
432 LOG(ERROR) << "Could not create process handle for process " 432 LOG(ERROR) << "Could not create process handle for process "
433 << process_entry->pid(); 433 << process_entry->pid();
434 continue; 434 continue;
435 } 435 }
436 scoped_ptr<base::ProcessMetrics> metrics( 436 scoped_ptr<base::ProcessMetrics> metrics(
437 base::ProcessMetrics::CreateProcessMetrics(process)); 437 base::ProcessMetrics::CreateProcessMetrics(process.Handle()));
438 const double usage = metrics->GetPlatformIndependentCPUUsage(); 438 const double usage = metrics->GetPlatformIndependentCPUUsage();
439 base::CloseProcessHandle(process);
440 DCHECK_LE(0, usage); 439 DCHECK_LE(0, usage);
441 if (usage > 0) { 440 if (usage > 0) {
442 // Convert CPU usage from "percentage of a single core" to "percentage of 441 // Convert CPU usage from "percentage of a single core" to "percentage of
443 // all CPU available". 442 // all CPU available".
444 cpu_usage.push_back(usage / num_processors); 443 cpu_usage.push_back(usage / num_processors);
445 } 444 }
446 } 445 }
447 return cpu_usage; 446 return cpu_usage;
448 } 447 }
449 448
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 ScheduleGeolocationUpdateRequest(); 765 ScheduleGeolocationUpdateRequest();
767 } 766 }
768 767
769 void DeviceStatusCollector::ReceiveVolumeInfo( 768 void DeviceStatusCollector::ReceiveVolumeInfo(
770 const std::vector<em::VolumeInfo>& info) { 769 const std::vector<em::VolumeInfo>& info) {
771 if (report_hardware_status_) 770 if (report_hardware_status_)
772 volume_info_ = info; 771 volume_info_ = info;
773 } 772 }
774 773
775 } // namespace policy 774 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698