File: feedstore_util.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 (101 lines) | stat: -rw-r--r-- 4,089 bytes parent folder | download | duplicates (5)
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
// Copyright 2021 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_FEEDSTORE_UTIL_H_
#define COMPONENTS_FEED_CORE_V2_FEEDSTORE_UTIL_H_

#include <optional>
#include <string>
#include <string_view>

#include "base/containers/flat_set.h"
#include "base/time/time.h"
#include "components/feed/core/proto/v2/store.pb.h"
#include "components/feed/core/v2/public/stream_type.h"
#include "components/feed/core/v2/types.h"

namespace feedwire {
class ConsistencyToken;
}

namespace feedstore {
class Metadata;

const char kForYouStreamKey[] = "i";
const char kFollowStreamKey[] = "w";
constexpr std::string_view kSingleWebFeedStreamKeyPrefix = "c";
constexpr std::string_view kSingleWebFeedMenuStreamKeyPrefix = "m/";
constexpr std::string_view kSingleWebFeedOtherStreamKeyPrefix = "o/";

std::string StreamKey(const feed::StreamType& stream_type);
feed::StreamType StreamTypeFromKey(std::string_view key);

std::string_view StreamPrefix(feed::StreamKind stream_type);

///////////////////////////////////////////////////
// Functions that operate on feedstore proto types.

int64_t ToTimestampMillis(base::Time t);
base::Time FromTimestampMillis(int64_t millis);
int64_t ToTimestampNanos(base::Time t);
base::Time FromTimestampMicros(int64_t millis);
void SetLastAddedTime(base::Time t, feedstore::StreamData& data);
void SetLastServerResponseTime(Metadata& metadata,
                               const feed::StreamType& stream_type,
                               const base::Time& server_time);

base::Time GetLastAddedTime(const feedstore::StreamData& data);
base::Time GetSessionIdExpiryTime(const feedstore::Metadata& metadata);
base::Time GetStreamViewTime(const Metadata& metadata,
                             const feed::StreamType& stream_type);

bool IsKnownStale(const Metadata& metadata,
                  const feed::StreamType& stream_type);
base::Time GetLastFetchTime(const Metadata& metadata,
                            const feed::StreamType& stream_type);
void SetLastFetchTime(Metadata& metadata,
                      const feed::StreamType& stream_type,
                      const base::Time& fetch_time);
feedstore::Metadata MakeMetadata(const std::string& gaia);
feedstore::DocView CreateDocView(uint64_t docid,
                                 base::Time timestamp = base::Time::Now());

// Mutations of Metadata. Metadata will need stored again after being changed,
// call `FeedStream::SetMetadata()`.
void SetSessionId(feedstore::Metadata& metadata,
                  std::string token,
                  base::Time expiry_time);
void SetContentLifetime(
    feedstore::Metadata& metadata,
    const feed::StreamType& stream_type,
    feedstore::Metadata::StreamMetadata::ContentLifetime content_lifetime);
void MaybeUpdateSessionId(feedstore::Metadata& metadata,
                          std::optional<std::string> token);
std::optional<Metadata> MaybeUpdateConsistencyToken(
    const feedstore::Metadata& metadata,
    const feedwire::ConsistencyToken& token);
feed::LocalActionId GetNextActionId(feedstore::Metadata& metadata);
const Metadata::StreamMetadata* FindMetadataForStream(
    const Metadata& metadata,
    const feed::StreamType& stream_type);
Metadata::StreamMetadata& MetadataForStream(
    Metadata& metadata,
    const feed::StreamType& stream_type);
std::optional<Metadata> SetStreamViewContentHashes(
    const Metadata& metadata,
    const feed::StreamType& stream_type,
    const feed::ContentHashSet& content_hashes);
feed::ContentHashSet GetContentIds(const StreamData& stream_data);
feed::ContentHashSet GetViewContentIds(const Metadata& metadata,
                                       const feed::StreamType& stream_type);
int32_t ContentHashFromPrefetchMetadata(
    const feedwire::PrefetchMetadata& prefetch_metadata);

base::flat_set<uint32_t> GetViewedContentHashes(
    const Metadata& metadata,
    const feed::StreamType& stream_type);

}  // namespace feedstore

#endif  // COMPONENTS_FEED_CORE_V2_FEEDSTORE_UTIL_H_