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

Unified Diff: sync/engine/commit.cc

Issue 10210009: sync: Loop committing items without downloading updates (v2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, remove class, modify loop exit Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: sync/engine/commit.cc
diff --git a/sync/engine/commit.cc b/sync/engine/commit.cc
new file mode 100644
index 0000000000000000000000000000000000000000..67563494098ad5ff64660f31654ab3e72bade458
--- /dev/null
+++ b/sync/engine/commit.cc
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/engine/commit.h"
+
+#include "base/debug/trace_event.h"
+#include "sync/engine/build_commit_command.h"
+#include "sync/engine/get_commit_ids_command.h"
+#include "sync/engine/process_commit_response_command.h"
+#include "sync/engine/syncer_proto_util.h"
+#include "sync/sessions/sync_session.h"
+
+using syncable::SYNCER;
+using syncable::WriteTransaction;
+
+namespace browser_sync {
+
+using sessions::SyncSession;
+using sessions::StatusController;
+
+SyncerError BuildAndPostCommits(sessions::SyncSession* session) {
+ StatusController* status_controller = session->mutable_status_controller();
+ size_t items_to_commit_count = 0;
tim (not reviewing) 2012/05/11 18:42:16 Perhaps this should be inside the loop.
rlarocque 2012/05/14 23:10:43 I tried. It won't work. The while() condition of
+ const size_t batch_size = session->context()->max_commit_batch_size();
+ do {
+ sessions::OrderedCommitSet commit_set(session->routing_info());
+ ClientToServerMessage commit_message;
+ ClientToServerResponse commit_response;
+
+ {
+ TRACE_EVENT0("sync", "BuildCommit");
+ WriteTransaction trans(FROM_HERE, SYNCER,
+ session->context()->directory());
+ sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans);
+ GetCommitIdsCommand get_commit_ids_command(batch_size, &commit_set,
tim (not reviewing) 2012/05/11 18:42:16 This line is kind of taunting me to suggest an opt
rlarocque 2012/05/14 23:10:43 I agree that we can do better. At first, I tried
+ &items_to_commit_count);
+ get_commit_ids_command.Execute(session);
+
+ DVLOG(1) << "Found " << commit_set.Size()
+ << " item(s) to commit in this batch.";
+
+ if (commit_set.Empty())
+ return SYNCER_OK;
+
+ BuildCommitCommand build_commit_command(commit_set,
+ &commit_message);
+ build_commit_command.Execute(session);
+ } // Time for some network IO. Release the lock.
+
+ DVLOG(1) << "Sending a commit message";
+ TRACE_EVENT_BEGIN0("sync", "PostCommit");
+ status_controller->set_last_post_commit_result(
+ SyncerProtoUtil::PostClientToServerMessage(commit_message,
tim (not reviewing) 2012/05/11 18:42:16 As general practice all over the code, we ought to
rlarocque 2012/05/14 23:10:43 The ServerConnectionManager would handle that sort
tim (not reviewing) 2012/05/15 22:25:00 My main point was that in general the delegate is
+ &commit_response,
+ session));
+ TRACE_EVENT_END0("sync", "PostCommit");
+
+ // ProcessCommitResponse includes some code that cleans up after a failure
+ // to post a commit message, so we must run it regardless of whether or not
+ // the commit succeeds.
+
+ TRACE_EVENT_BEGIN0("sync", "ProcessCommitResponse");
+ ProcessCommitResponseCommand process_response_command(
+ commit_set, commit_message, commit_response);
+ status_controller->set_last_process_commit_response_result(
+ process_response_command.Execute(session));
+ TRACE_EVENT_END0("sync", "ProcessCommitResponse");
+
+ // Exit early if either the commit or the response processing failed.
+ if (status_controller->last_post_commit_result() != SYNCER_OK) {
+ return status_controller->last_post_commit_result();
+ }
+ if (status_controller->last_process_commit_response_result() != SYNCER_OK) {
+ return status_controller->last_process_commit_response_result();
+ }
+ } while (items_to_commit_count > batch_size);
rlarocque 2012/05/11 00:52:16 I realized after posting this patch that there is
tim (not reviewing) 2012/05/11 18:42:16 A comment explaining what happens if local changes
+
+ return SYNCER_OK;
+}
+
+} // namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698