Commit ffaec538 authored by jam's avatar jam Committed by Commit bot

Add comments for struct members that were changed from size_t to uin32_t or...

Add comments for struct members that were changed from size_t to uin32_t or uint64_t for IPC safety.

Also add a few checked_cast for places where we converted from size_t and we're sure that it's safe.

BUG=581409

Review URL: https://codereview.chromium.org/1684793003

Cr-Commit-Position: refs/heads/master@{#374788}
parent ac440714
......@@ -188,7 +188,7 @@ void TaskGroup::RefreshGpuMemory(
return;
}
gpu_memory_ = static_cast<int64_t>(itr->second.video_memory);
gpu_memory_ = itr->second.video_memory;
gpu_memory_has_duplicates_ = itr->second.has_duplicates;
}
......
......@@ -8,6 +8,7 @@
#include "base/i18n/number_formatting.h"
#include "base/i18n/rtl.h"
#include "base/location.h"
#include "base/numerics/safe_conversions.h"
#include "base/process/process_metrics.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
......@@ -666,7 +667,9 @@ bool TaskManagerModel::GetVideoMemory(int index,
if (i == video_memory_usage_stats_.process_map.end())
return false;
values.is_video_memory_valid = true;
values.video_memory = i->second.video_memory;
// If this checked_cast asserts, then need to change this code to use
// uint64_t instead of size_t.
values.video_memory = base::checked_cast<size_t>(i->second.video_memory);
values.video_memory_has_duplicates = i->second.has_duplicates;
}
*video_memory = values.video_memory;
......
......@@ -29,6 +29,9 @@ class SpellCheckMarker {
: hash(hash), offset(offset) {}
uint32_t hash;
// Note: we use uint32_t instead of size_t because this struct is sent over
// IPC which could span 32 & 64 bit processes. This is fine since the offset
// shouldn't exceed UINT32_MAX even on 64 bit builds.
uint32_t offset;
};
......
......@@ -45,6 +45,9 @@ struct FormFieldData {
base::string16 value;
std::string form_control_type;
std::string autocomplete_attribute;
// Note: we use uint32_t instead of size_t because this struct is sent over
// IPC which could span 32 & 64 bit processes. This is fine since the length
// shouldn't exceed UINT32_MAX even on 64 bit builds.
uint32_t max_length;
bool is_autofilled;
bool is_checked;
......
......@@ -118,7 +118,7 @@ void GpuMemoryManager::SendUmaStatsToBrowser() {
GPUMemoryUmaStats params;
params.bytes_allocated_current = GetCurrentUsage();
params.bytes_allocated_max = bytes_allocated_historical_max_;
params.context_group_count = tracking_groups_.size();
params.context_group_count = static_cast<uint32_t>(tracking_groups_.size());
channel_manager_->Send(new GpuHostMsg_GpuMemoryUmaStats(params));
}
} // namespace content
......@@ -11,6 +11,8 @@ namespace content {
// Memory usage statistics send periodically to the browser process to report
// in UMA histograms if the GPU process crashes.
// Note: we use uint64_t instead of size_t for byte count because this struct
// is sent over IPC which could span 32 & 64 bit processes.
struct GPUMemoryUmaStats {
GPUMemoryUmaStats()
: bytes_allocated_current(0),
......@@ -19,10 +21,10 @@ struct GPUMemoryUmaStats {
}
// The number of bytes currently allocated.
uint32_t bytes_allocated_current;
uint64_t bytes_allocated_current;
// The maximum number of bytes ever allocated at once.
uint32_t bytes_allocated_max;
uint64_t bytes_allocated_max;
// The number of context groups.
uint32_t context_group_count;
......
......@@ -17,6 +17,8 @@
namespace content {
// Note: we use uint64_t instead of size_t for byte count because this struct
// is sent over IPC which could span 32 & 64 bit processes.
struct CONTENT_EXPORT GPUVideoMemoryUsageStats {
GPUVideoMemoryUsageStats();
~GPUVideoMemoryUsageStats();
......@@ -26,7 +28,7 @@ struct CONTENT_EXPORT GPUVideoMemoryUsageStats {
~ProcessStats();
// The bytes of GPU resources accessible by this process
uint32_t video_memory;
uint64_t video_memory;
// Set to true if this process' GPU resource count is inflated because
// it is counting other processes' resources (e.g, the GPU process has
......@@ -39,10 +41,10 @@ struct CONTENT_EXPORT GPUVideoMemoryUsageStats {
ProcessMap process_map;
// The total amount of GPU memory allocated at the time of the request.
uint32_t bytes_allocated;
uint64_t bytes_allocated;
// The maximum amount of GPU memory ever allocated at once.
uint32_t bytes_allocated_historical_max;
uint64_t bytes_allocated_historical_max;
};
} // namespace content
......
......@@ -29,6 +29,9 @@ struct StackFrame {
bool operator==(const StackFrame& rhs) const;
// Note: we use uint32_t instead of size_t because this struct is sent over
// IPC which could span 32 & 64 bit processes. This is fine since line numbers
// and column numbers shouldn't exceed UINT32_MAX even on 64 bit builds.
uint32_t line_number;
uint32_t column_number;
base::string16 source;
......
......@@ -64,6 +64,8 @@ struct FrameEvent {
int height;
// Size of encoded frame in bytes. Only set for FRAME_ENCODED event.
// Note: we use uint32_t instead of size_t for byte count because this struct
// is sent over IPC which could span 32 & 64 bit processes.
uint32_t size;
// Time of event logged.
......
......@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/debug/dump_without_crashing.h"
#include "base/message_loop/message_loop.h"
#include "base/numerics/safe_conversions.h"
namespace media {
namespace cast {
......@@ -354,7 +355,7 @@ void PacedSender::LogPacketEvent(const Packet& packet, CastLoggingEvent type) {
success &= reader.Skip(2);
success &= reader.ReadU16(&event.packet_id);
success &= reader.ReadU16(&event.max_packet_id);
event.size = packet.size();
event.size = base::checked_cast<uint32_t>(packet.size());
DCHECK(success);
}
......
......@@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/numerics/safe_conversions.h"
#include "media/cast/cast_config.h"
#include "media/cast/cast_defines.h"
#include "media/cast/cast_environment.h"
......@@ -129,7 +130,7 @@ void FrameReceiver::ProcessParsedPacket(const RtpCastHeader& rtp_header,
receive_event->frame_id = rtp_header.frame_id;
receive_event->packet_id = rtp_header.packet_id;
receive_event->max_packet_id = rtp_header.max_packet_id;
receive_event->size = payload_size;
receive_event->size = base::checked_cast<uint32_t>(payload_size);
cast_environment_->logger()->DispatchPacketEvent(std::move(receive_event));
bool duplicate = false;
......
......@@ -10,6 +10,7 @@
#include <vector>
#include "base/macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/trace_event/trace_event.h"
#include "media/cast/cast_defines.h"
#include "media/cast/constants.h"
......@@ -239,7 +240,7 @@ void FrameSender::SendEncodedFrame(
encode_event->media_type = is_audio_ ? AUDIO_EVENT : VIDEO_EVENT;
encode_event->rtp_timestamp = encoded_frame->rtp_timestamp;
encode_event->frame_id = frame_id;
encode_event->size = encoded_frame->data.size();
encode_event->size = base::checked_cast<uint32_t>(encoded_frame->data.size());
encode_event->key_frame = encoded_frame->dependency == EncodedFrame::KEY;
encode_event->target_bitrate = requested_bitrate_before_encode;
encode_event->encoder_cpu_utilization = encoded_frame->deadline_utilization;
......
......@@ -108,6 +108,9 @@ class GFX_EXPORT Range {
std::string ToString() const;
private:
// Note: we use uint32_t instead of size_t because this struct is sent over
// IPC which could span 32 & 64 bit processes. This is fine since text spans
// shouldn't exceed UINT32_MAX even on 64 bit builds.
uint32_t start_;
uint32_t end_;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment