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..610d300022c54828abce773247320d286ad7d82f |
| --- /dev/null |
| +++ b/components/sync_sessions/task_tracker.h |
| @@ -0,0 +1,70 @@ |
| +// 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 new |
| +// navigation of a tab, |
| +// UpdateTask(int current_nav_index, |
| +// ui::PageTransition current_nav_transition, |
| +// 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.
|
| +// needs to be called to update the objects. |
| +class TabTasks { |
| + public: |
| + explicit TabTasks(base::Clock* clock); |
| + virtual ~TabTasks(); |
| + |
| + // Returns task id as a vector of int64_t for |nav_index|-th navigation of the |
| + // tab. |
| + std::vector<int64_t> GetTaskIdAtNavIndex(int nav_index) const; |
| + |
| + int GetNavigationsCount() const { return ids_.size(); } |
| + |
| + // Updates the current task of the tab, given current navigation index of the |
| + // tab as |current_nav_index|, and its transition |current_nav_transition|. |
| + void UpdateTask(int current_nav_index, |
| + 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
|
| + |
| + private: |
| + base::Clock* clock_; // not owned |
| + 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.
|
| + 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.
|
| +}; |
| + |
| +// 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 |
|
Nicolas Zea
2017/03/27 20:43:53
nit: newline above
shenchao
2017/04/06 00:54:55
Done.
|
| + // 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_; |
| +}; |
| + |
| +} // namespace sync_sessions |
| + |
| +#endif // COMPONENTS_SYNC_SESSIONS_TASK_TRACKER_H_ |