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

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: Inline PostCommitMessageCommand Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/engine/commit.h ('k') | sync/engine/get_commit_ids_command.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/engine/commit.cc
diff --git a/sync/engine/commit.cc b/sync/engine/commit.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d537cb35f3fdbbbb5841e5bfd130f2b72ccfda4d
--- /dev/null
+++ b/sync/engine/commit.cc
@@ -0,0 +1,79 @@
+// 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"
tim (not reviewing) 2012/04/25 06:48:13 Can we add a commit_unittest to test high level Bu
rlarocque 2012/04/25 18:13:22 This function is well covered by the SyncerTests.
+
+#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(SyncSession* session) {
+ StatusController* status_controller = session->mutable_status_controller();
+ syncable::Directory* dir = session->context()->directory();
+ size_t batch_size = session->context()->max_commit_batch_size();
+ for ( ; ; ) {
tim (not reviewing) 2012/04/25 06:48:13 What is this loop for? It's not obvious to me. D
rlarocque 2012/04/25 18:13:22 The initial idea was to loop over the set of all c
+ sessions::OrderedCommitSet commit_set(session->routing_info());
+ ClientToServerMessage commit_message;
+ ClientToServerResponse commit_response;
+
+ {
+ TRACE_EVENT0("sync", "BuildCommit");
+ WriteTransaction trans(FROM_HERE, SYNCER, dir);
+ sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans);
+ GetCommitIdsCommand get_commit_ids_command(batch_size, &commit_set);
+ get_commit_ids_command.Execute(session);
+
+ DVLOG(1) << "Found " << commit_set.Size()
+ << " item(s) to commit in this batch.";
+
+ // Exit if we have nothing left to commit. This is the normal exit point.
+ 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,
+ &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();
+ }
+ }
+}
tim (not reviewing) 2012/04/25 06:48:13 http://google-styleguide.googlecode.com/svn/trunk/
tim (not reviewing) 2012/04/25 06:48:13 Does this address / maintain somehow the early-exi
rlarocque 2012/04/25 18:13:22 I believe it does. If we receive an early exit re
rlarocque 2012/04/25 18:13:22 This is exactly the sort of thing I want to encour
tim (not reviewing) 2012/04/26 06:47:54 Yeah, I'm not saying I wholesale disagree with tha
rlarocque 2012/05/08 00:48:32 On that point, I agree. The batch_size and dir de
+
+} // namespace browser_sync
« no previous file with comments | « sync/engine/commit.h ('k') | sync/engine/get_commit_ids_command.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698