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

Side by Side Diff: chrome/browser/sync/test/integration/profile_sync_service_harness.cc

Issue 2716413003: Initial clear server data impl (Closed)
Patch Set: Fixed various CL comments Created 3 years, 9 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/integration/profile_sync_service_harness.h" 5 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <iterator> 8 #include <iterator>
9 #include <ostream> 9 #include <ostream>
10 #include <sstream> 10 #include <sstream>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 123
124 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { } 124 ProfileSyncServiceHarness::~ProfileSyncServiceHarness() { }
125 125
126 void ProfileSyncServiceHarness::SetCredentials(const std::string& username, 126 void ProfileSyncServiceHarness::SetCredentials(const std::string& username,
127 const std::string& password) { 127 const std::string& password) {
128 username_ = username; 128 username_ = username;
129 password_ = password; 129 password_ = password;
130 } 130 }
131 131
132 bool ProfileSyncServiceHarness::SetupSync() { 132 bool ProfileSyncServiceHarness::SetupSync() {
133 bool result = SetupSync(syncer::UserSelectableTypes()); 133 bool result = SetupSync(syncer::UserSelectableTypes(), false);
134 if (result == false) { 134 if (!result) {
135 std::string status = GetServiceStatus(); 135 LOG(ERROR) << profile_debug_name_ << ": SetupSync failed. Syncer status:\n"
136 LOG(ERROR) << profile_debug_name_ 136 << GetServiceStatus();
137 << ": SetupSync failed. Syncer status:\n" << status;
138 } else { 137 } else {
139 DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; 138 DVLOG(1) << profile_debug_name_ << ": SetupSync successful.";
140 } 139 }
141 return result; 140 return result;
142 } 141 }
143 142
144 bool ProfileSyncServiceHarness::SetupSync( 143 bool ProfileSyncServiceHarness::SetupSyncForClear() {
145 syncer::ModelTypeSet synced_datatypes) { 144 bool result = SetupSync(syncer::UserSelectableTypes(), true);
145 if (!result) {
146 LOG(ERROR) << profile_debug_name_
147 << ": SetupSyncForClear failed. Syncer status:\n"
148 << GetServiceStatus();
149 } else {
150 DVLOG(1) << profile_debug_name_ << ": SetupSyncForClear successful.";
151 }
152 return result;
153 }
154
155 bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes,
156 bool forClear) {
skym 2017/03/08 00:23:48 should be named for_clear. https://google.github.i
wylieb 2017/03/08 00:58:51 Done.
146 DCHECK(!profile_->IsLegacySupervised()) 157 DCHECK(!profile_->IsLegacySupervised())
147 << "SetupSync should not be used for legacy supervised users."; 158 << "SetupSync should not be used for legacy supervised users.";
148 159
149 // Initialize the sync client's profile sync service object. 160 // Initialize the sync client's profile sync service object.
150 if (service() == nullptr) { 161 if (service() == nullptr) {
151 LOG(ERROR) << "SetupSync(): service() is null."; 162 LOG(ERROR) << "SetupSync(): service() is null.";
152 return false; 163 return false;
153 } 164 }
154 165
155 // Tell the sync service that setup is in progress so we don't start syncing 166 // Tell the sync service that setup is in progress so we don't start syncing
(...skipping 16 matching lines...) Expand all
172 service()->GoogleSigninSucceeded(account_id, username_, password_); 183 service()->GoogleSigninSucceeded(account_id, username_, password_);
173 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> 184 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
174 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString()); 185 UpdateCredentials(account_id, GenerateFakeOAuth2RefreshTokenString());
175 } else { 186 } else {
176 LOG(ERROR) << "Unsupported profile signin type."; 187 LOG(ERROR) << "Unsupported profile signin type.";
177 } 188 }
178 189
179 // Now that auth is completed, request that sync actually start. 190 // Now that auth is completed, request that sync actually start.
180 service()->RequestStart(); 191 service()->RequestStart();
181 192
182 if (!AwaitEngineInitialization()) { 193 if (forClear && !AwaitEngineInitializationForClear()) {
194 return false;
195 } else if (!forClear && !AwaitEngineInitialization()) {
183 return false; 196 return false;
184 } 197 }
185 198
186 // Choose the datatypes to be synced. If all datatypes are to be synced, 199 // Choose the datatypes to be synced. If all datatypes are to be synced,
187 // set sync_everything to true; otherwise, set it to false. 200 // set sync_everything to true; otherwise, set it to false.
188 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes()); 201 bool sync_everything = (synced_datatypes == syncer::UserSelectableTypes());
189 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes); 202 service()->OnUserChoseDatatypes(sync_everything, synced_datatypes);
190 203
191 // Notify ProfileSyncService that we are done with configuration. 204 // Notify ProfileSyncService that we are done with configuration.
192 FinishSyncSetup(); 205 FinishSyncSetup();
193 206
194 if ((signin_type_ == SigninType::UI_SIGNIN) && 207 if ((signin_type_ == SigninType::UI_SIGNIN) &&
195 !login_ui_test_utils::DismissSyncConfirmationDialog( 208 !login_ui_test_utils::DismissSyncConfirmationDialog(
196 chrome::FindBrowserWithProfile(profile_), 209 chrome::FindBrowserWithProfile(profile_),
197 base::TimeDelta::FromSeconds(30))) { 210 base::TimeDelta::FromSeconds(30))) {
198 LOG(ERROR) << "Failed to dismiss sync confirmation dialog."; 211 LOG(ERROR) << "Failed to dismiss sync confirmation dialog.";
199 return false; 212 return false;
200 } 213 }
201 214
215 // If we're setting up for clear, we don't need to wait for passphrase
216 // decryption or setup completion.
skym 2017/03/08 00:23:48 I'd just drop the "passphrase description or", I'm
wylieb 2017/03/08 00:58:51 Done.
217 if (forClear) {
218 return true;
219 }
220
202 // Set an implicit passphrase for encryption if an explicit one hasn't already 221 // Set an implicit passphrase for encryption if an explicit one hasn't already
203 // been set. If an explicit passphrase has been set, immediately return false, 222 // been set. If an explicit passphrase has been set, immediately return false,
204 // since a decryption passphrase is required. 223 // since a decryption passphrase is required.
205 if (!service()->IsUsingSecondaryPassphrase()) { 224 if (!service()->IsUsingSecondaryPassphrase()) {
206 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); 225 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT);
207 } else { 226 } else {
208 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" 227 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
209 " until SetDecryptionPassphrase is called."; 228 " until SetDecryptionPassphrase is called.";
210 return false; 229 return false;
211 } 230 }
212 231
213 // Wait for initial sync cycle to be completed. 232 // Wait for initial sync cycle to be completed.
214 if (!AwaitSyncSetupCompletion()) { 233 if (!AwaitSyncSetupCompletion()) {
215 LOG(ERROR) << "Initial sync cycle timed out.";
216 return false; 234 return false;
217 } 235 }
218 236
219 return true; 237 return true;
220 } 238 }
221 239
240 bool ProfileSyncServiceHarness::RestartSyncService() {
241 auto blocker = service()->GetSetupInProgressHandle();
skym 2017/03/08 00:23:48 I think auto is bad here. You're obscuring if this
wylieb 2017/03/08 00:58:51 Done.
242 DVLOG(1) << "Requesting stop for service.";
243 service()->RequestStop(ProfileSyncService::CLEAR_DATA);
244 DVLOG(1) << "Requesting start for service";
245
246 service()->RequestStart();
247 if (!AwaitEngineInitialization()) {
248 LOG(ERROR) << "AwaitEngineInitialization failed.";
249 return false;
250 }
251
252 // This passphrase should be implicit because ClearServerData should be called
skym 2017/03/08 00:23:48 Erm, doesn't implicit mean that it is the GAIA pas
wylieb 2017/03/08 00:58:51 Done.
253 // prior.
254 if (!service()->IsUsingSecondaryPassphrase()) {
255 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT);
256 } else {
257 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
258 " until SetDecryptionPassphrase is called.";
259 return false;
260 }
261
262 blocker.reset();
skym 2017/03/08 00:23:48 You shouldn't need this, it'll be destructed when
wylieb 2017/03/08 00:58:51 Done.
263 service()->SetFirstSetupComplete();
skym 2017/03/08 00:23:48 I'm confused why you need both the blocker and thi
wylieb 2017/03/08 00:58:51 Seems like something to be addressed in another CL
skym 2017/03/08 19:15:02 Okay... I'm okay with you having both the SetFirst
264
265 return true;
266 }
267
222 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( 268 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion(
223 ProfileSyncServiceHarness* partner) { 269 ProfileSyncServiceHarness* partner) {
224 std::vector<ProfileSyncServiceHarness*> harnesses; 270 std::vector<ProfileSyncServiceHarness*> harnesses;
225 harnesses.push_back(this); 271 harnesses.push_back(this);
226 harnesses.push_back(partner); 272 harnesses.push_back(partner);
227 return AwaitQuiescence(harnesses); 273 return AwaitQuiescence(harnesses);
228 } 274 }
229 275
230 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( 276 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion(
231 const std::vector<ProfileSyncServiceHarness*>& partners) { 277 const std::vector<ProfileSyncServiceHarness*>& partners) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 311 }
266 312
267 if (HasAuthError(service())) { 313 if (HasAuthError(service())) {
268 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed."; 314 LOG(ERROR) << "Credentials were rejected. Sync cannot proceed.";
269 return false; 315 return false;
270 } 316 }
271 317
272 return true; 318 return true;
273 } 319 }
274 320
321 bool ProfileSyncServiceHarness::AwaitEngineInitializationForClear() {
322 if (!EngineInitializeChecker(service()).Wait()) {
323 LOG(ERROR)
324 << "Initializing up for clear: EngineInitializeChecker timed out.";
325 return false;
326 }
327
328 if (!service()->IsEngineInitialized()) {
329 LOG(ERROR) << "Initializing up for clear: Service engine not initialized.";
330 return false;
331 }
332
333 if (HasAuthError(service())) {
334 LOG(ERROR) << "Initializing up for clear: Credentials were rejected. Sync "
335 "cannot proceed.";
336 return false;
337 }
338
339 return true;
340 }
341
275 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { 342 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() {
276 if (!SyncSetupChecker(service()).Wait()) { 343 if (!SyncSetupChecker(service()).Wait()) {
277 LOG(ERROR) << "SyncSetupChecker timed out."; 344 LOG(ERROR) << "SyncSetupChecker timed out.";
278 return false; 345 return false;
279 } 346 }
280 347
281 // Make sure that initial sync wasn't blocked by a missing passphrase. 348 // Make sure that initial sync wasn't blocked by a missing passphrase.
282 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { 349 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) {
283 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" 350 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
284 " until SetDecryptionPassphrase is called."; 351 " until SetDecryptionPassphrase is called.";
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 543
477 std::string ProfileSyncServiceHarness::GetServiceStatus() { 544 std::string ProfileSyncServiceHarness::GetServiceStatus() {
478 std::unique_ptr<base::DictionaryValue> value( 545 std::unique_ptr<base::DictionaryValue> value(
479 syncer::sync_ui_util::ConstructAboutInformation( 546 syncer::sync_ui_util::ConstructAboutInformation(
480 service(), service()->signin(), chrome::GetChannel())); 547 service(), service()->signin(), chrome::GetChannel()));
481 std::string service_status; 548 std::string service_status;
482 base::JSONWriter::WriteWithOptions( 549 base::JSONWriter::WriteWithOptions(
483 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); 550 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status);
484 return service_status; 551 return service_status;
485 } 552 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698