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

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: 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 unified diff | Download patch | Annotate | Revision Log
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"
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(sessions::SyncSession* session) {
23 StatusController* status_controller = session->mutable_status_controller();
24 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
25 const size_t batch_size = session->context()->max_commit_batch_size();
26 do {
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,
34 session->context()->directory());
35 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans);
36 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
37 &items_to_commit_count);
38 get_commit_ids_command.Execute(session);
39
40 DVLOG(1) << "Found " << commit_set.Size()
41 << " item(s) to commit in this batch.";
42
43 if (commit_set.Empty())
44 return SYNCER_OK;
45
46 BuildCommitCommand build_commit_command(commit_set,
47 &commit_message);
48 build_commit_command.Execute(session);
49 } // Time for some network IO. Release the lock.
50
51 DVLOG(1) << "Sending a commit message";
52 TRACE_EVENT_BEGIN0("sync", "PostCommit");
53 status_controller->set_last_post_commit_result(
54 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
55 &commit_response,
56 session));
57 TRACE_EVENT_END0("sync", "PostCommit");
58
59 // ProcessCommitResponse includes some code that cleans up after a failure
60 // to post a commit message, so we must run it regardless of whether or not
61 // the commit succeeds.
62
63 TRACE_EVENT_BEGIN0("sync", "ProcessCommitResponse");
64 ProcessCommitResponseCommand process_response_command(
65 commit_set, commit_message, commit_response);
66 status_controller->set_last_process_commit_response_result(
67 process_response_command.Execute(session));
68 TRACE_EVENT_END0("sync", "ProcessCommitResponse");
69
70 // Exit early if either the commit or the response processing failed.
71 if (status_controller->last_post_commit_result() != SYNCER_OK) {
72 return status_controller->last_post_commit_result();
73 }
74 if (status_controller->last_process_commit_response_result() != SYNCER_OK) {
75 return status_controller->last_process_commit_response_result();
76 }
77 } 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
78
79 return SYNCER_OK;
80 }
81
82 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698