Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_METADATA_DATABASE_H_ | |
| 6 #define COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_METADATA_DATABASE_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "components/sync/base/model_type.h" | |
| 10 #include "components/sync/model/metadata_batch.h" | |
| 11 #include "sql/meta_table.h" | |
| 12 | |
| 13 namespace sql { | |
| 14 class Connection; | |
| 15 } | |
| 16 | |
| 17 namespace history { | |
| 18 | |
| 19 // A sync metadata database needs to maintain two tables: entity metadata table | |
| 20 // and datatype state table. Entity metadata table contains metadata(sync | |
| 21 // states) for each url. Datatype state table contains the state of typed url | |
| 22 // datatype. | |
| 23 class TypedURLSyncMetadataDatabase { | |
| 24 public: | |
| 25 // Must call InitVisitTable() before using to make sure the database is | |
| 26 // initialized. | |
| 27 TypedURLSyncMetadataDatabase(); | |
| 28 virtual ~TypedURLSyncMetadataDatabase(); | |
| 29 | |
| 30 // Read all the stored metadata for typed URL and fill |metadata_batch| | |
| 31 // with it. | |
| 32 bool GetAllSyncMetadata(syncer::MetadataBatch* metadata_batch); | |
| 33 | |
| 34 // Update the metadata row for typed URL, keyed by |storage_key|, to | |
| 35 // contain the contents of |metadata|. | |
| 36 bool UpdateSyncMetadata(const std::string& storage_key, | |
|
brettw
2017/03/20 17:27:06
I was expecting the types here would match the dat
Gang Wu
2017/03/20 21:34:48
Actually, I am think about make those functions as
| |
| 37 const sync_pb::EntityMetadata& metadata); | |
| 38 | |
| 39 // Remove the metadata row of typed URL keyed by |storage_key|. | |
| 40 bool ClearSyncMetadata(const std::string& storage_key); | |
| 41 | |
| 42 // Update the stored sync state for the typed URL. | |
| 43 bool UpdateModelTypeState(const sync_pb::ModelTypeState& model_type_state); | |
| 44 | |
| 45 // Clear the stored sync state for typed URL. | |
| 46 bool ClearModelTypeState(); | |
| 47 | |
| 48 protected: | |
| 49 // Returns the database for the functions in this interface. | |
| 50 virtual sql::Connection& GetDB() = 0; | |
| 51 | |
| 52 // Called by the derived classes on initialization to make sure the tables | |
| 53 // and indices are properly set up. Must be called before anything else. | |
| 54 bool InitSyncTable(); | |
| 55 | |
| 56 sql::MetaTable* GetMetaTable() { return &meta_table_; } | |
| 57 | |
| 58 private: | |
| 59 // Read all sync_pb::EntityMetadata for typed URL and fill | |
| 60 // |metadata_records| with it. | |
| 61 bool GetAllSyncEntityMetadata(syncer::EntityMetadataMap* metadata_records); | |
| 62 | |
| 63 // Read sync_pb::ModelTypeState for typed URL and fill |state| with it. | |
| 64 bool GetModelTypeState(sync_pb::ModelTypeState* state); | |
| 65 | |
| 66 // Own by this class, but initialed by HistoryDatabase. | |
| 67 // Check if meta_table_->GetVersionNumber() is greater than 0 to make sure | |
| 68 // meta_table_ is initialed. | |
| 69 sql::MetaTable meta_table_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(TypedURLSyncMetadataDatabase); | |
| 72 }; | |
| 73 | |
| 74 } // namespace history | |
| 75 | |
| 76 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_METADATA_DATABASE_H_ | |
| OLD | NEW |