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_updates_command.h" | 5 #include "chrome/browser/sync/engine/process_updates_command.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace browser_sync { | 21 namespace browser_sync { |
22 | 22 |
23 using sessions::SyncSession; | 23 using sessions::SyncSession; |
24 using sessions::StatusController; | 24 using sessions::StatusController; |
25 | 25 |
26 ProcessUpdatesCommand::ProcessUpdatesCommand() {} | 26 ProcessUpdatesCommand::ProcessUpdatesCommand() {} |
27 ProcessUpdatesCommand::~ProcessUpdatesCommand() {} | 27 ProcessUpdatesCommand::~ProcessUpdatesCommand() {} |
28 | 28 |
29 bool ProcessUpdatesCommand::ModelNeutralExecuteImpl(SyncSession* session) { | 29 bool ProcessUpdatesCommand::ModelNeutralExecuteImpl(SyncSession* session) { |
30 const GetUpdatesResponse& updates = | 30 const GetUpdatesResponse& updates = |
31 session->status_controller()->updates_response().get_updates(); | 31 session->status_controller().updates_response().get_updates(); |
32 const int update_count = updates.entries_size(); | 32 const int update_count = updates.entries_size(); |
33 | 33 |
34 // Don't bother processing updates if there were none. | 34 // Don't bother processing updates if there were none. |
35 return update_count != 0; | 35 return update_count != 0; |
36 } | 36 } |
37 | 37 |
38 void ProcessUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) { | 38 void ProcessUpdatesCommand::ModelChangingExecuteImpl(SyncSession* session) { |
39 syncable::ScopedDirLookup dir(session->context()->directory_manager(), | 39 syncable::ScopedDirLookup dir(session->context()->directory_manager(), |
40 session->context()->account_name()); | 40 session->context()->account_name()); |
41 if (!dir.good()) { | 41 if (!dir.good()) { |
42 LOG(ERROR) << "Scoped dir lookup failed!"; | 42 LOG(ERROR) << "Scoped dir lookup failed!"; |
43 return; | 43 return; |
44 } | 44 } |
45 | 45 |
46 StatusController* status = session->status_controller(); | 46 const sessions::UpdateProgress* progress = |
| 47 session->status_controller().update_progress(); |
| 48 if (!progress) |
| 49 return; // Nothing to do. |
47 | 50 |
48 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir); | 51 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir); |
49 const sessions::UpdateProgress& progress(status->update_progress()); | |
50 vector<sessions::VerifiedUpdate>::const_iterator it; | 52 vector<sessions::VerifiedUpdate>::const_iterator it; |
51 for (it = progress.VerifiedUpdatesBegin(); | 53 for (it = progress->VerifiedUpdatesBegin(); |
52 it != progress.VerifiedUpdatesEnd(); | 54 it != progress->VerifiedUpdatesEnd(); |
53 ++it) { | 55 ++it) { |
54 const sync_pb::SyncEntity& update = it->second; | 56 const sync_pb::SyncEntity& update = it->second; |
55 | 57 |
56 if (it->first != VERIFY_SUCCESS && it->first != VERIFY_UNDELETE) | 58 if (it->first != VERIFY_SUCCESS && it->first != VERIFY_UNDELETE) |
57 continue; | 59 continue; |
58 switch (ProcessUpdate(dir, update, &trans)) { | 60 switch (ProcessUpdate(dir, update, &trans)) { |
59 case SUCCESS_PROCESSED: | 61 case SUCCESS_PROCESSED: |
60 case SUCCESS_STORED: | 62 case SUCCESS_STORED: |
61 break; | 63 break; |
62 default: | 64 default: |
63 NOTREACHED(); | 65 NOTREACHED(); |
64 break; | 66 break; |
65 } | 67 } |
66 } | 68 } |
67 | 69 |
| 70 StatusController* status = session->mutable_status_controller(); |
68 status->set_num_consecutive_errors(0); | 71 status->set_num_consecutive_errors(0); |
69 | |
70 status->mutable_update_progress()->ClearVerifiedUpdates(); | 72 status->mutable_update_progress()->ClearVerifiedUpdates(); |
71 return; | |
72 } | 73 } |
73 | 74 |
74 namespace { | 75 namespace { |
75 // Returns true if the entry is still ok to process. | 76 // Returns true if the entry is still ok to process. |
76 bool ReverifyEntry(syncable::WriteTransaction* trans, const SyncEntity& entry, | 77 bool ReverifyEntry(syncable::WriteTransaction* trans, const SyncEntity& entry, |
77 syncable::MutableEntry* same_id) { | 78 syncable::MutableEntry* same_id) { |
78 | 79 |
79 const bool deleted = entry.has_deleted() && entry.deleted(); | 80 const bool deleted = entry.has_deleted() && entry.deleted(); |
80 const bool is_directory = entry.IsFolder(); | 81 const bool is_directory = entry.IsFolder(); |
81 const syncable::ModelType model_type = entry.GetModelType(); | 82 const syncable::ModelType model_type = entry.GetModelType(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Force application of this update, no matter what. | 146 // Force application of this update, no matter what. |
146 target_entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); | 147 target_entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
147 } | 148 } |
148 | 149 |
149 SyncerUtil::UpdateServerFieldsFromUpdate(&target_entry, update, name); | 150 SyncerUtil::UpdateServerFieldsFromUpdate(&target_entry, update, name); |
150 | 151 |
151 return SUCCESS_PROCESSED; | 152 return SUCCESS_PROCESSED; |
152 } | 153 } |
153 | 154 |
154 } // namespace browser_sync | 155 } // namespace browser_sync |
OLD | NEW |