Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/sync_sessions/task_tracker.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/numerics/safe_conversions.h" | |
| 10 | |
| 11 namespace sync_sessions { | |
| 12 | |
| 13 TabTasks::TabTasks(base::Clock* clock) : clock_(clock) {} | |
| 14 | |
| 15 TabTasks::~TabTasks() {} | |
| 16 | |
| 17 std::vector<int64_t> TabTasks::GetTaskIdAtNavIndex(int nav_index) const { | |
| 18 CHECK(base::checked_cast<size_t>(nav_index) < ids_.size()); | |
|
Nicolas Zea
2017/03/27 20:43:52
CHECK_LT
shenchao
2017/04/06 00:54:55
Done.
| |
| 19 std::vector<int64_t> id; | |
| 20 for (int i = 0; i <= nav_index; i++) { | |
| 21 if (ids_[i] != -1) | |
| 22 id.push_back(ids_[i]); | |
| 23 } | |
| 24 return id; | |
| 25 } | |
| 26 | |
| 27 void TabTasks::UpdateTask(int current_nav_index, | |
| 28 ui::PageTransition current_nav_transition) { | |
| 29 // We expect current_nav_index == 0 when the function is first called. | |
| 30 // However it's possible that current_nav_index == 1 when navigation at 0 is | |
| 31 // chrome://newtab, which is ignored by session sync. | |
| 32 if (current_nav_index == 1 && current_task_index_ == -1) { | |
|
Nicolas Zea
2017/03/27 20:43:52
This seems a bit brittle, as it assumes behavior o
shenchao
2017/04/06 00:54:55
Done.
| |
| 33 ids_.push_back(-1); | |
| 34 current_task_index_ = 0; | |
| 35 } | |
| 36 | |
| 37 // Triggered by some notifications on the current page, do nothing. | |
| 38 if (current_nav_index < 0 || current_nav_index == current_task_index_) { | |
| 39 DVLOG(1) << "Doing nothing"; | |
|
Nicolas Zea
2017/03/27 20:43:52
nit: for debugability, might be good to also print
shenchao
2017/04/06 00:54:55
Done.
| |
| 40 return; | |
| 41 } | |
| 42 | |
| 43 // Back to some previous navigation or forward to some future navigation after | |
| 44 // going back. | |
| 45 if (current_nav_index < current_task_index_ || | |
| 46 (current_nav_index > current_task_index_ && | |
| 47 current_nav_transition & ui::PAGE_TRANSITION_FORWARD_BACK && | |
| 48 base::checked_cast<size_t>(current_nav_index) < ids_.size())) { | |
| 49 DVLOG(1) << "Just updating task depth."; | |
| 50 current_task_index_ = current_nav_index; | |
| 51 return; | |
| 52 } | |
| 53 | |
| 54 // a new navigation | |
|
Nicolas Zea
2017/03/27 20:43:52
grammar nit: "A new navigation."
shenchao
2017/04/06 00:54:55
Done.
| |
| 55 if (current_nav_index == current_task_index_ + 1) { | |
|
Nicolas Zea
2017/03/27 20:43:52
This seems to create a new task regardless of tran
shenchao
2017/04/06 00:54:55
Done.
| |
| 56 DVLOG(1) << "Creating a task."; | |
| 57 current_task_index_ = current_nav_index; | |
| 58 ids_.erase(ids_.begin() + current_nav_index, ids_.end()); | |
| 59 ids_.push_back(clock_->Now().ToTimeT()); | |
|
Nicolas Zea
2017/03/27 20:43:52
I think the ids can't be based on their own clock.
shenchao
2017/04/06 00:54:55
We can't use global id so have to create our own t
| |
| 60 return; | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 TaskTracker::TaskTracker(std::unique_ptr<base::Clock> clock) | |
| 65 : clock_(std::move(clock)) {} | |
| 66 | |
| 67 TaskTracker::~TaskTracker() {} | |
| 68 | |
| 69 TabTasks* TaskTracker::GetTabTasks(SessionID::id_type tab_id) { | |
| 70 if (local_tab_tasks_map_.find(tab_id) == local_tab_tasks_map_.end()) { | |
| 71 local_tab_tasks_map_[tab_id] = base::MakeUnique<TabTasks>(clock_.get()); | |
| 72 } | |
| 73 return local_tab_tasks_map_[tab_id].get(); | |
| 74 } | |
| 75 | |
| 76 } // namespace sync_sessions | |
| OLD | NEW |