File: pending_write_store.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; 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,806; 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 (87 lines) | stat: -rw-r--r-- 3,076 bytes parent folder | download | duplicates (6)
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
// 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 ASH_QUICK_PAIR_REPOSITORY_FAST_PAIR_PENDING_WRITE_STORE_H_
#define ASH_QUICK_PAIR_REPOSITORY_FAST_PAIR_PENDING_WRITE_STORE_H_

#include <optional>
#include <string>
#include <vector>

#include "ash/quick_pair/proto/fastpair_data.pb.h"
#include "base/values.h"

class PrefRegistrySimple;

namespace ash {
namespace quick_pair {

// Saves the Fast Pair account key to disk for peripherals that have been
// paired with this device for the active user, using the bluetooth MAC address
// as a lookup key, and user prefs for storage.
class PendingWriteStore {
 public:
  PendingWriteStore();
  PendingWriteStore(const PendingWriteStore&) = delete;
  PendingWriteStore& operator=(const PendingWriteStore&) = delete;
  ~PendingWriteStore();

  // Registers preferences used by this class in the provided |registry|.
  static void RegisterProfilePrefs(PrefRegistrySimple* registry);

  struct PendingWrite {
    PendingWrite(const std::string& mac_address,
                 const nearby::fastpair::FastPairInfo fast_pair_info);
    PendingWrite(PendingWrite&& pending_write);
    ~PendingWrite();

    const std::string mac_address;
    const nearby::fastpair::FastPairInfo fast_pair_info;
  };

  struct PendingDelete {
    PendingDelete(const std::string& mac_address,
                  const std::string& hex_account_key);
    ~PendingDelete();

    const std::string mac_address;
    const std::string hex_account_key;
  };

  // Saves details about a pending request to add a new paired device to
  // Footprints.
  void WritePairedDevice(const std::string& mac_address,
                         const nearby::fastpair::FastPairInfo fast_pair_info);

  // Gets a list of all devices which have been paired but not yet written to
  // the server.
  std::vector<PendingWrite> GetPendingWrites();

  // To be called after a paired device is saved to Footprints, this removes
  // pending device from storage.
  void OnPairedDeviceSaved(const std::string& mac_address);

  // Saves required details about a pending delete request to disk.
  void DeletePairedDevice(const std::string& mac_address,
                          const std::string& hex_account_key);

  // Gets a list of all devices which have been unpaired but not yet removed
  // from the server.
  std::vector<PendingWriteStore::PendingDelete> GetPendingDeletes();

  // To be called after a paired device is successfully deleted from Footprints,
  // this overloaded method removes the pending delete from storage by
  // |mac_address|.
  void OnPairedDeviceDeleted(const std::string& mac_address);

  // To be called after a paired device is successfully deleted from Footprints,
  // this overloaded method removes the pending delete from storage by
  // |account_key|.
  void OnPairedDeviceDeleted(const std::vector<uint8_t>& account_key);
};

}  // namespace quick_pair
}  // namespace ash

#endif  // ASH_QUICK_PAIR_REPOSITORY_FAST_PAIR_PENDING_WRITE_STORE_H_