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 #ifndef COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ | |
| 6 #define COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <memory> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/time/clock.h" | |
| 15 #include "base/time/default_clock.h" | |
| 16 #include "base/time/time.h" | |
| 17 #include "components/sessions/core/session_id.h" | |
| 18 #include "components/sessions/core/session_types.h" | |
| 19 #include "components/sync_sessions/synced_tab_delegate.h" | |
| 20 #include "ui/base/page_transition_types.h" | |
| 21 | |
| 22 namespace sync_sessions { | |
| 23 | |
| 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, | |
| 26 // ui::PageTransition transition) | |
| 27 // needs to be called to update the object. | |
| 28 // | |
| 29 // TODO(shenchao): If the tab is restored, then the input navigation is not | |
| 30 // necessary the first navigation in this case. Need to fix it by initalizing | |
|
Nicolas Zea
2017/04/10 17:09:01
nit: necessary -> necessarily
shenchao
2017/04/11 18:53:45
Done.
| |
| 31 // the object with restored data. | |
| 32 // TODO(shenchao): Support to track tasks cross tabs. | |
| 33 class TabTasks { | |
| 34 public: | |
| 35 explicit TabTasks(base::Clock* clock); | |
| 36 virtual ~TabTasks(); | |
| 37 | |
| 38 // Returns top-down task id list of ancestors and itself as a vector for | |
| 39 // |navigation_index|-th navigation of the tab. | |
| 40 std::vector<int64_t> RootToSelfTaskIdsOfNavigationIndex( | |
|
Nicolas Zea
2017/04/10 17:09:00
This name is pretty tough to understand. How about
shenchao
2017/04/11 18:53:45
Done.
| |
| 41 int navigation_index) const; | |
| 42 | |
| 43 int GetNavigationsCount() const { return task_ids_.size(); } | |
| 44 | |
| 45 // Updates the current task of the tab, given current navigation index of the | |
| 46 // tab as |navigation_index|, and its |transition|. | |
| 47 // If the navigation is from going back/forward of the tab, we set its first | |
| 48 // visit as current task; if the navigation is new, we create a subtask of the | |
| 49 // previous navigation if it's linked from the previous one or a root task | |
| 50 // otherwise. | |
| 51 void UpdateWithNavigation(int64_t navigation_index, | |
| 52 ui::PageTransition transition); | |
| 53 | |
| 54 private: | |
| 55 struct TaskIdAndRoot { | |
| 56 // Root task index in task_ids_. Negative value means it's an invalid task | |
| 57 // just for filling the task_ids_. | |
| 58 int root_navigation_index; | |
| 59 int64_t task_id; | |
| 60 }; | |
| 61 | |
| 62 base::Clock* clock_; | |
| 63 // Task ids (with root task) for the navigations of the tab. The vector is | |
| 64 // corresponding to the sequence of navigations of the tab. | |
| 65 std::vector<TaskIdAndRoot> task_ids_; | |
| 66 // Index of current navigation in task_ids_. | |
| 67 int64_t current_navigation_index_ = -1; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(TabTasks); | |
| 70 }; | |
| 71 | |
| 72 // Tracks tasks of current session. | |
| 73 class TaskTracker { | |
| 74 public: | |
| 75 // Constructs with a clock to get timestamp as new task ids. | |
| 76 explicit TaskTracker(std::unique_ptr<base::Clock> clock = | |
| 77 base::MakeUnique<base::DefaultClock>()); | |
| 78 virtual ~TaskTracker(); | |
| 79 | |
| 80 // Returns a TabTasks pointer, which is owned by this object, for the tab of | |
| 81 // given |tab_id|. | |
| 82 TabTasks* GetTabTasks(SessionID::id_type tab_id); | |
| 83 | |
| 84 private: | |
| 85 std::unique_ptr<base::Clock> clock_; | |
| 86 std::map<SessionID::id_type, std::unique_ptr<TabTasks>> local_tab_tasks_map_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(TaskTracker); | |
| 89 }; | |
| 90 | |
| 91 } // namespace sync_sessions | |
| 92 | |
| 93 #endif // COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ | |
| OLD | NEW |