123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- // Copyright 2018 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "components/sync/driver/test_sync_service.h"
- #include <utility>
- #include <vector>
- #include "base/time/time.h"
- #include "base/values.h"
- #include "components/sync/base/progress_marker_map.h"
- #include "components/sync/driver/sync_token_status.h"
- #include "components/sync/engine/cycle/model_neutral_state.h"
- #include "components/sync/model/type_entities_count.h"
- namespace syncer {
- namespace {
- SyncCycleSnapshot MakeDefaultCycleSnapshot() {
- return SyncCycleSnapshot(
- /*birthday=*/"", /*bag_of_chips=*/"", ModelNeutralState(),
- ProgressMarkerMap(), /*is_silenced-*/ false,
- /*num_server_conflicts=*/7, /*notifications_enabled=*/false,
- /*sync_start_time=*/base::Time::Now(),
- /*poll_finish_time=*/base::Time::Now(),
- /*get_updates_origin=*/sync_pb::SyncEnums::UNKNOWN_ORIGIN,
- /*poll_interval=*/base::Minutes(30),
- /*has_remaining_local_changes=*/false);
- }
- } // namespace
- TestSyncService::TestSyncService()
- : user_settings_(this),
- preferred_data_types_(ModelTypeSet::All()),
- active_data_types_(ModelTypeSet::All()),
- last_cycle_snapshot_(MakeDefaultCycleSnapshot()) {}
- TestSyncService::~TestSyncService() = default;
- void TestSyncService::SetDisableReasons(DisableReasonSet disable_reasons) {
- disable_reasons_ = disable_reasons;
- }
- void TestSyncService::SetTransportState(TransportState transport_state) {
- transport_state_ = transport_state;
- }
- void TestSyncService::SetLocalSyncEnabled(bool local_sync_enabled) {
- local_sync_enabled_ = local_sync_enabled;
- }
- void TestSyncService::SetAccountInfo(const CoreAccountInfo& account_info) {
- account_info_ = account_info;
- }
- void TestSyncService::SetSetupInProgress(bool in_progress) {
- setup_in_progress_ = in_progress;
- }
- void TestSyncService::SetHasSyncConsent(bool has_sync_consent) {
- has_sync_consent_ = has_sync_consent;
- }
- void TestSyncService::SetAuthError(const GoogleServiceAuthError& auth_error) {
- auth_error_ = auth_error;
- }
- void TestSyncService::SetFirstSetupComplete(bool first_setup_complete) {
- if (first_setup_complete)
- user_settings_.SetFirstSetupComplete();
- else
- user_settings_.ClearFirstSetupComplete();
- }
- void TestSyncService::SetPreferredDataTypes(const ModelTypeSet& types) {
- preferred_data_types_ = types;
- }
- void TestSyncService::SetActiveDataTypes(const ModelTypeSet& types) {
- active_data_types_ = types;
- }
- void TestSyncService::SetLastCycleSnapshot(const SyncCycleSnapshot& snapshot) {
- last_cycle_snapshot_ = snapshot;
- }
- void TestSyncService::SetEmptyLastCycleSnapshot() {
- SetLastCycleSnapshot(SyncCycleSnapshot());
- }
- void TestSyncService::SetNonEmptyLastCycleSnapshot() {
- SetLastCycleSnapshot(MakeDefaultCycleSnapshot());
- }
- void TestSyncService::SetDetailedSyncStatus(bool engine_available,
- SyncStatus status) {
- detailed_sync_status_engine_available_ = engine_available;
- detailed_sync_status_ = status;
- }
- void TestSyncService::SetPassphraseRequired(bool required) {
- user_settings_.SetPassphraseRequired(required);
- }
- void TestSyncService::SetPassphraseRequiredForPreferredDataTypes(
- bool required) {
- user_settings_.SetPassphraseRequiredForPreferredDataTypes(required);
- }
- void TestSyncService::SetTrustedVaultKeyRequired(bool required) {
- user_settings_.SetTrustedVaultKeyRequired(required);
- }
- void TestSyncService::SetTrustedVaultKeyRequiredForPreferredDataTypes(
- bool required) {
- user_settings_.SetTrustedVaultKeyRequiredForPreferredDataTypes(required);
- }
- void TestSyncService::SetTrustedVaultRecoverabilityDegraded(bool degraded) {
- user_settings_.SetTrustedVaultRecoverabilityDegraded(degraded);
- }
- void TestSyncService::SetIsUsingExplicitPassphrase(bool enabled) {
- user_settings_.SetIsUsingExplicitPassphrase(enabled);
- }
- void TestSyncService::FireStateChanged() {
- for (SyncServiceObserver& observer : observers_)
- observer.OnStateChanged(this);
- }
- void TestSyncService::FireSyncCycleCompleted() {
- for (SyncServiceObserver& observer : observers_)
- observer.OnSyncCycleCompleted(this);
- }
- SyncUserSettings* TestSyncService::GetUserSettings() {
- return &user_settings_;
- }
- const SyncUserSettings* TestSyncService::GetUserSettings() const {
- return &user_settings_;
- }
- SyncService::DisableReasonSet TestSyncService::GetDisableReasons() const {
- return disable_reasons_;
- }
- SyncService::TransportState TestSyncService::GetTransportState() const {
- return transport_state_;
- }
- bool TestSyncService::IsLocalSyncEnabled() const {
- return local_sync_enabled_;
- }
- CoreAccountInfo TestSyncService::GetAccountInfo() const {
- return account_info_;
- }
- bool TestSyncService::HasSyncConsent() const {
- return has_sync_consent_;
- }
- GoogleServiceAuthError TestSyncService::GetAuthError() const {
- return auth_error_;
- }
- base::Time TestSyncService::GetAuthErrorTime() const {
- return base::Time();
- }
- bool TestSyncService::RequiresClientUpgrade() const {
- return detailed_sync_status_.sync_protocol_error.action ==
- syncer::UPGRADE_CLIENT;
- }
- std::unique_ptr<SyncSetupInProgressHandle>
- TestSyncService::GetSetupInProgressHandle() {
- return nullptr;
- }
- bool TestSyncService::IsSetupInProgress() const {
- return setup_in_progress_;
- }
- ModelTypeSet TestSyncService::GetPreferredDataTypes() const {
- return preferred_data_types_;
- }
- ModelTypeSet TestSyncService::GetActiveDataTypes() const {
- return active_data_types_;
- }
- void TestSyncService::StopAndClear() {}
- void TestSyncService::OnDataTypeRequestsSyncStartup(ModelType type) {}
- void TestSyncService::TriggerRefresh(const ModelTypeSet& types) {}
- void TestSyncService::DataTypePreconditionChanged(ModelType type) {}
- void TestSyncService::AddObserver(SyncServiceObserver* observer) {
- observers_.AddObserver(observer);
- }
- void TestSyncService::RemoveObserver(SyncServiceObserver* observer) {
- observers_.RemoveObserver(observer);
- }
- bool TestSyncService::HasObserver(const SyncServiceObserver* observer) const {
- return observers_.HasObserver(observer);
- }
- SyncTokenStatus TestSyncService::GetSyncTokenStatusForDebugging() const {
- SyncTokenStatus token;
- if (GetAuthError().state() != GoogleServiceAuthError::NONE) {
- token.connection_status = ConnectionStatus::CONNECTION_AUTH_ERROR;
- token.last_get_token_error =
- GoogleServiceAuthError::FromServiceError("error");
- }
- return token;
- }
- bool TestSyncService::QueryDetailedSyncStatusForDebugging(
- SyncStatus* result) const {
- *result = detailed_sync_status_;
- return detailed_sync_status_engine_available_;
- }
- base::Time TestSyncService::GetLastSyncedTimeForDebugging() const {
- return base::Time();
- }
- SyncCycleSnapshot TestSyncService::GetLastCycleSnapshotForDebugging() const {
- return last_cycle_snapshot_;
- }
- std::unique_ptr<base::Value> TestSyncService::GetTypeStatusMapForDebugging()
- const {
- return std::make_unique<base::ListValue>();
- }
- void TestSyncService::GetEntityCountsForDebugging(
- base::OnceCallback<void(const std::vector<TypeEntitiesCount>&)> callback)
- const {
- std::move(callback).Run({});
- }
- const GURL& TestSyncService::GetSyncServiceUrlForDebugging() const {
- return sync_service_url_;
- }
- std::string TestSyncService::GetUnrecoverableErrorMessageForDebugging() const {
- return std::string();
- }
- base::Location TestSyncService::GetUnrecoverableErrorLocationForDebugging()
- const {
- return base::Location();
- }
- void TestSyncService::AddProtocolEventObserver(
- ProtocolEventObserver* observer) {}
- void TestSyncService::RemoveProtocolEventObserver(
- ProtocolEventObserver* observer) {}
- void TestSyncService::GetAllNodesForDebugging(
- base::OnceCallback<void(base::Value::List)> callback) {}
- void TestSyncService::SetInvalidationsForSessionsEnabled(bool enabled) {}
- void TestSyncService::AddTrustedVaultDecryptionKeysFromWeb(
- const std::string& gaia_id,
- const std::vector<std::vector<uint8_t>>& keys,
- int last_key_version) {}
- void TestSyncService::AddTrustedVaultRecoveryMethodFromWeb(
- const std::string& gaia_id,
- const std::vector<uint8_t>& public_key,
- int method_type_hint,
- base::OnceClosure callback) {}
- void TestSyncService::Shutdown() {
- for (SyncServiceObserver& observer : observers_)
- observer.OnSyncShutdown(this);
- }
- } // namespace syncer
|