Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Unified Diff: chrome/browser/sync/glue/sync_backend_host_impl.h

Issue 61183003: Refactor SyncBackendHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove double virtual Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/glue/sync_backend_host_impl.h
diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host_impl.h
similarity index 62%
copy from chrome/browser/sync/glue/sync_backend_host.h
copy to chrome/browser/sync/glue/sync_backend_host_impl.h
index 0480e962c0d3e6caf9008aad6ee01a67a9e5a882..b30ede9f5f44aa59d6c1e01ce84f5f24ee0cd832 100644
--- a/chrome/browser/sync/glue/sync_backend_host.h
+++ b/chrome/browser/sync/glue/sync_backend_host_impl.h
@@ -2,29 +2,25 @@
// 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_BACKEND_HOST_H_
-#define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
+#ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_IMPL_H_
+#define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_IMPL_H_
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
-#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
-#include "chrome/browser/invalidation/invalidation_service.h"
#include "chrome/browser/sync/glue/backend_data_type_configurer.h"
#include "chrome/browser/sync/glue/extensions_activity_monitor.h"
+#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-#include "google_apis/gaia/google_service_auth_error.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/configure_reason.h"
-#include "sync/internal_api/public/engine/model_safe_worker.h"
#include "sync/internal_api/public/sessions/sync_session_snapshot.h"
-#include "sync/internal_api/public/sync_encryption_handler.h"
#include "sync/internal_api/public/sync_manager.h"
#include "sync/internal_api/public/util/report_unrecoverable_error_function.h"
#include "sync/internal_api/public/util/unrecoverable_error_handler.h"
@@ -33,14 +29,18 @@
#include "sync/protocol/encryption.pb.h"
#include "sync/protocol/sync_protocol_error.h"
#include "sync/util/extensions_activity.h"
-#include "url/gurl.h"
+class GURL;
class Profile;
namespace base {
class MessageLoop;
}
+namespace invalidation {
+class InvalidationService;
+}
+
namespace syncer {
class SyncManagerFactory;
}
@@ -48,108 +48,18 @@ class SyncManagerFactory;
namespace browser_sync {
class ChangeProcessor;
-class InvalidatorStorage;
+class SyncBackendHostCore;
class SyncBackendRegistrar;
class SyncPrefs;
class SyncedDeviceTracker;
-struct Experiments;
-
-// 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() {}
-
- // 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;
-
- protected:
- // Don't delete through SyncFrontend interface.
- virtual ~SyncFrontend() {
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(SyncFrontend);
-};
+struct DoInitializeOptions;
// A UI-thread safe API into the sync backend that "hosts" the top-level
// syncapi element, the SyncManager, on its own thread. This class handles
// dispatch of potentially blocking calls to appropriate threads and ensures
// that the SyncFrontend is only accessed on the UI loop.
-class SyncBackendHost
- : public BackendDataTypeConfigurer,
+class SyncBackendHostImpl
+ : public SyncBackendHost,
public content::NotificationObserver,
public syncer::InvalidationHandler {
public:
@@ -158,24 +68,18 @@ class SyncBackendHost
// Create a SyncBackendHost with a reference to the |frontend| that
// it serves and communicates to via the SyncFrontend interface (on
// the same thread it used to call the constructor). Must outlive
- // |sync_prefs| and |invalidator_storage|.
- SyncBackendHost(
+ // |sync_prefs|.
+ SyncBackendHostImpl(
const std::string& name,
Profile* profile,
const base::WeakPtr<SyncPrefs>& sync_prefs);
-
- // For testing.
- // TODO(skrul): Extract an interface so this is not needed.
- explicit SyncBackendHost(Profile* profile);
- virtual ~SyncBackendHost();
+ virtual ~SyncBackendHostImpl();
// Called on |frontend_loop_| to kick off asynchronous initialization.
- // As a fallback when no cached auth information is available, try to
- // bootstrap authentication using |lsid|, if it isn't empty.
// Optionally delete the Sync Data folder (if it's corrupt).
// |report_unrecoverable_error_function| can be NULL.
// Note: |unrecoverable_error_handler| may be invoked from any thread.
- void Initialize(
+ virtual void Initialize(
SyncFrontend* frontend,
scoped_ptr<base::Thread> sync_thread,
const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
@@ -185,16 +89,17 @@ class SyncBackendHost
scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory,
scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler,
syncer::ReportUnrecoverableErrorFunction
- report_unrecoverable_error_function);
+ report_unrecoverable_error_function) OVERRIDE;
// Called on |frontend_loop| to update SyncCredentials.
- virtual void UpdateCredentials(const syncer::SyncCredentials& credentials);
+ virtual void UpdateCredentials(
+ const syncer::SyncCredentials& credentials) OVERRIDE;
// This starts the SyncerThread running a Syncer object to communicate with
// sync servers. Until this is called, no changes will leave or enter this
// browser from the cloud / sync servers.
// Called on |frontend_loop_|.
- virtual void StartSyncingWithServer();
+ virtual void StartSyncingWithServer() OVERRIDE;
// Called on |frontend_loop_| to asynchronously set a new passphrase for
// encryption. Note that it is an error to call SetEncryptionPassphrase under
@@ -207,7 +112,9 @@ class SyncBackendHost
// passphrase passed in is cached so we can re-encrypt with it in future.
// - If there are no pending keys, data is encrypted with |passphrase| (this
// is a no-op if data was already encrypted with |passphrase|.)
- void SetEncryptionPassphrase(const std::string& passphrase, bool is_explicit);
+ virtual void SetEncryptionPassphrase(
+ const std::string& passphrase,
+ bool is_explicit) OVERRIDE;
// Called on |frontend_loop_| to use the provided passphrase to asynchronously
// attempt decryption. Returns false immediately if the passphrase could not
@@ -215,13 +122,13 @@ class SyncBackendHost
// otherwise. If new encrypted keys arrive during the asynchronous call,
// OnPassphraseRequired may be triggered at a later time. It is an error to
// call this when there are no pending keys.
- bool SetDecryptionPassphrase(const std::string& passphrase)
- WARN_UNUSED_RESULT;
+ virtual bool SetDecryptionPassphrase(const std::string& passphrase)
+ WARN_UNUSED_RESULT OVERRIDE;
// Called on |frontend_loop_| to kick off shutdown procedure. Attempts to cut
// short any long-lived or blocking sync thread tasks so that the shutdown on
// sync thread task that we're about to post won't have to wait very long.
- virtual void StopSyncingForShutdown();
+ virtual void StopSyncingForShutdown() OVERRIDE;
// Called on |frontend_loop_| to kick off shutdown.
// See the implementation and Core::DoShutdown for details.
@@ -231,16 +138,11 @@ class SyncBackendHost
// * sync loop may be stopped on main loop and cause it to be blocked.
// * new/old backend may interfere with each other if new backend is created
// before old one finishes cleanup.
- enum ShutdownOption {
- STOP, // Stop syncing and let backend stop sync thread.
- STOP_AND_CLAIM_THREAD, // Stop syncing and return sync thread.
- DISABLE_AND_CLAIM_THREAD, // Disable sync and return sync thread.
- };
- scoped_ptr<base::Thread> Shutdown(ShutdownOption option);
+ virtual scoped_ptr<base::Thread> Shutdown(ShutdownOption option) OVERRIDE;
// Removes all current registrations from the backend on the
// InvalidationService.
- void UnregisterInvalidationIds();
+ virtual void UnregisterInvalidationIds() OVERRIDE;
// Changes the set of data types that are currently being synced.
// The ready_task will be run when configuration is done with the
@@ -254,56 +156,59 @@ class SyncBackendHost
const base::Callback<void()>& retry_callback) OVERRIDE;
// Turns on encryption of all present and future sync data.
- virtual void EnableEncryptEverything();
+ virtual void EnableEncryptEverything() OVERRIDE;
// Activates change processing for the given data type. This must
// be called synchronously with the data type's model association so
// no changes are dropped between model association and change
// processor activation.
- void ActivateDataType(
+ virtual void ActivateDataType(
syncer::ModelType type, syncer::ModelSafeGroup group,
- ChangeProcessor* change_processor);
+ ChangeProcessor* change_processor) OVERRIDE;
// Deactivates change processing for the given data type.
- void DeactivateDataType(syncer::ModelType type);
+ virtual void DeactivateDataType(syncer::ModelType type) OVERRIDE;
// Called on |frontend_loop_| to obtain a handle to the UserShare needed for
// creating transactions. Should not be called before we signal
// initialization is complete with OnBackendInitialized().
- syncer::UserShare* GetUserShare() const;
+ virtual syncer::UserShare* GetUserShare() const OVERRIDE;
// Called from any thread to obtain current status information in detailed or
// summarized form.
- Status GetDetailedStatus();
- syncer::sessions::SyncSessionSnapshot GetLastSessionSnapshot() const;
+ virtual Status GetDetailedStatus() OVERRIDE;
+ virtual syncer::sessions::SyncSessionSnapshot
+ GetLastSessionSnapshot() const OVERRIDE;
// Determines if the underlying sync engine has made any local changes to
// items that have not yet been synced with the server.
// ONLY CALL THIS IF OnInitializationComplete was called!
- bool HasUnsyncedItems() const;
+ virtual bool HasUnsyncedItems() const OVERRIDE;
// Whether or not we are syncing encryption keys.
- bool IsNigoriEnabled() const;
+ virtual bool IsNigoriEnabled() const OVERRIDE;
// Returns the type of passphrase being used to encrypt data. See
// sync_encryption_handler.h.
- syncer::PassphraseType GetPassphraseType() const;
+ virtual syncer::PassphraseType GetPassphraseType() const OVERRIDE;
// If an explicit passphrase is in use, returns the time at which that
// passphrase was set (if available).
- base::Time GetExplicitPassphraseTime() const;
+ virtual base::Time GetExplicitPassphraseTime() const OVERRIDE;
// True if the cryptographer has any keys available to attempt decryption.
// Could mean we've downloaded and loaded Nigori objects, or we bootstrapped
// using a token previously received.
- bool IsCryptographerReady(const syncer::BaseTransaction* trans) const;
+ virtual bool IsCryptographerReady(
+ const syncer::BaseTransaction* trans) const OVERRIDE;
- void GetModelSafeRoutingInfo(syncer::ModelSafeRoutingInfo* out) const;
+ virtual void GetModelSafeRoutingInfo(
+ syncer::ModelSafeRoutingInfo* out) const OVERRIDE;
// Fetches the DeviceInfo tracker.
- virtual SyncedDeviceTracker* GetSyncedDeviceTracker() const;
+ virtual SyncedDeviceTracker* GetSyncedDeviceTracker() const OVERRIDE;
- base::MessageLoop* GetSyncLoopForTesting();
+ virtual base::MessageLoop* GetSyncLoopForTesting() OVERRIDE;
protected:
// The types and functions below are protected so that test
@@ -312,53 +217,6 @@ class SyncBackendHost
// TODO(akalin): Figure out a better way for tests to hook into
// SyncBackendHost.
- // Utility struct for holding initialization options.
- struct DoInitializeOptions {
- DoInitializeOptions(
- base::MessageLoop* sync_loop,
- SyncBackendRegistrar* registrar,
- const syncer::ModelSafeRoutingInfo& routing_info,
- const std::vector<syncer::ModelSafeWorker*>& workers,
- const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity,
- const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
- const GURL& service_url,
- scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory,
- const syncer::SyncCredentials& credentials,
- const std::string& invalidator_client_id,
- scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory,
- bool delete_sync_data_folder,
- const std::string& restored_key_for_bootstrapping,
- const std::string& restored_keystore_key_for_bootstrapping,
- scoped_ptr<syncer::InternalComponentsFactory>
- internal_components_factory,
- scoped_ptr<syncer::UnrecoverableErrorHandler>
- unrecoverable_error_handler,
- syncer::ReportUnrecoverableErrorFunction
- report_unrecoverable_error_function);
- ~DoInitializeOptions();
-
- base::MessageLoop* sync_loop;
- SyncBackendRegistrar* registrar;
- syncer::ModelSafeRoutingInfo routing_info;
- std::vector<syncer::ModelSafeWorker*> workers;
- scoped_refptr<syncer::ExtensionsActivity> extensions_activity;
- syncer::WeakHandle<syncer::JsEventHandler> event_handler;
- GURL service_url;
- // Overridden by tests.
- scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory;
- syncer::SyncCredentials credentials;
- const std::string invalidator_client_id;
- scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory;
- std::string lsid;
- bool delete_sync_data_folder;
- std::string restored_key_for_bootstrapping;
- std::string restored_keystore_key_for_bootstrapping;
- scoped_ptr<syncer::InternalComponentsFactory> internal_components_factory;
- scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler;
- syncer::ReportUnrecoverableErrorFunction
- report_unrecoverable_error_function;
- };
-
// Allows tests to perform alternate core initialization work.
virtual void InitCore(scoped_ptr<DoInitializeOptions> options);
@@ -398,21 +256,7 @@ class SyncBackendHost
SyncFrontend* frontend() { return frontend_; }
private:
- // The real guts of SyncBackendHost, to keep the public client API clean.
- class Core;
-
- // An enum representing the steps to initializing the SyncBackendHost.
- enum InitializationState {
- NOT_ATTEMPTED,
- CREATING_SYNC_MANAGER, // We're waiting for the first callback from the
- // sync thread to inform us that the sync
- // manager has been created.
- NOT_INITIALIZED, // Initialization hasn't completed, but we've
- // constructed a SyncManager.
- INITIALIZATING_CONTROL_TYPES, // Downloading control types and
- // initializing their handlers.
- INITIALIZED, // Initialization is complete.
- };
+ friend class SyncBackendHostCore;
// Checks if we have received a notice to turn on experimental datatypes
// (via the nigori node) and informs the frontend if that is the case.
@@ -523,7 +367,7 @@ class SyncBackendHost
// Our core, which communicates directly to the syncapi. Use refptr instead
// of WeakHandle because |core_| is created on UI loop but released on
// sync loop.
- scoped_refptr<Core> core_;
+ scoped_refptr<SyncBackendHostCore> core_;
bool initialized_;
@@ -562,11 +406,12 @@ class SyncBackendHost
invalidation::InvalidationService* invalidator_;
bool invalidation_handler_registered_;
- base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_;
+ base::WeakPtrFactory<SyncBackendHostImpl> weak_ptr_factory_;
- DISALLOW_COPY_AND_ASSIGN(SyncBackendHost);
+ DISALLOW_COPY_AND_ASSIGN(SyncBackendHostImpl);
};
} // namespace browser_sync
-#endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
+#endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_IMPL_H_
+

Powered by Google App Engine
This is Rietveld 408576698