OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "sync/internal_api/sync_backup_manager.h" |
| 6 |
| 7 #include "sync/internal_api/public/write_transaction.h" |
| 8 #include "sync/syncable/directory.h" |
| 9 #include "sync/syncable/mutable_entry.h" |
| 10 |
| 11 namespace syncer { |
| 12 |
| 13 SyncBackupManager::SyncBackupManager() |
| 14 : in_normalization_(false) { |
| 15 } |
| 16 |
| 17 SyncBackupManager::~SyncBackupManager() { |
| 18 } |
| 19 |
| 20 void SyncBackupManager::Init( |
| 21 const base::FilePath& database_location, |
| 22 const WeakHandle<JsEventHandler>& event_handler, |
| 23 const std::string& sync_server_and_path, |
| 24 int sync_server_port, |
| 25 bool use_ssl, |
| 26 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 27 const std::vector<scoped_refptr<ModelSafeWorker> >& workers, |
| 28 ExtensionsActivity* extensions_activity, |
| 29 SyncManager::ChangeDelegate* change_delegate, |
| 30 const SyncCredentials& credentials, |
| 31 const std::string& invalidator_client_id, |
| 32 const std::string& restored_key_for_bootstrapping, |
| 33 const std::string& restored_keystore_key_for_bootstrapping, |
| 34 InternalComponentsFactory* internal_components_factory, |
| 35 Encryptor* encryptor, |
| 36 scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler, |
| 37 ReportUnrecoverableErrorFunction |
| 38 report_unrecoverable_error_function, |
| 39 CancelationSignal* cancelation_signal) { |
| 40 SyncRollbackManagerBase::Init(database_location, event_handler, |
| 41 sync_server_and_path, sync_server_port, |
| 42 use_ssl, post_factory.Pass(), |
| 43 workers, extensions_activity, change_delegate, |
| 44 credentials, invalidator_client_id, |
| 45 restored_key_for_bootstrapping, |
| 46 restored_keystore_key_for_bootstrapping, |
| 47 internal_components_factory, encryptor, |
| 48 unrecoverable_error_handler.Pass(), |
| 49 report_unrecoverable_error_function, |
| 50 cancelation_signal); |
| 51 |
| 52 GetUserShare()->directory->CollectMetaHandleCounts( |
| 53 &status_.num_entries_by_type, |
| 54 &status_.num_to_delete_entries_by_type); |
| 55 } |
| 56 |
| 57 void SyncBackupManager::SaveChanges() { |
| 58 NormalizeEntries(); |
| 59 GetUserShare()->directory->SaveChanges(); |
| 60 } |
| 61 |
| 62 SyncStatus SyncBackupManager::GetDetailedStatus() const { |
| 63 return status_; |
| 64 } |
| 65 |
| 66 ModelTypeSet SyncBackupManager::HandleTransactionEndingChangeEvent( |
| 67 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, |
| 68 syncable::BaseTransaction* trans) { |
| 69 ModelTypeSet types; |
| 70 if (in_normalization_) { |
| 71 // Skip if in our own WriteTransaction from NormalizeEntries(). |
| 72 in_normalization_ = false; |
| 73 return types; |
| 74 } |
| 75 |
| 76 for (syncable::EntryKernelMutationMap::const_iterator it = |
| 77 write_transaction_info.Get().mutations.Get().begin(); |
| 78 it != write_transaction_info.Get().mutations.Get().end(); ++it) { |
| 79 int64 id = it->first; |
| 80 if (unsynced_.find(id) == unsynced_.end()) { |
| 81 unsynced_.insert(id); |
| 82 |
| 83 const syncable::EntryKernel& e = it->second.mutated; |
| 84 ModelType type = e.GetModelType(); |
| 85 types.Put(type); |
| 86 if (!e.ref(syncable::ID).ServerKnows()) |
| 87 status_.num_entries_by_type[type]++; |
| 88 if (e.ref(syncable::IS_DEL)) |
| 89 status_.num_to_delete_entries_by_type[type]++; |
| 90 } |
| 91 } |
| 92 return types; |
| 93 } |
| 94 |
| 95 void SyncBackupManager::NormalizeEntries() { |
| 96 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 97 in_normalization_ = true; |
| 98 for (std::set<int64>::const_iterator it = unsynced_.begin(); |
| 99 it != unsynced_.end(); ++it) { |
| 100 syncable::MutableEntry entry(trans.GetWrappedWriteTrans(), |
| 101 syncable::GET_BY_HANDLE, *it); |
| 102 CHECK(entry.good()); |
| 103 |
| 104 if (!entry.GetId().ServerKnows()) |
| 105 entry.PutId(syncable::Id::CreateFromServerId(entry.GetId().value())); |
| 106 entry.PutBaseVersion(1); |
| 107 entry.PutIsUnsynced(false); |
| 108 } |
| 109 unsynced_.clear(); |
| 110 } |
| 111 |
| 112 } // namespace syncer |
OLD | NEW |