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, |
| 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 // Returns MetaTable, so this sync can store ModelTypeState in MetaTable. |
| 53 // Check if GetMetaTable().GetVersionNumber() is greater than 0 to make sure |
| 54 // MetaTable is initialed. |
| 55 virtual sql::MetaTable& GetMetaTable() = 0; |
| 56 |
| 57 // Called by the derived classes on initialization to make sure the tables |
| 58 // and indices are properly set up. Must be called before anything else. |
| 59 bool InitSyncTable(); |
| 60 |
| 61 private: |
| 62 // Read all sync_pb::EntityMetadata for typed URL and fill |
| 63 // |metadata_records| with it. |
| 64 bool GetAllSyncEntityMetadata(syncer::EntityMetadataMap* metadata_records); |
| 65 |
| 66 // Read sync_pb::ModelTypeState for typed URL and fill |state| with it. |
| 67 bool GetModelTypeState(sync_pb::ModelTypeState* state); |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(TypedURLSyncMetadataDatabase); |
| 70 }; |
| 71 |
| 72 } // namespace history |
| 73 |
| 74 #endif // COMPONENTS_HISTORY_CORE_BROWSER_TYPED_URL_SYNC_METADATA_DATABASE_H_ |
OLD | NEW |