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

Side by Side Diff: chrome/browser/sync/test_profile_sync_service.cc

Issue 10804039: Make SyncBackendRegistrar aware of loaded data (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More init changes Created 8 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/sync/test_profile_sync_service.h" 5 #include "chrome/browser/sync/test_profile_sync_service.h"
6 6
7 #include "chrome/browser/signin/signin_manager.h" 7 #include "chrome/browser/signin/signin_manager.h"
8 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" 8 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
9 #include "chrome/browser/sync/glue/data_type_controller.h" 9 #include "chrome/browser/sync/glue/data_type_controller.h"
10 #include "chrome/browser/sync/glue/sync_backend_host.h" 10 #include "chrome/browser/sync/glue/sync_backend_host.h"
(...skipping 14 matching lines...) Expand all
25 using syncer::sessions::SyncSourceInfo; 25 using syncer::sessions::SyncSourceInfo;
26 using syncer::UserShare; 26 using syncer::UserShare;
27 using syncer::syncable::Directory; 27 using syncer::syncable::Directory;
28 28
29 namespace browser_sync { 29 namespace browser_sync {
30 30
31 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( 31 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest(
32 Profile* profile, 32 Profile* profile,
33 const base::WeakPtr<SyncPrefs>& sync_prefs, 33 const base::WeakPtr<SyncPrefs>& sync_prefs,
34 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, 34 const base::WeakPtr<InvalidatorStorage>& invalidator_storage,
35 syncer::TestIdFactory& id_factory,
36 base::Closure& callback,
35 bool set_initial_sync_ended_on_init, 37 bool set_initial_sync_ended_on_init,
36 bool synchronous_init, 38 bool synchronous_init,
37 bool fail_initial_download, 39 bool fail_initial_download,
38 bool use_real_database) 40 bool use_real_database)
39 : browser_sync::SyncBackendHost( 41 : browser_sync::SyncBackendHost(
40 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), 42 profile->GetDebugName(), profile, sync_prefs, invalidator_storage),
43 id_factory_(id_factory),
44 callback_(callback),
45 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init),
41 synchronous_init_(synchronous_init), 46 synchronous_init_(synchronous_init),
42 fail_initial_download_(fail_initial_download), 47 fail_initial_download_(fail_initial_download),
43 use_real_database_(use_real_database) {} 48 use_real_database_(use_real_database) {}
44 49
45 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} 50 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {}
46 51
47 namespace { 52 namespace {
48 53
49 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() { 54 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() {
50 return scoped_ptr<syncer::HttpPostProviderFactory>( 55 return scoped_ptr<syncer::HttpPostProviderFactory>(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 const base::Closure& retry_callback) { 93 const base::Closure& retry_callback) {
89 syncer::ModelTypeSet sync_ended; 94 syncer::ModelTypeSet sync_ended;
90 if (!fail_initial_download_) 95 if (!fail_initial_download_)
91 sync_ended.PutAll(types_to_config); 96 sync_ended.PutAll(types_to_config);
92 97
93 FinishConfigureDataTypesOnFrontendLoop(types_to_config, 98 FinishConfigureDataTypesOnFrontendLoop(types_to_config,
94 sync_ended, 99 sync_ended,
95 ready_task); 100 ready_task);
96 } 101 }
97 102
103 void SyncBackendHostForProfileSyncTest
104 ::HandleSyncManagerInitializationOnFrontendLoop(
105 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success,
106 syncer::ModelTypeSet restored_types) {
107 // Here's our opportunity to pretend to do things that the SyncManager would
108 // normally do during initialization, but can't because this is a test.
109 bool send_passphrase_required = false;
110 if (success) {
111 // Set up any nodes the test wants around before model association.
112 if (!callback_.is_null()) {
113 callback_.Run();
114 }
115
116 // Pretend we downloaded initial updates and set initial sync ended bits
117 // if we were asked to.
118 if (set_initial_sync_ended_on_init_) {
119 UserShare* user_share = GetUserShare();
120 Directory* directory = user_share->directory.get();
121
122 if (!directory->initial_sync_ended_for_type(syncer::NIGORI)) {
123 ProfileSyncServiceTestHelper::CreateRoot(
124 syncer::NIGORI, user_share, &id_factory_);
125
126 // A side effect of adding the NIGORI mode (normally done by the
127 // syncer) is a decryption attempt, which will fail the first time.
128 send_passphrase_required = true;
129 }
130
131 SetInitialSyncEndedForAllTypes();
132 restored_types = syncer::ModelTypeSet::All();
133 }
134 }
135
136 SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop(
137 js_backend, success, restored_types);
138 }
139
140 void SyncBackendHostForProfileSyncTest::SetInitialSyncEndedForAllTypes() {
141 UserShare* user_share = GetUserShare();
142 Directory* directory = user_share->directory.get();
143
144 for (int i = syncer::FIRST_REAL_MODEL_TYPE;
145 i < syncer::MODEL_TYPE_COUNT; ++i) {
146 directory->set_initial_sync_ended_for_type(
147 syncer::ModelTypeFromInt(i), true);
148 }
149 }
150
98 } // namespace browser_sync 151 } // namespace browser_sync
99 152
100 syncer::TestIdFactory* TestProfileSyncService::id_factory() { 153 syncer::TestIdFactory* TestProfileSyncService::id_factory() {
101 return &id_factory_; 154 return &id_factory_;
102 } 155 }
103 156
104 browser_sync::SyncBackendHostForProfileSyncTest* 157 browser_sync::SyncBackendHostForProfileSyncTest*
105 TestProfileSyncService::GetBackendForTest() { 158 TestProfileSyncService::GetBackendForTest() {
106 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>( 159 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>(
107 ProfileSyncService::GetBackendForTest()); 160 ProfileSyncService::GetBackendForTest());
(...skipping 16 matching lines...) Expand all
124 callback_(callback), 177 callback_(callback),
125 set_initial_sync_ended_on_init_(true), 178 set_initial_sync_ended_on_init_(true),
126 fail_initial_download_(false), 179 fail_initial_download_(false),
127 use_real_database_(false) { 180 use_real_database_(false) {
128 SetSyncSetupCompleted(); 181 SetSyncSetupCompleted();
129 } 182 }
130 183
131 TestProfileSyncService::~TestProfileSyncService() { 184 TestProfileSyncService::~TestProfileSyncService() {
132 } 185 }
133 186
134 void TestProfileSyncService::SetInitialSyncEndedForAllTypes() {
135 UserShare* user_share = GetUserShare();
136 Directory* directory = user_share->directory.get();
137
138 for (int i = syncer::FIRST_REAL_MODEL_TYPE;
139 i < syncer::MODEL_TYPE_COUNT; ++i) {
140 directory->set_initial_sync_ended_for_type(
141 syncer::ModelTypeFromInt(i), true);
142 }
143 }
144
145 void TestProfileSyncService::OnBackendInitialized( 187 void TestProfileSyncService::OnBackendInitialized(
146 const syncer::WeakHandle<syncer::JsBackend>& backend, 188 const syncer::WeakHandle<syncer::JsBackend>& backend,
147 bool success) { 189 bool success) {
148 bool send_passphrase_required = false;
149 if (success) {
150 // Set this so below code can access GetUserShare().
151 backend_initialized_ = true;
152
153 // Set up any nodes the test wants around before model association.
154 if (!callback_.is_null()) {
155 callback_.Run();
156 callback_.Reset();
157 }
158
159 // Pretend we downloaded initial updates and set initial sync ended bits
160 // if we were asked to.
161 if (set_initial_sync_ended_on_init_) {
162 UserShare* user_share = GetUserShare();
163 Directory* directory = user_share->directory.get();
164
165 if (!directory->initial_sync_ended_for_type(syncer::NIGORI)) {
166 ProfileSyncServiceTestHelper::CreateRoot(
167 syncer::NIGORI, GetUserShare(),
168 id_factory());
169
170 // A side effect of adding the NIGORI mode (normally done by the
171 // syncer) is a decryption attempt, which will fail the first time.
172 send_passphrase_required = true;
173 }
174
175 SetInitialSyncEndedForAllTypes();
176 }
177 }
178
179 ProfileSyncService::OnBackendInitialized(backend, success); 190 ProfileSyncService::OnBackendInitialized(backend, success);
180 if (success && send_passphrase_required)
181 OnPassphraseRequired(syncer::REASON_DECRYPTION, sync_pb::EncryptedData());
182 191
183 // TODO(akalin): Figure out a better way to do this. 192 // TODO(akalin): Figure out a better way to do this.
184 if (synchronous_backend_initialization_) { 193 if (synchronous_backend_initialization_) {
185 MessageLoop::current()->Quit(); 194 MessageLoop::current()->Quit();
186 } 195 }
187 } 196 }
188 197
189 void TestProfileSyncService::Observe( 198 void TestProfileSyncService::Observe(
190 int type, 199 int type,
191 const content::NotificationSource& source, 200 const content::NotificationSource& source,
192 const content::NotificationDetails& details) { 201 const content::NotificationDetails& details) {
193 ProfileSyncService::Observe(type, source, details); 202 ProfileSyncService::Observe(type, source, details);
194 if (type == chrome::NOTIFICATION_SYNC_CONFIGURE_DONE && 203 if (type == chrome::NOTIFICATION_SYNC_CONFIGURE_DONE &&
195 !synchronous_sync_configuration_) { 204 !synchronous_sync_configuration_) {
196 MessageLoop::current()->Quit(); 205 MessageLoop::current()->Quit();
197 } 206 }
198 } 207 }
199 208
209 UserShare* TestProfileSyncService::GetUserShare() const {
210 return backend_->GetUserShare();
211 }
212
200 void TestProfileSyncService::dont_set_initial_sync_ended_on_init() { 213 void TestProfileSyncService::dont_set_initial_sync_ended_on_init() {
201 set_initial_sync_ended_on_init_ = false; 214 set_initial_sync_ended_on_init_ = false;
202 } 215 }
203 void TestProfileSyncService::set_synchronous_sync_configuration() { 216 void TestProfileSyncService::set_synchronous_sync_configuration() {
204 synchronous_sync_configuration_ = true; 217 synchronous_sync_configuration_ = true;
205 } 218 }
206 void TestProfileSyncService::fail_initial_download() { 219 void TestProfileSyncService::fail_initial_download() {
207 fail_initial_download_ = true; 220 fail_initial_download_ = true;
208 } 221 }
209 void TestProfileSyncService::set_use_real_database() { 222 void TestProfileSyncService::set_use_real_database() {
210 use_real_database_ = true; 223 use_real_database_ = true;
211 } 224 }
212 225
213 void TestProfileSyncService::CreateBackend() { 226 void TestProfileSyncService::CreateBackend() {
214 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( 227 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest(
215 profile(), 228 profile(),
216 sync_prefs_.AsWeakPtr(), 229 sync_prefs_.AsWeakPtr(),
217 invalidator_storage_.AsWeakPtr(), 230 invalidator_storage_.AsWeakPtr(),
231 id_factory_,
232 callback_,
218 set_initial_sync_ended_on_init_, 233 set_initial_sync_ended_on_init_,
219 synchronous_backend_initialization_, 234 synchronous_backend_initialization_,
220 fail_initial_download_, 235 fail_initial_download_,
221 use_real_database_)); 236 use_real_database_));
222 } 237 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698