OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/process_commit_response_command.h" | 5 #include "chrome/browser/sync/engine/process_commit_response_command.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 bool ProcessCommitResponseCommand::ModelNeutralExecuteImpl( | 62 bool ProcessCommitResponseCommand::ModelNeutralExecuteImpl( |
63 sessions::SyncSession* session) { | 63 sessions::SyncSession* session) { |
64 ScopedDirLookup dir(session->context()->directory_manager(), | 64 ScopedDirLookup dir(session->context()->directory_manager(), |
65 session->context()->account_name()); | 65 session->context()->account_name()); |
66 if (!dir.good()) { | 66 if (!dir.good()) { |
67 LOG(ERROR) << "Scoped dir lookup failed!"; | 67 LOG(ERROR) << "Scoped dir lookup failed!"; |
68 return false; | 68 return false; |
69 } | 69 } |
70 | 70 |
71 StatusController* status = session->status_controller(); | 71 const StatusController& status = session->status_controller(); |
72 const ClientToServerResponse& response(status->commit_response()); | 72 const ClientToServerResponse& response(status.commit_response()); |
73 const vector<syncable::Id>& commit_ids(status->commit_ids()); | 73 const vector<syncable::Id>& commit_ids(status.commit_ids()); |
74 | 74 |
75 if (!response.has_commit()) { | 75 if (!response.has_commit()) { |
76 // TODO(sync): What if we didn't try to commit anything? | 76 // TODO(sync): What if we didn't try to commit anything? |
77 LOG(WARNING) << "Commit response has no commit body!"; | 77 LOG(WARNING) << "Commit response has no commit body!"; |
78 IncrementErrorCounters(status); | 78 IncrementErrorCounters(session->mutable_status_controller()); |
79 return false; | 79 return false; |
80 } | 80 } |
81 | 81 |
82 const CommitResponse& cr = response.commit(); | 82 const CommitResponse& cr = response.commit(); |
83 int commit_count = commit_ids.size(); | 83 int commit_count = commit_ids.size(); |
84 if (cr.entryresponse_size() != commit_count) { | 84 if (cr.entryresponse_size() != commit_count) { |
85 LOG(ERROR) << "Commit response has wrong number of entries! Expected:" << | 85 LOG(ERROR) << "Commit response has wrong number of entries! Expected:" << |
86 commit_count << " Got:" << cr.entryresponse_size(); | 86 commit_count << " Got:" << cr.entryresponse_size(); |
87 for (int i = 0 ; i < cr.entryresponse_size() ; i++) { | 87 for (int i = 0 ; i < cr.entryresponse_size() ; i++) { |
88 LOG(ERROR) << "Response #" << i << " Value: " << | 88 LOG(ERROR) << "Response #" << i << " Value: " << |
89 cr.entryresponse(i).response_type(); | 89 cr.entryresponse(i).response_type(); |
90 if (cr.entryresponse(i).has_error_message()) | 90 if (cr.entryresponse(i).has_error_message()) |
91 LOG(ERROR) << " " << cr.entryresponse(i).error_message(); | 91 LOG(ERROR) << " " << cr.entryresponse(i).error_message(); |
92 } | 92 } |
93 IncrementErrorCounters(status); | 93 IncrementErrorCounters(session->mutable_status_controller()); |
94 return false; | 94 return false; |
95 } | 95 } |
96 return true; | 96 return true; |
97 } | 97 } |
98 | 98 |
99 void ProcessCommitResponseCommand::ModelChangingExecuteImpl( | 99 void ProcessCommitResponseCommand::ModelChangingExecuteImpl( |
100 SyncSession* session) { | 100 SyncSession* session) { |
101 ProcessCommitResponse(session); | 101 ProcessCommitResponse(session); |
102 ExtensionsActivityMonitor* monitor = session->context()->extensions_monitor(); | 102 ExtensionsActivityMonitor* monitor = session->context()->extensions_monitor(); |
103 if (session->status_controller()->HasBookmarkCommitActivity() && | 103 if (session->status_controller().HasBookmarkCommitActivity() && |
104 session->status_controller()->syncer_status() | 104 session->status_controller().syncer_status() |
105 .num_successful_bookmark_commits == 0) { | 105 .num_successful_bookmark_commits == 0) { |
106 monitor->PutRecords(session->extensions_activity()); | 106 monitor->PutRecords(session->extensions_activity()); |
107 session->mutable_extensions_activity()->clear(); | 107 session->mutable_extensions_activity()->clear(); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 void ProcessCommitResponseCommand::ProcessCommitResponse( | 111 void ProcessCommitResponseCommand::ProcessCommitResponse( |
112 SyncSession* session) { | 112 SyncSession* session) { |
113 // TODO(sync): This function returns if it sees problems. We probably want | 113 // TODO(sync): This function returns if it sees problems. We probably want |
114 // to flag the need for an update or similar. | 114 // to flag the need for an update or similar. |
115 ScopedDirLookup dir(session->context()->directory_manager(), | 115 ScopedDirLookup dir(session->context()->directory_manager(), |
116 session->context()->account_name()); | 116 session->context()->account_name()); |
117 if (!dir.good()) { | 117 if (!dir.good()) { |
118 LOG(ERROR) << "Scoped dir lookup failed!"; | 118 LOG(ERROR) << "Scoped dir lookup failed!"; |
119 return; | 119 return; |
120 } | 120 } |
121 | 121 |
122 StatusController* status = session->status_controller(); | 122 StatusController* status = session->mutable_status_controller(); |
123 const ClientToServerResponse& response(status->commit_response()); | 123 const ClientToServerResponse& response(status->commit_response()); |
124 const CommitResponse& cr = response.commit(); | 124 const CommitResponse& cr = response.commit(); |
125 const sync_pb::CommitMessage& commit_message = | 125 const sync_pb::CommitMessage& commit_message = |
126 status->commit_message().commit(); | 126 status->commit_message().commit(); |
127 | 127 |
128 // If we try to commit a parent and child together and the parent conflicts | 128 // If we try to commit a parent and child together and the parent conflicts |
129 // the child will have a bad parent causing an error. As this is not a | 129 // the child will have a bad parent causing an error. As this is not a |
130 // critical error, we trap it and don't LOG(ERROR). To enable this we keep | 130 // critical error, we trap it and don't LOG(ERROR). To enable this we keep |
131 // a map of conflicting new folders. | 131 // a map of conflicting new folders. |
132 int transient_error_commits = 0; | 132 int transient_error_commits = 0; |
(...skipping 19 matching lines...) Expand all Loading... |
152 break; | 152 break; |
153 case CommitResponse::CONFLICT: | 153 case CommitResponse::CONFLICT: |
154 ++conflicting_commits; | 154 ++conflicting_commits; |
155 // Only server CONFLICT responses will activate conflict resolution. | 155 // Only server CONFLICT responses will activate conflict resolution. |
156 conflict_progress->AddConflictingItemById( | 156 conflict_progress->AddConflictingItemById( |
157 status->GetCommitIdAt(proj[i])); | 157 status->GetCommitIdAt(proj[i])); |
158 break; | 158 break; |
159 case CommitResponse::SUCCESS: | 159 case CommitResponse::SUCCESS: |
160 // TODO(sync): worry about sync_rate_ rate calc? | 160 // TODO(sync): worry about sync_rate_ rate calc? |
161 ++successes; | 161 ++successes; |
162 if (status->GetCommitIdModelTypeAt(proj[i]) == syncable::BOOKMARKS) | 162 if (status->GetCommitModelTypeAt(proj[i]) == syncable::BOOKMARKS) |
163 status->increment_num_successful_bookmark_commits(); | 163 status->increment_num_successful_bookmark_commits(); |
164 status->increment_num_successful_commits(); | 164 status->increment_num_successful_commits(); |
165 break; | 165 break; |
166 case CommitResponse::OVER_QUOTA: | 166 case CommitResponse::OVER_QUOTA: |
167 // We handle over quota like a retry, which is same as transient. | 167 // We handle over quota like a retry, which is same as transient. |
168 case CommitResponse::RETRY: | 168 case CommitResponse::RETRY: |
169 case CommitResponse::TRANSIENT_ERROR: | 169 case CommitResponse::TRANSIENT_ERROR: |
170 // TODO(tim): Now that we have SyncSession::Delegate, we | 170 // TODO(tim): Now that we have SyncSession::Delegate, we |
171 // should plumb this directly for exponential backoff purposes rather | 171 // should plumb this directly for exponential backoff purposes rather |
172 // than trying to infer from HasMoreToSync(). See | 172 // than trying to infer from HasMoreToSync(). See |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 // been recursively deleted. | 485 // been recursively deleted. |
486 // TODO(nick): Here, commit_message.deleted() would be more correct than | 486 // TODO(nick): Here, commit_message.deleted() would be more correct than |
487 // local_entry->Get(IS_DEL). For example, an item could be renamed, and then | 487 // local_entry->Get(IS_DEL). For example, an item could be renamed, and then |
488 // deleted during the commit of the rename. Unit test & fix. | 488 // deleted during the commit of the rename. Unit test & fix. |
489 if (local_entry->Get(IS_DIR) && local_entry->Get(IS_DEL)) { | 489 if (local_entry->Get(IS_DIR) && local_entry->Get(IS_DEL)) { |
490 deleted_folders->insert(local_entry->Get(ID)); | 490 deleted_folders->insert(local_entry->Get(ID)); |
491 } | 491 } |
492 } | 492 } |
493 | 493 |
494 } // namespace browser_sync | 494 } // namespace browser_sync |
OLD | NEW |