Commit 62cb7055 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Change behavior of a couple truncating divisions to rounding.

Both of these locations are approximating a higher-precision number
with a lower one for human consumption, so rounding produces the least
error.  (In practice the difference won't be noticed; the more desirable
effect of this change is to use explicit safe float->int conversions.)

Bug: 1104532
Change-Id: I2173e7848778c99f9eb629870bc0c5383d5cb263
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2293630
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787932}
parent 79d4091b
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ash/app_list/views/expand_arrow_view.h" #include "ash/app_list/views/expand_arrow_view.h"
#include <algorithm>
#include <memory> #include <memory>
#include <utility> #include <utility>
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
#include "ash/public/cpp/app_list/vector_icons/vector_icons.h" #include "ash/public/cpp/app_list/vector_icons/vector_icons.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/animation/slide_animation.h" #include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
...@@ -333,7 +335,7 @@ void ExpandArrowView::AnimationProgressed(const gfx::Animation* animation) { ...@@ -333,7 +335,7 @@ void ExpandArrowView::AnimationProgressed(const gfx::Animation* animation) {
} }
// Update pulse radius. // Update pulse radius.
pulse_radius_ = static_cast<int>( pulse_radius_ = base::Round(
(kPulseMaxRadius - kPulseMinRadius) * (kPulseMaxRadius - kPulseMinRadius) *
gfx::Tween::CalculateValue( gfx::Tween::CalculateValue(
gfx::Tween::EASE_IN_OUT, gfx::Tween::EASE_IN_OUT,
...@@ -349,14 +351,14 @@ void ExpandArrowView::AnimationProgressed(const gfx::Animation* animation) { ...@@ -349,14 +351,14 @@ void ExpandArrowView::AnimationProgressed(const gfx::Animation* animation) {
const double progress = const double progress =
(time - kArrowMoveOutBeginTime).InMillisecondsF() / (time - kArrowMoveOutBeginTime).InMillisecondsF() /
(kArrowMoveOutEndTime - kArrowMoveOutBeginTime).InMillisecondsF(); (kArrowMoveOutEndTime - kArrowMoveOutBeginTime).InMillisecondsF();
arrow_y_offset_ = static_cast<int>( arrow_y_offset_ =
-kTotalArrowYOffset * base::Round(-kTotalArrowYOffset *
gfx::Tween::CalculateValue(gfx::Tween::EASE_IN, progress)); gfx::Tween::CalculateValue(gfx::Tween::EASE_IN, progress));
} else if (time > kArrowMoveInBeginTime && time <= kArrowMoveInEndTime) { } else if (time > kArrowMoveInBeginTime && time <= kArrowMoveInEndTime) {
const double progress = const double progress =
(time - kArrowMoveInBeginTime).InMillisecondsF() / (time - kArrowMoveInBeginTime).InMillisecondsF() /
(kArrowMoveInEndTime - kArrowMoveInBeginTime).InMillisecondsF(); (kArrowMoveInEndTime - kArrowMoveInBeginTime).InMillisecondsF();
arrow_y_offset_ = static_cast<int>( arrow_y_offset_ = base::Round(
kTotalArrowYOffset * kTotalArrowYOffset *
(1 - gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, progress))); (1 - gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, progress)));
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <stddef.h> #include <stddef.h>
#include "base/numerics/safe_conversions.h"
#include "base/process/process.h" #include "base/process/process.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -92,15 +93,13 @@ void Task::Refresh(const base::TimeDelta& update_interval, ...@@ -92,15 +93,13 @@ void Task::Refresh(const base::TimeDelta& update_interval,
int64_t current_cycle_read_byte_count = int64_t current_cycle_read_byte_count =
cumulative_bytes_read_ - last_refresh_cumulative_bytes_read_; cumulative_bytes_read_ - last_refresh_cumulative_bytes_read_;
network_read_rate_ = network_read_rate_ = base::Round<int64_t>(current_cycle_read_byte_count /
(current_cycle_read_byte_count * base::TimeDelta::FromSeconds(1)) / update_interval.InSecondsF());
update_interval;
int64_t current_cycle_sent_byte_count = int64_t current_cycle_sent_byte_count =
cumulative_bytes_sent_ - last_refresh_cumulative_bytes_sent_; cumulative_bytes_sent_ - last_refresh_cumulative_bytes_sent_;
network_sent_rate_ = network_sent_rate_ = base::Round<int64_t>(current_cycle_sent_byte_count /
(current_cycle_sent_byte_count * base::TimeDelta::FromSeconds(1)) / update_interval.InSecondsF());
update_interval;
last_refresh_cumulative_bytes_read_ = cumulative_bytes_read_; last_refresh_cumulative_bytes_read_ = cumulative_bytes_read_;
last_refresh_cumulative_bytes_sent_ = cumulative_bytes_sent_; last_refresh_cumulative_bytes_sent_ = cumulative_bytes_sent_;
......
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