Commit 19d48e40 authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

Use base::TimeTicks instead of doubles in FileWriter to record timestamps

file_writer.cc was using doubles to record timestamps that were used later on to
fire notifications after a given interval. Not only that, it was calling
base::Time when it should probably use base::TimeTicks as we are not interested
in dates but timestamps. That's why we're using now base::TimeTicks and
base::TimeDelta avoiding the unneeded conversions to doubles.

Bug: 979137
Change-Id: Id40fa2b6fe993aa253a9621b031950fa3765f2ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1706519Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Sergio Villar <svillar@igalia.com>
Cr-Commit-Position: refs/heads/master@{#678337}
parent e35a602b
......@@ -43,7 +43,8 @@
namespace blink {
static const int kMaxRecursionDepth = 3;
static const double kProgressNotificationIntervalMS = 50;
static const base::TimeDelta kProgressNotificationInterval =
base::TimeDelta::FromMilliseconds(50);
static constexpr uint64_t kMaxTruncateLength =
std::numeric_limits<uint64_t>::max();
......@@ -57,7 +58,6 @@ FileWriter::FileWriter(ExecutionContext* context)
truncate_length_(kMaxTruncateLength),
num_aborts_(0),
recursion_depth_(0),
last_progress_notification_time_ms_(0),
request_id_(0) {}
FileWriter::~FileWriter() {
......@@ -182,11 +182,11 @@ void FileWriter::DidWriteImpl(int64_t bytes, bool complete) {
uint64_t num_aborts = num_aborts_;
// We could get an abort in the handler for this event. If we do, it's
// already handled the cleanup and signalCompletion call.
double now = CurrentTimeMS();
if (complete || !last_progress_notification_time_ms_ ||
(now - last_progress_notification_time_ms_ >
kProgressNotificationIntervalMS)) {
last_progress_notification_time_ms_ = now;
base::TimeTicks now = base::TimeTicks::Now();
if (complete || !last_progress_notification_time_.is_null() ||
(now - last_progress_notification_time_ >
kProgressNotificationInterval)) {
last_progress_notification_time_ = now;
FireEvent(event_type_names::kProgress);
}
......
......@@ -127,7 +127,7 @@ class FileWriter final : public EventTargetWithInlineData,
uint64_t truncate_length_;
uint64_t num_aborts_;
uint8_t recursion_depth_;
double last_progress_notification_time_ms_;
base::TimeTicks last_progress_notification_time_;
Member<Blob> blob_being_written_;
int request_id_;
};
......
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