Commit 8f1b6d09 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Sync: Move SyncTokenStatus out of SyncService and into its own files

It really has little to do with SyncService. This allows clients to
only include the thing they need, rather than the whole sync_service.h.

TBRing trivial call site changes.
TBR=sebsg,bcwhite

Bug: none
Change-Id: Icaa165425f50c748904b6f4d4818b552185c4fe5
Reviewed-on: https://chromium-review.googlesource.com/1065820
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560666}
parent 9f1af3cd
......@@ -14,6 +14,7 @@
#include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/sync/driver/sync_token_status.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/http/http_status_code.h"
#include "net/url_request/url_request_status.h"
......
......@@ -8,6 +8,7 @@
#include "components/sync/base/model_type.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/engine/cycle/sync_cycle_snapshot.h"
......@@ -61,9 +62,8 @@ syncer::SyncCycleSnapshot TestSyncService::GetLastCycleSnapshot() const {
return syncer::SyncCycleSnapshot();
}
syncer::SyncService::SyncTokenStatus TestSyncService::GetSyncTokenStatus()
const {
syncer::SyncService::SyncTokenStatus token;
syncer::SyncTokenStatus TestSyncService::GetSyncTokenStatus() const {
syncer::SyncTokenStatus token;
if (is_in_auth_error_) {
token.connection_status = syncer::ConnectionStatus::CONNECTION_AUTH_ERROR;
......
......@@ -24,7 +24,7 @@ class TestSyncService : public syncer::FakeSyncService {
bool ConfigurationDone() const override;
syncer::SyncCycleSnapshot GetLastCycleSnapshot() const override;
const GoogleServiceAuthError& GetAuthError() const override;
syncer::SyncService::SyncTokenStatus GetSyncTokenStatus() const override;
syncer::SyncTokenStatus GetSyncTokenStatus() const override;
void SetCanSyncStart(bool can_sync_start) {
can_sync_start_ = can_sync_start;
......
......@@ -2091,8 +2091,7 @@ ProfileSyncService::GetDeviceInfoSyncControllerDelegateOnUIThread() {
->GetControllerDelegateOnUIThread();
}
syncer::SyncService::SyncTokenStatus ProfileSyncService::GetSyncTokenStatus()
const {
syncer::SyncTokenStatus ProfileSyncService::GetSyncTokenStatus() const {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
return auth_manager_->GetSyncTokenStatus();
}
......
......@@ -277,7 +277,7 @@ class ProfileSyncService : public syncer::SyncService,
void RegisterDataTypeController(std::unique_ptr<syncer::DataTypeController>
data_type_controller) override;
void ReenableDatatype(syncer::ModelType type) override;
SyncTokenStatus GetSyncTokenStatus() const override;
syncer::SyncTokenStatus GetSyncTokenStatus() const override;
std::string QuerySyncStatusSummaryString() override;
bool QueryDetailedSyncStatus(syncer::SyncStatus* result) override;
base::Time GetLastSyncedTime() const override;
......
......@@ -24,6 +24,7 @@
#include "components/sync/driver/sync_api_component_factory_mock.h"
#include "components/sync/driver/sync_driver_switches.h"
#include "components/sync/driver/sync_service_observer.h"
#include "components/sync/driver/sync_token_status.h"
#include "components/sync/driver/sync_util.h"
#include "components/sync/engine/fake_sync_engine.h"
#include "components/sync/model/model_type_store_test_util.h"
......@@ -553,8 +554,7 @@ TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) {
InitializeForNthSync();
// Initial status.
ProfileSyncService::SyncTokenStatus token_status =
service()->GetSyncTokenStatus();
syncer::SyncTokenStatus token_status = service()->GetSyncTokenStatus();
ASSERT_EQ(syncer::CONNECTION_NOT_ATTEMPTED, token_status.connection_status);
ASSERT_TRUE(token_status.connection_status_update_time.is_null());
ASSERT_TRUE(token_status.token_request_time.is_null());
......
......@@ -94,13 +94,12 @@ bool SyncAuthManager::RefreshTokenIsAvailable() const {
token_service_->RefreshTokenIsAvailable(account_id);
}
syncer::SyncService::SyncTokenStatus SyncAuthManager::GetSyncTokenStatus()
const {
syncer::SyncTokenStatus SyncAuthManager::GetSyncTokenStatus() const {
// Need to make a copy because this method is const, and we might want to
// clear |next_token_request_time|.
// TODO(treib): See if we can keep |token_status_.next_token_request_time| in
// the correct state instead.
syncer::SyncService::SyncTokenStatus status = token_status_;
syncer::SyncTokenStatus status = token_status_;
if (!request_access_token_retry_timer_.IsRunning()) {
status.next_token_request_time = base::Time();
}
......
......@@ -12,8 +12,7 @@
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "components/signin/core/browser/account_info.h"
// TODO(treib): Needed for SyncTokenStatus. Move that to its own file instead.
#include "components/sync/driver/sync_service.h"
#include "components/sync/driver/sync_token_status.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_token_service.h"
#include "net/base/backoff_entry.h"
......@@ -74,7 +73,7 @@ class SyncAuthManager : public identity::IdentityManager::Observer,
// Returns the state of the access token and token request, for display in
// internals UI.
syncer::SyncService::SyncTokenStatus GetSyncTokenStatus() const;
syncer::SyncTokenStatus GetSyncTokenStatus() const;
// Called by ProfileSyncService when the status of the connection to the Sync
// server changed. Updates auth error state accordingly.
......@@ -138,7 +137,7 @@ class SyncAuthManager : public identity::IdentityManager::Observer,
net::BackoffEntry request_access_token_backoff_;
// Info about the state of our access token, for display in the internals UI.
syncer::SyncService::SyncTokenStatus token_status_;
syncer::SyncTokenStatus token_status_;
base::WeakPtrFactory<SyncAuthManager> weak_ptr_factory_;
......
......@@ -149,6 +149,8 @@ jumbo_static_library("sync") {
"driver/sync_service_utils.h",
"driver/sync_stopped_reporter.cc",
"driver/sync_stopped_reporter.h",
"driver/sync_token_status.cc",
"driver/sync_token_status.h",
"driver/sync_type_preference_provider.h",
"driver/sync_util.cc",
"driver/sync_util.h",
......
......@@ -14,6 +14,7 @@
#include "base/values.h"
#include "components/strings/grit/components_strings.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/driver/sync_token_status.h"
#include "components/sync/engine/cycle/sync_cycle_snapshot.h"
#include "components/sync/engine/sync_status.h"
#include "components/sync/engine/sync_string_conversions.h"
......@@ -21,6 +22,7 @@
#include "components/sync/protocol/proto_enum_conversions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "url/gurl.h"
namespace syncer {
......@@ -219,7 +221,7 @@ std::string GetLastSyncedTimeString(base::Time last_synced_time) {
time_since_last_sync));
}
std::string GetConnectionStatus(const SyncService::SyncTokenStatus& status) {
std::string GetConnectionStatus(const SyncTokenStatus& status) {
switch (status.connection_status) {
case CONNECTION_NOT_ATTEMPTED:
return "not attempted";
......@@ -387,8 +389,7 @@ std::unique_ptr<base::DictionaryValue> ConstructAboutInformation(
SyncStatus full_status;
bool is_status_valid = service->QueryDetailedSyncStatus(&full_status);
const SyncCycleSnapshot& snapshot = service->GetLastCycleSnapshot();
const SyncService::SyncTokenStatus& token_status =
service->GetSyncTokenStatus();
const SyncTokenStatus& token_status = service->GetSyncTokenStatus();
// Summary.
if (is_status_valid)
......
......@@ -7,6 +7,7 @@
#include "base/values.h"
#include "components/signin/core/browser/account_info.h"
#include "components/sync/driver/data_type_controller.h"
#include "components/sync/driver/sync_token_status.h"
#include "components/sync/syncable/base_transaction.h"
#include "components/sync/syncable/user_share.h"
......@@ -156,8 +157,8 @@ void FakeSyncService::RegisterDataTypeController(
void FakeSyncService::ReenableDatatype(ModelType type) {}
FakeSyncService::SyncTokenStatus FakeSyncService::GetSyncTokenStatus() const {
return FakeSyncService::SyncTokenStatus();
syncer::SyncTokenStatus FakeSyncService::GetSyncTokenStatus() const {
return syncer::SyncTokenStatus();
}
std::string FakeSyncService::QuerySyncStatusSummaryString() {
......
......@@ -13,8 +13,4 @@ SyncSetupInProgressHandle::~SyncSetupInProgressHandle() {
on_destroy_.Run();
}
SyncService::SyncTokenStatus::SyncTokenStatus()
: connection_status(CONNECTION_NOT_ATTEMPTED),
last_get_token_error(GoogleServiceAuthError::AuthErrorNone()) {}
} // namespace syncer
......@@ -17,11 +17,10 @@
#include "components/sync/base/model_type.h"
#include "components/sync/driver/data_type_encryption_handler.h"
#include "components/sync/driver/sync_service_observer.h"
#include "components/sync/engine/connection_status.h"
#include "google_apis/gaia/google_service_auth_error.h"
struct AccountInfo;
class GoogleServiceAuthError;
class GURL;
namespace sync_sessions {
class OpenTabsUIDelegate;
......@@ -37,6 +36,7 @@ class GlobalIdMapper;
class ProtocolEventObserver;
class SyncClient;
class SyncCycleSnapshot;
struct SyncTokenStatus;
class TypeDebugInfoObserver;
struct SyncStatus;
struct UserShare;
......@@ -92,24 +92,6 @@ class SyncService : public DataTypeEncryptionHandler, public KeyedService {
CLEAR_DATA,
};
// Status of sync server connection, sync token and token request.
struct SyncTokenStatus {
SyncTokenStatus();
// Sync server connection status reported by sync engine.
base::Time connection_status_update_time;
ConnectionStatus connection_status;
// Times when OAuth2 access token is requested and received.
base::Time token_request_time;
base::Time token_receive_time;
// Error returned by OAuth2TokenService for token request and time when
// next request is scheduled.
GoogleServiceAuthError last_get_token_error;
base::Time next_token_request_time;
};
~SyncService() override {}
// Whether sync is enabled by user or not. This does not necessarily mean
......
......@@ -7,6 +7,7 @@
#include "components/sync/base/sync_prefs.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/engine/cycle/sync_cycle_snapshot.h"
#include "google_apis/gaia/google_service_auth_error.h"
namespace syncer {
......
// 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/sync_token_status.h"
namespace syncer {
SyncTokenStatus::SyncTokenStatus()
: connection_status(CONNECTION_NOT_ATTEMPTED),
last_get_token_error(GoogleServiceAuthError::AuthErrorNone()) {}
} // namespace syncer
// 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.
#ifndef COMPONENTS_SYNC_DRIVER_SYNC_TOKEN_STATUS_H_
#define COMPONENTS_SYNC_DRIVER_SYNC_TOKEN_STATUS_H_
#include "base/time/time.h"
#include "components/sync/engine/connection_status.h"
#include "google_apis/gaia/google_service_auth_error.h"
namespace syncer {
// Status of sync server connection, sync token and token request.
struct SyncTokenStatus {
SyncTokenStatus();
// Sync server connection status reported by sync engine.
base::Time connection_status_update_time;
ConnectionStatus connection_status;
// Times when OAuth2 access token is requested and received.
base::Time token_request_time;
base::Time token_receive_time;
// Error returned by OAuth2TokenService for token request and time when
// next request is scheduled.
GoogleServiceAuthError last_get_token_error;
base::Time next_token_request_time;
};
} // namespace syncer
#endif // COMPONENTS_SYNC_DRIVER_SYNC_TOKEN_STATUS_H_
......@@ -93,6 +93,7 @@ source_set("unit_tests") {
"//components/metrics",
"//components/metrics:test_support",
"//components/prefs:test_support",
"//components/sync",
"//components/sync:test_support_driver",
"//components/variations",
"//net:test_support",
......
......@@ -7,6 +7,7 @@
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "components/sync/driver/sync_token_status.h"
#include "components/sync/engine/connection_status.h"
namespace ukm {
......@@ -52,8 +53,7 @@ SyncDisableObserver::~SyncDisableObserver() {}
// static
SyncDisableObserver::SyncState SyncDisableObserver::GetSyncState(
syncer::SyncService* sync_service) {
syncer::SyncService::SyncTokenStatus status =
sync_service->GetSyncTokenStatus();
syncer::SyncTokenStatus status = sync_service->GetSyncTokenStatus();
SyncState state;
state.history_enabled = sync_service->GetPreferredDataTypes().Has(
syncer::HISTORY_DELETE_DIRECTIVES);
......
......@@ -6,6 +6,8 @@
#include "base/observer_list.h"
#include "components/sync/driver/fake_sync_service.h"
#include "components/sync/driver/sync_token_status.h"
#include "components/sync/engine/connection_status.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ukm {
......@@ -56,8 +58,8 @@ class MockSyncService : public syncer::FakeSyncService {
syncer::ModelTypeSet GetPreferredDataTypes() const override {
return preferred_data_types_;
}
SyncTokenStatus GetSyncTokenStatus() const override {
SyncTokenStatus status;
syncer::SyncTokenStatus GetSyncTokenStatus() const override {
syncer::SyncTokenStatus status;
status.connection_status = connection_status_;
return status;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment