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

Side by Side Diff: chrome/browser/sync/engine/process_updates_command.cc

Issue 1161006: Make it clear what last_sync_timestamp actually tracks. Update (Closed)
Patch Set: Undo accidental patch-juggling mistake. Created 10 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 (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "chrome/browser/sync/engine/process_updates_command.h" 5 #include "chrome/browser/sync/engine/process_updates_command.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "chrome/browser/sync/engine/syncer.h" 10 #include "chrome/browser/sync/engine/syncer.h"
11 #include "chrome/browser/sync/engine/syncer_proto_util.h" 11 #include "chrome/browser/sync/engine/syncer_proto_util.h"
12 #include "chrome/browser/sync/engine/syncer_util.h" 12 #include "chrome/browser/sync/engine/syncer_util.h"
13 #include "chrome/browser/sync/engine/syncproto.h" 13 #include "chrome/browser/sync/engine/syncproto.h"
14 #include "chrome/browser/sync/sessions/sync_session.h" 14 #include "chrome/browser/sync/sessions/sync_session.h"
15 #include "chrome/browser/sync/syncable/directory_manager.h" 15 #include "chrome/browser/sync/syncable/directory_manager.h"
16 #include "chrome/browser/sync/syncable/syncable.h" 16 #include "chrome/browser/sync/syncable/syncable.h"
17 17
18 using std::vector; 18 using std::vector;
19 19
20 namespace browser_sync { 20 namespace browser_sync {
21 21
22 using sessions::SyncSession; 22 using sessions::SyncSession;
23 using sessions::StatusController; 23 using sessions::StatusController;
24 24
25 ProcessUpdatesCommand::ProcessUpdatesCommand() {} 25 ProcessUpdatesCommand::ProcessUpdatesCommand() {}
26 ProcessUpdatesCommand::~ProcessUpdatesCommand() {} 26 ProcessUpdatesCommand::~ProcessUpdatesCommand() {}
27 27
28 bool ProcessUpdatesCommand::ModelNeutralExecuteImpl(SyncSession* session) {
29 const GetUpdatesResponse& updates =
30 session->status_controller()->updates_response().get_updates();
31 const int update_count = updates.entries_size();
32
33 // Don't bother processing updates if there were none.
34 return update_count != 0;
35 }
36
28 void ProcessUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) { 37 void ProcessUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) {
29 syncable::ScopedDirLookup dir(session->context()->directory_manager(), 38 syncable::ScopedDirLookup dir(session->context()->directory_manager(),
30 session->context()->account_name()); 39 session->context()->account_name());
31 if (!dir.good()) { 40 if (!dir.good()) {
32 LOG(ERROR) << "Scoped dir lookup failed!"; 41 LOG(ERROR) << "Scoped dir lookup failed!";
33 return; 42 return;
34 } 43 }
35 44
36 const GetUpdatesResponse& updates = 45 StatusController* status = session->status_controller();
37 session->status_controller()->updates_response().get_updates();
38 const int update_count = updates.entries_size();
39 46
40 LOG(INFO) << "Get updates from ts " << dir->last_sync_timestamp() <<
41 " returned " << update_count << " updates.";
42
43 StatusController* status = session->status_controller();
44 if (updates.has_changes_remaining()) {
45 int64 changes_left = updates.changes_remaining();
46 LOG(INFO) << "Changes remaining:" << changes_left;
47 status->set_num_server_changes_remaining(changes_left);
48 }
49
50 int64 new_timestamp = 0;
51 if (updates.has_new_timestamp()) {
52 new_timestamp = updates.new_timestamp();
53 LOG(INFO) << "Get Updates got new timestamp: " << new_timestamp;
54 if (0 == update_count) {
55 if (new_timestamp > dir->last_sync_timestamp()) {
56 dir->set_last_sync_timestamp(new_timestamp);
57 status->set_got_new_timestamp();
58 }
59 return;
60 }
61 }
62
63 // If we have updates that are ALL supposed to be skipped, we don't want to
64 // get them again. In fact, the account's final updates are all supposed to
65 // be skipped and we DON'T step past them, we will sync forever.
66 int64 latest_skip_timestamp = 0;
67 bool any_non_skip_results = false;
68 const sessions::UpdateProgress& progress(status->update_progress()); 47 const sessions::UpdateProgress& progress(status->update_progress());
69 vector<sessions::VerifiedUpdate>::const_iterator it; 48 vector<sessions::VerifiedUpdate>::const_iterator it;
70 for (it = progress.VerifiedUpdatesBegin(); 49 for (it = progress.VerifiedUpdatesBegin();
71 it != progress.VerifiedUpdatesEnd(); 50 it != progress.VerifiedUpdatesEnd();
72 ++it) { 51 ++it) {
73 const sync_pb::SyncEntity& update = it->second; 52 const sync_pb::SyncEntity& update = it->second;
74 53
75 any_non_skip_results = (it->first != VERIFY_SKIP);
76 if (!any_non_skip_results) {
77 // ALL updates were to be skipped, including this one.
78 if (update.sync_timestamp() > latest_skip_timestamp) {
79 latest_skip_timestamp = update.sync_timestamp();
80 }
81 } else {
82 latest_skip_timestamp = 0;
83 }
84
85 if (it->first != VERIFY_SUCCESS && it->first != VERIFY_UNDELETE) 54 if (it->first != VERIFY_SUCCESS && it->first != VERIFY_UNDELETE)
86 continue; 55 continue;
87 switch (ProcessUpdate(dir, update)) { 56 switch (ProcessUpdate(dir, update)) {
88 case SUCCESS_PROCESSED: 57 case SUCCESS_PROCESSED:
89 case SUCCESS_STORED: 58 case SUCCESS_STORED:
90 // We can update the timestamp because we store the update even if we
91 // can't apply it now.
92 if (update.sync_timestamp() > new_timestamp)
93 new_timestamp = update.sync_timestamp();
94 break; 59 break;
95 default: 60 default:
96 NOTREACHED(); 61 NOTREACHED();
97 break; 62 break;
98 } 63 }
99
100 }
101
102 if (latest_skip_timestamp > new_timestamp)
103 new_timestamp = latest_skip_timestamp;
104
105 if (new_timestamp > dir->last_sync_timestamp()) {
106 dir->set_last_sync_timestamp(new_timestamp);
107 status->set_got_new_timestamp();
108 } 64 }
109 65
110 status->set_num_consecutive_errors(0); 66 status->set_num_consecutive_errors(0);
111 // TODO(tim): Related to bug 30665, the Directory needs last sync timestamp 67
112 // per data type. Until then, use UNSPECIFIED. 68 // TODO(nick): The following line makes no sense to me.
113 status->set_current_sync_timestamp(syncable::UNSPECIFIED,
114 dir->last_sync_timestamp());
115 status->set_syncing(true); 69 status->set_syncing(true);
116 return; 70 return;
117 } 71 }
118 72
119 namespace { 73 namespace {
120 // Returns true if the entry is still ok to process. 74 // Returns true if the entry is still ok to process.
121 bool ReverifyEntry(syncable::WriteTransaction* trans, const SyncEntity& entry, 75 bool ReverifyEntry(syncable::WriteTransaction* trans, const SyncEntity& entry,
122 syncable::MutableEntry* same_id) { 76 syncable::MutableEntry* same_id) {
123 77
124 const bool deleted = entry.has_deleted() && entry.deleted(); 78 const bool deleted = entry.has_deleted() && entry.deleted();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // will just clobber the data. Conflict resolution will overwrite and 119 // will just clobber the data. Conflict resolution will overwrite and
166 // take one side as the winner and does not try to merge, so strict 120 // take one side as the winner and does not try to merge, so strict
167 // equality isn't necessary. 121 // equality isn't necessary.
168 LOG_IF(ERROR, !SyncerUtil::ServerAndLocalEntriesMatch(&update_entry)) 122 LOG_IF(ERROR, !SyncerUtil::ServerAndLocalEntriesMatch(&update_entry))
169 << update_entry; 123 << update_entry;
170 } 124 }
171 return SUCCESS_PROCESSED; 125 return SUCCESS_PROCESSED;
172 } 126 }
173 127
174 } // namespace browser_sync 128 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/process_updates_command.h ('k') | chrome/browser/sync/engine/store_timestamps_command.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698