| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/internal_api/sync_backup_manager.h" | 5 #include "sync/internal_api/sync_backup_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <vector> | 9 #include <vector> |
| 8 | 10 |
| 9 #include "sync/internal_api/public/read_node.h" | 11 #include "sync/internal_api/public/read_node.h" |
| 10 #include "sync/internal_api/public/write_transaction.h" | 12 #include "sync/internal_api/public/write_transaction.h" |
| 11 #include "sync/syncable/directory.h" | 13 #include "sync/syncable/directory.h" |
| 12 #include "sync/syncable/mutable_entry.h" | 14 #include "sync/syncable/mutable_entry.h" |
| 13 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 14 | 16 |
| 15 namespace syncer { | 17 namespace syncer { |
| 16 | 18 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 ModelTypeSet types; | 53 ModelTypeSet types; |
| 52 if (in_normalization_) { | 54 if (in_normalization_) { |
| 53 // Skip if in our own WriteTransaction from NormalizeEntries(). | 55 // Skip if in our own WriteTransaction from NormalizeEntries(). |
| 54 in_normalization_ = false; | 56 in_normalization_ = false; |
| 55 return types; | 57 return types; |
| 56 } | 58 } |
| 57 | 59 |
| 58 for (syncable::EntryKernelMutationMap::const_iterator it = | 60 for (syncable::EntryKernelMutationMap::const_iterator it = |
| 59 write_transaction_info.Get().mutations.Get().begin(); | 61 write_transaction_info.Get().mutations.Get().begin(); |
| 60 it != write_transaction_info.Get().mutations.Get().end(); ++it) { | 62 it != write_transaction_info.Get().mutations.Get().end(); ++it) { |
| 61 int64 id = it->first; | 63 int64_t id = it->first; |
| 62 if (unsynced_.find(id) == unsynced_.end()) { | 64 if (unsynced_.find(id) == unsynced_.end()) { |
| 63 unsynced_.insert(id); | 65 unsynced_.insert(id); |
| 64 | 66 |
| 65 const syncable::EntryKernel& e = it->second.mutated; | 67 const syncable::EntryKernel& e = it->second.mutated; |
| 66 ModelType type = e.GetModelType(); | 68 ModelType type = e.GetModelType(); |
| 67 types.Put(type); | 69 types.Put(type); |
| 68 if (!e.ref(syncable::ID).ServerKnows()) | 70 if (!e.ref(syncable::ID).ServerKnows()) |
| 69 status_.num_entries_by_type[type]++; | 71 status_.num_entries_by_type[type]++; |
| 70 if (e.ref(syncable::IS_DEL)) | 72 if (e.ref(syncable::IS_DEL)) |
| 71 status_.num_to_delete_entries_by_type[type]++; | 73 status_.num_to_delete_entries_by_type[type]++; |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 return types; | 76 return types; |
| 75 } | 77 } |
| 76 | 78 |
| 77 void SyncBackupManager::NormalizeEntries() { | 79 void SyncBackupManager::NormalizeEntries() { |
| 78 WriteTransaction trans(FROM_HERE, GetUserShare()); | 80 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 79 in_normalization_ = true; | 81 in_normalization_ = true; |
| 80 for (std::set<int64>::const_iterator it = unsynced_.begin(); | 82 for (std::set<int64_t>::const_iterator it = unsynced_.begin(); |
| 81 it != unsynced_.end(); ++it) { | 83 it != unsynced_.end(); ++it) { |
| 82 syncable::MutableEntry entry(trans.GetWrappedWriteTrans(), | 84 syncable::MutableEntry entry(trans.GetWrappedWriteTrans(), |
| 83 syncable::GET_BY_HANDLE, *it); | 85 syncable::GET_BY_HANDLE, *it); |
| 84 CHECK(entry.good()); | 86 CHECK(entry.good()); |
| 85 | 87 |
| 86 if (!entry.GetId().ServerKnows()) | 88 if (!entry.GetId().ServerKnows()) |
| 87 entry.PutId(syncable::Id::CreateFromServerId(entry.GetId().value())); | 89 entry.PutId(syncable::Id::CreateFromServerId(entry.GetId().value())); |
| 88 if (!entry.GetParentId().IsNull() && !entry.GetParentId().ServerKnows()) { | 90 if (!entry.GetParentId().IsNull() && !entry.GetParentId().ServerKnows()) { |
| 89 entry.PutParentIdPropertyOnly(syncable::Id::CreateFromServerId( | 91 entry.PutParentIdPropertyOnly(syncable::Id::CreateFromServerId( |
| 90 entry.GetParentId().value())); | 92 entry.GetParentId().value())); |
| 91 } | 93 } |
| 92 entry.PutBaseVersion(1); | 94 entry.PutBaseVersion(1); |
| 93 entry.PutIsUnsynced(false); | 95 entry.PutIsUnsynced(false); |
| 94 } | 96 } |
| 95 unsynced_.clear(); | 97 unsynced_.clear(); |
| 96 } | 98 } |
| 97 | 99 |
| 98 void SyncBackupManager::HideSyncPreference(ModelType type) { | 100 void SyncBackupManager::HideSyncPreference(ModelType type) { |
| 99 WriteTransaction trans(FROM_HERE, GetUserShare()); | 101 WriteTransaction trans(FROM_HERE, GetUserShare()); |
| 100 ReadNode pref_root(&trans); | 102 ReadNode pref_root(&trans); |
| 101 if (BaseNode::INIT_OK != pref_root.InitTypeRoot(type)) | 103 if (BaseNode::INIT_OK != pref_root.InitTypeRoot(type)) |
| 102 return; | 104 return; |
| 103 | 105 |
| 104 std::vector<int64> pref_ids; | 106 std::vector<int64_t> pref_ids; |
| 105 pref_root.GetChildIds(&pref_ids); | 107 pref_root.GetChildIds(&pref_ids); |
| 106 for (uint32 i = 0; i < pref_ids.size(); ++i) { | 108 for (uint32_t i = 0; i < pref_ids.size(); ++i) { |
| 107 syncable::MutableEntry entry(trans.GetWrappedWriteTrans(), | 109 syncable::MutableEntry entry(trans.GetWrappedWriteTrans(), |
| 108 syncable::GET_BY_HANDLE, pref_ids[i]); | 110 syncable::GET_BY_HANDLE, pref_ids[i]); |
| 109 if (entry.good()) { | 111 if (entry.good()) { |
| 110 // HACKY: Set IS_DEL to true to remove entry from parent-children | 112 // HACKY: Set IS_DEL to true to remove entry from parent-children |
| 111 // index so that it's not returned when syncable service asks | 113 // index so that it's not returned when syncable service asks |
| 112 // for sync data. Syncable service then creates entry for local | 114 // for sync data. Syncable service then creates entry for local |
| 113 // model. Then the existing entry is undeleted and set to local value | 115 // model. Then the existing entry is undeleted and set to local value |
| 114 // because it has the same unique client tag. | 116 // because it has the same unique client tag. |
| 115 entry.PutIsDel(true); | 117 entry.PutIsDel(true); |
| 116 entry.PutIsUnsynced(false); | 118 entry.PutIsUnsynced(false); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 140 | 142 |
| 141 bool SyncBackupManager::HasDirectoryTypeDebugInfoObserver( | 143 bool SyncBackupManager::HasDirectoryTypeDebugInfoObserver( |
| 142 syncer::TypeDebugInfoObserver* observer) { return false; } | 144 syncer::TypeDebugInfoObserver* observer) { return false; } |
| 143 | 145 |
| 144 void SyncBackupManager::RequestEmitDebugInfo() {} | 146 void SyncBackupManager::RequestEmitDebugInfo() {} |
| 145 | 147 |
| 146 void SyncBackupManager::ClearServerData( | 148 void SyncBackupManager::ClearServerData( |
| 147 const ClearServerDataCallback& callback) {} | 149 const ClearServerDataCallback& callback) {} |
| 148 | 150 |
| 149 } // namespace syncer | 151 } // namespace syncer |
| OLD | NEW |