Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(664)

Side by Side Diff: components/sync/core_impl/test/test_user_share.cc

Issue 2407163004: [Sync] Move some directory-related things from core/ to syncable/. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2012 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 "components/sync/core/test/test_user_share.h"
6
7 #include "base/compiler_specific.h"
8 #include "components/sync/syncable/directory.h"
9 #include "components/sync/syncable/mutable_entry.h"
10 #include "components/sync/syncable/syncable_read_transaction.h"
11 #include "components/sync/syncable/syncable_write_transaction.h"
12 #include "components/sync/test/engine/test_directory_setter_upper.h"
13 #include "components/sync/test/engine/test_id_factory.h"
14 #include "components/sync/test/engine/test_syncable_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace syncer {
18
19 TestUserShare::TestUserShare() : dir_maker_(new TestDirectorySetterUpper()) {}
20
21 TestUserShare::~TestUserShare() {
22 if (user_share_)
23 ADD_FAILURE() << "Should have called TestUserShare::TearDown()";
24 }
25
26 void TestUserShare::SetUp() {
27 user_share_.reset(new UserShare());
28 dir_maker_->SetUp();
29
30 // The pointer is owned by dir_maker_, we should not be storing it in a
31 // unique_ptr. We must be careful to ensure the unique_ptr never deletes it.
32 user_share_->directory.reset(dir_maker_->directory());
33 }
34
35 void TestUserShare::TearDown() {
36 // Ensure the unique_ptr doesn't delete the memory we don't own.
37 ignore_result(user_share_->directory.release());
38
39 user_share_.reset();
40 dir_maker_->TearDown();
41 }
42
43 bool TestUserShare::Reload() {
44 if (!user_share_->directory->SaveChanges())
45 return false;
46
47 syncable::DirectoryBackingStore* saved_store =
48 user_share_->directory->store_.release();
49
50 // Ensure the unique_ptr doesn't delete the memory we don't own.
51 ignore_result(user_share_->directory.release());
52 user_share_.reset(new UserShare());
53 dir_maker_->SetUpWith(saved_store);
54 user_share_->directory.reset(dir_maker_->directory());
55 return true;
56 }
57
58 UserShare* TestUserShare::user_share() {
59 return user_share_.get();
60 }
61
62 SyncEncryptionHandler* TestUserShare::encryption_handler() {
63 return dir_maker_->encryption_handler();
64 }
65
66 syncable::TestTransactionObserver* TestUserShare::transaction_observer() {
67 return dir_maker_->transaction_observer();
68 }
69
70 /* static */
71 bool TestUserShare::CreateRoot(ModelType model_type, UserShare* user_share) {
72 syncable::Directory* directory = user_share->directory.get();
73 syncable::WriteTransaction wtrans(FROM_HERE, syncable::UNITTEST, directory);
74 CreateTypeRoot(&wtrans, directory, model_type);
75 return true;
76 }
77
78 size_t TestUserShare::GetDeleteJournalSize() const {
79 syncable::ReadTransaction trans(FROM_HERE, user_share_->directory.get());
80 return user_share_->directory->delete_journal()->GetDeleteJournalSize(&trans);
81 }
82
83 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/core_impl/test/sync_manager_for_profile_sync_test.cc ('k') | components/sync/driver/backend_migrator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698