| 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 "sync/engine/commit.h" |
| 6 | 6 |
| 7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
| 8 #include "sync/engine/commit_contribution.h" | 8 #include "sync/engine/commit_contribution.h" |
| 9 #include "sync/engine/commit_processor.h" | 9 #include "sync/engine/commit_processor.h" |
| 10 #include "sync/engine/commit_util.h" | 10 #include "sync/engine/commit_util.h" |
| 11 #include "sync/engine/syncer.h" | 11 #include "sync/engine/syncer.h" |
| 12 #include "sync/engine/syncer_proto_util.h" | 12 #include "sync/engine/syncer_proto_util.h" |
| 13 #include "sync/internal_api/public/events/commit_request_event.h" | 13 #include "sync/internal_api/public/events/commit_request_event.h" |
| 14 #include "sync/internal_api/public/events/commit_response_event.h" | 14 #include "sync/internal_api/public/events/commit_response_event.h" |
| 15 #include "sync/sessions/sync_session.h" | 15 #include "sync/sessions/sync_session.h" |
| 16 | 16 |
| 17 namespace syncer { | 17 namespace syncer { |
| 18 | 18 |
| 19 Commit::Commit( | 19 Commit::Commit(ContributionMap contributions, |
| 20 const std::map<ModelType, CommitContribution*>& contributions, | 20 const sync_pb::ClientToServerMessage& message, |
| 21 const sync_pb::ClientToServerMessage& message, | 21 ExtensionsActivity::Records extensions_activity_buffer) |
| 22 ExtensionsActivity::Records extensions_activity_buffer) | 22 : contributions_(contributions.Pass()), |
| 23 : contributions_(contributions), | 23 message_(message), |
| 24 deleter_(&contributions_), | 24 extensions_activity_buffer_(extensions_activity_buffer), |
| 25 message_(message), | 25 cleaned_up_(false) { |
| 26 extensions_activity_buffer_(extensions_activity_buffer), | |
| 27 cleaned_up_(false) { | |
| 28 } | 26 } |
| 29 | 27 |
| 30 Commit::~Commit() { | 28 Commit::~Commit() { |
| 31 DCHECK(cleaned_up_); | 29 DCHECK(cleaned_up_); |
| 32 } | 30 } |
| 33 | 31 |
| 34 Commit* Commit::Init( | 32 Commit* Commit::Init( |
| 35 ModelTypeSet requested_types, | 33 ModelTypeSet requested_types, |
| 36 ModelTypeSet enabled_types, | 34 ModelTypeSet enabled_types, |
| 37 size_t max_entries, | 35 size_t max_entries, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 52 | 50 |
| 53 sync_pb::ClientToServerMessage message; | 51 sync_pb::ClientToServerMessage message; |
| 54 message.set_message_contents(sync_pb::ClientToServerMessage::COMMIT); | 52 message.set_message_contents(sync_pb::ClientToServerMessage::COMMIT); |
| 55 message.set_share(account_name); | 53 message.set_share(account_name); |
| 56 | 54 |
| 57 sync_pb::CommitMessage* commit_message = message.mutable_commit(); | 55 sync_pb::CommitMessage* commit_message = message.mutable_commit(); |
| 58 commit_message->set_cache_guid(cache_guid); | 56 commit_message->set_cache_guid(cache_guid); |
| 59 | 57 |
| 60 // Set extensions activity if bookmark commits are present. | 58 // Set extensions activity if bookmark commits are present. |
| 61 ExtensionsActivity::Records extensions_activity_buffer; | 59 ExtensionsActivity::Records extensions_activity_buffer; |
| 62 ContributionMap::iterator it = contributions.find(syncer::BOOKMARKS); | 60 ContributionMap::const_iterator it = contributions.find(syncer::BOOKMARKS); |
| 63 if (it != contributions.end() && it->second->GetNumEntries() != 0) { | 61 if (it != contributions.end() && it->second->GetNumEntries() != 0) { |
| 64 commit_util::AddExtensionsActivityToMessage( | 62 commit_util::AddExtensionsActivityToMessage( |
| 65 extensions_activity, | 63 extensions_activity, |
| 66 &extensions_activity_buffer, | 64 &extensions_activity_buffer, |
| 67 commit_message); | 65 commit_message); |
| 68 } | 66 } |
| 69 | 67 |
| 70 // Set the client config params. | 68 // Set the client config params. |
| 71 commit_util::AddClientConfigParamsToMessage( | 69 commit_util::AddClientConfigParamsToMessage( |
| 72 enabled_types, | 70 enabled_types, |
| 73 commit_message); | 71 commit_message); |
| 74 | 72 |
| 75 // Finally, serialize all our contributions. | 73 // Finally, serialize all our contributions. |
| 76 for (std::map<ModelType, CommitContribution*>::iterator it = | 74 for (std::map<ModelType, CommitContribution*>::const_iterator it = |
| 77 contributions.begin(); it != contributions.end(); ++it) { | 75 contributions.begin(); |
| 76 it != contributions.end(); ++it) { |
| 78 it->second->AddToCommitMessage(&message); | 77 it->second->AddToCommitMessage(&message); |
| 79 } | 78 } |
| 80 | 79 |
| 81 // If we made it this far, then we've successfully prepared a commit message. | 80 // If we made it this far, then we've successfully prepared a commit message. |
| 82 return new Commit(contributions, message, extensions_activity_buffer); | 81 return new Commit(contributions.Pass(), message, extensions_activity_buffer); |
| 83 } | 82 } |
| 84 | 83 |
| 85 SyncerError Commit::PostAndProcessResponse( | 84 SyncerError Commit::PostAndProcessResponse( |
| 86 sessions::NudgeTracker* nudge_tracker, | 85 sessions::NudgeTracker* nudge_tracker, |
| 87 sessions::SyncSession* session, | 86 sessions::SyncSession* session, |
| 88 sessions::StatusController* status, | 87 sessions::StatusController* status, |
| 89 ExtensionsActivity* extensions_activity) { | 88 ExtensionsActivity* extensions_activity) { |
| 90 ModelTypeSet request_types; | 89 ModelTypeSet request_types; |
| 91 for (ContributionMap::const_iterator it = contributions_.begin(); | 90 for (ContributionMap::const_iterator it = contributions_.begin(); |
| 92 it != contributions_.end(); ++it) { | 91 it != contributions_.end(); ++it) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 140 } |
| 142 | 141 |
| 143 if (session->context()->debug_info_getter()) { | 142 if (session->context()->debug_info_getter()) { |
| 144 // Clear debug info now that we have successfully sent it to the server. | 143 // Clear debug info now that we have successfully sent it to the server. |
| 145 DVLOG(1) << "Clearing client debug info."; | 144 DVLOG(1) << "Clearing client debug info."; |
| 146 session->context()->debug_info_getter()->ClearDebugInfo(); | 145 session->context()->debug_info_getter()->ClearDebugInfo(); |
| 147 } | 146 } |
| 148 | 147 |
| 149 // Let the contributors process the responses to each of their requests. | 148 // Let the contributors process the responses to each of their requests. |
| 150 SyncerError processing_result = SYNCER_OK; | 149 SyncerError processing_result = SYNCER_OK; |
| 151 for (std::map<ModelType, CommitContribution*>::iterator it = | 150 for (ContributionMap::const_iterator it = contributions_.begin(); |
| 152 contributions_.begin(); it != contributions_.end(); ++it) { | 151 it != contributions_.end(); ++it) { |
| 153 TRACE_EVENT1("sync", "ProcessCommitResponse", | 152 TRACE_EVENT1("sync", "ProcessCommitResponse", |
| 154 "type", ModelTypeToString(it->first)); | 153 "type", ModelTypeToString(it->first)); |
| 155 SyncerError type_result = | 154 SyncerError type_result = |
| 156 it->second->ProcessCommitResponse(response_, status); | 155 it->second->ProcessCommitResponse(response_, status); |
| 157 if (type_result == SERVER_RETURN_CONFLICT) { | 156 if (type_result == SERVER_RETURN_CONFLICT) { |
| 158 nudge_tracker->RecordCommitConflict(it->first); | 157 nudge_tracker->RecordCommitConflict(it->first); |
| 159 } | 158 } |
| 160 if (processing_result == SYNCER_OK && type_result != SYNCER_OK) { | 159 if (processing_result == SYNCER_OK && type_result != SYNCER_OK) { |
| 161 processing_result = type_result; | 160 processing_result = type_result; |
| 162 } | 161 } |
| 163 } | 162 } |
| 164 | 163 |
| 165 // Handle bookmarks' special extensions activity stats. | 164 // Handle bookmarks' special extensions activity stats. |
| 166 if (session->status_controller(). | 165 if (session->status_controller(). |
| 167 model_neutral_state().num_successful_bookmark_commits == 0) { | 166 model_neutral_state().num_successful_bookmark_commits == 0) { |
| 168 extensions_activity->PutRecords(extensions_activity_buffer_); | 167 extensions_activity->PutRecords(extensions_activity_buffer_); |
| 169 } | 168 } |
| 170 | 169 |
| 171 return processing_result; | 170 return processing_result; |
| 172 } | 171 } |
| 173 | 172 |
| 174 void Commit::CleanUp() { | 173 void Commit::CleanUp() { |
| 175 for (ContributionMap::iterator it = contributions_.begin(); | 174 for (ContributionMap::const_iterator it = contributions_.begin(); |
| 176 it != contributions_.end(); ++it) { | 175 it != contributions_.end(); ++it) { |
| 177 it->second->CleanUp(); | 176 it->second->CleanUp(); |
| 178 } | 177 } |
| 179 cleaned_up_ = true; | 178 cleaned_up_ = true; |
| 180 } | 179 } |
| 181 | 180 |
| 182 } // namespace syncer | 181 } // namespace syncer |
| OLD | NEW |