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: Better comments 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 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::Callback<void(UserShare*)>& 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(GetUserShareForTest());
114 callback_.Reset();
115 }
116
117 // Pretend we downloaded initial updates and set initial sync ended bits
118 // if we were asked to.
119 if (set_initial_sync_ended_on_init_) {
120 UserShare* user_share = GetUserShareForTest();
121 Directory* directory = user_share->directory.get();
122
123 if (!directory->initial_sync_ended_for_type(syncer::NIGORI)) {
124 ProfileSyncServiceTestHelper::CreateRoot(
125 syncer::NIGORI, GetUserShareForTest(),
126 &id_factory_);
127
128 // A side effect of adding the NIGORI mode (normally done by the
129 // syncer) is a decryption attempt, which will fail the first time.
130 send_passphrase_required = true;
131 }
132
133 SetInitialSyncEndedForAllTypes();
134 restored_types = syncer::ModelTypeSet::All();
135 }
136 }
137
138 SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop(
139 js_backend, success, restored_types);
140 }
141
142 void SyncBackendHostForProfileSyncTest::SetInitialSyncEndedForAllTypes() {
143 UserShare* user_share = GetUserShareForTest();
144 Directory* directory = user_share->directory.get();
145
146 for (int i = syncer::FIRST_REAL_MODEL_TYPE;
147 i < syncer::MODEL_TYPE_COUNT; ++i) {
148 directory->set_initial_sync_ended_for_type(
149 syncer::ModelTypeFromInt(i), true);
150 }
151 }
152
98 } // namespace browser_sync 153 } // namespace browser_sync
99 154
100 syncer::TestIdFactory* TestProfileSyncService::id_factory() { 155 syncer::TestIdFactory* TestProfileSyncService::id_factory() {
101 return &id_factory_; 156 return &id_factory_;
102 } 157 }
103 158
104 browser_sync::SyncBackendHostForProfileSyncTest* 159 browser_sync::SyncBackendHostForProfileSyncTest*
105 TestProfileSyncService::GetBackendForTest() { 160 TestProfileSyncService::GetBackendForTest() {
106 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>( 161 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>(
107 ProfileSyncService::GetBackendForTest()); 162 ProfileSyncService::GetBackendForTest());
108 } 163 }
109 164
165 static void DoNothingCallback(syncer::UserShare*) {
166 }
167
168 // static
169 base::Callback<void(syncer::UserShare*)>
170 TestProfileSyncService::NullCallback() {
171 return base::Bind(DoNothingCallback);
172 }
173
110 TestProfileSyncService::TestProfileSyncService( 174 TestProfileSyncService::TestProfileSyncService(
111 ProfileSyncComponentsFactory* factory, 175 ProfileSyncComponentsFactory* factory,
112 Profile* profile, 176 Profile* profile,
113 SigninManager* signin, 177 SigninManager* signin,
114 ProfileSyncService::StartBehavior behavior, 178 ProfileSyncService::StartBehavior behavior,
115 bool synchronous_backend_initialization, 179 bool synchronous_backend_initialization,
116 const base::Closure& callback) 180 const base::Callback<void(UserShare*)>& callback)
117 : ProfileSyncService(factory, 181 : ProfileSyncService(factory,
118 profile, 182 profile,
119 signin, 183 signin,
120 behavior), 184 behavior),
121 synchronous_backend_initialization_( 185 synchronous_backend_initialization_(
122 synchronous_backend_initialization), 186 synchronous_backend_initialization),
123 synchronous_sync_configuration_(false), 187 synchronous_sync_configuration_(false),
124 callback_(callback), 188 callback_(callback),
125 set_initial_sync_ended_on_init_(true), 189 set_initial_sync_ended_on_init_(true),
126 fail_initial_download_(false), 190 fail_initial_download_(false),
127 use_real_database_(false) { 191 use_real_database_(false) {
128 SetSyncSetupCompleted(); 192 SetSyncSetupCompleted();
129 } 193 }
130 194
131 TestProfileSyncService::~TestProfileSyncService() { 195 TestProfileSyncService::~TestProfileSyncService() {
132 } 196 }
133 197
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( 198 void TestProfileSyncService::OnBackendInitialized(
146 const syncer::WeakHandle<syncer::JsBackend>& backend, 199 const syncer::WeakHandle<syncer::JsBackend>& backend,
147 bool success) { 200 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); 201 ProfileSyncService::OnBackendInitialized(backend, success);
180 if (success && send_passphrase_required)
181 OnPassphraseRequired(syncer::REASON_DECRYPTION, sync_pb::EncryptedData());
182 202
183 // TODO(akalin): Figure out a better way to do this. 203 // TODO(akalin): Figure out a better way to do this.
184 if (synchronous_backend_initialization_) { 204 if (synchronous_backend_initialization_) {
185 MessageLoop::current()->Quit(); 205 MessageLoop::current()->Quit();
186 } 206 }
187 } 207 }
188 208
189 void TestProfileSyncService::Observe( 209 void TestProfileSyncService::Observe(
190 int type, 210 int type,
191 const content::NotificationSource& source, 211 const content::NotificationSource& source,
(...skipping 16 matching lines...) Expand all
208 } 228 }
209 void TestProfileSyncService::set_use_real_database() { 229 void TestProfileSyncService::set_use_real_database() {
210 use_real_database_ = true; 230 use_real_database_ = true;
211 } 231 }
212 232
213 void TestProfileSyncService::CreateBackend() { 233 void TestProfileSyncService::CreateBackend() {
214 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( 234 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest(
215 profile(), 235 profile(),
216 sync_prefs_.AsWeakPtr(), 236 sync_prefs_.AsWeakPtr(),
217 invalidator_storage_.AsWeakPtr(), 237 invalidator_storage_.AsWeakPtr(),
238 id_factory_,
239 callback_,
218 set_initial_sync_ended_on_init_, 240 set_initial_sync_ended_on_init_,
219 synchronous_backend_initialization_, 241 synchronous_backend_initialization_,
220 fail_initial_download_, 242 fail_initial_download_,
221 use_real_database_)); 243 use_real_database_));
222 } 244 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698