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

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: Rebase Created 5 years, 10 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 resource_usage_.pop_front(); 430 resource_usage_.pop_front();
431 } 431 }
432 432
433 std::vector<double> DeviceStatusCollector::GetPerProcessCPUUsage() { 433 std::vector<double> DeviceStatusCollector::GetPerProcessCPUUsage() {
434 std::vector<double> cpu_usage; 434 std::vector<double> cpu_usage;
435 base::ProcessIterator process_iter(nullptr); 435 base::ProcessIterator process_iter(nullptr);
436 436
437 const int num_processors = base::SysInfo::NumberOfProcessors(); 437 const int num_processors = base::SysInfo::NumberOfProcessors();
438 while (const base::ProcessEntry* process_entry = 438 while (const base::ProcessEntry* process_entry =
439 process_iter.NextProcessEntry()) { 439 process_iter.NextProcessEntry()) {
440 base::ProcessHandle process; 440 base::Process process = base::Process::Open(process_entry->pid());
441 if (!base::OpenProcessHandle(process_entry->pid(), &process)) { 441 if (!process.IsValid()) {
442 LOG(ERROR) << "Could not create process handle for process " 442 LOG(ERROR) << "Could not create process handle for process "
443 << process_entry->pid(); 443 << process_entry->pid();
444 continue; 444 continue;
445 } 445 }
446 scoped_ptr<base::ProcessMetrics> metrics( 446 scoped_ptr<base::ProcessMetrics> metrics(
447 base::ProcessMetrics::CreateProcessMetrics(process)); 447 base::ProcessMetrics::CreateProcessMetrics(process.Handle()));
448 const double usage = metrics->GetPlatformIndependentCPUUsage(); 448 const double usage = metrics->GetPlatformIndependentCPUUsage();
449 base::CloseProcessHandle(process);
450 DCHECK_LE(0, usage); 449 DCHECK_LE(0, usage);
451 if (usage > 0) { 450 if (usage > 0) {
452 // Convert CPU usage from "percentage of a single core" to "percentage of 451 // Convert CPU usage from "percentage of a single core" to "percentage of
453 // all CPU available". 452 // all CPU available".
454 cpu_usage.push_back(usage / num_processors); 453 cpu_usage.push_back(usage / num_processors);
455 } 454 }
456 } 455 }
457 return cpu_usage; 456 return cpu_usage;
458 } 457 }
459 458
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 ScheduleGeolocationUpdateRequest(); 785 ScheduleGeolocationUpdateRequest();
787 } 786 }
788 787
789 void DeviceStatusCollector::ReceiveVolumeInfo( 788 void DeviceStatusCollector::ReceiveVolumeInfo(
790 const std::vector<em::VolumeInfo>& info) { 789 const std::vector<em::VolumeInfo>& info) {
791 if (report_hardware_status_) 790 if (report_hardware_status_)
792 volume_info_ = info; 791 volume_info_ = info;
793 } 792 }
794 793
795 } // namespace policy 794 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698