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_rollback_manager.h" | 5 #include "sync/internal_api/sync_rollback_manager.h" |
6 | 6 |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "sync/internal_api/public/read_node.h" | 9 #include "sync/internal_api/public/read_node.h" |
10 #include "sync/internal_api/public/read_transaction.h" | 10 #include "sync/internal_api/public/read_transaction.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 run_loop.Run(); | 126 run_loop.Run(); |
127 } | 127 } |
128 | 128 |
129 // Create and persist an entry by unique tag in DB. | 129 // Create and persist an entry by unique tag in DB. |
130 void PrepopulateDb(ModelType type, const std::string& client_tag) { | 130 void PrepopulateDb(ModelType type, const std::string& client_tag) { |
131 SyncBackupManager backup_manager; | 131 SyncBackupManager backup_manager; |
132 TestChangeDelegate delegate; | 132 TestChangeDelegate delegate; |
133 InitManager(&backup_manager, ModelTypeSet(type), &delegate, | 133 InitManager(&backup_manager, ModelTypeSet(type), &delegate, |
134 STORAGE_ON_DISK); | 134 STORAGE_ON_DISK); |
135 CreateEntry(backup_manager.GetUserShare(), type, client_tag); | 135 CreateEntry(backup_manager.GetUserShare(), type, client_tag); |
136 backup_manager.ShutdownOnSyncThread(); | 136 backup_manager.ShutdownOnSyncThread(STOP_SYNC); |
137 } | 137 } |
138 | 138 |
139 // Verify entry with |client_tag| exists in sync directory. | 139 // Verify entry with |client_tag| exists in sync directory. |
140 bool VerifyEntry(UserShare* user_share, ModelType type, | 140 bool VerifyEntry(UserShare* user_share, ModelType type, |
141 const std::string& client_tag) { | 141 const std::string& client_tag) { |
142 ReadTransaction trans(FROM_HERE, user_share); | 142 ReadTransaction trans(FROM_HERE, user_share); |
143 ReadNode node(&trans); | 143 ReadNode node(&trans); |
144 return BaseNode::INIT_OK == node.InitByClientTagLookup(type, client_tag); | 144 return BaseNode::INIT_OK == node.InitByClientTagLookup(type, client_tag); |
145 } | 145 } |
146 | 146 |
147 private: | 147 private: |
148 void ConfigureSyncer() { | 148 void ConfigureSyncer() { |
149 manager_->ConfigureSyncer( | 149 manager_->ConfigureSyncer( |
150 CONFIGURE_REASON_NEW_CLIENT, | 150 CONFIGURE_REASON_NEW_CLIENT, |
151 types_, | 151 types_, |
152 ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), | 152 ModelTypeSet(), ModelTypeSet(), ModelTypeSet(), |
153 ModelSafeRoutingInfo(), | 153 ModelSafeRoutingInfo(), |
154 base::Bind(&SyncRollbackManagerTest::OnConfigDone, | 154 base::Bind(&SyncRollbackManagerTest::OnConfigDone, |
155 base::Unretained(this), true), | 155 base::Unretained(this), true), |
156 base::Bind(&SyncRollbackManagerTest::OnConfigDone, | 156 base::Bind(&SyncRollbackManagerTest::OnConfigDone, |
157 base::Unretained(this), false)); | 157 base::Unretained(this), false)); |
158 } | 158 } |
159 | 159 |
160 void HandleInit(bool success) { | 160 void HandleInit(bool success) { |
161 if (success) { | 161 if (success) { |
162 loop_.PostTask(FROM_HERE, | 162 loop_.PostTask(FROM_HERE, |
163 base::Bind(&SyncRollbackManagerTest::ConfigureSyncer, | 163 base::Bind(&SyncRollbackManagerTest::ConfigureSyncer, |
164 base::Unretained(this))); | 164 base::Unretained(this))); |
165 } else { | 165 } else { |
166 manager_->ShutdownOnSyncThread(); | 166 manager_->ShutdownOnSyncThread(STOP_SYNC); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 base::ScopedTempDir temp_dir_; | 170 base::ScopedTempDir temp_dir_; |
171 scoped_refptr<ModelSafeWorker> worker_; | 171 scoped_refptr<ModelSafeWorker> worker_; |
172 base::MessageLoop loop_; // Needed for WeakHandle | 172 base::MessageLoop loop_; // Needed for WeakHandle |
173 SyncManager* manager_; | 173 SyncManager* manager_; |
174 ModelTypeSet types_; | 174 ModelTypeSet types_; |
175 }; | 175 }; |
176 | 176 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 TestChangeDelegate delegate; | 235 TestChangeDelegate delegate; |
236 scoped_ptr<SyncRollbackManager> rollback_manager( | 236 scoped_ptr<SyncRollbackManager> rollback_manager( |
237 new SyncRollbackManager); | 237 new SyncRollbackManager); |
238 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), &delegate, | 238 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), &delegate, |
239 STORAGE_ON_DISK); | 239 STORAGE_ON_DISK); |
240 | 240 |
241 // Simulate a new entry added during type initialization. | 241 // Simulate a new entry added during type initialization. |
242 CreateEntry(rollback_manager->GetUserShare(), PREFERENCES, "pref2"); | 242 CreateEntry(rollback_manager->GetUserShare(), PREFERENCES, "pref2"); |
243 | 243 |
244 // Manager was shut down before sync starts. | 244 // Manager was shut down before sync starts. |
245 rollback_manager->ShutdownOnSyncThread(); | 245 rollback_manager->ShutdownOnSyncThread(STOP_SYNC); |
246 | 246 |
247 // Verify new entry was not persisted. | 247 // Verify new entry was not persisted. |
248 rollback_manager.reset(new SyncRollbackManager); | 248 rollback_manager.reset(new SyncRollbackManager); |
249 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), &delegate, | 249 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), &delegate, |
250 STORAGE_ON_DISK); | 250 STORAGE_ON_DISK); |
251 EXPECT_FALSE(VerifyEntry(rollback_manager->GetUserShare(), PREFERENCES, | 251 EXPECT_FALSE(VerifyEntry(rollback_manager->GetUserShare(), PREFERENCES, |
252 "pref2")); | 252 "pref2")); |
253 } | 253 } |
254 | 254 |
255 TEST_F(SyncRollbackManagerTest, OnInitializationFailure) { | 255 TEST_F(SyncRollbackManagerTest, OnInitializationFailure) { |
256 // Test graceful shutdown on initialization failure. | 256 // Test graceful shutdown on initialization failure. |
257 scoped_ptr<SyncRollbackManager> rollback_manager( | 257 scoped_ptr<SyncRollbackManager> rollback_manager( |
258 new SyncRollbackManager); | 258 new SyncRollbackManager); |
259 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), NULL, | 259 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), NULL, |
260 STORAGE_ON_DISK); | 260 STORAGE_ON_DISK); |
261 } | 261 } |
262 | 262 |
263 } // anonymous namespace | 263 } // anonymous namespace |
264 | 264 |
265 } // namespace syncer | 265 } // namespace syncer |
OLD | NEW |