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 new | |
25 // navigation of a tab, | |
26 // UpdateTask(int current_nav_index, | |
27 // ui::PageTransition current_nav_transition, | |
28 // int64_t new_id) | |
Nicolas Zea
2017/03/27 20:43:52
new_id doesn't seem to be a param anymore?
shenchao
2017/04/06 00:54:56
Done.
| |
29 // needs to be called to update the objects. | |
30 class TabTasks { | |
31 public: | |
32 explicit TabTasks(base::Clock* clock); | |
33 virtual ~TabTasks(); | |
34 | |
35 // Returns task id as a vector of int64_t for |nav_index|-th navigation of the | |
36 // tab. | |
37 std::vector<int64_t> GetTaskIdAtNavIndex(int nav_index) const; | |
38 | |
39 int GetNavigationsCount() const { return ids_.size(); } | |
40 | |
41 // Updates the current task of the tab, given current navigation index of the | |
42 // tab as |current_nav_index|, and its transition |current_nav_transition|. | |
43 void UpdateTask(int current_nav_index, | |
44 ui::PageTransition current_nav_transition); | |
Nicolas Zea
2017/03/27 20:43:52
Would be good to also explain what happens when a
shenchao
2017/04/06 00:54:56
Actually the current_nav_transition param is not i
| |
45 | |
46 private: | |
47 base::Clock* clock_; // not owned | |
48 std::vector<int64_t> ids_; | |
Nicolas Zea
2017/03/27 20:43:53
ids_ is pretty ambiguous. Perhaps call this task_i
shenchao
2017/04/06 00:54:56
Done.
| |
49 int current_task_index_ = -1; | |
Nicolas Zea
2017/03/27 20:43:52
Add DISALLOW_COPY_AND_ASSIGN macro (here and below
shenchao
2017/04/06 00:54:56
Done.
| |
50 }; | |
51 | |
52 // Tracks tasks of current session. | |
53 class TaskTracker { | |
54 public: | |
55 // Constructs with a clock to get timestamp as new task ids. | |
56 explicit TaskTracker(std::unique_ptr<base::Clock> clock = | |
57 base::MakeUnique<base::DefaultClock>()); | |
58 virtual ~TaskTracker(); | |
59 // Returns a TabTasks pointer, which is owned by this object, for the tab of | |
Nicolas Zea
2017/03/27 20:43:53
nit: newline above
shenchao
2017/04/06 00:54:55
Done.
| |
60 // given |tab_id|. | |
61 TabTasks* GetTabTasks(SessionID::id_type tab_id); | |
62 | |
63 private: | |
64 std::unique_ptr<base::Clock> clock_; | |
65 std::map<SessionID::id_type, std::unique_ptr<TabTasks>> local_tab_tasks_map_; | |
66 }; | |
67 | |
68 } // namespace sync_sessions | |
69 | |
70 #endif // COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ | |
OLD | NEW |