Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: components/sync_sessions/task_tracker.cc

Issue 2776633003: Add taskid for navigation, created in session sync (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 namespace sync_sessions {
8
9 TabTasks::TabTasks() {}
10
11 TabTasks::~TabTasks() {}
12
13 std::vector<int64_t> TabTasks::GetTaskIdAtNav(int nav_index) const {
14 CHECK(nav_index >= 0 && (unsigned)nav_index < ids_.size());
15 std::vector<int64_t> id;
16 for (int i = 0; i <= nav_index; i++) {
17 if (ids_[i] != -1)
18 id.push_back(ids_[i]);
19 }
20 return id;
21 }
22
23 void TabTasks::UpdateTask(int current_nav_index,
24 ui::PageTransition current_nav_transition,
25 int64_t new_id) {
26 // 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
27 if (current_nav_index == 1 && current_task_index_ == -1) {
28 ids_.push_back(-1);
29 current_task_index_ = 0;
30 }
31
32 // Trigger by some notifications on the current page, do nothing.
33 if (current_nav_index < 0 || current_nav_index == current_task_index_) {
34 DVLOG(1) << "Doing nothing";
35 return;
36 }
37
38 // Back to some previous navigation or forward to some future navigation after
39 // going back.
40 if (current_nav_index < current_task_index_ ||
41 (current_nav_index > current_task_index_ &&
42 current_nav_transition & ui::PAGE_TRANSITION_FORWARD_BACK &&
43 (unsigned)current_nav_index < ids_.size())) {
44 DVLOG(1) << "Just updating task depth.";
45 current_task_index_ = current_nav_index;
46 return;
47 }
48
49 // a new navigation
50 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
51 DVLOG(1) << "Creating a task.";
52 current_task_index_ = current_nav_index;
53 ids_.erase(ids_.begin() + current_nav_index, ids_.end());
54 ids_.push_back(new_id);
55 return;
56 }
57 }
58
59 TaskTracker::TaskTracker() {}
60
61 TaskTracker::~TaskTracker() {}
62
63 TabTasks* TaskTracker::GetTabTasks(SessionID::id_type tab_id) {
64 if (local_tab_tasks_map_.find(tab_id) == local_tab_tasks_map_.end()) {
65 local_tab_tasks_map_[tab_id] = base::MakeUnique<TabTasks>();
66 }
67 return local_tab_tasks_map_[tab_id].get();
68 }
69
70 } // namespace sync_sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698