| 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 "sync/engine/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 "sync/engine/commit_contribution.h" | 11 #include "components/sync/base/data_type_histogram.h" | 
| 12 #include "sync/engine/commit_processor.h" | 12 #include "components/sync/engine/events/commit_request_event.h" | 
| 13 #include "sync/engine/commit_util.h" | 13 #include "components/sync/engine/events/commit_response_event.h" | 
| 14 #include "sync/engine/syncer.h" | 14 #include "components/sync/engine_impl/commit_contribution.h" | 
| 15 #include "sync/engine/syncer_proto_util.h" | 15 #include "components/sync/engine_impl/commit_processor.h" | 
| 16 #include "sync/internal_api/public/events/commit_request_event.h" | 16 #include "components/sync/engine_impl/commit_util.h" | 
| 17 #include "sync/internal_api/public/events/commit_response_event.h" | 17 #include "components/sync/engine_impl/syncer.h" | 
| 18 #include "sync/sessions/sync_session.h" | 18 #include "components/sync/engine_impl/syncer_proto_util.h" | 
| 19 #include "sync/util/data_type_histogram.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 26 matching lines...) Expand all  Loading... | 
| 56   message.set_share(account_name); | 56   message.set_share(account_name); | 
| 57 | 57 | 
| 58   sync_pb::CommitMessage* commit_message = message.mutable_commit(); | 58   sync_pb::CommitMessage* commit_message = message.mutable_commit(); | 
| 59   commit_message->set_cache_guid(cache_guid); | 59   commit_message->set_cache_guid(cache_guid); | 
| 60 | 60 | 
| 61   // Set extensions activity if bookmark commits are present. | 61   // Set extensions activity if bookmark commits are present. | 
| 62   ExtensionsActivity::Records extensions_activity_buffer; | 62   ExtensionsActivity::Records extensions_activity_buffer; | 
| 63   ContributionMap::const_iterator it = contributions.find(syncer::BOOKMARKS); | 63   ContributionMap::const_iterator it = contributions.find(syncer::BOOKMARKS); | 
| 64   if (it != contributions.end() && it->second->GetNumEntries() != 0) { | 64   if (it != contributions.end() && it->second->GetNumEntries() != 0) { | 
| 65     commit_util::AddExtensionsActivityToMessage( | 65     commit_util::AddExtensionsActivityToMessage( | 
| 66         extensions_activity, | 66         extensions_activity, &extensions_activity_buffer, commit_message); | 
| 67         &extensions_activity_buffer, |  | 
| 68         commit_message); |  | 
| 69   } | 67   } | 
| 70 | 68 | 
| 71   // Set the client config params. | 69   // Set the client config params. | 
| 72   commit_util::AddClientConfigParamsToMessage( | 70   commit_util::AddClientConfigParamsToMessage( | 
| 73       enabled_types, | 71       enabled_types, cookie_jar_mismatch, commit_message); | 
| 74       cookie_jar_mismatch, |  | 
| 75       commit_message); |  | 
| 76 | 72 | 
| 77   int previous_message_size = message.ByteSize(); | 73   int previous_message_size = message.ByteSize(); | 
| 78   // Finally, serialize all our contributions. | 74   // Finally, serialize all our contributions. | 
| 79   for (const auto& contribution : contributions) { | 75   for (const auto& contribution : contributions) { | 
| 80     contribution.second->AddToCommitMessage(&message); | 76     contribution.second->AddToCommitMessage(&message); | 
| 81     int current_entry_size = message.ByteSize() - previous_message_size; | 77     int current_entry_size = message.ByteSize() - previous_message_size; | 
| 82     previous_message_size = message.ByteSize(); | 78     previous_message_size = message.ByteSize(); | 
| 83     int local_integer_model_type = ModelTypeToHistogramInt(contribution.first); | 79     int local_integer_model_type = ModelTypeToHistogramInt(contribution.first); | 
| 84     if (current_entry_size > 0) { | 80     if (current_entry_size > 0) { | 
| 85       SyncRecordDatatypeBin("DataUse.Sync.Upload.Bytes", | 81       SyncRecordDatatypeBin("DataUse.Sync.Upload.Bytes", | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 106   } | 102   } | 
| 107   session->mutable_status_controller()->set_commit_request_types(request_types); | 103   session->mutable_status_controller()->set_commit_request_types(request_types); | 
| 108 | 104 | 
| 109   if (session->context()->debug_info_getter()) { | 105   if (session->context()->debug_info_getter()) { | 
| 110     sync_pb::DebugInfo* debug_info = message_.mutable_debug_info(); | 106     sync_pb::DebugInfo* debug_info = message_.mutable_debug_info(); | 
| 111     session->context()->debug_info_getter()->GetDebugInfo(debug_info); | 107     session->context()->debug_info_getter()->GetDebugInfo(debug_info); | 
| 112   } | 108   } | 
| 113 | 109 | 
| 114   DVLOG(1) << "Sending commit message."; | 110   DVLOG(1) << "Sending commit message."; | 
| 115 | 111 | 
| 116   CommitRequestEvent request_event( | 112   CommitRequestEvent request_event(base::Time::Now(), | 
| 117       base::Time::Now(), | 113                                    message_.commit().entries_size(), | 
| 118       message_.commit().entries_size(), | 114                                    request_types, message_); | 
| 119       request_types, |  | 
| 120       message_); |  | 
| 121   session->SendProtocolEvent(request_event); | 115   session->SendProtocolEvent(request_event); | 
| 122 | 116 | 
| 123   TRACE_EVENT_BEGIN0("sync", "PostCommit"); | 117   TRACE_EVENT_BEGIN0("sync", "PostCommit"); | 
| 124   const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( | 118   const SyncerError post_result = SyncerProtoUtil::PostClientToServerMessage( | 
| 125       &message_, &response_, session, NULL); | 119       &message_, &response_, session, NULL); | 
| 126   TRACE_EVENT_END0("sync", "PostCommit"); | 120   TRACE_EVENT_END0("sync", "PostCommit"); | 
| 127 | 121 | 
| 128   // TODO(rlarocque): Use result that includes errors captured later? | 122   // TODO(rlarocque): Use result that includes errors captured later? | 
| 129   CommitResponseEvent response_event( | 123   CommitResponseEvent response_event(base::Time::Now(), post_result, response_); | 
| 130       base::Time::Now(), |  | 
| 131       post_result, |  | 
| 132       response_); |  | 
| 133   session->SendProtocolEvent(response_event); | 124   session->SendProtocolEvent(response_event); | 
| 134 | 125 | 
| 135   if (post_result != SYNCER_OK) { | 126   if (post_result != SYNCER_OK) { | 
| 136     LOG(WARNING) << "Post commit failed"; | 127     LOG(WARNING) << "Post commit failed"; | 
| 137     return post_result; | 128     return post_result; | 
| 138   } | 129   } | 
| 139 | 130 | 
| 140   if (!response_.has_commit()) { | 131   if (!response_.has_commit()) { | 
| 141     LOG(WARNING) << "Commit response has no commit body!"; | 132     LOG(WARNING) << "Commit response has no commit body!"; | 
| 142     return SERVER_RESPONSE_VALIDATION_FAILED; | 133     return SERVER_RESPONSE_VALIDATION_FAILED; | 
| 143   } | 134   } | 
| 144 | 135 | 
| 145   size_t message_entries = message_.commit().entries_size(); | 136   size_t message_entries = message_.commit().entries_size(); | 
| 146   size_t response_entries = response_.commit().entryresponse_size(); | 137   size_t response_entries = response_.commit().entryresponse_size(); | 
| 147   if (message_entries != response_entries) { | 138   if (message_entries != response_entries) { | 
| 148     LOG(ERROR) | 139     LOG(ERROR) << "Commit response has wrong number of entries! " | 
| 149        << "Commit response has wrong number of entries! " | 140                << "Expected: " << message_entries << ", " | 
| 150        << "Expected: " << message_entries << ", " | 141                << "Got: " << response_entries; | 
| 151        << "Got: " << response_entries; |  | 
| 152     return SERVER_RESPONSE_VALIDATION_FAILED; | 142     return SERVER_RESPONSE_VALIDATION_FAILED; | 
| 153   } | 143   } | 
| 154 | 144 | 
| 155   if (session->context()->debug_info_getter()) { | 145   if (session->context()->debug_info_getter()) { | 
| 156     // 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. | 
| 157     DVLOG(1) << "Clearing client debug info."; | 147     DVLOG(1) << "Clearing client debug info."; | 
| 158     session->context()->debug_info_getter()->ClearDebugInfo(); | 148     session->context()->debug_info_getter()->ClearDebugInfo(); | 
| 159   } | 149   } | 
| 160 | 150 | 
| 161   // Let the contributors process the responses to each of their requests. | 151   // Let the contributors process the responses to each of their requests. | 
| 162   SyncerError processing_result = SYNCER_OK; | 152   SyncerError processing_result = SYNCER_OK; | 
| 163   for (ContributionMap::const_iterator it = contributions_.begin(); | 153   for (ContributionMap::const_iterator it = contributions_.begin(); | 
| 164        it != contributions_.end(); ++it) { | 154        it != contributions_.end(); ++it) { | 
| 165     TRACE_EVENT1("sync", "ProcessCommitResponse", | 155     TRACE_EVENT1("sync", "ProcessCommitResponse", "type", | 
| 166                  "type", ModelTypeToString(it->first)); | 156                  ModelTypeToString(it->first)); | 
| 167     SyncerError type_result = | 157     SyncerError type_result = | 
| 168         it->second->ProcessCommitResponse(response_, status); | 158         it->second->ProcessCommitResponse(response_, status); | 
| 169     if (type_result == SERVER_RETURN_CONFLICT) { | 159     if (type_result == SERVER_RETURN_CONFLICT) { | 
| 170       nudge_tracker->RecordCommitConflict(it->first); | 160       nudge_tracker->RecordCommitConflict(it->first); | 
| 171     } | 161     } | 
| 172     if (processing_result == SYNCER_OK && type_result != SYNCER_OK) { | 162     if (processing_result == SYNCER_OK && type_result != SYNCER_OK) { | 
| 173       processing_result = type_result; | 163       processing_result = type_result; | 
| 174     } | 164     } | 
| 175   } | 165   } | 
| 176 | 166 | 
| 177   // Handle bookmarks' special extensions activity stats. | 167   // Handle bookmarks' special extensions activity stats. | 
| 178   if (session->status_controller(). | 168   if (session->status_controller() | 
| 179           model_neutral_state().num_successful_bookmark_commits == 0) { | 169           .model_neutral_state() | 
|  | 170           .num_successful_bookmark_commits == 0) { | 
| 180     extensions_activity->PutRecords(extensions_activity_buffer_); | 171     extensions_activity->PutRecords(extensions_activity_buffer_); | 
| 181   } | 172   } | 
| 182 | 173 | 
| 183   return processing_result; | 174   return processing_result; | 
| 184 } | 175 } | 
| 185 | 176 | 
| 186 void Commit::CleanUp() { | 177 void Commit::CleanUp() { | 
| 187   for (ContributionMap::const_iterator it = contributions_.begin(); | 178   for (ContributionMap::const_iterator it = contributions_.begin(); | 
| 188        it != contributions_.end(); ++it) { | 179        it != contributions_.end(); ++it) { | 
| 189     it->second->CleanUp(); | 180     it->second->CleanUp(); | 
| 190   } | 181   } | 
| 191   cleaned_up_ = true; | 182   cleaned_up_ = true; | 
| 192 } | 183 } | 
| 193 | 184 | 
| 194 }  // namespace syncer | 185 }  // namespace syncer | 
| OLD | NEW | 
|---|