Index: components/sync_sessions/task_tracker.cc |
diff --git a/components/sync_sessions/task_tracker.cc b/components/sync_sessions/task_tracker.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ddaa9c43babf960969d19f6ef868d5322151c51c |
--- /dev/null |
+++ b/components/sync_sessions/task_tracker.cc |
@@ -0,0 +1,70 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/sync_sessions/task_tracker.h" |
+ |
+namespace sync_sessions { |
+ |
+TabTasks::TabTasks() {} |
+ |
+TabTasks::~TabTasks() {} |
+ |
+std::vector<int64_t> TabTasks::GetTaskIdAtNav(int nav_index) const { |
+ CHECK(nav_index >= 0 && (unsigned)nav_index < ids_.size()); |
+ std::vector<int64_t> id; |
+ for (int i = 0; i <= nav_index; i++) { |
+ if (ids_[i] != -1) |
+ id.push_back(ids_[i]); |
+ } |
+ return id; |
+} |
+ |
+void TabTasks::UpdateTask(int current_nav_index, |
+ ui::PageTransition current_nav_transition, |
+ int64_t new_id) { |
+ // Assuming the first navigation is chrome://newtab |
Patrick Noland
2017/03/24 20:51:57
Is that always true? What about links opened in a
shenchao
2017/03/25 23:53:13
Not unless the if-condition is true. Added comment
|
+ if (current_nav_index == 1 && current_task_index_ == -1) { |
+ ids_.push_back(-1); |
+ current_task_index_ = 0; |
+ } |
+ |
+ // Trigger by some notifications on the current page, do nothing. |
+ if (current_nav_index < 0 || current_nav_index == current_task_index_) { |
+ DVLOG(1) << "Doing nothing"; |
+ return; |
+ } |
+ |
+ // Back to some previous navigation or forward to some future navigation after |
+ // going back. |
+ if (current_nav_index < current_task_index_ || |
+ (current_nav_index > current_task_index_ && |
+ current_nav_transition & ui::PAGE_TRANSITION_FORWARD_BACK && |
+ (unsigned)current_nav_index < ids_.size())) { |
+ DVLOG(1) << "Just updating task depth."; |
+ current_task_index_ = current_nav_index; |
+ return; |
+ } |
+ |
+ // a new navigation |
+ if (current_nav_index == current_task_index_ + 1) { |
Patrick Noland
2017/03/24 20:51:57
This doesn't seem to account for transitions that
shenchao
2017/03/25 23:53:13
current_nav_index == current_task_index_ + 1 && cu
|
+ DVLOG(1) << "Creating a task."; |
+ current_task_index_ = current_nav_index; |
+ ids_.erase(ids_.begin() + current_nav_index, ids_.end()); |
+ ids_.push_back(new_id); |
+ return; |
+ } |
+} |
+ |
+TaskTracker::TaskTracker() {} |
+ |
+TaskTracker::~TaskTracker() {} |
+ |
+TabTasks* TaskTracker::GetTabTasks(SessionID::id_type tab_id) { |
+ if (local_tab_tasks_map_.find(tab_id) == local_tab_tasks_map_.end()) { |
+ local_tab_tasks_map_[tab_id] = base::MakeUnique<TabTasks>(); |
+ } |
+ return local_tab_tasks_map_[tab_id].get(); |
+} |
+ |
+} // namespace sync_sessions |