Chromium Code Reviews| Index: ash/laser/laser_pointer_points.cc |
| diff --git a/ash/laser/laser_pointer_points.cc b/ash/laser/laser_pointer_points.cc |
| index 8f2176ed8dbdfe42a5a5d5d2e78c3425e5797c5b..122fe654c2815dfcd02037764a7b06707f316769 100644 |
| --- a/ash/laser/laser_pointer_points.cc |
| +++ b/ash/laser/laser_pointer_points.cc |
| @@ -15,10 +15,25 @@ LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration) |
| LaserPointerPoints::~LaserPointerPoints() {} |
| void LaserPointerPoints::AddPoint(const gfx::Point& point) { |
| + base::Time current_time = base::Time::Now(); |
| + // If the collection is empty, set the latest time to the time of the first |
| + // added point. |
| + if (IsEmpty()) |
| + collection_latest_time_ = current_time; |
|
jdufault
2016/09/23 23:59:19
We should always be updating collection_latest_tim
sammiequon
2016/09/26 19:30:38
Done.
|
| LaserPoint new_point; |
| new_point.location = point; |
| - new_point.creation_time = base::Time::Now(); |
| + new_point.creation_time = current_time; |
| points_.push_back(new_point); |
| + MoveForwardInTime(current_time); |
| +} |
| + |
| +void LaserPointerPoints::MoveForwardInTime() { |
| + collection_latest_time_ = base::Time::Now(); |
|
jdufault
2016/09/23 23:59:19
Call MoveFowardInTime(base::Time::Now())
sammiequon
2016/09/26 19:30:38
Done.
|
| + ClearOldPoints(); |
| +} |
| + |
| +void LaserPointerPoints::MoveForwardInTime(const base::Time& new_latest_time) { |
|
jdufault
2016/09/23 23:59:19
Rename one of the MoveForwardInTime methods so the
sammiequon
2016/09/26 19:30:38
Done.
|
| + collection_latest_time_ = new_latest_time; |
| ClearOldPoints(); |
| } |
| @@ -49,6 +64,14 @@ LaserPointerPoints::LaserPoint LaserPointerPoints::GetNewest() const { |
| return points_.back(); |
| } |
| +base::Time LaserPointerPoints::GetCollectionLatestTime() const { |
| + return collection_latest_time_; |
| +} |
| + |
| +base::Time LaserPointerPoints::GetCollectionEarliestTime() const { |
| + return collection_latest_time_ - life_duration_; |
| +} |
| + |
| bool LaserPointerPoints::IsEmpty() const { |
| return points_.empty(); |
| } |
| @@ -63,10 +86,12 @@ LaserPointerPoints::laser_points() { |
| } |
| void LaserPointerPoints::ClearOldPoints() { |
| - DCHECK(!IsEmpty()); |
| + if (IsEmpty()) |
|
jdufault
2016/09/23 23:59:19
Why do we need this if?
sammiequon
2016/09/26 19:30:38
Done.
|
| + return; |
| + |
| auto first_alive_point = |
| std::find_if(points_.begin(), points_.end(), [this](LaserPoint& p) { |
| - return GetNewest().creation_time - p.creation_time < life_duration_; |
| + return collection_latest_time_ - p.creation_time < life_duration_; |
| }); |
| points_.erase(points_.begin(), first_alive_point); |
| } |