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

Unified Diff: remoting/host/process_stats_sender.cc

Issue 2860803002: [Chromoting] Allow ProcessStatsSender to receive nullptr ProcessStatsAgent
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/process_stats_sender.cc
diff --git a/remoting/host/process_stats_sender.cc b/remoting/host/process_stats_sender.cc
index a734877e51887d5c92d33ab8f1686f94ad2db2dd..2bfd4c2186f1045f4536585097d9d7af0b943cec 100644
--- a/remoting/host/process_stats_sender.cc
+++ b/remoting/host/process_stats_sender.cc
@@ -13,16 +13,31 @@
namespace remoting {
+namespace {
+
+std::vector<ProcessStatsAgent*> RemoveNullAgent(
+ std::initializer_list<ProcessStatsAgent*> agents) {
+ std::vector<ProcessStatsAgent*> result;
+ for (auto* const agent : agents) {
+ if (agent) {
+ result.push_back(agent);
+ }
+ }
+ return result;
+}
+
+} // namespace
+
ProcessStatsSender::ProcessStatsSender(
protocol::ProcessStatsStub* host_stats_stub,
base::TimeDelta interval,
std::initializer_list<ProcessStatsAgent*> agents)
: host_stats_stub_(host_stats_stub),
- agents_(agents),
+ 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 :)
thread_checker_() {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(host_stats_stub_);
- DCHECK(!interval.is_zero());
+ 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
DCHECK(!agents_.empty());
timer_.Start(FROM_HERE, interval, this, &ProcessStatsSender::ReportUsage);

Powered by Google App Engine
This is Rietveld 408576698