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

Side by Side Diff: sync/engine/verify_updates_command.cc

Issue 9702083: sync: Count and report reflected updates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit tests Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/engine/verify_updates_command.h" 5 #include "sync/engine/verify_updates_command.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "sync/engine/syncer.h" 10 #include "sync/engine/syncer.h"
11 #include "sync/engine/syncer_proto_util.h" 11 #include "sync/engine/syncer_proto_util.h"
12 #include "sync/engine/syncer_types.h" 12 #include "sync/engine/syncer_types.h"
13 #include "sync/engine/syncer_util.h" 13 #include "sync/engine/syncer_util.h"
14 #include "sync/engine/syncproto.h" 14 #include "sync/engine/syncproto.h"
15 #include "sync/protocol/bookmark_specifics.pb.h" 15 #include "sync/protocol/bookmark_specifics.pb.h"
16 #include "sync/syncable/syncable.h" 16 #include "sync/syncable/syncable.h"
17 17
18 namespace browser_sync { 18 namespace browser_sync {
19 19
20 using syncable::WriteTransaction; 20 using syncable::WriteTransaction;
21 21
22 using syncable::GET_BY_ID; 22 using syncable::GET_BY_ID;
23 using syncable::SYNCER; 23 using syncable::SYNCER;
24 24
25 namespace {
26
27 // Returns true if the update's version is greather than the version of the
tim (not reviewing) 2012/03/20 20:43:53 nit - greater
rlarocque 2012/03/21 17:42:34 Done.
28 // existing matching entry. Will return true if there is no matching entry.
29 bool UpdateContainsNewVersion(syncable::BaseTransaction *trans,
30 const SyncEntity &update) {
31 int64 existing_version = -1; // The server always sends positive versions.
32 syncable::Entry existing_entry(trans, GET_BY_ID, update.id());
tim (not reviewing) 2012/03/20 20:43:53 When we create an item (version 0), we expect to s
rlarocque 2012/03/21 17:42:34 Interesting. I hadn't fully considered the new ID
tim (not reviewing) 2012/03/21 18:23:57 Makes sense.
33 if (existing_entry.good()) {
tim (not reviewing) 2012/03/20 20:43:53 nit - no braces around single line ifs in this fil
rlarocque 2012/03/21 17:42:34 Done.
34 existing_version = existing_entry.Get(syncable::BASE_VERSION);
35 }
36
37 return existing_version < update.version();
tim (not reviewing) 2012/03/20 20:43:53 Does this catch redeliveries in general, or only o
rlarocque 2012/03/21 17:42:34 I assumed that we're looking for redeliveries in g
38 }
39
40 // In the event that IDs match, but tags differ AttemptReuniteClient tag
41 // will have refused to unify the update.
42 // We should not attempt to apply it at all since it violates consistency
43 // rules.
44 VerifyResult VerifyTagConsistency(const SyncEntity& entry,
45 const syncable::MutableEntry& same_id) {
46 if (entry.has_client_defined_unique_tag() &&
47 entry.client_defined_unique_tag() !=
48 same_id.Get(syncable::UNIQUE_CLIENT_TAG)) {
49 return VERIFY_FAIL;
50 }
51 return VERIFY_UNDECIDED;
52 }
53 } // namespace
54
25 VerifyUpdatesCommand::VerifyUpdatesCommand() {} 55 VerifyUpdatesCommand::VerifyUpdatesCommand() {}
26 VerifyUpdatesCommand::~VerifyUpdatesCommand() {} 56 VerifyUpdatesCommand::~VerifyUpdatesCommand() {}
27 57
28 std::set<ModelSafeGroup> VerifyUpdatesCommand::GetGroupsToChange( 58 std::set<ModelSafeGroup> VerifyUpdatesCommand::GetGroupsToChange(
29 const sessions::SyncSession& session) const { 59 const sessions::SyncSession& session) const {
30 std::set<ModelSafeGroup> groups_with_updates; 60 std::set<ModelSafeGroup> groups_with_updates;
31 61
32 const GetUpdatesResponse& updates = 62 const GetUpdatesResponse& updates =
33 session.status_controller().updates_response().get_updates(); 63 session.status_controller().updates_response().get_updates();
34 for (int i = 0; i < updates.entries().size(); i++) { 64 for (int i = 0; i < updates.entries().size(); i++) {
(...skipping 20 matching lines...) Expand all
55 *reinterpret_cast<const SyncEntity *>(&(updates.entries(i))); 85 *reinterpret_cast<const SyncEntity *>(&(updates.entries(i)));
56 ModelSafeGroup g = GetGroupForModelType(update.GetModelType(), 86 ModelSafeGroup g = GetGroupForModelType(update.GetModelType(),
57 session->routing_info()); 87 session->routing_info());
58 if (g != status->group_restriction()) 88 if (g != status->group_restriction())
59 continue; 89 continue;
60 90
61 VerifyUpdateResult result = VerifyUpdate(&trans, update, 91 VerifyUpdateResult result = VerifyUpdate(&trans, update,
62 session->routing_info()); 92 session->routing_info());
63 status->mutable_update_progress()->AddVerifyResult(result.value, update); 93 status->mutable_update_progress()->AddVerifyResult(result.value, update);
64 status->increment_num_updates_downloaded_by(1); 94 status->increment_num_updates_downloaded_by(1);
95 if (!UpdateContainsNewVersion(&trans, update))
96 status->increment_num_echo_updates_downloaded_by(1);
65 if (update.deleted()) 97 if (update.deleted())
66 status->increment_num_tombstone_updates_downloaded_by(1); 98 status->increment_num_tombstone_updates_downloaded_by(1);
67 } 99 }
68 100
69 return SYNCER_OK; 101 return SYNCER_OK;
70 } 102 }
71 103
72 namespace {
73 // In the event that IDs match, but tags differ AttemptReuniteClient tag
74 // will have refused to unify the update.
75 // We should not attempt to apply it at all since it violates consistency
76 // rules.
77 VerifyResult VerifyTagConsistency(const SyncEntity& entry,
78 const syncable::MutableEntry& same_id) {
79 if (entry.has_client_defined_unique_tag() &&
80 entry.client_defined_unique_tag() !=
81 same_id.Get(syncable::UNIQUE_CLIENT_TAG)) {
82 return VERIFY_FAIL;
83 }
84 return VERIFY_UNDECIDED;
85 }
86 } // namespace
87
88 VerifyUpdatesCommand::VerifyUpdateResult VerifyUpdatesCommand::VerifyUpdate( 104 VerifyUpdatesCommand::VerifyUpdateResult VerifyUpdatesCommand::VerifyUpdate(
89 syncable::WriteTransaction* trans, const SyncEntity& entry, 105 syncable::WriteTransaction* trans, const SyncEntity& entry,
90 const ModelSafeRoutingInfo& routes) { 106 const ModelSafeRoutingInfo& routes) {
91 syncable::Id id = entry.id(); 107 syncable::Id id = entry.id();
92 VerifyUpdateResult result = {VERIFY_FAIL, GROUP_PASSIVE}; 108 VerifyUpdateResult result = {VERIFY_FAIL, GROUP_PASSIVE};
93 109
94 const bool deleted = entry.has_deleted() && entry.deleted(); 110 const bool deleted = entry.has_deleted() && entry.deleted();
95 const bool is_directory = entry.IsFolder(); 111 const bool is_directory = entry.IsFolder();
96 const syncable::ModelType model_type = entry.GetModelType(); 112 const syncable::ModelType model_type = entry.GetModelType();
97 113
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 deleted, is_directory, model_type); 146 deleted, is_directory, model_type);
131 } 147 }
132 148
133 if (VERIFY_UNDECIDED == result.value) 149 if (VERIFY_UNDECIDED == result.value)
134 result.value = VERIFY_SUCCESS; // No news is good news. 150 result.value = VERIFY_SUCCESS; // No news is good news.
135 151
136 return result; // This might be VERIFY_SUCCESS as well 152 return result; // This might be VERIFY_SUCCESS as well
137 } 153 }
138 154
139 } // namespace browser_sync 155 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698