File: send_tab_to_self_entry.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (106 lines) | stat: -rw-r--r-- 3,716 bytes parent folder | download | duplicates (11)
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
// Copyright 2018 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_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_ENTRY_H_
#define COMPONENTS_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_ENTRY_H_

#include <string>

#include "base/time/time.h"
#include "url/gurl.h"

namespace sync_pb {
class SendTabToSelfSpecifics;
}

namespace send_tab_to_self {

constexpr base::TimeDelta kExpiryTime = base::Days(10);

class SendTabToSelfLocal;

// A tab that is being shared. The URL is a unique identifier for an entry, as
// such it should not be empty and is the only thing considered when comparing
// entries.
// The java version of this class: SendTabToSelfEntry.java
class SendTabToSelfEntry {
 public:
  // Creates a SendTabToSelf entry. |url| and |title| are the main fields of the
  // entry.
  // |now| is used to fill the |creation_time_us_| and all the update timestamp
  // fields.
  SendTabToSelfEntry(const std::string& guid,
                     const GURL& url,
                     const std::string& title,
                     base::Time shared_time,
                     const std::string& device_name,
                     const std::string& target_device_sync_cache_guid);

  SendTabToSelfEntry(const SendTabToSelfEntry&);
  SendTabToSelfEntry& operator=(const SendTabToSelfEntry&) = delete;

  ~SendTabToSelfEntry();

  // The unique random id for the entry.
  const std::string& GetGUID() const;
  // The URL of the page the user would like to send to themselves.
  const GURL& GetURL() const;
  // The title of the entry. Might be empty.
  const std::string& GetTitle() const;
  // The time that the tab was shared.
  base::Time GetSharedTime() const;
  // The name of the device that originated the sent tab.
  const std::string& GetDeviceName() const;
  // The cache guid of of the device that this tab is shared with.
  const std::string& GetTargetDeviceSyncCacheGuid() const;
  // The opened state of the entry.
  bool IsOpened() const;
  // Sets the opened state of the entry to true.
  void MarkOpened();

  // The state of this entry's notification: if it has been |dismissed|.
  void SetNotificationDismissed(bool notification_dismissed);
  bool GetNotificationDismissed() const;

  // Returns a protobuf encoding the content of this SendTabToSelfEntry for
  // local storage.
  SendTabToSelfLocal AsLocalProto() const;

  // Creates a SendTabToSelfEntry from the protobuf format.
  // If creation time is not set, it will be set to |now|.
  static std::unique_ptr<SendTabToSelfEntry> FromProto(
      const sync_pb::SendTabToSelfSpecifics& pb_entry,
      base::Time now);

  // Creates a SendTabToSelfEntry from the protobuf format.
  // If creation time is not set, it will be set to |now|.
  static std::unique_ptr<SendTabToSelfEntry> FromLocalProto(
      const SendTabToSelfLocal& pb_entry,
      base::Time now);

  // Returns if the Entry has expired based on the |current_time|.
  bool IsExpired(base::Time current_time) const;

  // Creates a SendTabToSelfEntry consisting of only the required fields.
  // This entry will have an expired SharedTime and therefor this function
  // should only be used for testing.
  static std::unique_ptr<SendTabToSelfEntry> FromRequiredFields(
      const std::string& guid,
      const GURL& url,
      const std::string& target_device_sync_cache_guid);

 private:
  std::string guid_;
  GURL url_;
  std::string title_;
  std::string device_name_;
  std::string target_device_sync_cache_guid_;
  base::Time shared_time_;
  bool notification_dismissed_;
  bool opened_;
};

}  // namespace send_tab_to_self

#endif  // COMPONENTS_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_ENTRY_H_