File: power_bookmark_sync_metadata_database.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 (83 lines) | stat: -rw-r--r-- 3,082 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
// Copyright 2022 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_POWER_BOOKMARKS_STORAGE_POWER_BOOKMARK_SYNC_METADATA_DATABASE_H_
#define COMPONENTS_POWER_BOOKMARKS_STORAGE_POWER_BOOKMARK_SYNC_METADATA_DATABASE_H_

#include <string>

#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "components/sync/base/data_type.h"
#include "components/sync/model/sync_metadata_store.h"
#include "sql/meta_table.h"

namespace sql {
class Database;
class MetaTable;
}  // namespace sql

namespace syncer {
class MetadataBatch;
}  // namespace syncer

namespace power_bookmarks {

class PowerBookmarkSyncMetadataDatabaseTest;

// A sync metadata database maintains two things: the entity metadata table and
// the datatype state, stored in the MetaTable. The entity metadata table
// contains metadata (sync states) for each entity. The datatype state is the
// overall state of the power bookmarks datatype.
class PowerBookmarkSyncMetadataDatabase : public syncer::SyncMetadataStore {
 public:
  // After construction, Init() must be called before doing anything else to
  // make sure the database is initialized.
  PowerBookmarkSyncMetadataDatabase(sql::Database* db,
                                    sql::MetaTable* meta_table);

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

  ~PowerBookmarkSyncMetadataDatabase() override;

  // Makes sure the tables and indices are properly set up. Must be called
  // before anything else.
  bool Init();

  // syncer::SyncMetadataStore implementation.
  bool UpdateEntityMetadata(syncer::DataType data_type,
                            const std::string& storage_key,
                            const sync_pb::EntityMetadata& metadata) override;
  bool ClearEntityMetadata(syncer::DataType data_type,
                           const std::string& storage_key) override;
  bool UpdateDataTypeState(
      syncer::DataType data_type,
      const sync_pb::DataTypeState& data_type_state) override;
  bool ClearDataTypeState(syncer::DataType data_type) override;

  // Creates a sync::MetadataBatch and fills it with entity metadata and
  // DataTypeState information.
  std::unique_ptr<syncer::MetadataBatch> GetAllSyncMetadata();

 private:
  friend class PowerBookmarkSyncMetadataDatabaseTest;

  // Reads all sync_pb::EntityMetadata and fills `metadata_batch` with it.
  // Returns whether the call succeeded.
  bool GetAllSyncEntityMetadata(syncer::MetadataBatch* metadata_batch);

  // Reads the stored DataTypeState and fills `metadata_batch` with it.
  // Returns whether the call succeeded.
  bool GetDataTypeState(syncer::MetadataBatch* metadata_batch) const;

  const raw_ptr<sql::Database> db_;
  const raw_ptr<sql::MetaTable> meta_table_;
};

}  // namespace power_bookmarks

#endif  // COMPONENTS_POWER_BOOKMARKS_STORAGE_POWER_BOOKMARK_SYNC_METADATA_DATABASE_H_