Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromoting_param_traits.h" | 5 #include "remoting/host/chromoting_param_traits.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "ipc/ipc_message_utils.h" | 10 #include "ipc/ipc_message_utils.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 } | 274 } |
| 275 | 275 |
| 276 // static | 276 // static |
| 277 void ParamTraits<remoting::DesktopEnvironmentOptions>::Log( | 277 void ParamTraits<remoting::DesktopEnvironmentOptions>::Log( |
| 278 const remoting::DesktopEnvironmentOptions& p, | 278 const remoting::DesktopEnvironmentOptions& p, |
| 279 std::string* l) { | 279 std::string* l) { |
| 280 l->append("DesktopEnvironmentOptions()"); | 280 l->append("DesktopEnvironmentOptions()"); |
| 281 } | 281 } |
| 282 | 282 |
| 283 // static | 283 // static |
| 284 void ParamTraits<remoting::protocol::AggregatedProcessResourceUsage>::GetSize( | |
| 285 base::PickleSizer* s, const param_type& p) { | |
| 286 GetParamSize(s, p.usages_size()); | |
| 287 for (int i = 0; i < p.usages_size(); i++) { | |
| 288 const auto& usage = p.usages().Get(i); | |
| 289 GetParamSize(s, usage.process_name()); | |
| 290 GetParamSize(s, usage.processor_usage()); | |
| 291 GetParamSize(s, usage.working_set_size()); | |
| 292 GetParamSize(s, usage.pagefile_size()); | |
| 293 } | |
| 294 } | |
| 295 | |
| 296 // static | |
| 284 void ParamTraits<remoting::protocol::AggregatedProcessResourceUsage>::Write( | 297 void ParamTraits<remoting::protocol::AggregatedProcessResourceUsage>::Write( |
| 285 base::Pickle* m, | 298 base::Pickle* m, |
| 286 const remoting::protocol::AggregatedProcessResourceUsage& p) { | 299 const remoting::protocol::AggregatedProcessResourceUsage& p) { |
| 287 m->WriteString(p.name()); | 300 m->WriteInt(p.usages_size()); |
|
estark
2017/07/02 00:24:04
Can this be a WriteUint64?
Hzj_jie
2017/07/02 20:59:05
According to the generated code (https://cs.chromi
dcheng
2017/07/06 00:01:56
Since this is specified to return int (currently),
Hzj_jie
2017/07/06 00:45:37
Since RepeatedField<T> is a standard instead of an
dcheng
2017/07/06 08:08:10
Well, it seems like this CL introduces serializati
Hzj_jie
2017/07/07 00:59:49
Definitely, the change is at https://codereview.ch
| |
| 288 m->WriteDouble(p.processor_usage()); | 301 for (int i = 0; i < p.usages_size(); i++) { |
| 289 m->WriteUInt64(p.working_set_size()); | 302 const auto& usage = p.usages().Get(i); |
| 290 m->WriteUInt64(p.pagefile_size()); | 303 m->WriteString(usage.process_name()); |
| 304 m->WriteDouble(usage.processor_usage()); | |
| 305 m->WriteUInt64(usage.working_set_size()); | |
| 306 m->WriteUInt64(usage.pagefile_size()); | |
| 307 } | |
| 291 } | 308 } |
| 292 | 309 |
| 293 // static | 310 // static |
| 294 bool ParamTraits<remoting::protocol::AggregatedProcessResourceUsage>::Read( | 311 bool ParamTraits<remoting::protocol::AggregatedProcessResourceUsage>::Read( |
| 295 const base::Pickle* m, | 312 const base::Pickle* m, |
| 296 base::PickleIterator* iter, | 313 base::PickleIterator* iter, |
| 297 remoting::protocol::AggregatedProcessResourceUsage* p) { | 314 remoting::protocol::AggregatedProcessResourceUsage* p) { |
| 298 std::string name; | 315 int usages_size = 0; |
| 299 double processor_usage; | 316 if (!iter->ReadInt(&usages_size)) { |
| 300 uint64_t working_set_size; | |
| 301 uint64_t pagefile_size; | |
| 302 if (!iter->ReadString(&name) || | |
| 303 !iter->ReadDouble(&processor_usage) || | |
| 304 !iter->ReadUInt64(&working_set_size) || | |
| 305 !iter->ReadUInt64(&pagefile_size)) { | |
| 306 return false; | 317 return false; |
| 307 } | 318 } |
| 308 | 319 |
| 309 p->set_name(name); | 320 for (int i = 0; i < usages_size; i++) { |
|
dcheng
2017/07/06 00:01:57
Most importantly, that lets us consolidate checks
Hzj_jie
2017/07/06 00:45:37
I have replaced GetInt() with GetLength(). But I d
dcheng
2017/07/06 08:08:09
It won't crash here. But in general, it's preferab
Hzj_jie
2017/07/07 00:59:49
Got you. The newly prepared change should also fix
| |
| 310 p->set_processor_usage(processor_usage); | 321 std::string process_name; |
| 311 p->set_working_set_size(working_set_size); | 322 double processor_usage; |
| 312 p->set_pagefile_size(pagefile_size); | 323 uint64_t working_set_size; |
| 324 uint64_t pagefile_size; | |
| 325 if (!iter->ReadString(&process_name) || | |
| 326 !iter->ReadDouble(&processor_usage) || | |
| 327 !iter->ReadUInt64(&working_set_size) || | |
| 328 !iter->ReadUInt64(&pagefile_size)) { | |
| 329 return false; | |
| 330 } | |
| 331 | |
| 332 remoting::protocol::ProcessResourceUsage usage; | |
| 333 usage.set_process_name(process_name); | |
| 334 usage.set_processor_usage(processor_usage); | |
| 335 usage.set_working_set_size(working_set_size); | |
| 336 usage.set_pagefile_size(pagefile_size); | |
| 337 *p->add_usages() = usage; | |
| 338 } | |
| 313 return true; | 339 return true; |
| 314 } | 340 } |
| 315 | 341 |
| 316 // static | 342 // static |
| 317 void ParamTraits<remoting::protocol::AggregatedProcessResourceUsage>::Log( | 343 void ParamTraits<remoting::protocol::AggregatedProcessResourceUsage>::Log( |
| 318 const remoting::protocol::AggregatedProcessResourceUsage& p, | 344 const remoting::protocol::AggregatedProcessResourceUsage& p, |
| 319 std::string* l) { | 345 std::string* l) { |
| 320 l->append("AggregatedProcessResourceUsage()"); | 346 l->append("AggregatedProcessResourceUsage()"); |
| 321 } | 347 } |
| 322 | 348 |
| 323 } // namespace IPC | 349 } // namespace IPC |
| 324 | 350 |
| OLD | NEW |