OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ | 5 #ifndef COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ |
6 #define COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ | 6 #define COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 11 matching lines...) Expand all Loading... |
22 namespace sync_sessions { | 22 namespace sync_sessions { |
23 | 23 |
24 // Class to generate and manage task ids for navigations of a tab. For each | 24 // Class to generate and manage task ids for navigations of a tab. For each |
25 // current navigation of a tab, UpdateWithNavigation(int navigation_index, | 25 // current navigation of a tab, UpdateWithNavigation(int navigation_index, |
26 // ui::PageTransition transition) | 26 // ui::PageTransition transition) |
27 // needs to be called to update the object. | 27 // needs to be called to update the object. |
28 // | 28 // |
29 // TODO(shenchao): If the tab is restored, then the input navigation is not | 29 // TODO(shenchao): If the tab is restored, then the input navigation is not |
30 // necessarily the first navigation in this case. Need to fix it by initalizing | 30 // necessarily the first navigation in this case. Need to fix it by initalizing |
31 // the object with restored data. | 31 // the object with restored data. |
32 // TODO(shenchao): Support to track tasks cross tabs. | |
33 class TabTasks { | 32 class TabTasks { |
34 public: | 33 public: |
35 TabTasks(); | 34 TabTasks(); |
| 35 explicit TabTasks(const TabTasks* source_tab); |
36 virtual ~TabTasks(); | 36 virtual ~TabTasks(); |
37 | 37 |
38 // Gets top-down task id list of ancestors and itself for | 38 // Gets top-down task id list of ancestors and itself for |
39 // |navigation_index|-th navigation of the tab. | 39 // |navigation_index|-th navigation of the tab. |
40 std::vector<int64_t> GetTaskIdsForNavigation(int navigation_index) const; | 40 std::vector<int64_t> GetTaskIdsForNavigation(int navigation_index) const; |
41 | 41 |
42 int GetNavigationsCount() const; | 42 int GetNavigationsCount() const; |
43 | 43 |
44 // Updates the current task of the tab, given current navigation index of the | 44 // Updates the current task of the tab, given current navigation index of the |
45 // tab as |navigation_index|, and its |transition|. | 45 // tab as |navigation_index|, and its |transition|. |
(...skipping 11 matching lines...) Expand all Loading... |
57 FRIEND_TEST_ALL_PREFIXES(TaskTrackerTest, | 57 FRIEND_TEST_ALL_PREFIXES(TaskTrackerTest, |
58 CreateSubTaskFromExcludedAncestorTask); | 58 CreateSubTaskFromExcludedAncestorTask); |
59 | 59 |
60 struct TaskIdAndRoot { | 60 struct TaskIdAndRoot { |
61 // Root task index in task_ids_. Negative value means it's an invalid task | 61 // Root task index in task_ids_. Negative value means it's an invalid task |
62 // just for filling the task_ids_. | 62 // just for filling the task_ids_. |
63 int root_navigation_index; | 63 int root_navigation_index; |
64 int64_t task_id; | 64 int64_t task_id; |
65 }; | 65 }; |
66 | 66 |
| 67 // Get position within task_ids_ for the navigation at |navigation_index| of |
| 68 // the tab. |
| 69 int GetTaskIdPositionFromNavigationIndex(int navigation_index) const; |
| 70 |
| 71 // Get index of corresponding navigation of the tab at |task_id_position| |
| 72 // within task_ids_. |
| 73 int GetNavigationIndexFromTaskIdPosition(int task_id_position) const; |
| 74 |
67 // Task ids (with root task) for the navigations of the tab. The vector is | 75 // Task ids (with root task) for the navigations of the tab. The vector is |
68 // corresponding to the sequence of navigations of the tab. | 76 // corresponding to the sequence of navigations of the tab. |
69 std::vector<TaskIdAndRoot> task_ids_; | 77 std::vector<TaskIdAndRoot> task_ids_; |
70 // Index of current navigation in task_ids_. | 78 // Index of current navigation in task_ids_. |
71 int current_navigation_index_ = -1; | 79 int current_navigation_index_ = -1; |
72 // Number of oldest ancestors which have been excluded from being tracked in | 80 // Number of oldest ancestors which have been excluded from being tracked in |
73 // task_ids_; | 81 // task_ids_; |
74 int excluded_navigation_num_ = 0; | 82 int excluded_navigation_num_ = 0; |
| 83 // Number of tasks from source tab. |
| 84 int source_tab_task_num_ = 0; |
75 | 85 |
76 DISALLOW_COPY_AND_ASSIGN(TabTasks); | 86 DISALLOW_COPY_AND_ASSIGN(TabTasks); |
77 }; | 87 }; |
78 | 88 |
79 // Tracks tasks of current session. | 89 // Tracks tasks of current session. |
80 class TaskTracker { | 90 class TaskTracker { |
81 public: | 91 public: |
82 // Constructs with a clock to get timestamp as new task ids. | 92 // Constructs with a clock to get timestamp as new task ids. |
83 TaskTracker(); | 93 TaskTracker(); |
84 virtual ~TaskTracker(); | 94 virtual ~TaskTracker(); |
85 | 95 |
86 // Returns a TabTasks pointer, which is owned by this object, for the tab of | 96 // Returns a TabTasks pointer, which is owned by this object, for the tab of |
87 // given |tab_id|. | 97 // given |tab_id|. |
88 TabTasks* GetTabTasks(SessionID::id_type tab_id); | 98 TabTasks* GetTabTasks(SessionID::id_type tab_id); |
89 | 99 |
| 100 // Returns a TabTasks pointer, which is owned by this object, for the tab of |
| 101 // given |tab_id|, which is created from a source tab |source_tab_id|. |
| 102 TabTasks* GetTabTasks(SessionID::id_type tab_id, |
| 103 SessionID::id_type source_tab_id); |
| 104 |
90 // Cleans tracked task ids of navigations in the tab of |tab_id|. | 105 // Cleans tracked task ids of navigations in the tab of |tab_id|. |
91 void CleanTabTasks(SessionID::id_type tab_id); | 106 void CleanTabTasks(SessionID::id_type tab_id); |
92 | 107 |
93 private: | 108 private: |
94 FRIEND_TEST_ALL_PREFIXES(TaskTrackerTest, CleanTabTasks); | 109 FRIEND_TEST_ALL_PREFIXES(TaskTrackerTest, CleanTabTasks); |
95 std::map<SessionID::id_type, std::unique_ptr<TabTasks>> local_tab_tasks_map_; | 110 std::map<SessionID::id_type, std::unique_ptr<TabTasks>> local_tab_tasks_map_; |
96 | 111 |
97 DISALLOW_COPY_AND_ASSIGN(TaskTracker); | 112 DISALLOW_COPY_AND_ASSIGN(TaskTracker); |
98 }; | 113 }; |
99 | 114 |
100 } // namespace sync_sessions | 115 } // namespace sync_sessions |
101 | 116 |
102 #endif // COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ | 117 #endif // COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ |
OLD | NEW |