synced_session.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright 2012 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. #ifndef COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_
  5. #define COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_
  6. #include <map>
  7. #include <memory>
  8. #include <set>
  9. #include <string>
  10. #include "base/time/time.h"
  11. #include "components/sessions/core/serialized_navigation_entry.h"
  12. #include "components/sessions/core/session_id.h"
  13. #include "components/sessions/core/session_types.h"
  14. #include "components/sync/protocol/session_specifics.pb.h"
  15. #include "components/sync/protocol/sync_enums.pb.h"
  16. #include "third_party/abseil-cpp/absl/types/optional.h"
  17. namespace sync_sessions {
  18. // Construct a SerializedNavigationEntry for a particular index from a sync
  19. // protocol buffer. Note that the sync protocol buffer doesn't contain all
  20. // SerializedNavigationEntry fields. Also, the timestamp of the returned
  21. // SerializedNavigationEntry is nulled out, as we assume that the protocol
  22. // buffer is from a foreign session.
  23. sessions::SerializedNavigationEntry SessionNavigationFromSyncData(
  24. int index,
  25. const sync_pb::TabNavigation& sync_data);
  26. // Convert |navigation| into its sync protocol buffer equivalent. Note that the
  27. // protocol buffer doesn't contain all SerializedNavigationEntry fields.
  28. sync_pb::TabNavigation SessionNavigationToSyncData(
  29. const sessions::SerializedNavigationEntry& navigation);
  30. // Set all the fields of |*tab| object from the given sync data and timestamp.
  31. // Uses SerializedNavigationEntry::FromSyncData() to fill |navigations|. Note
  32. // that the sync protocol buffer doesn't contain all SerializedNavigationEntry
  33. // fields. |tab| must not be null.
  34. void SetSessionTabFromSyncData(const sync_pb::SessionTab& sync_data,
  35. base::Time timestamp,
  36. sessions::SessionTab* tab);
  37. // Convert |tab| into its sync protocol buffer equivalent. Uses
  38. // SerializedNavigationEntry::ToSyncData to convert |navigations|. Note that the
  39. // protocol buffer doesn't contain all SerializedNavigationEntry fields, and
  40. // that the returned protocol buffer doesn't have any favicon data.
  41. // |browser_type| needs to be provided separately because its (in local terms) a
  42. // property of the window.
  43. sync_pb::SessionTab SessionTabToSyncData(
  44. const sessions::SessionTab& tab,
  45. absl::optional<sync_pb::SyncEnums::BrowserType> browser_type);
  46. // A Sync wrapper for a SessionWindow.
  47. struct SyncedSessionWindow {
  48. SyncedSessionWindow();
  49. SyncedSessionWindow(const SyncedSessionWindow&) = delete;
  50. SyncedSessionWindow& operator=(const SyncedSessionWindow&) = delete;
  51. ~SyncedSessionWindow();
  52. // Convert this object into its sync protocol buffer equivalent.
  53. sync_pb::SessionWindow ToSessionWindowProto() const;
  54. // Type of the window. See session_specifics.proto.
  55. sync_pb::SyncEnums::BrowserType window_type;
  56. // The SessionWindow this object wraps.
  57. sessions::SessionWindow wrapped_window;
  58. };
  59. // Defines a synced session for use by session sync. A synced session is a
  60. // list of windows along with a unique session identifer (tag) and meta-data
  61. // about the device being synced.
  62. struct SyncedSession {
  63. SyncedSession();
  64. SyncedSession(const SyncedSession&) = delete;
  65. SyncedSession& operator=(const SyncedSession&) = delete;
  66. ~SyncedSession();
  67. // Unique tag for each session.
  68. std::string session_tag;
  69. // User-visible name
  70. std::string session_name;
  71. // Type of device this session is from.
  72. sync_pb::SyncEnums::DeviceType device_type;
  73. // Last time this session was modified remotely. This is the max of the header
  74. // and all children tab mtimes.
  75. base::Time modified_time;
  76. // Map of windows that make up this session.
  77. std::map<SessionID, std::unique_ptr<SyncedSessionWindow>> windows;
  78. // Convert this object to its protocol buffer equivalent. Shallow conversion,
  79. // does not create SessionTab protobufs.
  80. sync_pb::SessionHeader ToSessionHeaderProto() const;
  81. };
  82. } // namespace sync_sessions
  83. #endif // COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_