| 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 15 matching lines...) Expand all Loading... |
| 26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "components/browser_sync/browser/profile_sync_service.h" | 27 #include "components/browser_sync/browser/profile_sync_service.h" |
| 28 #include "components/invalidation/impl/p2p_invalidation_service.h" | 28 #include "components/invalidation/impl/p2p_invalidation_service.h" |
| 29 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 29 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 30 #include "components/signin/core/browser/signin_manager_base.h" | 30 #include "components/signin/core/browser/signin_manager_base.h" |
| 31 #include "components/sync/base/progress_marker_map.h" | 31 #include "components/sync/base/progress_marker_map.h" |
| 32 #include "components/sync/driver/about_sync_util.h" | 32 #include "components/sync/driver/about_sync_util.h" |
| 33 #include "components/sync/engine/sync_string_conversions.h" | 33 #include "components/sync/engine/sync_string_conversions.h" |
| 34 #include "google_apis/gaia/gaia_constants.h" | 34 #include "google_apis/gaia/gaia_constants.h" |
| 35 | 35 |
| 36 using syncer::sessions::SyncSessionSnapshot; | 36 using syncer::SyncCycleSnapshot; |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 std::string GetGaiaIdForUsername(const std::string& username) { | 40 std::string GetGaiaIdForUsername(const std::string& username) { |
| 41 return "gaia-id-" + username; | 41 return "gaia-id-" + username; |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool HasAuthError(ProfileSyncService* service) { | 44 bool HasAuthError(ProfileSyncService* service) { |
| 45 return service->GetAuthError().state() == | 45 return service->GetAuthError().state() == |
| 46 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 46 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 310 |
| 311 bool ProfileSyncServiceHarness::IsSyncDisabled() const { | 311 bool ProfileSyncServiceHarness::IsSyncDisabled() const { |
| 312 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete(); | 312 return !service()->IsSetupInProgress() && !service()->IsFirstSetupComplete(); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void ProfileSyncServiceHarness::FinishSyncSetup() { | 315 void ProfileSyncServiceHarness::FinishSyncSetup() { |
| 316 sync_blocker_.reset(); | 316 sync_blocker_.reset(); |
| 317 service()->SetFirstSetupComplete(); | 317 service()->SetFirstSetupComplete(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 SyncSessionSnapshot ProfileSyncServiceHarness::GetLastSessionSnapshot() const { | 320 SyncCycleSnapshot ProfileSyncServiceHarness::GetLastCycleSnapshot() const { |
| 321 DCHECK(service() != NULL) << "Sync service has not yet been set up."; | 321 DCHECK(service() != NULL) << "Sync service has not yet been set up."; |
| 322 if (service()->IsSyncActive()) { | 322 if (service()->IsSyncActive()) { |
| 323 return service()->GetLastSessionSnapshot(); | 323 return service()->GetLastCycleSnapshot(); |
| 324 } | 324 } |
| 325 return SyncSessionSnapshot(); | 325 return SyncCycleSnapshot(); |
| 326 } | 326 } |
| 327 | 327 |
| 328 bool ProfileSyncServiceHarness::EnableSyncForDatatype( | 328 bool ProfileSyncServiceHarness::EnableSyncForDatatype( |
| 329 syncer::ModelType datatype) { | 329 syncer::ModelType datatype) { |
| 330 DVLOG(1) << GetClientInfoString( | 330 DVLOG(1) << GetClientInfoString( |
| 331 "EnableSyncForDatatype(" | 331 "EnableSyncForDatatype(" |
| 332 + std::string(syncer::ModelTypeToString(datatype)) + ")"); | 332 + std::string(syncer::ModelTypeToString(datatype)) + ")"); |
| 333 | 333 |
| 334 if (IsSyncDisabled()) | 334 if (IsSyncDisabled()) |
| 335 return SetupSync(syncer::ModelTypeSet(datatype)); | 335 return SetupSync(syncer::ModelTypeSet(datatype)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 return true; | 431 return true; |
| 432 } | 432 } |
| 433 | 433 |
| 434 // TODO(sync): Clean up this method in a separate CL. Remove all snapshot fields | 434 // TODO(sync): Clean up this method in a separate CL. Remove all snapshot fields |
| 435 // and log shorter, more meaningful messages. | 435 // and log shorter, more meaningful messages. |
| 436 std::string ProfileSyncServiceHarness::GetClientInfoString( | 436 std::string ProfileSyncServiceHarness::GetClientInfoString( |
| 437 const std::string& message) const { | 437 const std::string& message) const { |
| 438 std::stringstream os; | 438 std::stringstream os; |
| 439 os << profile_debug_name_ << ": " << message << ": "; | 439 os << profile_debug_name_ << ": " << message << ": "; |
| 440 if (service()) { | 440 if (service()) { |
| 441 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); | 441 const SyncCycleSnapshot& snap = GetLastCycleSnapshot(); |
| 442 ProfileSyncService::Status status; | 442 ProfileSyncService::Status status; |
| 443 service()->QueryDetailedSyncStatus(&status); | 443 service()->QueryDetailedSyncStatus(&status); |
| 444 // Capture select info from the sync session snapshot and syncer status. | 444 // Capture select info from the sync session snapshot and syncer status. |
| 445 os << ", has_unsynced_items: " | 445 os << ", has_unsynced_items: " |
| 446 << (service()->IsSyncActive() ? service()->HasUnsyncedItems() : 0) | 446 << (service()->IsSyncActive() ? service()->HasUnsyncedItems() : 0) |
| 447 << ", did_commit: " | 447 << ", did_commit: " |
| 448 << (snap.model_neutral_state().num_successful_commits == 0 && | 448 << (snap.model_neutral_state().num_successful_commits == 0 && |
| 449 snap.model_neutral_state().commit_result == syncer::SYNCER_OK) | 449 snap.model_neutral_state().commit_result == syncer::SYNCER_OK) |
| 450 << ", encryption conflicts: " | 450 << ", encryption conflicts: " |
| 451 << snap.num_encryption_conflicts() | 451 << snap.num_encryption_conflicts() |
| (...skipping 22 matching lines...) Expand all Loading... |
| 474 | 474 |
| 475 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 475 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 476 std::unique_ptr<base::DictionaryValue> value( | 476 std::unique_ptr<base::DictionaryValue> value( |
| 477 sync_driver::sync_ui_util::ConstructAboutInformation( | 477 sync_driver::sync_ui_util::ConstructAboutInformation( |
| 478 service(), service()->signin(), chrome::GetChannel())); | 478 service(), service()->signin(), chrome::GetChannel())); |
| 479 std::string service_status; | 479 std::string service_status; |
| 480 base::JSONWriter::WriteWithOptions( | 480 base::JSONWriter::WriteWithOptions( |
| 481 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); | 481 *value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &service_status); |
| 482 return service_status; | 482 return service_status; |
| 483 } | 483 } |
| OLD | NEW |