OLD | NEW |
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 140 } |
141 return result; | 141 return result; |
142 } | 142 } |
143 | 143 |
144 bool ProfileSyncServiceHarness::SetupSync( | 144 bool ProfileSyncServiceHarness::SetupSync( |
145 syncer::ModelTypeSet synced_datatypes) { | 145 syncer::ModelTypeSet synced_datatypes) { |
146 DCHECK(!profile_->IsLegacySupervised()) | 146 DCHECK(!profile_->IsLegacySupervised()) |
147 << "SetupSync should not be used for legacy supervised users."; | 147 << "SetupSync should not be used for legacy supervised users."; |
148 | 148 |
149 // Initialize the sync client's profile sync service object. | 149 // Initialize the sync client's profile sync service object. |
150 if (service() == NULL) { | 150 if (service() == nullptr) { |
151 LOG(ERROR) << "SetupSync(): service() is null."; | 151 LOG(ERROR) << "SetupSync(): service() is null."; |
152 return false; | 152 return false; |
153 } | 153 } |
154 | 154 |
155 // Tell the sync service that setup is in progress so we don't start syncing | 155 // Tell the sync service that setup is in progress so we don't start syncing |
156 // until we've finished configuration. | 156 // until we've finished configuration. |
157 sync_blocker_ = service()->GetSetupInProgressHandle(); | 157 sync_blocker_ = service()->GetSetupInProgressHandle(); |
158 | 158 |
159 DCHECK(!username_.empty()); | 159 DCHECK(!username_.empty()); |
160 if (signin_type_ == SigninType::UI_SIGNIN) { | 160 if (signin_type_ == SigninType::UI_SIGNIN) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 bool ProfileSyncServiceHarness::IsSyncDisabled() const { | 301 bool ProfileSyncServiceHarness::IsSyncDisabled() const { |
302 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete(); | 302 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete(); |
303 } | 303 } |
304 | 304 |
305 void ProfileSyncServiceHarness::FinishSyncSetup() { | 305 void ProfileSyncServiceHarness::FinishSyncSetup() { |
306 sync_blocker_.reset(); | 306 sync_blocker_.reset(); |
307 service()->SetFirstSetupComplete(); | 307 service()->SetFirstSetupComplete(); |
308 } | 308 } |
309 | 309 |
310 SyncCycleSnapshot ProfileSyncServiceHarness::GetLastCycleSnapshot() const { | 310 SyncCycleSnapshot ProfileSyncServiceHarness::GetLastCycleSnapshot() const { |
311 DCHECK(service() != NULL) << "Sync service has not yet been set up."; | 311 DCHECK(service() != nullptr) << "Sync service has not yet been set up."; |
312 if (service()->IsSyncActive()) { | 312 if (service()->IsSyncActive()) { |
313 return service()->GetLastCycleSnapshot(); | 313 return service()->GetLastCycleSnapshot(); |
314 } | 314 } |
315 return SyncCycleSnapshot(); | 315 return SyncCycleSnapshot(); |
316 } | 316 } |
317 | 317 |
318 bool ProfileSyncServiceHarness::EnableSyncForDatatype( | 318 bool ProfileSyncServiceHarness::EnableSyncForDatatype( |
319 syncer::ModelType datatype) { | 319 syncer::ModelType datatype) { |
320 DVLOG(1) << GetClientInfoString( | 320 DVLOG(1) << GetClientInfoString( |
321 "EnableSyncForDatatype(" | 321 "EnableSyncForDatatype(" |
322 + std::string(syncer::ModelTypeToString(datatype)) + ")"); | 322 + std::string(syncer::ModelTypeToString(datatype)) + ")"); |
323 | 323 |
324 if (IsSyncDisabled()) | 324 if (IsSyncDisabled()) |
325 return SetupSync(syncer::ModelTypeSet(datatype)); | 325 return SetupSync(syncer::ModelTypeSet(datatype)); |
326 | 326 |
327 if (service() == NULL) { | 327 if (service() == nullptr) { |
328 LOG(ERROR) << "EnableSyncForDatatype(): service() is null."; | 328 LOG(ERROR) << "EnableSyncForDatatype(): service() is null."; |
329 return false; | 329 return false; |
330 } | 330 } |
331 | 331 |
332 syncer::ModelTypeSet synced_datatypes = service()->GetPreferredDataTypes(); | 332 syncer::ModelTypeSet synced_datatypes = service()->GetPreferredDataTypes(); |
333 if (synced_datatypes.Has(datatype)) { | 333 if (synced_datatypes.Has(datatype)) { |
334 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " | 334 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " |
335 << syncer::ModelTypeToString(datatype) | 335 << syncer::ModelTypeToString(datatype) |
336 << " on " << profile_debug_name_ << "."; | 336 << " on " << profile_debug_name_ << "."; |
337 return true; | 337 return true; |
(...skipping 12 matching lines...) Expand all Loading... |
350 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); | 350 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); |
351 return false; | 351 return false; |
352 } | 352 } |
353 | 353 |
354 bool ProfileSyncServiceHarness::DisableSyncForDatatype( | 354 bool ProfileSyncServiceHarness::DisableSyncForDatatype( |
355 syncer::ModelType datatype) { | 355 syncer::ModelType datatype) { |
356 DVLOG(1) << GetClientInfoString( | 356 DVLOG(1) << GetClientInfoString( |
357 "DisableSyncForDatatype(" | 357 "DisableSyncForDatatype(" |
358 + std::string(syncer::ModelTypeToString(datatype)) + ")"); | 358 + std::string(syncer::ModelTypeToString(datatype)) + ")"); |
359 | 359 |
360 if (service() == NULL) { | 360 if (service() == nullptr) { |
361 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; | 361 LOG(ERROR) << "DisableSyncForDatatype(): service() is null."; |
362 return false; | 362 return false; |
363 } | 363 } |
364 | 364 |
365 syncer::ModelTypeSet synced_datatypes = service()->GetPreferredDataTypes(); | 365 syncer::ModelTypeSet synced_datatypes = service()->GetPreferredDataTypes(); |
366 if (!synced_datatypes.Has(datatype)) { | 366 if (!synced_datatypes.Has(datatype)) { |
367 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " | 367 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " |
368 << syncer::ModelTypeToString(datatype) | 368 << syncer::ModelTypeToString(datatype) |
369 << " on " << profile_debug_name_ << "."; | 369 << " on " << profile_debug_name_ << "."; |
370 return true; | 370 return true; |
(...skipping 12 matching lines...) Expand all Loading... |
383 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); | 383 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); |
384 return false; | 384 return false; |
385 } | 385 } |
386 | 386 |
387 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { | 387 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { |
388 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); | 388 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); |
389 | 389 |
390 if (IsSyncDisabled()) | 390 if (IsSyncDisabled()) |
391 return SetupSync(); | 391 return SetupSync(); |
392 | 392 |
393 if (service() == NULL) { | 393 if (service() == nullptr) { |
394 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; | 394 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; |
395 return false; | 395 return false; |
396 } | 396 } |
397 | 397 |
398 service()->OnUserChoseDatatypes(true, syncer::UserSelectableTypes()); | 398 service()->OnUserChoseDatatypes(true, syncer::UserSelectableTypes()); |
399 if (AwaitSyncSetupCompletion()) { | 399 if (AwaitSyncSetupCompletion()) { |
400 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes " | 400 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes " |
401 << "on " << profile_debug_name_ << "."; | 401 << "on " << profile_debug_name_ << "."; |
402 return true; | 402 return true; |
403 } | 403 } |
404 | 404 |
405 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); | 405 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); |
406 return false; | 406 return false; |
407 } | 407 } |
408 | 408 |
409 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { | 409 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { |
410 DVLOG(1) << GetClientInfoString("DisableSyncForAllDatatypes"); | 410 DVLOG(1) << GetClientInfoString("DisableSyncForAllDatatypes"); |
411 | 411 |
412 if (service() == NULL) { | 412 if (service() == nullptr) { |
413 LOG(ERROR) << "DisableSyncForAllDatatypes(): service() is null."; | 413 LOG(ERROR) << "DisableSyncForAllDatatypes(): service() is null."; |
414 return false; | 414 return false; |
415 } | 415 } |
416 | 416 |
417 service()->RequestStop(ProfileSyncService::CLEAR_DATA); | 417 service()->RequestStop(ProfileSyncService::CLEAR_DATA); |
418 | 418 |
419 DVLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all " | 419 DVLOG(1) << "DisableSyncForAllDatatypes(): Disabled sync for all " |
420 << "datatypes on " << profile_debug_name_; | 420 << "datatypes on " << profile_debug_name_; |
421 return true; | 421 return true; |
422 } | 422 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 | 464 |
465 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 465 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
466 std::unique_ptr<base::DictionaryValue> value( | 466 std::unique_ptr<base::DictionaryValue> value( |
467 syncer::sync_ui_util::ConstructAboutInformation( | 467 syncer::sync_ui_util::ConstructAboutInformation( |
468 service(), service()->signin(), chrome::GetChannel())); | 468 service(), service()->signin(), chrome::GetChannel())); |
469 std::string service_status; | 469 std::string service_status; |
470 base::JSONWriter::WriteWithOptions( | 470 base::JSONWriter::WriteWithOptions( |
471 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); | 471 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); |
472 return service_status; | 472 return service_status; |
473 } | 473 } |
OLD | NEW |