| 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/glue/generic_change_processor.h" | 5 #include "chrome/browser/sync/glue/generic_change_processor.h" |
| 6 | 6 |
| 7 #include "base/tracked.h" | 7 #include "base/tracked.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/sync/api/syncable_service.h" | 9 #include "chrome/browser/sync/api/syncable_service.h" |
| 10 #include "chrome/browser/sync/api/sync_change.h" | 10 #include "chrome/browser/sync/api/sync_change.h" |
| 11 #include "chrome/browser/sync/api/sync_error.h" | 11 #include "chrome/browser/sync/api/sync_error.h" |
| 12 #include "chrome/browser/sync/internal_api/change_record.h" |
| 12 #include "chrome/browser/sync/internal_api/read_node.h" | 13 #include "chrome/browser/sync/internal_api/read_node.h" |
| 13 #include "chrome/browser/sync/internal_api/read_transaction.h" | 14 #include "chrome/browser/sync/internal_api/read_transaction.h" |
| 14 #include "chrome/browser/sync/internal_api/sync_manager.h" | |
| 15 #include "chrome/browser/sync/internal_api/write_node.h" | 15 #include "chrome/browser/sync/internal_api/write_node.h" |
| 16 #include "chrome/browser/sync/internal_api/write_transaction.h" | 16 #include "chrome/browser/sync/internal_api/write_transaction.h" |
| 17 #include "chrome/browser/sync/unrecoverable_error_handler.h" | 17 #include "chrome/browser/sync/unrecoverable_error_handler.h" |
| 18 | 18 |
| 19 namespace browser_sync { | 19 namespace browser_sync { |
| 20 | 20 |
| 21 GenericChangeProcessor::GenericChangeProcessor( | 21 GenericChangeProcessor::GenericChangeProcessor( |
| 22 SyncableService* local_service, | 22 SyncableService* local_service, |
| 23 UnrecoverableErrorHandler* error_handler, | 23 UnrecoverableErrorHandler* error_handler, |
| 24 sync_api::UserShare* user_share) | 24 sync_api::UserShare* user_share) |
| 25 : ChangeProcessor(error_handler), | 25 : ChangeProcessor(error_handler), |
| 26 local_service_(local_service), | 26 local_service_(local_service), |
| 27 user_share_(user_share) { | 27 user_share_(user_share) { |
| 28 DCHECK(local_service_); | 28 DCHECK(local_service_); |
| 29 } | 29 } |
| 30 | 30 |
| 31 GenericChangeProcessor::~GenericChangeProcessor() { | 31 GenericChangeProcessor::~GenericChangeProcessor() { |
| 32 // Set to null to ensure it's not used after destruction. | 32 // Set to null to ensure it's not used after destruction. |
| 33 local_service_ = NULL; | 33 local_service_ = NULL; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void GenericChangeProcessor::ApplyChangesFromSyncModel( | 36 void GenericChangeProcessor::ApplyChangesFromSyncModel( |
| 37 const sync_api::BaseTransaction* trans, | 37 const sync_api::BaseTransaction* trans, |
| 38 const sync_api::SyncManager::ChangeRecord* changes, | 38 const sync_api::ImmutableChangeRecordList& changes) { |
| 39 int change_count) { | |
| 40 DCHECK(running()); | 39 DCHECK(running()); |
| 41 DCHECK(syncer_changes_.empty()); | 40 DCHECK(syncer_changes_.empty()); |
| 42 for (int i = 0; i < change_count; ++i) { | 41 for (sync_api::ChangeRecordList::const_iterator it = |
| 42 changes.Get().begin(); it != changes.Get().end(); ++it) { |
| 43 SyncChange::SyncChangeType action; | 43 SyncChange::SyncChangeType action; |
| 44 sync_pb::EntitySpecifics const* specifics = NULL; | 44 sync_pb::EntitySpecifics const* specifics = NULL; |
| 45 if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE == | 45 if (sync_api::ChangeRecord::ACTION_DELETE == it->action) { |
| 46 changes[i].action) { | |
| 47 action = SyncChange::ACTION_DELETE; | 46 action = SyncChange::ACTION_DELETE; |
| 48 specifics = &changes[i].specifics; | 47 specifics = &it->specifics; |
| 49 DCHECK(specifics); | 48 DCHECK(specifics); |
| 50 } else if (sync_api::SyncManager::ChangeRecord::ACTION_ADD == | 49 } else if (sync_api::ChangeRecord::ACTION_ADD == it->action) { |
| 51 changes[i].action) { | |
| 52 action = SyncChange::ACTION_ADD; | 50 action = SyncChange::ACTION_ADD; |
| 53 } else { // ACTION_UPDATE. | 51 } else { // ACTION_UPDATE. |
| 54 action = SyncChange::ACTION_UPDATE; | 52 action = SyncChange::ACTION_UPDATE; |
| 55 } | 53 } |
| 56 if (!specifics) { | 54 if (!specifics) { |
| 57 // Need to load from node. | 55 // Need to load from node. |
| 58 sync_api::ReadNode read_node(trans); | 56 sync_api::ReadNode read_node(trans); |
| 59 if (!read_node.InitByIdLookup(changes[i].id)) { | 57 if (!read_node.InitByIdLookup(it->id)) { |
| 60 error_handler()->OnUnrecoverableError(FROM_HERE, "Failed to look up " | 58 error_handler()->OnUnrecoverableError(FROM_HERE, "Failed to look up " |
| 61 " data for received change with id " + changes[i].id); | 59 " data for received change with id " + it->id); |
| 62 return; | 60 return; |
| 63 } | 61 } |
| 64 syncer_changes_.push_back(SyncChange(action, | 62 syncer_changes_.push_back(SyncChange(action, |
| 65 SyncData::CreateRemoteData(read_node.GetEntitySpecifics()))); | 63 SyncData::CreateRemoteData(read_node.GetEntitySpecifics()))); |
| 66 } else { | 64 } else { |
| 67 syncer_changes_.push_back( | 65 syncer_changes_.push_back( |
| 68 SyncChange(action, SyncData::CreateRemoteData(*specifics))); | 66 SyncChange(action, SyncData::CreateRemoteData(*specifics))); |
| 69 } | 67 } |
| 70 } | 68 } |
| 71 } | 69 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 227 |
| 230 void GenericChangeProcessor::StartImpl(Profile* profile) {} | 228 void GenericChangeProcessor::StartImpl(Profile* profile) {} |
| 231 | 229 |
| 232 void GenericChangeProcessor::StopImpl() {} | 230 void GenericChangeProcessor::StopImpl() {} |
| 233 | 231 |
| 234 sync_api::UserShare* GenericChangeProcessor::share_handle() { | 232 sync_api::UserShare* GenericChangeProcessor::share_handle() { |
| 235 return user_share_; | 233 return user_share_; |
| 236 } | 234 } |
| 237 | 235 |
| 238 } // namespace browser_sync | 236 } // namespace browser_sync |
| OLD | NEW |