File: protocol_translator.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (111 lines) | stat: -rw-r--r-- 3,678 bytes parent folder | download | duplicates (4)
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
// Copyright 2020 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_FEED_CORE_V2_PROTOCOL_TRANSLATOR_H_
#define COMPONENTS_FEED_CORE_V2_PROTOCOL_TRANSLATOR_H_

#include <memory>
#include <optional>
#include <vector>

#include "base/time/time.h"
#include "components/feed/core/proto/v2/packing.pb.h"
#include "components/feed/core/proto/v2/store.pb.h"
#include "components/feed/core/proto/v2/wire/data_operation.pb.h"
#include "components/feed/core/proto/v2/wire/response.pb.h"
#include "components/feed/core/v2/public/types.h"
#include "components/feed/core/v2/scheduling.h"
#include "components/feed/core/v2/types.h"

namespace feed {

// Data for updating StreamModel. This can be sourced from the network or
// persistent storage.
struct StreamModelUpdateRequest {
 public:
  enum class Source {
    kNetworkUpdate,
    kInitialLoadFromStore,
    kNetworkLoadMore,
  };

  StreamModelUpdateRequest();
  ~StreamModelUpdateRequest();
  StreamModelUpdateRequest(const StreamModelUpdateRequest&);
  StreamModelUpdateRequest& operator=(const StreamModelUpdateRequest&);

  // Whether this data originates is from the initial load of content from
  // the local data store.
  Source source = Source::kNetworkUpdate;

  // The set of Contents marked UPDATE_OR_APPEND in the response, in the order
  // in which they were received.
  std::vector<feedstore::Content> content;

  // Contains the root ContentId, tokens, a timestamp for when the most recent
  // content was added, and a list of ContentIds for clusters in the response.
  feedstore::StreamData stream_data;

  // The set of StreamSharedStates marked UPDATE_OR_APPEND in the order in which
  // they were received.
  std::vector<feedstore::StreamSharedState> shared_states;

  std::vector<feedstore::StreamStructure> stream_structures;

  int32_t max_structure_sequence_number = 0;
};

struct RefreshResponseData {
  RefreshResponseData();
  ~RefreshResponseData();
  RefreshResponseData(RefreshResponseData&&);
  RefreshResponseData& operator=(RefreshResponseData&&);

  std::unique_ptr<StreamModelUpdateRequest> model_update_request;

  // Server-defined request schedule, if provided.
  std::optional<RequestSchedule> request_schedule;

  // Server-defined content lifetime, if provided.
  std::optional<feedstore::Metadata::StreamMetadata::ContentLifetime>
      content_lifetime;

  // Server-defined session id token, if provided.
  std::optional<std::string> session_id;

  // List of experiments from the server, if provided.
  std::optional<Experiments> experiments;

  // Serialized server-provided feed launch CUI metadata.
  std::optional<std::string> feed_launch_cui_metadata;

  // Server-reported network timestamps. They can be compared to
  // each other but not to client timestamps.
  base::Time server_request_received_timestamp;
  base::Time server_response_sent_timestamp;

  // The client-side timestamp that the response is fetched.
  base::Time last_fetch_timestamp;

  bool web_and_app_activity_enabled = false;
  bool discover_personalization_enabled = false;
};

std::optional<feedstore::DataOperation> TranslateDataOperation(
    base::Time current_time,
    feedwire::DataOperation wire_operation);

RefreshResponseData TranslateWireResponse(
    feedwire::Response response,
    StreamModelUpdateRequest::Source source,
    const AccountInfo& account_info,
    base::Time current_time);

std::vector<feedstore::DataOperation> TranslateDismissData(
    base::Time current_time,
    feedpacking::DismissData data);

}  // namespace feed

#endif  // COMPONENTS_FEED_CORE_V2_PROTOCOL_TRANSLATOR_H_