OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "remoting/host/process_stats_sender.h" | 5 #include "remoting/host/process_stats_sender.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "remoting/host/process_stats_agent.h" | 11 #include "remoting/host/process_stats_agent.h" |
12 #include "remoting/host/process_stats_util.h" | 12 #include "remoting/host/process_stats_util.h" |
13 | 13 |
14 namespace remoting { | 14 namespace remoting { |
15 | 15 |
16 namespace { | |
17 | |
18 std::vector<ProcessStatsAgent*> RemoveNullAgent( | |
19 std::initializer_list<ProcessStatsAgent*> agents) { | |
20 std::vector<ProcessStatsAgent*> result; | |
21 for (auto* const agent : agents) { | |
22 if (agent) { | |
23 result.push_back(agent); | |
24 } | |
25 } | |
26 return result; | |
27 } | |
28 | |
29 } // namespace | |
30 | |
16 ProcessStatsSender::ProcessStatsSender( | 31 ProcessStatsSender::ProcessStatsSender( |
17 protocol::ProcessStatsStub* host_stats_stub, | 32 protocol::ProcessStatsStub* host_stats_stub, |
18 base::TimeDelta interval, | 33 base::TimeDelta interval, |
19 std::initializer_list<ProcessStatsAgent*> agents) | 34 std::initializer_list<ProcessStatsAgent*> agents) |
20 : host_stats_stub_(host_stats_stub), | 35 : host_stats_stub_(host_stats_stub), |
21 agents_(agents), | 36 agents_(RemoveNullAgent(agents)), |
joedow
2017/05/03 21:41:01
I'm not sure about the approach here. It seems mu
Hzj_jie
2017/05/03 22:18:04
:)
| |
22 thread_checker_() { | 37 thread_checker_() { |
23 DCHECK(thread_checker_.CalledOnValidThread()); | 38 DCHECK(thread_checker_.CalledOnValidThread()); |
24 DCHECK(host_stats_stub_); | 39 DCHECK(host_stats_stub_); |
25 DCHECK(!interval.is_zero()); | 40 DCHECK(interval > base::TimeDelta()); |
joedow
2017/05/03 21:41:01
The !is_zero() check seems more readable, why the
Hzj_jie
2017/05/03 22:18:04
Timer handles negative interval as 0:
https://cs.c
joedow
2017/05/08 16:25:41
I haven't experienced negative TimeDeltas being a
Hzj_jie
2017/05/08 18:16:19
Yes, and I also think silently accepting negative
| |
26 DCHECK(!agents_.empty()); | 41 DCHECK(!agents_.empty()); |
27 | 42 |
28 timer_.Start(FROM_HERE, interval, this, &ProcessStatsSender::ReportUsage); | 43 timer_.Start(FROM_HERE, interval, this, &ProcessStatsSender::ReportUsage); |
29 } | 44 } |
30 | 45 |
31 ProcessStatsSender::~ProcessStatsSender() { | 46 ProcessStatsSender::~ProcessStatsSender() { |
32 DCHECK(thread_checker_.CalledOnValidThread()); | 47 DCHECK(thread_checker_.CalledOnValidThread()); |
33 timer_.Stop(); | 48 timer_.Stop(); |
34 } | 49 } |
35 | 50 |
36 void ProcessStatsSender::ReportUsage() { | 51 void ProcessStatsSender::ReportUsage() { |
37 DCHECK(thread_checker_.CalledOnValidThread()); | 52 DCHECK(thread_checker_.CalledOnValidThread()); |
38 | 53 |
39 std::vector<protocol::ProcessResourceUsage> usages; | 54 std::vector<protocol::ProcessResourceUsage> usages; |
40 for (auto* const agent : agents_) { | 55 for (auto* const agent : agents_) { |
41 DCHECK(agent); | 56 DCHECK(agent); |
42 protocol::ProcessResourceUsage usage = agent->GetResourceUsage(); | 57 protocol::ProcessResourceUsage usage = agent->GetResourceUsage(); |
43 if (!IsEmptyProcessResourceUsage(usage)) { | 58 if (!IsEmptyProcessResourceUsage(usage)) { |
44 usages.push_back(std::move(usage)); | 59 usages.push_back(std::move(usage)); |
45 } | 60 } |
46 } | 61 } |
47 | 62 |
48 host_stats_stub_->OnProcessStats(AggregateProcessResourceUsage(usages)); | 63 host_stats_stub_->OnProcessStats(AggregateProcessResourceUsage(usages)); |
49 } | 64 } |
50 | 65 |
51 } // namespace remoting | 66 } // namespace remoting |
OLD | NEW |