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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/commit.h ('k') | sync/engine/get_commit_ids_command.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #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.
6
7 #include "base/debug/trace_event.h"
8 #include "sync/engine/build_commit_command.h"
9 #include "sync/engine/get_commit_ids_command.h"
10 #include "sync/engine/process_commit_response_command.h"
11 #include "sync/engine/syncer_proto_util.h"
12 #include "sync/sessions/sync_session.h"
13
14 using syncable::SYNCER;
15 using syncable::WriteTransaction;
16
17 namespace browser_sync {
18
19 using sessions::SyncSession;
20 using sessions::StatusController;
21
22 SyncerError BuildAndPostCommits(SyncSession* session) {
23 StatusController* status_controller = session->mutable_status_controller();
24 syncable::Directory* dir = session->context()->directory();
25 size_t batch_size = session->context()->max_commit_batch_size();
26 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
27 sessions::OrderedCommitSet commit_set(session->routing_info());
28 ClientToServerMessage commit_message;
29 ClientToServerResponse commit_response;
30
31 {
32 TRACE_EVENT0("sync", "BuildCommit");
33 WriteTransaction trans(FROM_HERE, SYNCER, dir);
34 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans);
35 GetCommitIdsCommand get_commit_ids_command(batch_size, &commit_set);
36 get_commit_ids_command.Execute(session);
37
38 DVLOG(1) << "Found " << commit_set.Size()
39 << " item(s) to commit in this batch.";
40
41 // Exit if we have nothing left to commit. This is the normal exit point.
42 if (commit_set.Empty())
43 return SYNCER_OK;
44
45 BuildCommitCommand build_commit_command(commit_set,
46 &commit_message);
47 build_commit_command.Execute(session);
48 } // Time for some network IO. Release the lock.
49
50 DVLOG(1) << "Sending a commit message";
51 TRACE_EVENT_BEGIN0("sync", "PostCommit");
52 status_controller->set_last_post_commit_result(
53 SyncerProtoUtil::PostClientToServerMessage(commit_message,
54 &commit_response,
55 session));
56 TRACE_EVENT_END0("sync", "PostCommit");
57
58 // ProcessCommitResponse includes some code that cleans up after a failure
59 // to post a commit message, so we must run it regardless of whether or not
60 // the commit succeeds.
61
62 TRACE_EVENT_BEGIN0("sync", "ProcessCommitResponse");
63 ProcessCommitResponseCommand process_response_command(
64 commit_set, commit_message, commit_response);
65 status_controller->set_last_process_commit_response_result(
66 process_response_command.Execute(session));
67 TRACE_EVENT_END0("sync", "ProcessCommitResponse");
68
69 // Exit early if either the commit or the response processing failed.
70 if (status_controller->last_post_commit_result() != SYNCER_OK) {
71 return status_controller->last_post_commit_result();
72 }
73 if (status_controller->last_process_commit_response_result() != SYNCER_OK) {
74 return status_controller->last_process_commit_response_result();
75 }
76 }
77 }
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
78
79 } // namespace browser_sync
OLDNEW
« 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