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

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: Created 8 years, 5 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 12 matching lines...) Expand all
23 using syncer::sessions::SyncSourceInfo; 23 using syncer::sessions::SyncSourceInfo;
24 using syncer::UserShare; 24 using syncer::UserShare;
25 using syncer::syncable::Directory; 25 using syncer::syncable::Directory;
26 26
27 namespace browser_sync { 27 namespace browser_sync {
28 28
29 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( 29 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest(
30 Profile* profile, 30 Profile* profile,
31 const base::WeakPtr<SyncPrefs>& sync_prefs, 31 const base::WeakPtr<SyncPrefs>& sync_prefs,
32 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, 32 const base::WeakPtr<InvalidatorStorage>& invalidator_storage,
33 syncer::TestIdFactory& id_factory,
34 base::Callback<void(UserShare*)>& callback,
33 bool set_initial_sync_ended_on_init, 35 bool set_initial_sync_ended_on_init,
34 bool synchronous_init, 36 bool synchronous_init,
35 bool fail_initial_download, 37 bool fail_initial_download,
36 bool use_real_database) 38 bool use_real_database)
37 : browser_sync::SyncBackendHost( 39 : browser_sync::SyncBackendHost(
38 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), 40 profile->GetDebugName(), profile, sync_prefs, invalidator_storage),
41 id_factory_(id_factory),
42 callback_(callback),
43 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init),
39 synchronous_init_(synchronous_init), 44 synchronous_init_(synchronous_init),
40 fail_initial_download_(fail_initial_download), 45 fail_initial_download_(fail_initial_download),
41 use_real_database_(use_real_database) {} 46 use_real_database_(use_real_database) {}
42 47
43 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} 48 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {}
44 49
45 namespace { 50 namespace {
46 51
47 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() { 52 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() {
48 return scoped_ptr<syncer::HttpPostProviderFactory>( 53 return scoped_ptr<syncer::HttpPostProviderFactory>(
(...skipping 30 matching lines...) Expand all
79 const base::Closure& retry_callback) { 84 const base::Closure& retry_callback) {
80 syncer::ModelTypeSet sync_ended; 85 syncer::ModelTypeSet sync_ended;
81 if (!fail_initial_download_) 86 if (!fail_initial_download_)
82 sync_ended.PutAll(types_to_config); 87 sync_ended.PutAll(types_to_config);
83 88
84 FinishConfigureDataTypesOnFrontendLoop(types_to_config, 89 FinishConfigureDataTypesOnFrontendLoop(types_to_config,
85 sync_ended, 90 sync_ended,
86 ready_task); 91 ready_task);
87 } 92 }
88 93
94 void SyncBackendHostForProfileSyncTest
95 ::HandleSyncManagerInitializationOnFrontendLoop(
96 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success,
97 syncer::ModelTypeSet restored_types) {
98 // Here's our opportunity to pretend to do things that the SyncManager would
99 // normally do during initialization, but can't because this is a test.
100 bool send_passphrase_required = false;
101 if (success) {
102 // Set up any nodes the test wants around before model association.
103 if (!callback_.is_null()) {
104 callback_.Run(GetUserShareForTest());
tim (not reviewing) 2012/07/20 21:00:57 Plumbing the UserShare* around sure got a bit mess
rlarocque 2012/07/20 21:17:59 The main problem is that that no one is allowed to
tim (not reviewing) 2012/07/23 20:33:19 I agree it's good to keep the DCHECKs in the gener
rlarocque 2012/07/23 20:50:30 The callbacks only have access to a TestProfileSyn
tim (not reviewing) 2012/07/23 21:01:58 Yeah, I think it would be too (my initial comment
105 callback_.Reset();
106 }
107
108 // Pretend we downloaded initial updates and set initial sync ended bits
109 // if we were asked to.
110 if (set_initial_sync_ended_on_init_) {
111 UserShare* user_share = GetUserShareForTest();
112 Directory* directory = user_share->directory.get();
113
114 if (!directory->initial_sync_ended_for_type(syncer::NIGORI)) {
115 ProfileSyncServiceTestHelper::CreateRoot(
116 syncer::NIGORI, GetUserShareForTest(),
117 &id_factory_);
118
119 // A side effect of adding the NIGORI mode (normally done by the
120 // syncer) is a decryption attempt, which will fail the first time.
121 send_passphrase_required = true;
122 }
123
124 SetInitialSyncEndedForAllTypes();
125 restored_types = syncer::ModelTypeSet::All();
126 }
127 }
128
129 SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop(
130 js_backend, success, restored_types);
131 }
132
133 void SyncBackendHostForProfileSyncTest::SetInitialSyncEndedForAllTypes() {
134 UserShare* user_share = GetUserShareForTest();
135 Directory* directory = user_share->directory.get();
136
137 for (int i = syncer::FIRST_REAL_MODEL_TYPE;
138 i < syncer::MODEL_TYPE_COUNT; ++i) {
139 directory->set_initial_sync_ended_for_type(
140 syncer::ModelTypeFromInt(i), true);
141 }
142 }
143
89 } // namespace browser_sync 144 } // namespace browser_sync
90 145
91 syncer::TestIdFactory* TestProfileSyncService::id_factory() { 146 syncer::TestIdFactory* TestProfileSyncService::id_factory() {
92 return &id_factory_; 147 return &id_factory_;
93 } 148 }
94 149
95 browser_sync::SyncBackendHostForProfileSyncTest* 150 browser_sync::SyncBackendHostForProfileSyncTest*
96 TestProfileSyncService::GetBackendForTest() { 151 TestProfileSyncService::GetBackendForTest() {
97 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>( 152 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>(
98 ProfileSyncService::GetBackendForTest()); 153 ProfileSyncService::GetBackendForTest());
99 } 154 }
100 155
156 static void DoNothingCallback(syncer::UserShare*) {
tim (not reviewing) 2012/07/20 21:00:57 I think you can get rid of this (and more boilerpl
157 }
158
159 // static
160 base::Callback<void(syncer::UserShare*)>
161 TestProfileSyncService::NullCallback() {
162 return base::Bind(DoNothingCallback);
163 }
164
101 TestProfileSyncService::TestProfileSyncService( 165 TestProfileSyncService::TestProfileSyncService(
102 ProfileSyncComponentsFactory* factory, 166 ProfileSyncComponentsFactory* factory,
103 Profile* profile, 167 Profile* profile,
104 SigninManager* signin, 168 SigninManager* signin,
105 ProfileSyncService::StartBehavior behavior, 169 ProfileSyncService::StartBehavior behavior,
106 bool synchronous_backend_initialization, 170 bool synchronous_backend_initialization,
107 const base::Closure& callback) 171 const base::Callback<void(UserShare*)>& callback)
108 : ProfileSyncService(factory, 172 : ProfileSyncService(factory,
109 profile, 173 profile,
110 signin, 174 signin,
111 behavior), 175 behavior),
112 synchronous_backend_initialization_( 176 synchronous_backend_initialization_(
113 synchronous_backend_initialization), 177 synchronous_backend_initialization),
114 synchronous_sync_configuration_(false), 178 synchronous_sync_configuration_(false),
115 callback_(callback), 179 callback_(callback),
116 set_initial_sync_ended_on_init_(true), 180 set_initial_sync_ended_on_init_(true),
117 fail_initial_download_(false), 181 fail_initial_download_(false),
118 use_real_database_(false) { 182 use_real_database_(false) {
119 SetSyncSetupCompleted(); 183 SetSyncSetupCompleted();
120 } 184 }
121 185
122 TestProfileSyncService::~TestProfileSyncService() { 186 TestProfileSyncService::~TestProfileSyncService() {
123 } 187 }
124 188
125 void TestProfileSyncService::SetInitialSyncEndedForAllTypes() {
126 UserShare* user_share = GetUserShare();
127 Directory* directory = user_share->directory.get();
128
129 for (int i = syncer::FIRST_REAL_MODEL_TYPE;
130 i < syncer::MODEL_TYPE_COUNT; ++i) {
131 directory->set_initial_sync_ended_for_type(
132 syncer::ModelTypeFromInt(i), true);
133 }
134 }
135
136 void TestProfileSyncService::OnBackendInitialized( 189 void TestProfileSyncService::OnBackendInitialized(
137 const syncer::WeakHandle<syncer::JsBackend>& backend, 190 const syncer::WeakHandle<syncer::JsBackend>& backend,
138 bool success) { 191 bool success) {
139 bool send_passphrase_required = false;
140 if (success) {
141 // Set this so below code can access GetUserShare().
142 backend_initialized_ = true;
143
144 // Set up any nodes the test wants around before model association.
145 if (!callback_.is_null()) {
146 callback_.Run();
147 callback_.Reset();
148 }
149
150 // Pretend we downloaded initial updates and set initial sync ended bits
151 // if we were asked to.
152 if (set_initial_sync_ended_on_init_) {
153 UserShare* user_share = GetUserShare();
154 Directory* directory = user_share->directory.get();
155
156 if (!directory->initial_sync_ended_for_type(syncer::NIGORI)) {
157 ProfileSyncServiceTestHelper::CreateRoot(
158 syncer::NIGORI, GetUserShare(),
159 id_factory());
160
161 // A side effect of adding the NIGORI mode (normally done by the
162 // syncer) is a decryption attempt, which will fail the first time.
163 send_passphrase_required = true;
164 }
165
166 SetInitialSyncEndedForAllTypes();
167 }
168 }
169
170 ProfileSyncService::OnBackendInitialized(backend, success); 192 ProfileSyncService::OnBackendInitialized(backend, success);
171 if (success && send_passphrase_required)
172 OnPassphraseRequired(syncer::REASON_DECRYPTION, sync_pb::EncryptedData());
173 193
174 // TODO(akalin): Figure out a better way to do this. 194 // TODO(akalin): Figure out a better way to do this.
175 if (synchronous_backend_initialization_) { 195 if (synchronous_backend_initialization_) {
176 MessageLoop::current()->Quit(); 196 MessageLoop::current()->Quit();
177 } 197 }
178 } 198 }
179 199
180 void TestProfileSyncService::Observe( 200 void TestProfileSyncService::Observe(
181 int type, 201 int type,
182 const content::NotificationSource& source, 202 const content::NotificationSource& source,
(...skipping 16 matching lines...) Expand all
199 } 219 }
200 void TestProfileSyncService::set_use_real_database() { 220 void TestProfileSyncService::set_use_real_database() {
201 use_real_database_ = true; 221 use_real_database_ = true;
202 } 222 }
203 223
204 void TestProfileSyncService::CreateBackend() { 224 void TestProfileSyncService::CreateBackend() {
205 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( 225 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest(
206 profile(), 226 profile(),
207 sync_prefs_.AsWeakPtr(), 227 sync_prefs_.AsWeakPtr(),
208 invalidator_storage_.AsWeakPtr(), 228 invalidator_storage_.AsWeakPtr(),
229 id_factory_,
230 callback_,
209 set_initial_sync_ended_on_init_, 231 set_initial_sync_ended_on_init_,
210 synchronous_backend_initialization_, 232 synchronous_backend_initialization_,
211 fail_initial_download_, 233 fail_initial_download_,
212 use_real_database_)); 234 use_real_database_));
213 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698