Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: sync/syncable/directory_backing_store.cc

Issue 1866243002: Convert //sync from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "sync/syncable/directory_backing_store.h" 5 #include "sync/syncable/directory_backing_store.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 prev_length = length; 119 prev_length = length;
120 prev_index = *index; 120 prev_index = *index;
121 ++(*total_entry_copies); 121 ++(*total_entry_copies);
122 } 122 }
123 } 123 }
124 } 124 }
125 125
126 // The caller owns the returned EntryKernel*. Assumes the statement currently 126 // The caller owns the returned EntryKernel*. Assumes the statement currently
127 // points to a valid row in the metas table. Returns NULL to indicate that 127 // points to a valid row in the metas table. Returns NULL to indicate that
128 // it detected a corruption in the data on unpacking. 128 // it detected a corruption in the data on unpacking.
129 scoped_ptr<EntryKernel> UnpackEntry(sql::Statement* statement, 129 std::unique_ptr<EntryKernel> UnpackEntry(sql::Statement* statement,
130 int* total_specifics_copies) { 130 int* total_specifics_copies) {
131 scoped_ptr<EntryKernel> kernel(new EntryKernel()); 131 std::unique_ptr<EntryKernel> kernel(new EntryKernel());
132 DCHECK_EQ(statement->ColumnCount(), static_cast<int>(FIELD_COUNT)); 132 DCHECK_EQ(statement->ColumnCount(), static_cast<int>(FIELD_COUNT));
133 int i = 0; 133 int i = 0;
134 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { 134 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) {
135 kernel->put(static_cast<Int64Field>(i), statement->ColumnInt64(i)); 135 kernel->put(static_cast<Int64Field>(i), statement->ColumnInt64(i));
136 } 136 }
137 for ( ; i < TIME_FIELDS_END; ++i) { 137 for ( ; i < TIME_FIELDS_END; ++i) {
138 kernel->put(static_cast<TimeField>(i), 138 kernel->put(static_cast<TimeField>(i),
139 ProtoTimeToTime(statement->ColumnInt64(i))); 139 ProtoTimeToTime(statement->ColumnInt64(i)));
140 } 140 }
141 for ( ; i < ID_FIELDS_END; ++i) { 141 for ( ; i < ID_FIELDS_END; ++i) {
142 kernel->mutable_ref(static_cast<IdField>(i)).s_ = 142 kernel->mutable_ref(static_cast<IdField>(i)).s_ =
143 statement->ColumnString(i); 143 statement->ColumnString(i);
144 } 144 }
145 for ( ; i < BIT_FIELDS_END; ++i) { 145 for ( ; i < BIT_FIELDS_END; ++i) {
146 kernel->put(static_cast<BitField>(i), (0 != statement->ColumnInt(i))); 146 kernel->put(static_cast<BitField>(i), (0 != statement->ColumnInt(i)));
147 } 147 }
148 for ( ; i < STRING_FIELDS_END; ++i) { 148 for ( ; i < STRING_FIELDS_END; ++i) {
149 kernel->put(static_cast<StringField>(i), 149 kernel->put(static_cast<StringField>(i),
150 statement->ColumnString(i)); 150 statement->ColumnString(i));
151 } 151 }
152 UnpackProtoFields<sync_pb::EntitySpecifics, ProtoField>( 152 UnpackProtoFields<sync_pb::EntitySpecifics, ProtoField>(
153 statement, kernel.get(), &i, PROTO_FIELDS_END, total_specifics_copies); 153 statement, kernel.get(), &i, PROTO_FIELDS_END, total_specifics_copies);
154 for ( ; i < UNIQUE_POSITION_FIELDS_END; ++i) { 154 for ( ; i < UNIQUE_POSITION_FIELDS_END; ++i) {
155 std::string temp; 155 std::string temp;
156 statement->ColumnBlobAsString(i, &temp); 156 statement->ColumnBlobAsString(i, &temp);
157 157
158 sync_pb::UniquePosition proto; 158 sync_pb::UniquePosition proto;
159 if (!proto.ParseFromString(temp)) { 159 if (!proto.ParseFromString(temp)) {
160 DVLOG(1) << "Unpacked invalid position. Assuming the DB is corrupt"; 160 DVLOG(1) << "Unpacked invalid position. Assuming the DB is corrupt";
161 return scoped_ptr<EntryKernel>(); 161 return std::unique_ptr<EntryKernel>();
162 } 162 }
163 163
164 kernel->mutable_ref(static_cast<UniquePositionField>(i)) = 164 kernel->mutable_ref(static_cast<UniquePositionField>(i)) =
165 UniquePosition::FromProto(proto); 165 UniquePosition::FromProto(proto);
166 } 166 }
167 int attachemnt_specifics_counts = 0; 167 int attachemnt_specifics_counts = 0;
168 UnpackProtoFields<sync_pb::AttachmentMetadata, AttachmentMetadataField>( 168 UnpackProtoFields<sync_pb::AttachmentMetadata, AttachmentMetadataField>(
169 statement, kernel.get(), &i, ATTACHMENT_METADATA_FIELDS_END, 169 statement, kernel.get(), &i, ATTACHMENT_METADATA_FIELDS_END,
170 &attachemnt_specifics_counts); 170 &attachemnt_specifics_counts);
171 171
172 // Sanity check on positions. We risk strange and rare crashes if our 172 // Sanity check on positions. We risk strange and rare crashes if our
173 // assumptions about unique position values are broken. 173 // assumptions about unique position values are broken.
174 if (kernel->ShouldMaintainPosition() && 174 if (kernel->ShouldMaintainPosition() &&
175 !kernel->ref(UNIQUE_POSITION).IsValid()) { 175 !kernel->ref(UNIQUE_POSITION).IsValid()) {
176 DVLOG(1) << "Unpacked invalid position on an entity that should have a " 176 DVLOG(1) << "Unpacked invalid position on an entity that should have a "
177 << "valid position. Assuming the DB is corrupt."; 177 << "valid position. Assuming the DB is corrupt.";
178 return scoped_ptr<EntryKernel>(); 178 return std::unique_ptr<EntryKernel>();
179 } 179 }
180 180
181 return kernel; 181 return kernel;
182 } 182 }
183 183
184 namespace { 184 namespace {
185 185
186 // This just has to be big enough to hold an UPDATE or INSERT statement that 186 // This just has to be big enough to hold an UPDATE or INSERT statement that
187 // modifies all the columns in the entry table. 187 // modifies all the columns in the entry table.
188 static const string::size_type kUpdateStatementBufferSize = 2048; 188 static const string::size_type kUpdateStatementBufferSize = 2048;
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 select.append(" FROM metas"); 657 select.append(" FROM metas");
658 int total_specifics_copies = 0; 658 int total_specifics_copies = 0;
659 int model_type_entry_count[MODEL_TYPE_COUNT]; 659 int model_type_entry_count[MODEL_TYPE_COUNT];
660 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) { 660 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) {
661 model_type_entry_count[i] = 0; 661 model_type_entry_count[i] = 0;
662 } 662 }
663 663
664 sql::Statement s(db_->GetUniqueStatement(select.c_str())); 664 sql::Statement s(db_->GetUniqueStatement(select.c_str()));
665 665
666 while (s.Step()) { 666 while (s.Step()) {
667 scoped_ptr<EntryKernel> kernel = UnpackEntry(&s, &total_specifics_copies); 667 std::unique_ptr<EntryKernel> kernel =
668 UnpackEntry(&s, &total_specifics_copies);
668 // A null kernel is evidence of external data corruption. 669 // A null kernel is evidence of external data corruption.
669 if (!kernel) 670 if (!kernel)
670 return false; 671 return false;
671 672
672 int64_t handle = kernel->ref(META_HANDLE); 673 int64_t handle = kernel->ref(META_HANDLE);
673 if (SafeToPurgeOnLoading(*kernel)) { 674 if (SafeToPurgeOnLoading(*kernel)) {
674 metahandles_to_purge->insert(handle); 675 metahandles_to_purge->insert(handle);
675 } else { 676 } else {
676 ModelType model_type = kernel->GetModelType(); 677 ModelType model_type = kernel->GetModelType();
677 if (!IsRealDataType(model_type)) { 678 if (!IsRealDataType(model_type)) {
(...skipping 25 matching lines...) Expand all
703 string select; 704 string select;
704 select.reserve(kUpdateStatementBufferSize); 705 select.reserve(kUpdateStatementBufferSize);
705 select.append("SELECT "); 706 select.append("SELECT ");
706 AppendColumnList(&select); 707 AppendColumnList(&select);
707 select.append(" FROM deleted_metas"); 708 select.append(" FROM deleted_metas");
708 709
709 sql::Statement s(db_->GetUniqueStatement(select.c_str())); 710 sql::Statement s(db_->GetUniqueStatement(select.c_str()));
710 711
711 while (s.Step()) { 712 while (s.Step()) {
712 int total_entry_copies; 713 int total_entry_copies;
713 scoped_ptr<EntryKernel> kernel = UnpackEntry(&s, &total_entry_copies); 714 std::unique_ptr<EntryKernel> kernel = UnpackEntry(&s, &total_entry_copies);
714 // A null kernel is evidence of external data corruption. 715 // A null kernel is evidence of external data corruption.
715 if (!kernel) 716 if (!kernel)
716 return false; 717 return false;
717 delete_journals->insert(kernel.release()); 718 delete_journals->insert(kernel.release());
718 } 719 }
719 return s.Succeeded(); 720 return s.Succeeded();
720 } 721 }
721 722
722 bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) { 723 bool DirectoryBackingStore::LoadInfo(Directory::KernelLoadInfo* info) {
723 { 724 {
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1758 DCHECK(CalledOnValidThread()); 1759 DCHECK(CalledOnValidThread());
1759 DCHECK(!catastrophic_error_handler.is_null()); 1760 DCHECK(!catastrophic_error_handler.is_null());
1760 catastrophic_error_handler_ = catastrophic_error_handler; 1761 catastrophic_error_handler_ = catastrophic_error_handler;
1761 sql::Connection::ErrorCallback error_callback = 1762 sql::Connection::ErrorCallback error_callback =
1762 base::Bind(&OnSqliteError, catastrophic_error_handler_); 1763 base::Bind(&OnSqliteError, catastrophic_error_handler_);
1763 db_->set_error_callback(error_callback); 1764 db_->set_error_callback(error_callback);
1764 } 1765 }
1765 1766
1766 } // namespace syncable 1767 } // namespace syncable
1767 } // namespace syncer 1768 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698