Refactor SyncBackendHost

Split SyncBackendHost into SyncBackendHost, SyncBackendHostImpl and
SyncBackendHostCore.

The SyncBackendHost class is now a pure virtual interface.  It is the
contains the interface exposed to the ProfileSyncService.

The SyncBackendHostImpl class implements the functionality of the
SyncBackendHost.  It contains most of the code that used to reside in
SyncBackendHost.

The SyncBackendHostCore is the old SyncBackendHost::Core under a new
name.  It's been moved out of the SyncBackendHost's .cc file and into
its own, publicly declared class.  This will hopefully enable better
testing in the future.

This is a pure refactoring change.  It should have no impact on program
behavior.

BUG=312999

Review URL: https://codereview.chromium.org/61183003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233533 0039d316-1c4b-4281-b951-d872f2087c98
parent d03afdba
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright 2013 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 "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/glue/sync_backend_host_impl.h"
#include <cstddef>
......@@ -15,6 +15,7 @@
#include "chrome/browser/invalidation/invalidator_storage.h"
#include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/browser/sync/glue/device_info.h"
#include "chrome/browser/sync/glue/sync_frontend.h"
#include "chrome/browser/sync/glue/synced_device_tracker.h"
#include "chrome/browser/sync/sync_prefs.h"
#include "chrome/test/base/testing_profile.h"
......@@ -137,7 +138,7 @@ class SyncBackendHostTest : public testing::Test {
virtual void SetUp() OVERRIDE {
profile_.reset(new TestingProfile());
sync_prefs_.reset(new SyncPrefs(profile_->GetPrefs()));
backend_.reset(new SyncBackendHost(
backend_.reset(new SyncBackendHostImpl(
profile_->GetDebugName(),
profile_.get(),
sync_prefs_->AsWeakPtr()));
......
// Copyright 2013 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 "chrome/browser/sync/glue/sync_frontend.h"
namespace browser_sync {
SyncFrontend::SyncFrontend() {}
SyncFrontend::~SyncFrontend() {}
} // namespace browser_sync
// Copyright 2013 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 CHROME_BROWSER_SYNC_GLUE_SYNC_FRONTEND_H_
#define CHROME_BROWSER_SYNC_GLUE_SYNC_FRONTEND_H_
#include "base/basictypes.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/sync_encryption_handler.h"
#include "sync/internal_api/public/sync_manager.h"
#include "sync/internal_api/public/util/weak_handle.h"
#include "sync/protocol/sync_protocol_error.h"
namespace syncer {
class DataTypeDebugInfoListener;
class JsBackend;
} // namespace syncer
namespace sync_pb {
class EncryptedData;
} // namespace sync_pb
namespace browser_sync {
// SyncFrontend is the interface used by SyncBackendHost to communicate with
// the entity that created it and, presumably, is interested in sync-related
// activity.
// NOTE: All methods will be invoked by a SyncBackendHost on the same thread
// used to create that SyncBackendHost.
class SyncFrontend {
public:
SyncFrontend();
virtual ~SyncFrontend();
// The backend has completed initialization and it is now ready to
// accept and process changes. If success is false, initialization
// wasn't able to be completed and should be retried.
//
// |js_backend| is what about:sync interacts with; it's different
// from the 'Backend' in 'OnBackendInitialized' (unfortunately). It
// is initialized only if |success| is true.
virtual void OnBackendInitialized(
const syncer::WeakHandle<syncer::JsBackend>& js_backend,
const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
debug_info_listener,
bool success) = 0;
// The backend queried the server recently and received some updates.
virtual void OnSyncCycleCompleted() = 0;
// Configure ran into some kind of error. But it is scheduled to be
// retried.
virtual void OnSyncConfigureRetry() = 0;
// The status of the connection to the sync server has changed.
virtual void OnConnectionStatusChange(
syncer::ConnectionStatus status) = 0;
// We are no longer permitted to communicate with the server. Sync should
// be disabled and state cleaned up at once.
virtual void OnStopSyncingPermanently() = 0;
// The syncer requires a passphrase to decrypt sensitive updates. This is
// called when the first sensitive data type is setup by the user and anytime
// the passphrase is changed by another synced client. |reason| denotes why
// the passphrase was required. |pending_keys| is a copy of the
// cryptographer's pending keys to be passed on to the frontend in order to
// be cached.
virtual void OnPassphraseRequired(
syncer::PassphraseRequiredReason reason,
const sync_pb::EncryptedData& pending_keys) = 0;
// Called when the passphrase provided by the user is
// accepted. After this is called, updates to sensitive nodes are
// encrypted using the accepted passphrase.
virtual void OnPassphraseAccepted() = 0;
// Called when the set of encrypted types or the encrypt everything
// flag has been changed. Note that encryption isn't complete until
// the OnEncryptionComplete() notification has been sent (see
// below).
//
// |encrypted_types| will always be a superset of
// syncer::Cryptographer::SensitiveTypes(). If |encrypt_everything| is
// true, |encrypted_types| will be the set of all known types.
//
// Until this function is called, observers can assume that the set
// of encrypted types is syncer::Cryptographer::SensitiveTypes() and that
// the encrypt everything flag is false.
virtual void OnEncryptedTypesChanged(
syncer::ModelTypeSet encrypted_types,
bool encrypt_everything) = 0;
// Called after we finish encrypting the current set of encrypted
// types.
virtual void OnEncryptionComplete() = 0;
// Called to perform migration of |types|.
virtual void OnMigrationNeededForTypes(syncer::ModelTypeSet types) = 0;
// Inform the Frontend that new datatypes are available for registration.
virtual void OnExperimentsChanged(
const syncer::Experiments& experiments) = 0;
// Called when the sync cycle returns there is an user actionable error.
virtual void OnActionableError(const syncer::SyncProtocolError& error) = 0;
};
} // namespace browser_sync
#endif // CHROME_BROWSER_SYNC_GLUE_SYNC_FRONTEND_H_
......@@ -44,6 +44,8 @@
#include "chrome/browser/sync/glue/device_info.h"
#include "chrome/browser/sync/glue/session_data_type_controller.h"
#include "chrome/browser/sync/glue/session_model_associator.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/glue/sync_backend_host_impl.h"
#include "chrome/browser/sync/glue/synced_device_tracker.h"
#include "chrome/browser/sync/glue/typed_url_data_type_controller.h"
#include "chrome/browser/sync/profile_sync_components_factory_impl.h"
......@@ -513,8 +515,9 @@ void ProfileSyncService::InitializeBackend(bool delete_stale_data) {
void ProfileSyncService::CreateBackend() {
backend_.reset(
new SyncBackendHost(profile_->GetDebugName(),
profile_, sync_prefs_.AsWeakPtr()));
new browser_sync::SyncBackendHostImpl(profile_->GetDebugName(),
profile_,
sync_prefs_.AsWeakPtr()));
}
bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
......
......@@ -28,6 +28,7 @@
#include "chrome/browser/sync/glue/data_type_manager_observer.h"
#include "chrome/browser/sync/glue/failed_data_types_handler.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/glue/sync_frontend.h"
#include "chrome/browser/sync/glue/synced_device_tracker.h"
#include "chrome/browser/sync/profile_sync_service_base.h"
#include "chrome/browser/sync/profile_sync_service_observer.h"
......
......@@ -8,6 +8,7 @@
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/glue/sync_backend_host_core.h"
#include "chrome/browser/sync/profile_sync_components_factory.h"
#include "chrome/browser/sync/test/test_http_bridge_factory.h"
#include "sync/internal_api/public/test/sync_manager_factory_for_profile_sync_test.h"
......@@ -30,7 +31,7 @@ SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest(
bool synchronous_init,
bool fail_initial_download,
syncer::StorageOption storage_option)
: browser_sync::SyncBackendHost(
: browser_sync::SyncBackendHostImpl(
profile->GetDebugName(), profile, sync_prefs),
callback_(callback),
fail_initial_download_(fail_initial_download),
......@@ -70,7 +71,7 @@ void SyncBackendHostForProfileSyncTest::InitCore(
options->internal_components_factory.reset(
new TestInternalComponentsFactory(factory_switches, storage));
SyncBackendHost::InitCore(options.Pass());
SyncBackendHostImpl::InitCore(options.Pass());
if (synchronous_init_ && !base::MessageLoop::current()->is_running()) {
// The SyncBackend posts a task to the current loop when
// initialization completes.
......@@ -130,7 +131,7 @@ SyncBackendHostForProfileSyncTest::HandleInitializationSuccessOnFrontendLoop(
if (synchronous_init_)
base::MessageLoop::current()->Quit();
} else {
SyncBackendHost::HandleInitializationSuccessOnFrontendLoop(
SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop(
js_backend,
debug_info_listener);
}
......
......@@ -14,6 +14,7 @@
#include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/sync/glue/data_type_manager_impl.h"
#include "chrome/browser/sync/glue/sync_backend_host_impl.h"
#include "chrome/browser/sync/profile_sync_components_factory_mock.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/sync_prefs.h"
......@@ -36,7 +37,7 @@ ACTION(ReturnNewDataTypeManager) {
namespace browser_sync {
class SyncBackendHostForProfileSyncTest : public SyncBackendHost {
class SyncBackendHostForProfileSyncTest : public SyncBackendHostImpl {
public:
// |synchronous_init| causes initialization to block until the syncapi has
// completed setting itself up and called us back.
......
......@@ -2277,8 +2277,14 @@
'browser/sync/glue/shared_change_processor_ref.h',
'browser/sync/glue/sync_backend_host.cc',
'browser/sync/glue/sync_backend_host.h',
'browser/sync/glue/sync_backend_host_core.cc',
'browser/sync/glue/sync_backend_host_core.h',
'browser/sync/glue/sync_backend_host_impl.cc',
'browser/sync/glue/sync_backend_host_impl.h',
'browser/sync/glue/sync_backend_registrar.cc',
'browser/sync/glue/sync_backend_registrar.h',
'browser/sync/glue/sync_frontend.h',
'browser/sync/glue/sync_frontend.cc',
'browser/sync/glue/sync_start_util.cc',
'browser/sync/glue/sync_start_util.h',
'browser/sync/glue/synced_device_tracker.cc',
......
......@@ -1320,7 +1320,7 @@
'browser/sync/glue/shared_change_processor_mock.cc',
'browser/sync/glue/shared_change_processor_mock.h',
'browser/sync/glue/shared_change_processor_unittest.cc',
'browser/sync/glue/sync_backend_host_unittest.cc',
'browser/sync/glue/sync_backend_host_impl_unittest.cc',
'browser/sync/glue/sync_backend_registrar_unittest.cc',
'browser/sync/glue/synced_device_tracker_unittest.cc',
'browser/sync/glue/synced_session_tracker_unittest.cc',
......
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