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