Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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()); | 72 commit_message->set_protocol_version(commit_message->protocol_version()); |
|
akalin
2012/07/11 01:42:22
im guessing this is what replaces the call in the
rlarocque
2012/07/11 19:22:16
Yes. We want to set the protocol version to the c
| |
| 74 | 73 |
| 75 WriteTransaction trans(FROM_HERE, SYNCER, session->context()->directory()); | 74 WriteTransaction trans(FROM_HERE, SYNCER, session->context()->directory()); |
| 76 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); | 75 sessions::ScopedSetSessionWriteTransaction set_trans(session, &trans); |
| 77 | 76 |
| 78 // Fetch the items to commit. | 77 // Fetch the items to commit. |
| 79 const size_t batch_size = session->context()->max_commit_batch_size(); | 78 const size_t batch_size = session->context()->max_commit_batch_size(); |
| 80 GetCommitIdsCommand get_commit_ids_command(batch_size, commit_set); | 79 GetCommitIdsCommand get_commit_ids_command(batch_size, commit_set); |
| 81 get_commit_ids_command.Execute(session); | 80 get_commit_ids_command.Execute(session); |
| 82 | 81 |
| 83 DVLOG(1) << "Commit message will contain " << commit_set->Size() << " items."; | 82 DVLOG(1) << "Commit message will contain " << commit_set->Size() << " items."; |
| 84 if (commit_set->Empty()) { | 83 if (commit_set->Empty()) { |
| 85 return false; | 84 return false; |
| 86 } | 85 } |
| 87 | 86 |
| 88 // Serialize the message. | 87 // Serialize the message. |
| 89 BuildCommitCommand build_commit_command(*commit_set, commit_message); | 88 BuildCommitCommand build_commit_command(*commit_set, commit_message); |
| 90 build_commit_command.Execute(session); | 89 build_commit_command.Execute(session); |
| 91 | 90 |
| 92 SetSyncingBits(session->write_transaction(), *commit_set); | 91 SetSyncingBits(session->write_transaction(), *commit_set); |
| 93 return true; | 92 return true; |
| 94 } | 93 } |
| 95 | 94 |
| 96 SyncerError BuildAndPostCommitsImpl(Syncer* syncer, | 95 SyncerError BuildAndPostCommitsImpl(Syncer* syncer, |
| 97 sessions::SyncSession* session, | 96 sessions::SyncSession* session, |
| 98 sessions::OrderedCommitSet* commit_set) { | 97 sessions::OrderedCommitSet* commit_set) { |
| 99 ClientToServerMessage commit_message; | 98 sync_pb::ClientToServerMessage commit_message; |
| 100 while (!syncer->ExitRequested() && | 99 while (!syncer->ExitRequested() && |
| 101 PrepareCommitMessage(session, commit_set, &commit_message)) { | 100 PrepareCommitMessage(session, commit_set, &commit_message)) { |
| 102 ClientToServerResponse commit_response; | 101 sync_pb::ClientToServerResponse commit_response; |
| 103 | 102 |
| 104 DVLOG(1) << "Sending commit message."; | 103 DVLOG(1) << "Sending commit message."; |
| 105 TRACE_EVENT_BEGIN0("sync", "PostCommit"); | 104 TRACE_EVENT_BEGIN0("sync", "PostCommit"); |
| 106 const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( | 105 const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( |
| 107 commit_message, &commit_response, session); | 106 commit_message, &commit_response, session); |
| 108 TRACE_EVENT_END0("sync", "PostCommit"); | 107 TRACE_EVENT_END0("sync", "PostCommit"); |
| 109 | 108 |
| 110 if (post_result != SYNCER_OK) { | 109 if (post_result != SYNCER_OK) { |
| 111 LOG(WARNING) << "Post commit failed"; | 110 LOG(WARNING) << "Post commit failed"; |
| 112 return post_result; | 111 return post_result; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 sessions::SyncSession* session) { | 148 sessions::SyncSession* session) { |
| 150 sessions::OrderedCommitSet commit_set(session->routing_info()); | 149 sessions::OrderedCommitSet commit_set(session->routing_info()); |
| 151 SyncerError result = BuildAndPostCommitsImpl(syncer, session, &commit_set); | 150 SyncerError result = BuildAndPostCommitsImpl(syncer, session, &commit_set); |
| 152 if (result != SYNCER_OK) { | 151 if (result != SYNCER_OK) { |
| 153 ClearSyncingBits(session->context()->directory(), commit_set); | 152 ClearSyncingBits(session->context()->directory(), commit_set); |
| 154 } | 153 } |
| 155 return result; | 154 return result; |
| 156 } | 155 } |
| 157 | 156 |
| 158 } // namespace syncer | 157 } // namespace syncer |
| OLD | NEW |