// 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.
//
// Sync protocol datatype extension for sessions.

// If you change or add any fields in this file, update proto_visitors.h and
// potentially proto_enum_conversions.{h, cc}.

syntax = "proto2";

package sync_pb;

import "components/sync/protocol/sync_enums.proto";
import "components/sync/protocol/tab_navigation.proto";

option java_multiple_files = true;
option java_package = "org.chromium.components.sync.protocol";
option optimize_for = LITE_RUNTIME;

message SessionSpecifics {
  // Unique id for the client. Since M89, this is sync's cache GUID (client
  // ID). Pre-existing sessions using a legacy ID were migrated in M143.
  optional string session_tag = 1;

  oneof content {
    SessionHeader header = 2;
    SessionTab tab = 3;
    // TODO(crbug.com/488242420): Fully remove tab_screenshot once all
    // server-side references are gone.
    SessionTabScreenshot tab_screenshot = 5 [deprecated = true];
  }

  // The local tab id used by sync. The same id can be used by at most two nodes
  // per client: A tab node and its corresponding screenshot node.
  optional int32 tab_node_id = 4 [default = -1];
}

// Properties of session sync objects.
message SessionHeader {
  // The timestamp when this session was started, i.e. when the user signed in
  // or turned on the sessions data type. Introduced in M130, and not populated
  // for sessions created/started before that milestone.
  optional int64 session_start_time_unix_epoch_millis = 6;
  // Each session is composed of windows.
  repeated SessionWindow window = 2;
  // A non-unique but human-readable name to describe this client.
  optional string client_name = 3;
  // The form factor of device.
  optional SyncEnums.DeviceFormFactor device_form_factor = 5;

  // The type of device.
  // Mandatory until M115. Replaced by device_form_factor afterwards, but still
  // populated for backward compatibility.
  optional SyncEnums.DeviceType device_type = 4 [deprecated = true];
}

message SessionWindow {
  // Unique (to the owner) id for this window.
  optional int32 window_id = 1;
  // Index of the selected tab in tabs; -1 if no tab is selected.
  optional int32 selected_tab_index = 2 [default = -1];
  // Type of the window.
  optional SyncEnums.BrowserType browser_type = 3 [default = TYPE_TABBED];
  // The tabs that compose a window (correspond to tab id's).
  repeated int32 tab = 4;
}

message SessionTab {
  // Unique (to the owner) id for this tab.
  optional int32 tab_id = 1 [default = -1];
  // The unique id for the window this tab belongs to.
  optional int32 window_id = 2;
  // Visual index of the tab within its window. There may be gaps in these
  // values.
  optional int32 tab_visual_index = 3 [default = -1];
  // Identifies the index of the current navigation in navigations. For
  // example, if this is 2 it means the current navigation is navigations[2].
  optional int32 current_navigation_index = 4 [default = -1];
  // True if the tab is pinned.
  optional bool pinned = 5 [default = false];
  // If non-empty, this tab is an app tab and this is the id of the extension.
  optional string extension_app_id = 6;
  // Tabs are navigated, and the navigation data is here.
  repeated TabNavigation navigation = 7;

  optional SyncEnums.BrowserType browser_type = 13;

  // Timestamp for when this tab was last activated.
  // Corresponds to WebContents::GetLastActiveTime().
  optional int64 last_active_time_unix_epoch_millis = 14;

  // The favicon for the current url the tab is displaying. Either empty
  // or a valid PNG encoded favicon.
  optional bytes favicon = 8 [deprecated = true];
  // The type of favicon. For now only normal web favicons are supported.
  enum FaviconType {
    TYPE_WEB_FAVICON = 1;
  }
  optional FaviconType favicon_type = 9 [deprecated = true];
  // The url of the actual favicon (as opposed to the page using the favicon).
  optional string favicon_source = 11 [deprecated = true];
  // Ids of the currently assigned variations which should be sent to sync.
  repeated uint64 variation_id = 12 [deprecated = true];
}

message SessionTabScreenshot {
  // The jpeg-compressed screenshot data.
  optional bytes screenshot_data = 1;
  // The URL of the page captured in the screenshot. This is meant to verify
  // that the screenshot (still) matches the tab's current URL. Such
  // verification is necessary since a tab and its screenshot are not always
  // updated at the same time, and so it's possible that a screenshot is stale.
  optional string url = 2;
  // The time when the screenshot was taken.
  optional int64 timestamp_unix_epoch_millis = 3;
}
