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

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

Issue 948113005: Sync: Small refactoring of Directory::CheckTreeInvariants (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.h" 5 #include "sync/syncable/directory.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 parentid = parent.GetParentId(); 1219 parentid = parent.GetParentId();
1220 if (!SyncAssert(--safety_count > 0, FROM_HERE, 1220 if (!SyncAssert(--safety_count > 0, FROM_HERE,
1221 "Count should be greater than zero.", trans)) 1221 "Count should be greater than zero.", trans))
1222 return false; 1222 return false;
1223 } 1223 }
1224 } 1224 }
1225 } 1225 }
1226 int64 base_version = e.GetBaseVersion(); 1226 int64 base_version = e.GetBaseVersion();
1227 int64 server_version = e.GetServerVersion(); 1227 int64 server_version = e.GetServerVersion();
1228 bool using_unique_client_tag = !e.GetUniqueClientTag().empty(); 1228 bool using_unique_client_tag = !e.GetUniqueClientTag().empty();
1229 bool is_type_root_folder =
1230 parentid.IsRoot() &&
1231 e.GetUniqueServerTag() == ModelTypeToRootTag(e.GetModelType());
1232 if (CHANGES_VERSION == base_version || 0 == base_version) { 1229 if (CHANGES_VERSION == base_version || 0 == base_version) {
1230 ModelType model_type = e.GetModelType();
1231 bool is_client_creatable_type_root_folder =
1232 parentid.IsRoot() &&
1233 IsTypeWithClientGeneratedRoot(model_type) &&
1234 e.GetUniqueServerTag() == ModelTypeToRootTag(model_type);
1233 if (e.GetIsUnappliedUpdate()) { 1235 if (e.GetIsUnappliedUpdate()) {
1234 // Must be a new item, or a de-duplicated unique client tag 1236 // Must be a new item, or a de-duplicated unique client tag
1237 // that was created both locally and remotely, or a type root folder
1235 // that was created both locally and remotely. 1238 // that was created both locally and remotely.
1236 if (!(using_unique_client_tag || is_type_root_folder)) { 1239 if (!(using_unique_client_tag ||
1240 is_client_creatable_type_root_folder)) {
1237 if (!SyncAssert(e.GetIsDel(), FROM_HERE, 1241 if (!SyncAssert(e.GetIsDel(), FROM_HERE,
1238 "The entry should have been deleted.", trans)) 1242 "The entry should have been deleted.", trans))
1239 return false; 1243 return false;
1240 } 1244 }
1241 // It came from the server, so it must have a server ID. 1245 // It came from the server, so it must have a server ID.
1242 if (!SyncAssert(id.ServerKnows(), FROM_HERE, 1246 if (!SyncAssert(id.ServerKnows(), FROM_HERE,
1243 "The id should be from a server.", 1247 "The id should be from a server.",
1244 trans)) 1248 trans))
1245 return false; 1249 return false;
1246 } else { 1250 } else {
1247 if (e.GetIsDir()) { 1251 if (e.GetIsDir()) {
1248 // TODO(chron): Implement this mode if clients ever need it. 1252 // TODO(chron): Implement this mode if clients ever need it.
1249 // For now, you can't combine a client tag and a directory. 1253 // For now, you can't combine a client tag and a directory.
1250 if (!SyncAssert(!using_unique_client_tag, FROM_HERE, 1254 if (!SyncAssert(!using_unique_client_tag, FROM_HERE,
1251 "Directory cannot have a client tag.", 1255 "Directory cannot have a client tag.",
1252 trans)) 1256 trans))
1253 return false; 1257 return false;
1254 } 1258 }
1255 if (is_type_root_folder) { 1259 if (is_client_creatable_type_root_folder) {
1256 // This must be a locally created type root folder 1260 // This must be a locally created type root folder.
1257 if (!SyncAssert( 1261 if (!SyncAssert(
1258 !e.GetIsUnsynced(), FROM_HERE, 1262 !e.GetIsUnsynced(), FROM_HERE,
1259 "Locally created type root folders should not be unsynced.", 1263 "Locally created type root folders should not be unsynced.",
1260 trans)) 1264 trans))
1261 return false; 1265 return false;
1262 1266
1263 if (!SyncAssert( 1267 if (!SyncAssert(
1264 !e.GetIsDel(), FROM_HERE, 1268 !e.GetIsDel(), FROM_HERE,
1265 "Locally created type root folders should not be deleted.", 1269 "Locally created type root folders should not be deleted.",
1266 trans)) 1270 trans))
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203). 1545 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203).
1542 std::set_difference(not_on_server_id_set.begin(), 1546 std::set_difference(not_on_server_id_set.begin(),
1543 not_on_server_id_set.end(), 1547 not_on_server_id_set.end(),
1544 on_server_id_set.begin(), 1548 on_server_id_set.begin(),
1545 on_server_id_set.end(), 1549 on_server_id_set.end(),
1546 std::inserter(*id_set, id_set->end())); 1550 std::inserter(*id_set, id_set->end()));
1547 } 1551 }
1548 1552
1549 } // namespace syncable 1553 } // namespace syncable
1550 } // namespace syncer 1554 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/public/base/model_type.h ('k') | sync/syncable/model_neutral_mutable_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698