Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: sync/engine/process_commit_response_command.cc

Issue 10523003: Refactor following sync commit loop change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another rebase Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/process_commit_response_command.h ('k') | sync/engine/syncer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/process_commit_response_command.h" 5 #include "sync/engine/process_commit_response_command.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 syncable::ReadTransaction trans(FROM_HERE, dir); 67 syncable::ReadTransaction trans(FROM_HERE, dir);
68 for (size_t i = 0; i < commit_set_.Size(); ++i) { 68 for (size_t i = 0; i < commit_set_.Size(); ++i) {
69 groups_with_commits.insert( 69 groups_with_commits.insert(
70 GetGroupForModelType(commit_set_.GetModelTypeAt(i), 70 GetGroupForModelType(commit_set_.GetModelTypeAt(i),
71 session.routing_info())); 71 session.routing_info()));
72 } 72 }
73 73
74 return groups_with_commits; 74 return groups_with_commits;
75 } 75 }
76 76
77 SyncerError ProcessCommitResponseCommand::ModelNeutralExecuteImpl(
78 SyncSession* session) {
79 syncable::Directory* dir = session->context()->directory();
80 const vector<syncable::Id>& commit_ids = commit_set_.GetAllCommitIds();
81
82 if (!commit_response_.has_commit()) {
83 LOG(WARNING) << "Commit response has no commit body!";
84 ClearSyncingBits(dir, commit_ids);
85 return SERVER_RESPONSE_VALIDATION_FAILED;
86 }
87
88 const CommitResponse& cr = commit_response_.commit();
89 int commit_count = commit_set_.Size();
90 if (cr.entryresponse_size() != commit_count) {
91 LOG(ERROR) << "Commit response has wrong number of entries! Expected:" <<
92 commit_count << " Got:" << cr.entryresponse_size();
93 for (int i = 0 ; i < cr.entryresponse_size() ; i++) {
94 LOG(ERROR) << "Response #" << i << " Value: " <<
95 cr.entryresponse(i).response_type();
96 if (cr.entryresponse(i).has_error_message())
97 LOG(ERROR) << " " << cr.entryresponse(i).error_message();
98 }
99 ClearSyncingBits(dir, commit_ids);
100 return SERVER_RESPONSE_VALIDATION_FAILED;
101 }
102 return SYNCER_OK;
103 }
104 77
105 SyncerError ProcessCommitResponseCommand::ModelChangingExecuteImpl( 78 SyncerError ProcessCommitResponseCommand::ModelChangingExecuteImpl(
106 SyncSession* session) { 79 SyncSession* session) {
107 SyncerError result = ProcessCommitResponse(session); 80 SyncerError result = ProcessCommitResponse(session);
108 ExtensionsActivityMonitor* monitor = session->context()->extensions_monitor(); 81 ExtensionsActivityMonitor* monitor = session->context()->extensions_monitor();
109 82
110 // This is to be run on one model only: the bookmark model. 83 // This is to be run on one model only: the bookmark model.
111 if (session->status_controller().HasBookmarkCommitActivity()) { 84 if (session->status_controller().HasBookmarkCommitActivity()) {
112 // If the commit failed, return the data to the ExtensionsActivityMonitor. 85 // If the commit failed, return the data to the ExtensionsActivityMonitor.
113 if (session->status_controller().syncer_status() 86 if (session->status_controller().syncer_status()
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // Make a note of any deleted folders, whose children would have 466 // Make a note of any deleted folders, whose children would have
494 // been recursively deleted. 467 // been recursively deleted.
495 // TODO(nick): Here, commit_message.deleted() would be more correct than 468 // TODO(nick): Here, commit_message.deleted() would be more correct than
496 // local_entry->Get(IS_DEL). For example, an item could be renamed, and then 469 // local_entry->Get(IS_DEL). For example, an item could be renamed, and then
497 // deleted during the commit of the rename. Unit test & fix. 470 // deleted during the commit of the rename. Unit test & fix.
498 if (local_entry->Get(IS_DIR) && local_entry->Get(IS_DEL)) { 471 if (local_entry->Get(IS_DIR) && local_entry->Get(IS_DEL)) {
499 deleted_folders->insert(local_entry->Get(ID)); 472 deleted_folders->insert(local_entry->Get(ID));
500 } 473 }
501 } 474 }
502 475
503 void ProcessCommitResponseCommand::ClearSyncingBits(
504 syncable::Directory *dir,
505 const vector<syncable::Id>& commit_ids) {
506 // This is part of the cleanup in the case of a failed commit. Normally we
507 // would unset the SYNCING bit when processing the commit response. In the
508 // failure case we don't process the response, so we need to clear those bits
509 // here.
510 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir);
511 for (size_t i = 0; i < commit_ids.size(); i++) {
512 syncable::MutableEntry entry(&trans, syncable::GET_BY_ID, commit_ids[i]);
513 if (entry.good()) {
514 entry.Put(syncable::SYNCING, false);
515 } else {
516 LOG(WARNING) << "Id: " << commit_ids[i] << " disappeared";
517 }
518 }
519 }
520
521 } // namespace browser_sync 476 } // namespace browser_sync
OLDNEW
« no previous file with comments | « sync/engine/process_commit_response_command.h ('k') | sync/engine/syncer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698