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

Side by Side Diff: chrome/test/sync/engine/test_directory_setter_upper.cc

Issue 7190001: [Sync] Split DirectoryChangeListener for thread-safety (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix copyright Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/test/sync/engine/test_directory_setter_upper.h" 5 #include "chrome/test/sync/engine/test_directory_setter_upper.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/tracked.h"
10 #include "chrome/browser/sync/syncable/directory_manager.h" 11 #include "chrome/browser/sync/syncable/directory_manager.h"
11 #include "chrome/browser/sync/syncable/syncable.h" 12 #include "chrome/browser/sync/syncable/syncable.h"
12 #include "chrome/common/deprecated/event_sys-inl.h" 13 #include "chrome/common/deprecated/event_sys-inl.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 using syncable::DirectoryManager; 16 using syncable::DirectoryManager;
16 using syncable::ReadTransaction; 17 using syncable::ReadTransaction;
17 using syncable::ScopedDirLookup; 18 using syncable::ScopedDirLookup;
18 19
19 namespace browser_sync { 20 namespace browser_sync {
(...skipping 11 matching lines...) Expand all
31 // temp dir. 32 // temp dir.
32 ASSERT_FALSE(file_util::PathExists(manager_->GetSyncDataDatabasePath())); 33 ASSERT_FALSE(file_util::PathExists(manager_->GetSyncDataDatabasePath()));
33 } 34 }
34 35
35 void TestDirectorySetterUpper::reset_directory_manager(DirectoryManager* d) { 36 void TestDirectorySetterUpper::reset_directory_manager(DirectoryManager* d) {
36 manager_.reset(d); 37 manager_.reset(d);
37 } 38 }
38 39
39 void TestDirectorySetterUpper::SetUp() { 40 void TestDirectorySetterUpper::SetUp() {
40 Init(); 41 Init();
41 ASSERT_TRUE(manager()->Open(name())); 42 ASSERT_TRUE(manager()->Open(name(), &delegate_));
42 } 43 }
43 44
44 void TestDirectorySetterUpper::TearDown() { 45 void TestDirectorySetterUpper::TearDown() {
45 if (!manager()) 46 if (!manager())
46 return; 47 return;
47 48
48 { 49 {
49 // A small scope so we don't have the dir open when we close it and reset 50 // A small scope so we don't have the dir open when we close it and reset
50 // the DirectoryManager below. 51 // the DirectoryManager below.
51 ScopedDirLookup dir(manager(), name()); 52 ScopedDirLookup dir(manager(), name());
52 CHECK(dir.good()) << "Bad directory during tear down check"; 53 CHECK(dir.good()) << "Bad directory during tear down check";
53 RunInvariantCheck(dir); 54 RunInvariantCheck(dir);
54 dir->SaveChanges(); 55 dir->SaveChanges();
55 RunInvariantCheck(dir); 56 RunInvariantCheck(dir);
56 dir->SaveChanges(); 57 dir->SaveChanges();
57 } 58 }
58 59
59 manager()->FinalSaveChangesForAll(); 60 manager()->FinalSaveChangesForAll();
60 manager()->Close(name()); 61 manager()->Close(name());
61 manager_.reset(); 62 manager_.reset();
62 ASSERT_TRUE(temp_dir_.Delete()); 63 ASSERT_TRUE(temp_dir_.Delete());
63 } 64 }
64 65
65 void TestDirectorySetterUpper::RunInvariantCheck(const ScopedDirLookup& dir) { 66 void TestDirectorySetterUpper::RunInvariantCheck(const ScopedDirLookup& dir) {
66 { 67 {
67 // Check invariants for in-memory items. 68 // Check invariants for in-memory items.
68 ReadTransaction trans(dir, __FILE__, __LINE__); 69 ReadTransaction trans(dir, FROM_HERE);
69 dir->CheckTreeInvariants(&trans, false); 70 dir->CheckTreeInvariants(&trans, false);
70 } 71 }
71 { 72 {
72 // Check invariants for all items. 73 // Check invariants for all items.
73 ReadTransaction trans(dir, __FILE__, __LINE__); 74 ReadTransaction trans(dir, FROM_HERE);
74 dir->CheckTreeInvariants(&trans, true); 75 dir->CheckTreeInvariants(&trans, true);
75 } 76 }
76 } 77 }
77 78
78 void ManuallyOpenedTestDirectorySetterUpper::SetUp() { 79 void ManuallyOpenedTestDirectorySetterUpper::SetUp() {
79 Init(); 80 Init();
80 } 81 }
81 82
82 void ManuallyOpenedTestDirectorySetterUpper::Open() { 83 void ManuallyOpenedTestDirectorySetterUpper::Open() {
83 ASSERT_TRUE(manager()->Open(name())); 84 ASSERT_TRUE(manager()->Open(name(), &delegate_));
84 was_opened_ = true; 85 was_opened_ = true;
85 } 86 }
86 87
87 void ManuallyOpenedTestDirectorySetterUpper::TearDown() { 88 void ManuallyOpenedTestDirectorySetterUpper::TearDown() {
88 if (was_opened_) { 89 if (was_opened_) {
89 TestDirectorySetterUpper::TearDown(); 90 TestDirectorySetterUpper::TearDown();
90 } 91 }
91 } 92 }
92 93
93 TriggeredOpenTestDirectorySetterUpper::TriggeredOpenTestDirectorySetterUpper( 94 TriggeredOpenTestDirectorySetterUpper::TriggeredOpenTestDirectorySetterUpper(
(...skipping 10 matching lines...) Expand all
104 manager()->GetOpenDirectories(&names); 105 manager()->GetOpenDirectories(&names);
105 if (!names.empty()) { 106 if (!names.empty()) {
106 ASSERT_EQ(1U, names.size()); 107 ASSERT_EQ(1U, names.size());
107 ASSERT_EQ(name(), names[0]); 108 ASSERT_EQ(name(), names[0]);
108 TestDirectorySetterUpper::TearDown(); 109 TestDirectorySetterUpper::TearDown();
109 } 110 }
110 } 111 }
111 112
112 MockDirectorySetterUpper::MockDirectory::MockDirectory( 113 MockDirectorySetterUpper::MockDirectory::MockDirectory(
113 const std::string& name) { 114 const std::string& name) {
114 init_kernel(name); 115 InitKernel(name, &delegate_);
115 } 116 }
116 117
117 MockDirectorySetterUpper::MockDirectory::~MockDirectory() {} 118 MockDirectorySetterUpper::MockDirectory::~MockDirectory() {}
118 119
119 MockDirectorySetterUpper::Manager::Manager( 120 MockDirectorySetterUpper::Manager::Manager(
120 const FilePath& root_path, syncable::Directory* dir) : 121 const FilePath& root_path, syncable::Directory* dir) :
121 syncable::DirectoryManager(root_path) { 122 syncable::DirectoryManager(root_path) {
122 managed_directory_ = dir; 123 managed_directory_ = dir;
123 } 124 }
124 125
125 MockDirectorySetterUpper::MockDirectorySetterUpper() 126 MockDirectorySetterUpper::MockDirectorySetterUpper()
126 : directory_(new MockDirectory(name())) { 127 : directory_(new MockDirectory(name())) {
127 } 128 }
128 129
129 MockDirectorySetterUpper::~MockDirectorySetterUpper() {} 130 MockDirectorySetterUpper::~MockDirectorySetterUpper() {}
130 131
131 void MockDirectorySetterUpper::SetUp() { 132 void MockDirectorySetterUpper::SetUp() {
132 reset_directory_manager(new Manager(FilePath(), directory_.get())); 133 reset_directory_manager(new Manager(FilePath(), directory_.get()));
133 } 134 }
134 135
135 void MockDirectorySetterUpper::TearDown() { 136 void MockDirectorySetterUpper::TearDown() {
136 // Nothing to do here. 137 // Nothing to do here.
137 } 138 }
138 139
139 } // namespace browser_sync 140 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/test/sync/engine/test_directory_setter_upper.h ('k') | chrome/test/sync/null_directory_change_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698