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

Side by Side Diff: sync/engine/commit.cc

Issue 10735041: Remove syncproto.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address most comments Created 8 years, 5 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/build_commit_command_unittest.cc ('k') | sync/engine/download_updates_command.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "sync/engine/commit.h" 5 #include "sync/engine/commit.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "sync/engine/build_commit_command.h" 8 #include "sync/engine/build_commit_command.h"
9 #include "sync/engine/get_commit_ids_command.h" 9 #include "sync/engine/get_commit_ids_command.h"
10 #include "sync/engine/process_commit_response_command.h" 10 #include "sync/engine/process_commit_response_command.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // The OrderedCommitSet parameter is an output parameter which will contain 56 // The OrderedCommitSet parameter is an output parameter which will contain
57 // the set of all items which are to be committed. The number of items in 57 // the set of all items which are to be committed. The number of items in
58 // the set shall not exceed the maximum batch size. (The default batch size 58 // the set shall not exceed the maximum batch size. (The default batch size
59 // is currently 25, though it can be overwritten by the server.) 59 // is currently 25, though it can be overwritten by the server.)
60 // 60 //
61 // The ClientToServerMessage parameter is an output parameter which will contain 61 // The ClientToServerMessage parameter is an output parameter which will contain
62 // the commit message which should be sent to the server. It is valid iff the 62 // the commit message which should be sent to the server. It is valid iff the
63 // return value of this function is true. 63 // return value of this function is true.
64 bool PrepareCommitMessage(sessions::SyncSession* session, 64 bool PrepareCommitMessage(sessions::SyncSession* session,
65 sessions::OrderedCommitSet* commit_set, 65 sessions::OrderedCommitSet* commit_set,
66 ClientToServerMessage* commit_message) { 66 sync_pb::ClientToServerMessage* commit_message) {
67 TRACE_EVENT0("sync", "PrepareCommitMessage"); 67 TRACE_EVENT0("sync", "PrepareCommitMessage");
68 68
69 commit_set->Clear(); 69 commit_set->Clear();
70 commit_message->Clear(); 70 commit_message->Clear();
71 71
72 // TODO(134769): This is a temporary fix for crbug.com/134715.
73 commit_message->set_protocol_version(commit_message->protocol_version());
74
75 WriteTransaction trans(FROM_HERE, SYNCER, session->context()->directory()); 72 WriteTransaction trans(FROM_HERE, SYNCER, session->context()->directory());
76 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); 73 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans);
77 74
78 // Fetch the items to commit. 75 // Fetch the items to commit.
79 const size_t batch_size = session->context()->max_commit_batch_size(); 76 const size_t batch_size = session->context()->max_commit_batch_size();
80 GetCommitIdsCommand get_commit_ids_command(batch_size, commit_set); 77 GetCommitIdsCommand get_commit_ids_command(batch_size, commit_set);
81 get_commit_ids_command.Execute(session); 78 get_commit_ids_command.Execute(session);
82 79
83 DVLOG(1) << "Commit message will contain " << commit_set->Size() << " items."; 80 DVLOG(1) << "Commit message will contain " << commit_set->Size() << " items.";
84 if (commit_set->Empty()) { 81 if (commit_set->Empty()) {
85 return false; 82 return false;
86 } 83 }
87 84
88 // Serialize the message. 85 // Serialize the message.
89 BuildCommitCommand build_commit_command(*commit_set, commit_message); 86 BuildCommitCommand build_commit_command(*commit_set, commit_message);
90 build_commit_command.Execute(session); 87 build_commit_command.Execute(session);
91 88
92 SetSyncingBits(session->write_transaction(), *commit_set); 89 SetSyncingBits(session->write_transaction(), *commit_set);
93 return true; 90 return true;
94 } 91 }
95 92
96 SyncerError BuildAndPostCommitsImpl(Syncer* syncer, 93 SyncerError BuildAndPostCommitsImpl(Syncer* syncer,
97 sessions::SyncSession* session, 94 sessions::SyncSession* session,
98 sessions::OrderedCommitSet* commit_set) { 95 sessions::OrderedCommitSet* commit_set) {
99 ClientToServerMessage commit_message; 96 sync_pb::ClientToServerMessage commit_message;
100 while (!syncer->ExitRequested() && 97 while (!syncer->ExitRequested() &&
101 PrepareCommitMessage(session, commit_set, &commit_message)) { 98 PrepareCommitMessage(session, commit_set, &commit_message)) {
102 ClientToServerResponse commit_response; 99 sync_pb::ClientToServerResponse commit_response;
103 100
104 DVLOG(1) << "Sending commit message."; 101 DVLOG(1) << "Sending commit message.";
105 TRACE_EVENT_BEGIN0("sync", "PostCommit"); 102 TRACE_EVENT_BEGIN0("sync", "PostCommit");
106 const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( 103 const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage(
107 commit_message, &commit_response, session); 104 commit_message, &commit_response, session);
108 TRACE_EVENT_END0("sync", "PostCommit"); 105 TRACE_EVENT_END0("sync", "PostCommit");
109 106
110 if (post_result != SYNCER_OK) { 107 if (post_result != SYNCER_OK) {
111 LOG(WARNING) << "Post commit failed"; 108 LOG(WARNING) << "Post commit failed";
112 return post_result; 109 return post_result;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 sessions::SyncSession* session) { 146 sessions::SyncSession* session) {
150 sessions::OrderedCommitSet commit_set(session->routing_info()); 147 sessions::OrderedCommitSet commit_set(session->routing_info());
151 SyncerError result = BuildAndPostCommitsImpl(syncer, session, &commit_set); 148 SyncerError result = BuildAndPostCommitsImpl(syncer, session, &commit_set);
152 if (result != SYNCER_OK) { 149 if (result != SYNCER_OK) {
153 ClearSyncingBits(session->context()->directory(), commit_set); 150 ClearSyncingBits(session->context()->directory(), commit_set);
154 } 151 }
155 return result; 152 return result;
156 } 153 }
157 154
158 } // namespace syncer 155 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/build_commit_command_unittest.cc ('k') | sync/engine/download_updates_command.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698