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 #include "components/history/core/browser/typed_url_sync_metadata_database.h" | 5 #include "components/history/core/browser/typed_url_sync_metadata_database.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "sql/statement.h" | 9 #include "sql/statement.h" |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 if (GetModelTypeState(&model_type_state)) { | 41 if (GetModelTypeState(&model_type_state)) { |
42 metadata_batch->SetModelTypeState(model_type_state); | 42 metadata_batch->SetModelTypeState(model_type_state); |
43 } else { | 43 } else { |
44 return false; | 44 return false; |
45 } | 45 } |
46 | 46 |
47 return true; | 47 return true; |
48 } | 48 } |
49 | 49 |
50 bool TypedURLSyncMetadataDatabase::UpdateSyncMetadata( | 50 bool TypedURLSyncMetadataDatabase::UpdateSyncMetadata( |
| 51 syncer::ModelType model_type, |
51 const std::string& storage_key, | 52 const std::string& storage_key, |
52 const sync_pb::EntityMetadata& metadata) { | 53 const sync_pb::EntityMetadata& metadata) { |
| 54 DCHECK_EQ(model_type, syncer::TYPED_URLS) |
| 55 << "Only the TYPED_URLS model type is supported"; |
| 56 |
53 int64_t storage_key_int = 0; | 57 int64_t storage_key_int = 0; |
54 if (!base::StringToInt64(storage_key, &storage_key_int)) { | 58 if (!base::StringToInt64(storage_key, &storage_key_int)) { |
55 return false; | 59 return false; |
56 } | 60 } |
57 sql::Statement s(GetDB().GetUniqueStatement( | 61 sql::Statement s(GetDB().GetUniqueStatement( |
58 "INSERT OR REPLACE INTO typed_url_sync_metadata " | 62 "INSERT OR REPLACE INTO typed_url_sync_metadata " |
59 "(storage_key, value) VALUES(?, ?)")); | 63 "(storage_key, value) VALUES(?, ?)")); |
60 s.BindInt64(0, storage_key_int); | 64 s.BindInt64(0, storage_key_int); |
61 s.BindString(1, metadata.SerializeAsString()); | 65 s.BindString(1, metadata.SerializeAsString()); |
62 | 66 |
63 return s.Run(); | 67 return s.Run(); |
64 } | 68 } |
65 | 69 |
66 bool TypedURLSyncMetadataDatabase::ClearSyncMetadata( | 70 bool TypedURLSyncMetadataDatabase::ClearSyncMetadata( |
| 71 syncer::ModelType model_type, |
67 const std::string& storage_key) { | 72 const std::string& storage_key) { |
| 73 DCHECK_EQ(model_type, syncer::TYPED_URLS) |
| 74 << "Only the TYPED_URLS model type is supported"; |
| 75 |
68 int64_t storage_key_int = 0; | 76 int64_t storage_key_int = 0; |
69 if (!base::StringToInt64(storage_key, &storage_key_int)) { | 77 if (!base::StringToInt64(storage_key, &storage_key_int)) { |
70 return false; | 78 return false; |
71 } | 79 } |
72 sql::Statement s(GetDB().GetUniqueStatement( | 80 sql::Statement s(GetDB().GetUniqueStatement( |
73 "DELETE FROM typed_url_sync_metadata WHERE storage_key=?")); | 81 "DELETE FROM typed_url_sync_metadata WHERE storage_key=?")); |
74 s.BindInt64(0, storage_key_int); | 82 s.BindInt64(0, storage_key_int); |
75 | 83 |
76 return s.Run(); | 84 return s.Run(); |
77 } | 85 } |
78 | 86 |
79 bool TypedURLSyncMetadataDatabase::UpdateModelTypeState( | 87 bool TypedURLSyncMetadataDatabase::UpdateModelTypeState( |
| 88 syncer::ModelType model_type, |
80 const sync_pb::ModelTypeState& model_type_state) { | 89 const sync_pb::ModelTypeState& model_type_state) { |
| 90 DCHECK_EQ(model_type, syncer::TYPED_URLS) |
| 91 << "Only the TYPED_URLS model type is supported"; |
81 DCHECK_GT(GetMetaTable().GetVersionNumber(), 0); | 92 DCHECK_GT(GetMetaTable().GetVersionNumber(), 0); |
82 | 93 |
83 std::string serialized_state = model_type_state.SerializeAsString(); | 94 std::string serialized_state = model_type_state.SerializeAsString(); |
84 return GetMetaTable().SetValue(kTypedURLModelTypeStateKey, serialized_state); | 95 return GetMetaTable().SetValue(kTypedURLModelTypeStateKey, serialized_state); |
85 } | 96 } |
86 | 97 |
87 bool TypedURLSyncMetadataDatabase::ClearModelTypeState() { | 98 bool TypedURLSyncMetadataDatabase::ClearModelTypeState( |
| 99 syncer::ModelType model_type) { |
| 100 DCHECK_EQ(model_type, syncer::TYPED_URLS) |
| 101 << "Only the TYPED_URLS model type is supported"; |
88 DCHECK_GT(GetMetaTable().GetVersionNumber(), 0); | 102 DCHECK_GT(GetMetaTable().GetVersionNumber(), 0); |
89 return GetMetaTable().DeleteKey(kTypedURLModelTypeStateKey); | 103 return GetMetaTable().DeleteKey(kTypedURLModelTypeStateKey); |
90 } | 104 } |
91 | 105 |
92 bool TypedURLSyncMetadataDatabase::InitSyncTable() { | 106 bool TypedURLSyncMetadataDatabase::InitSyncTable() { |
93 if (!GetDB().DoesTableExist("typed_url_sync_metadata")) { | 107 if (!GetDB().DoesTableExist("typed_url_sync_metadata")) { |
94 if (!GetDB().Execute("CREATE TABLE typed_url_sync_metadata (" | 108 if (!GetDB().Execute("CREATE TABLE typed_url_sync_metadata (" |
95 "storage_key INTEGER PRIMARY KEY NOT NULL," | 109 "storage_key INTEGER PRIMARY KEY NOT NULL," |
96 "value BLOB)")) { | 110 "value BLOB)")) { |
97 NOTREACHED(); | 111 NOTREACHED(); |
(...skipping 29 matching lines...) Expand all Loading... |
127 DCHECK_GT(GetMetaTable().GetVersionNumber(), 0); | 141 DCHECK_GT(GetMetaTable().GetVersionNumber(), 0); |
128 std::string serialized_state; | 142 std::string serialized_state; |
129 if (!GetMetaTable().GetValue(kTypedURLModelTypeStateKey, &serialized_state)) { | 143 if (!GetMetaTable().GetValue(kTypedURLModelTypeStateKey, &serialized_state)) { |
130 return true; | 144 return true; |
131 } | 145 } |
132 | 146 |
133 return state->ParseFromString(serialized_state); | 147 return state->ParseFromString(serialized_state); |
134 } | 148 } |
135 | 149 |
136 } // namespace history | 150 } // namespace history |
OLD | NEW |