Chromium Code Reviews| Index: components/sync_sessions/task_tracker.h |
| diff --git a/components/sync_sessions/task_tracker.h b/components/sync_sessions/task_tracker.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..40f452118b438daa835c8d06234faed3703659b8 |
| --- /dev/null |
| +++ b/components/sync_sessions/task_tracker.h |
| @@ -0,0 +1,93 @@ |
| +// 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. |
| + |
| +#ifndef COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ |
| +#define COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ |
| + |
| +#include <stddef.h> |
| + |
| +#include <map> |
| +#include <memory> |
| +#include <vector> |
| + |
| +#include "base/time/clock.h" |
| +#include "base/time/default_clock.h" |
| +#include "base/time/time.h" |
| +#include "components/sessions/core/session_id.h" |
| +#include "components/sessions/core/session_types.h" |
| +#include "components/sync_sessions/synced_tab_delegate.h" |
| +#include "ui/base/page_transition_types.h" |
| + |
| +namespace sync_sessions { |
| + |
| +// Class to generate and manage task ids for navigations of a tab. For each |
| +// current navigation of a tab, UpdateWithNavigation(int navigation_index, |
| +// ui::PageTransition transition) |
| +// needs to be called to update the object. |
| +// |
| +// TODO(shenchao): If the tab is restored, then the input navigation is not |
| +// 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.
|
| +// the object with restored data. |
| +// TODO(shenchao): Support to track tasks cross tabs. |
| +class TabTasks { |
| + public: |
| + explicit TabTasks(base::Clock* clock); |
| + virtual ~TabTasks(); |
| + |
| + // Returns top-down task id list of ancestors and itself as a vector for |
| + // |navigation_index|-th navigation of the tab. |
| + 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.
|
| + int navigation_index) const; |
| + |
| + int GetNavigationsCount() const { return task_ids_.size(); } |
| + |
| + // Updates the current task of the tab, given current navigation index of the |
| + // tab as |navigation_index|, and its |transition|. |
| + // If the navigation is from going back/forward of the tab, we set its first |
| + // visit as current task; if the navigation is new, we create a subtask of the |
| + // previous navigation if it's linked from the previous one or a root task |
| + // otherwise. |
| + void UpdateWithNavigation(int64_t navigation_index, |
| + ui::PageTransition transition); |
| + |
| + private: |
| + struct TaskIdAndRoot { |
| + // Root task index in task_ids_. Negative value means it's an invalid task |
| + // just for filling the task_ids_. |
| + int root_navigation_index; |
| + int64_t task_id; |
| + }; |
| + |
| + base::Clock* clock_; |
| + // Task ids (with root task) for the navigations of the tab. The vector is |
| + // corresponding to the sequence of navigations of the tab. |
| + std::vector<TaskIdAndRoot> task_ids_; |
| + // Index of current navigation in task_ids_. |
| + int64_t current_navigation_index_ = -1; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TabTasks); |
| +}; |
| + |
| +// Tracks tasks of current session. |
| +class TaskTracker { |
| + public: |
| + // Constructs with a clock to get timestamp as new task ids. |
| + explicit TaskTracker(std::unique_ptr<base::Clock> clock = |
| + base::MakeUnique<base::DefaultClock>()); |
| + virtual ~TaskTracker(); |
| + |
| + // Returns a TabTasks pointer, which is owned by this object, for the tab of |
| + // given |tab_id|. |
| + TabTasks* GetTabTasks(SessionID::id_type tab_id); |
| + |
| + private: |
| + std::unique_ptr<base::Clock> clock_; |
| + std::map<SessionID::id_type, std::unique_ptr<TabTasks>> local_tab_tasks_map_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TaskTracker); |
| +}; |
| + |
| +} // namespace sync_sessions |
| + |
| +#endif // COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ |