1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_
#define COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include "base/time/time.h"
#include "components/sessions/core/serialized_navigation_entry.h"
#include "components/sessions/core/session_id.h"
#include "components/sessions/core/session_types.h"
#include "components/sync/protocol/session_specifics.pb.h"
#include "components/sync/protocol/sync_enums.pb.h"
#include "components/sync_device_info/device_info.h"
namespace sync_sessions {
// Construct a SerializedNavigationEntry for a particular index from a sync
// protocol buffer. Note that the sync protocol buffer doesn't contain all
// SerializedNavigationEntry fields. Also, the timestamp of the returned
// SerializedNavigationEntry is nulled out, as we assume that the protocol
// buffer is from a foreign session.
sessions::SerializedNavigationEntry SessionNavigationFromSyncData(
int index,
const sync_pb::TabNavigation& sync_data);
// Convert |navigation| into its sync protocol buffer equivalent. Note that the
// protocol buffer doesn't contain all SerializedNavigationEntry fields.
sync_pb::TabNavigation SessionNavigationToSyncData(
const sessions::SerializedNavigationEntry& navigation);
// Set all the fields of |*tab| object from the given sync data and timestamp.
// Uses SerializedNavigationEntry::FromSyncData() to fill |navigations|. Note
// that the sync protocol buffer doesn't contain all SerializedNavigationEntry
// fields. |tab| must not be null.
void SetSessionTabFromSyncData(const sync_pb::SessionTab& sync_data,
base::Time timestamp,
sessions::SessionTab* tab);
// Convert |tab| into its sync protocol buffer equivalent. Uses
// SerializedNavigationEntry::ToSyncData to convert |navigations|. Note that the
// protocol buffer doesn't contain all SerializedNavigationEntry fields, and
// that the returned protocol buffer doesn't have any favicon data.
// |browser_type| needs to be provided separately because its (in local terms) a
// property of the window.
sync_pb::SessionTab SessionTabToSyncData(
const sessions::SessionTab& tab,
std::optional<sync_pb::SyncEnums::BrowserType> browser_type);
// A Sync wrapper for a SessionWindow.
struct SyncedSessionWindow {
SyncedSessionWindow();
SyncedSessionWindow(const SyncedSessionWindow&) = delete;
SyncedSessionWindow& operator=(const SyncedSessionWindow&) = delete;
~SyncedSessionWindow();
// Convert this object into its sync protocol buffer equivalent.
sync_pb::SessionWindow ToSessionWindowProto() const;
// Type of the window. See session_specifics.proto.
sync_pb::SyncEnums::BrowserType window_type;
// The SessionWindow this object wraps.
sessions::SessionWindow wrapped_window;
};
// Defines a synced session for use by session sync. A synced session is a
// list of windows along with a unique session identifer (tag) and meta-data
// about the device being synced.
// TODO(crbug.com/40879579): Change struct to class to follow style guides.
struct SyncedSession {
public:
SyncedSession();
SyncedSession(const SyncedSession&) = delete;
SyncedSession& operator=(const SyncedSession&) = delete;
~SyncedSession();
void SetSessionTag(const std::string& session_tag);
const std::string& GetSessionTag() const;
void SetSessionName(const std::string& session_name);
const std::string& GetSessionName() const;
// The timestamp when this session was started, i.e. when the user signed in
// or turned on the sessions data type. Only populated for sessions started in
// M130 or later.
void SetStartTime(base::Time start_time);
std::optional<base::Time> GetStartTime() const;
void SetModifiedTime(const base::Time& modified_time);
const base::Time& GetModifiedTime() const;
// Map of windows that make up this session.
std::map<SessionID, std::unique_ptr<SyncedSessionWindow>> windows;
// Convert this object to its protocol buffer equivalent. Shallow conversion,
// does not create SessionTab protobufs.
sync_pb::SessionHeader ToSessionHeaderProto() const;
void SetDeviceTypeAndFormFactor(
const sync_pb::SyncEnums::DeviceType& local_device_type,
const syncer::DeviceInfo::FormFactor& local_device_form_factor);
syncer::DeviceInfo::FormFactor GetDeviceFormFactor() const;
private:
// Unique tag for each session.
std::string session_tag_;
// User-visible name
std::string session_name_;
// The timestamp when this session was started, i.e. when the user signed in
// or turned on the sessions data type. Only populated for sessions started in
// M130 or later.
std::optional<base::Time> start_time_;
// Last time this session was modified remotely. This is the max of the header
// and all children tab mtimes.
base::Time modified_time_;
// Type of device this session is from.
// It's used only to populate deprecated device_type by
// ToSessionHeaderProto().
sync_pb::SyncEnums::DeviceType device_type;
// Form Factor of device this session is from.
syncer::DeviceInfo::FormFactor device_form_factor =
syncer::DeviceInfo::FormFactor::kUnknown;
};
} // namespace sync_sessions
#endif // COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_H_
|