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 "components/sync/engine_impl/model_type_worker.h" | 5 #include "components/sync/engine_impl/model_type_worker.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 DCHECK(!worker_); | 178 DCHECK(!worker_); |
179 | 179 |
180 // We don't get to own this object. The |worker_| keeps a unique_ptr to it. | 180 // We don't get to own this object. The |worker_| keeps a unique_ptr to it. |
181 auto processor = base::MakeUnique<MockModelTypeProcessor>(); | 181 auto processor = base::MakeUnique<MockModelTypeProcessor>(); |
182 mock_type_processor_ = processor.get(); | 182 mock_type_processor_ = processor.get(); |
183 processor->SetDisconnectCallback(base::Bind( | 183 processor->SetDisconnectCallback(base::Bind( |
184 &ModelTypeWorkerTest::DisconnectProcessor, base::Unretained(this))); | 184 &ModelTypeWorkerTest::DisconnectProcessor, base::Unretained(this))); |
185 | 185 |
186 std::unique_ptr<Cryptographer> cryptographer_copy; | 186 std::unique_ptr<Cryptographer> cryptographer_copy; |
187 if (cryptographer_) { | 187 if (cryptographer_) { |
188 cryptographer_copy.reset(new Cryptographer(*cryptographer_)); | 188 cryptographer_copy = base::MakeUnique<Cryptographer>(*cryptographer_); |
189 } | 189 } |
190 | 190 |
191 // TODO(maxbogue): crbug.com/529498: Inject pending updates somehow. | 191 // TODO(maxbogue): crbug.com/529498: Inject pending updates somehow. |
192 worker_.reset( | 192 worker_ = base::MakeUnique<ModelTypeWorker>( |
193 new ModelTypeWorker(kModelType, state, std::move(cryptographer_copy), | 193 kModelType, state, std::move(cryptographer_copy), &mock_nudge_handler_, |
194 &mock_nudge_handler_, std::move(processor))); | 194 std::move(processor)); |
195 } | 195 } |
196 | 196 |
197 // Introduce a new key that the local cryptographer can't decrypt. | 197 // Introduce a new key that the local cryptographer can't decrypt. |
198 void NewForeignEncryptionKey() { | 198 void NewForeignEncryptionKey() { |
199 if (!cryptographer_) { | 199 if (!cryptographer_) { |
200 cryptographer_.reset(new Cryptographer(&fake_encryptor_)); | 200 cryptographer_ = base::MakeUnique<Cryptographer>(&fake_encryptor_); |
201 } | 201 } |
202 | 202 |
203 foreign_encryption_key_index_++; | 203 foreign_encryption_key_index_++; |
204 | 204 |
205 sync_pb::NigoriKeyBag bag; | 205 sync_pb::NigoriKeyBag bag; |
206 | 206 |
207 for (int i = 0; i <= foreign_encryption_key_index_; ++i) { | 207 for (int i = 0; i <= foreign_encryption_key_index_; ++i) { |
208 Nigori nigori; | 208 Nigori nigori; |
209 KeyParams params = GetNthKeyParams(i); | 209 KeyParams params = GetNthKeyParams(i); |
210 nigori.InitByDerivation(params.hostname, params.username, | 210 nigori.InitByDerivation(params.hostname, params.username, |
(...skipping 26 matching lines...) Expand all Loading... |
237 // Update the worker with the latest cryptographer. | 237 // Update the worker with the latest cryptographer. |
238 if (worker_) { | 238 if (worker_) { |
239 worker_->UpdateCryptographer( | 239 worker_->UpdateCryptographer( |
240 base::MakeUnique<Cryptographer>(*cryptographer_)); | 240 base::MakeUnique<Cryptographer>(*cryptographer_)); |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 // Update the local cryptographer with all relevant keys. | 244 // Update the local cryptographer with all relevant keys. |
245 void UpdateLocalCryptographer() { | 245 void UpdateLocalCryptographer() { |
246 if (!cryptographer_) { | 246 if (!cryptographer_) { |
247 cryptographer_.reset(new Cryptographer(&fake_encryptor_)); | 247 cryptographer_ = base::MakeUnique<Cryptographer>(&fake_encryptor_); |
248 } | 248 } |
249 | 249 |
250 KeyParams params = GetNthKeyParams(foreign_encryption_key_index_); | 250 KeyParams params = GetNthKeyParams(foreign_encryption_key_index_); |
251 bool success = cryptographer_->DecryptPendingKeys(params); | 251 bool success = cryptographer_->DecryptPendingKeys(params); |
252 DCHECK(success); | 252 DCHECK(success); |
253 | 253 |
254 // Update the worker with the latest cryptographer. | 254 // Update the worker with the latest cryptographer. |
255 if (worker_) { | 255 if (worker_) { |
256 worker_->UpdateCryptographer( | 256 worker_->UpdateCryptographer( |
257 base::MakeUnique<Cryptographer>(*cryptographer_)); | 257 base::MakeUnique<Cryptographer>(*cryptographer_)); |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 // disconnected. | 1018 // disconnected. |
1019 TEST_F(ModelTypeWorkerTest, DisconnectProcessorFromSyncTest) { | 1019 TEST_F(ModelTypeWorkerTest, DisconnectProcessorFromSyncTest) { |
1020 // Initialize the worker with basic state. | 1020 // Initialize the worker with basic state. |
1021 NormalInitialize(); | 1021 NormalInitialize(); |
1022 EXPECT_FALSE(IsProcessorDisconnected()); | 1022 EXPECT_FALSE(IsProcessorDisconnected()); |
1023 ResetWorker(); | 1023 ResetWorker(); |
1024 EXPECT_TRUE(IsProcessorDisconnected()); | 1024 EXPECT_TRUE(IsProcessorDisconnected()); |
1025 } | 1025 } |
1026 | 1026 |
1027 } // namespace syncer | 1027 } // namespace syncer |
OLD | NEW |