| 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/syncable_service_adapter.h" | 5 #include "chrome/browser/sync/glue/syncable_service_adapter.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sync/api/sync_error.h" |
| 7 #include "chrome/browser/sync/api/syncable_service.h" | 8 #include "chrome/browser/sync/api/syncable_service.h" |
| 8 #include "chrome/browser/sync/api/sync_data.h" | 9 #include "chrome/browser/sync/api/sync_data.h" |
| 9 #include "chrome/browser/sync/glue/generic_change_processor.h" | 10 #include "chrome/browser/sync/glue/generic_change_processor.h" |
| 10 | 11 |
| 11 namespace browser_sync { | 12 namespace browser_sync { |
| 12 | 13 |
| 13 SyncableServiceAdapter::SyncableServiceAdapter( | 14 SyncableServiceAdapter::SyncableServiceAdapter( |
| 14 syncable::ModelType type, | 15 syncable::ModelType type, |
| 15 SyncableService* service, | 16 SyncableService* service, |
| 16 GenericChangeProcessor* sync_processor) | 17 GenericChangeProcessor* sync_processor) |
| 17 : syncing_(false), | 18 : syncing_(false), |
| 18 type_(type), | 19 type_(type), |
| 19 service_(service), | 20 service_(service), |
| 20 sync_processor_(sync_processor) { | 21 sync_processor_(sync_processor) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 SyncableServiceAdapter::~SyncableServiceAdapter() { | 24 SyncableServiceAdapter::~SyncableServiceAdapter() { |
| 24 if (syncing_) { | 25 if (syncing_) { |
| 25 NOTREACHED(); | 26 NOTREACHED(); |
| 26 LOG(ERROR) << "SyncableServiceAdapter for " | 27 LOG(ERROR) << "SyncableServiceAdapter for " |
| 27 << syncable::ModelTypeToString(type_) << " destroyed before " | 28 << syncable::ModelTypeToString(type_) << " destroyed before " |
| 28 << "without being shut down properly."; | 29 << "without being shut down properly."; |
| 29 service_->StopSyncing(type_); | 30 service_->StopSyncing(type_); |
| 30 } | 31 } |
| 31 } | 32 } |
| 32 | 33 |
| 33 bool SyncableServiceAdapter::AssociateModels() { | 34 bool SyncableServiceAdapter::AssociateModels(SyncError* error) { |
| 34 syncing_ = true; | 35 syncing_ = true; |
| 35 SyncDataList initial_sync_data; | 36 SyncDataList initial_sync_data; |
| 36 if (!sync_processor_->GetSyncDataForType(type_, &initial_sync_data)) { | 37 if (!sync_processor_->GetSyncDataForType(type_, |
| 38 &initial_sync_data, |
| 39 error)) { |
| 37 return false; | 40 return false; |
| 38 } | 41 } |
| 42 DCHECK(!error->IsInitialized()); |
| 39 return service_->MergeDataAndStartSyncing(type_, | 43 return service_->MergeDataAndStartSyncing(type_, |
| 40 initial_sync_data, | 44 initial_sync_data, |
| 41 sync_processor_); | 45 sync_processor_, |
| 46 error); |
| 42 } | 47 } |
| 43 | 48 |
| 44 bool SyncableServiceAdapter::DisassociateModels() { | 49 bool SyncableServiceAdapter::DisassociateModels(SyncError* error) { |
| 45 service_->StopSyncing(type_); | 50 service_->StopSyncing(type_); |
| 46 syncing_ = false; | 51 syncing_ = false; |
| 47 return true; | 52 return true; |
| 48 } | 53 } |
| 49 | 54 |
| 50 bool SyncableServiceAdapter::SyncModelHasUserCreatedNodes(bool* has_nodes) { | 55 bool SyncableServiceAdapter::SyncModelHasUserCreatedNodes(bool* has_nodes) { |
| 51 return sync_processor_->SyncModelHasUserCreatedNodes(type_, has_nodes); | 56 return sync_processor_->SyncModelHasUserCreatedNodes(type_, has_nodes); |
| 52 } | 57 } |
| 53 | 58 |
| 54 void SyncableServiceAdapter::AbortAssociation() { | 59 void SyncableServiceAdapter::AbortAssociation() { |
| 55 service_->StopSyncing(type_); | 60 service_->StopSyncing(type_); |
| 56 syncing_ = false; | 61 syncing_ = false; |
| 57 } | 62 } |
| 58 | 63 |
| 59 bool SyncableServiceAdapter::CryptoReadyIfNecessary() { | 64 bool SyncableServiceAdapter::CryptoReadyIfNecessary() { |
| 60 return sync_processor_->CryptoReadyIfNecessary(type_); | 65 return sync_processor_->CryptoReadyIfNecessary(type_); |
| 61 } | 66 } |
| 62 | 67 |
| 63 } // namespace browser_sync | 68 } // namespace browser_sync |
| OLD | NEW |