| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/sync/engine_impl/commit.h" | 5 #include "components/sync/engine_impl/commit.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/metrics/sparse_histogram.h" | 9 #include "base/metrics/sparse_histogram.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "components/sync/base/data_type_histogram.h" | 11 #include "components/sync/base/data_type_histogram.h" |
| 12 #include "components/sync/engine/events/commit_request_event.h" | 12 #include "components/sync/engine/events/commit_request_event.h" |
| 13 #include "components/sync/engine/events/commit_response_event.h" | 13 #include "components/sync/engine/events/commit_response_event.h" |
| 14 #include "components/sync/engine_impl/commit_contribution.h" | 14 #include "components/sync/engine_impl/commit_contribution.h" |
| 15 #include "components/sync/engine_impl/commit_processor.h" | 15 #include "components/sync/engine_impl/commit_processor.h" |
| 16 #include "components/sync/engine_impl/commit_util.h" | 16 #include "components/sync/engine_impl/commit_util.h" |
| 17 #include "components/sync/engine_impl/cycle/sync_cycle.h" |
| 17 #include "components/sync/engine_impl/syncer.h" | 18 #include "components/sync/engine_impl/syncer.h" |
| 18 #include "components/sync/engine_impl/syncer_proto_util.h" | 19 #include "components/sync/engine_impl/syncer_proto_util.h" |
| 19 #include "components/sync/sessions_impl/sync_session.h" | |
| 20 | 20 |
| 21 namespace syncer { | 21 namespace syncer { |
| 22 | 22 |
| 23 Commit::Commit(ContributionMap contributions, | 23 Commit::Commit(ContributionMap contributions, |
| 24 const sync_pb::ClientToServerMessage& message, | 24 const sync_pb::ClientToServerMessage& message, |
| 25 ExtensionsActivity::Records extensions_activity_buffer) | 25 ExtensionsActivity::Records extensions_activity_buffer) |
| 26 : contributions_(std::move(contributions)), | 26 : contributions_(std::move(contributions)), |
| 27 message_(message), | 27 message_(message), |
| 28 extensions_activity_buffer_(extensions_activity_buffer), | 28 extensions_activity_buffer_(extensions_activity_buffer), |
| 29 cleaned_up_(false) {} | 29 cleaned_up_(false) {} |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 UMA_HISTOGRAM_SPARSE_SLOWLY("DataUse.Sync.Upload.Count", | 84 UMA_HISTOGRAM_SPARSE_SLOWLY("DataUse.Sync.Upload.Count", |
| 85 local_integer_model_type); | 85 local_integer_model_type); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // If we made it this far, then we've successfully prepared a commit message. | 88 // If we made it this far, then we've successfully prepared a commit message. |
| 89 return new Commit(std::move(contributions), message, | 89 return new Commit(std::move(contributions), message, |
| 90 extensions_activity_buffer); | 90 extensions_activity_buffer); |
| 91 } | 91 } |
| 92 | 92 |
| 93 SyncerError Commit::PostAndProcessResponse( | 93 SyncerError Commit::PostAndProcessResponse( |
| 94 sessions::NudgeTracker* nudge_tracker, | 94 NudgeTracker* nudge_tracker, |
| 95 sessions::SyncSession* session, | 95 SyncCycle* cycle, |
| 96 sessions::StatusController* status, | 96 StatusController* status, |
| 97 ExtensionsActivity* extensions_activity) { | 97 ExtensionsActivity* extensions_activity) { |
| 98 ModelTypeSet request_types; | 98 ModelTypeSet request_types; |
| 99 for (ContributionMap::const_iterator it = contributions_.begin(); | 99 for (ContributionMap::const_iterator it = contributions_.begin(); |
| 100 it != contributions_.end(); ++it) { | 100 it != contributions_.end(); ++it) { |
| 101 request_types.Put(it->first); | 101 request_types.Put(it->first); |
| 102 } | 102 } |
| 103 session->mutable_status_controller()->set_commit_request_types(request_types); | 103 cycle->mutable_status_controller()->set_commit_request_types(request_types); |
| 104 | 104 |
| 105 if (session->context()->debug_info_getter()) { | 105 if (cycle->context()->debug_info_getter()) { |
| 106 sync_pb::DebugInfo* debug_info = message_.mutable_debug_info(); | 106 sync_pb::DebugInfo* debug_info = message_.mutable_debug_info(); |
| 107 session->context()->debug_info_getter()->GetDebugInfo(debug_info); | 107 cycle->context()->debug_info_getter()->GetDebugInfo(debug_info); |
| 108 } | 108 } |
| 109 | 109 |
| 110 DVLOG(1) << "Sending commit message."; | 110 DVLOG(1) << "Sending commit message."; |
| 111 | 111 |
| 112 CommitRequestEvent request_event(base::Time::Now(), | 112 CommitRequestEvent request_event(base::Time::Now(), |
| 113 message_.commit().entries_size(), | 113 message_.commit().entries_size(), |
| 114 request_types, message_); | 114 request_types, message_); |
| 115 session->SendProtocolEvent(request_event); | 115 cycle->SendProtocolEvent(request_event); |
| 116 | 116 |
| 117 TRACE_EVENT_BEGIN0("sync", "PostCommit"); | 117 TRACE_EVENT_BEGIN0("sync", "PostCommit"); |
| 118 const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( | 118 const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( |
| 119 &message_, &response_, session, NULL); | 119 &message_, &response_, cycle, NULL); |
| 120 TRACE_EVENT_END0("sync", "PostCommit"); | 120 TRACE_EVENT_END0("sync", "PostCommit"); |
| 121 | 121 |
| 122 // TODO(rlarocque): Use result that includes errors captured later? | 122 // TODO(rlarocque): Use result that includes errors captured later? |
| 123 CommitResponseEvent response_event(base::Time::Now(), post_result, response_); | 123 CommitResponseEvent response_event(base::Time::Now(), post_result, response_); |
| 124 session->SendProtocolEvent(response_event); | 124 cycle->SendProtocolEvent(response_event); |
| 125 | 125 |
| 126 if (post_result != SYNCER_OK) { | 126 if (post_result != SYNCER_OK) { |
| 127 LOG(WARNING) << "Post commit failed"; | 127 LOG(WARNING) << "Post commit failed"; |
| 128 return post_result; | 128 return post_result; |
| 129 } | 129 } |
| 130 | 130 |
| 131 if (!response_.has_commit()) { | 131 if (!response_.has_commit()) { |
| 132 LOG(WARNING) << "Commit response has no commit body!"; | 132 LOG(WARNING) << "Commit response has no commit body!"; |
| 133 return SERVER_RESPONSE_VALIDATION_FAILED; | 133 return SERVER_RESPONSE_VALIDATION_FAILED; |
| 134 } | 134 } |
| 135 | 135 |
| 136 size_t message_entries = message_.commit().entries_size(); | 136 size_t message_entries = message_.commit().entries_size(); |
| 137 size_t response_entries = response_.commit().entryresponse_size(); | 137 size_t response_entries = response_.commit().entryresponse_size(); |
| 138 if (message_entries != response_entries) { | 138 if (message_entries != response_entries) { |
| 139 LOG(ERROR) << "Commit response has wrong number of entries! " | 139 LOG(ERROR) << "Commit response has wrong number of entries! " |
| 140 << "Expected: " << message_entries << ", " | 140 << "Expected: " << message_entries << ", " |
| 141 << "Got: " << response_entries; | 141 << "Got: " << response_entries; |
| 142 return SERVER_RESPONSE_VALIDATION_FAILED; | 142 return SERVER_RESPONSE_VALIDATION_FAILED; |
| 143 } | 143 } |
| 144 | 144 |
| 145 if (session->context()->debug_info_getter()) { | 145 if (cycle->context()->debug_info_getter()) { |
| 146 // Clear debug info now that we have successfully sent it to the server. | 146 // Clear debug info now that we have successfully sent it to the server. |
| 147 DVLOG(1) << "Clearing client debug info."; | 147 DVLOG(1) << "Clearing client debug info."; |
| 148 session->context()->debug_info_getter()->ClearDebugInfo(); | 148 cycle->context()->debug_info_getter()->ClearDebugInfo(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Let the contributors process the responses to each of their requests. | 151 // Let the contributors process the responses to each of their requests. |
| 152 SyncerError processing_result = SYNCER_OK; | 152 SyncerError processing_result = SYNCER_OK; |
| 153 for (ContributionMap::const_iterator it = contributions_.begin(); | 153 for (ContributionMap::const_iterator it = contributions_.begin(); |
| 154 it != contributions_.end(); ++it) { | 154 it != contributions_.end(); ++it) { |
| 155 TRACE_EVENT1("sync", "ProcessCommitResponse", "type", | 155 TRACE_EVENT1("sync", "ProcessCommitResponse", "type", |
| 156 ModelTypeToString(it->first)); | 156 ModelTypeToString(it->first)); |
| 157 SyncerError type_result = | 157 SyncerError type_result = |
| 158 it->second->ProcessCommitResponse(response_, status); | 158 it->second->ProcessCommitResponse(response_, status); |
| 159 if (type_result == SERVER_RETURN_CONFLICT) { | 159 if (type_result == SERVER_RETURN_CONFLICT) { |
| 160 nudge_tracker->RecordCommitConflict(it->first); | 160 nudge_tracker->RecordCommitConflict(it->first); |
| 161 } | 161 } |
| 162 if (processing_result == SYNCER_OK && type_result != SYNCER_OK) { | 162 if (processing_result == SYNCER_OK && type_result != SYNCER_OK) { |
| 163 processing_result = type_result; | 163 processing_result = type_result; |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Handle bookmarks' special extensions activity stats. | 167 // Handle bookmarks' special extensions activity stats. |
| 168 if (session->status_controller() | 168 if (cycle->status_controller() |
| 169 .model_neutral_state() | 169 .model_neutral_state() |
| 170 .num_successful_bookmark_commits == 0) { | 170 .num_successful_bookmark_commits == 0) { |
| 171 extensions_activity->PutRecords(extensions_activity_buffer_); | 171 extensions_activity->PutRecords(extensions_activity_buffer_); |
| 172 } | 172 } |
| 173 | 173 |
| 174 return processing_result; | 174 return processing_result; |
| 175 } | 175 } |
| 176 | 176 |
| 177 void Commit::CleanUp() { | 177 void Commit::CleanUp() { |
| 178 for (ContributionMap::const_iterator it = contributions_.begin(); | 178 for (ContributionMap::const_iterator it = contributions_.begin(); |
| 179 it != contributions_.end(); ++it) { | 179 it != contributions_.end(); ++it) { |
| 180 it->second->CleanUp(); | 180 it->second->CleanUp(); |
| 181 } | 181 } |
| 182 cleaned_up_ = true; | 182 cleaned_up_ = true; |
| 183 } | 183 } |
| 184 | 184 |
| 185 } // namespace syncer | 185 } // namespace syncer |
| OLD | NEW |