1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SYNC_ENGINE_SYNC_MANAGER_H_
#define COMPONENTS_SYNC_ENGINE_SYNC_MANAGER_H_
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "base/task/task_runner.h"
#include "base/time/time.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/sync_invalidation.h"
#include "components/sync/engine/active_devices_invalidation_info.h"
#include "components/sync/engine/configure_reason.h"
#include "components/sync/engine/connection_status.h"
#include "components/sync/engine/data_type_connector.h"
#include "components/sync/engine/engine_components_factory.h"
#include "components/sync/engine/events/protocol_event.h"
#include "components/sync/engine/net/http_post_provider_factory.h"
#include "components/sync/engine/sync_credentials.h"
#include "components/sync/engine/sync_encryption_handler.h"
#include "components/sync/engine/sync_protocol_error.h"
#include "components/sync/engine/sync_status.h"
#include "url/gurl.h"
namespace syncer {
class CancelationSignal;
class EngineComponentsFactory;
class ExtensionsActivity;
class ProtocolEvent;
class SyncCycleSnapshot;
struct SyncStatus;
// Lives on the sync sequence.
class SyncManager {
public:
// An interface the embedding application implements to receive notifications
// from the SyncManager. Register an observer via SyncManager::AddObserver.
// All methods are called only on the sync sequence.
class Observer {
public:
// A round-trip sync-cycle took place and the syncer has resolved any
// conflicts that may have arisen.
virtual void OnSyncCycleCompleted(const SyncCycleSnapshot& snapshot) = 0;
// Called when the status of the connection to the sync server has
// changed.
virtual void OnConnectionStatusChange(ConnectionStatus status) = 0;
virtual void OnActionableProtocolError(
const SyncProtocolError& sync_protocol_error) = 0;
virtual void OnMigrationRequested(DataTypeSet types) = 0;
virtual void OnProtocolEvent(const ProtocolEvent& event) = 0;
virtual void OnSyncStatusChanged(const SyncStatus&) = 0;
protected:
virtual ~Observer();
};
// Arguments for initializing SyncManager.
struct InitArgs {
InitArgs();
~InitArgs();
// URL of the sync server.
GURL service_url;
// Whether the local backend provided by the LoopbackServer should be used
// and the location of the local sync backend storage.
bool enable_local_sync_backend = false;
base::FilePath local_sync_backend_folder;
// Used to communicate with the sync server.
std::unique_ptr<HttpPostProviderFactory> post_factory;
std::unique_ptr<SyncEncryptionHandler::Observer> encryption_observer_proxy;
// Must outlive SyncManager.
raw_ptr<ExtensionsActivity> extensions_activity = nullptr;
std::unique_ptr<EngineComponentsFactory> engine_components_factory;
// Must outlive SyncManager.
raw_ptr<SyncEncryptionHandler> encryption_handler = nullptr;
// Carries shutdown requests across sequences and will be used to cut short
// any network I/O and tell the syncer to exit early.
//
// Must outlive SyncManager.
raw_ptr<CancelationSignal> cancelation_signal = nullptr;
// Define the polling interval. Must not be zero.
base::TimeDelta poll_interval;
// Initial authoritative values (usually read from prefs).
std::string cache_guid;
std::string birthday;
std::string bag_of_chips;
};
// The state of sync the feature. If the user turned on sync explicitly, it
// will be set to ON. Will be set to INITIALIZING until we know the actual
// state.
enum class SyncFeatureState { INITIALIZING, ON, OFF };
SyncManager();
virtual ~SyncManager();
// Initialize the sync manager using arguments from `args`.
//
// Note, args is passed by non-const pointer because it contains objects like
// unique_ptr.
virtual void Init(InitArgs* args) = 0;
virtual DataTypeSet InitialSyncEndedTypes() = 0;
virtual DataTypeSet GetConnectedTypes() = 0;
// Update tokens that we're using in Sync. Email must stay the same.
virtual void UpdateCredentials(const SyncCredentials& credentials) = 0;
// Clears the authentication tokens.
virtual void InvalidateCredentials() = 0;
// Put the syncer in normal mode ready to perform nudges and polls.
virtual void StartSyncingNormally(base::Time last_poll_time) = 0;
// Put syncer in configuration mode. Only configuration sync cycles are
// performed. No local changes are committed to the server.
virtual void StartConfiguration() = 0;
// Switches the mode of operation to CONFIGURATION_MODE and performs
// any configuration tasks needed as determined by the params. Once complete,
// syncer will remain in CONFIGURATION_MODE until StartSyncingNormally is
// called.
// `ready_task` is invoked when the configuration completes.
virtual void ConfigureSyncer(ConfigureReason reason,
DataTypeSet to_download,
SyncFeatureState sync_feature_state,
base::OnceClosure ready_task) = 0;
// Inform the syncer of a change in the invalidator's state.
virtual void SetInvalidatorEnabled(bool invalidator_enabled) = 0;
// Inform the syncer that its cached information about a type is obsolete.
virtual void OnIncomingInvalidation(
DataType type,
std::unique_ptr<SyncInvalidation> invalidation) = 0;
// Adds a listener to be notified of sync events.
// NOTE: It is OK (in fact, it's probably a good idea) to call this before
// having received OnInitializationCompleted.
virtual void AddObserver(Observer* observer) = 0;
// Remove the given observer. Make sure to call this if the
// Observer is being destroyed so the SyncManager doesn't
// potentially dereference garbage.
virtual void RemoveObserver(Observer* observer) = 0;
virtual void ShutdownOnSyncThread() = 0;
// Returns non-owning pointer to DataTypeConnector. In contrast with
// DataTypeConnectorProxy all calls are executed synchronously, thus the
// pointer should be used on sync sequence.
virtual DataTypeConnector* GetDataTypeConnector() = 0;
// Returns an instance of the main interface for registering sync types with
// sync engine.
virtual std::unique_ptr<DataTypeConnector> GetDataTypeConnectorProxy() = 0;
// Returns the cache_guid of the currently open database.
// Requires that the SyncManager be initialized.
virtual std::string cache_guid() = 0;
// Returns the birthday of the currently open database.
// Requires that the SyncManager be initialized.
virtual std::string birthday() = 0;
// Returns the bag of chips of the currently open database.
// Requires that the SyncManager be initialized.
virtual std::string bag_of_chips() = 0;
// Returns whether there are remaining unsynced items.
virtual bool HasUnsyncedItemsForTest() = 0;
// Returns the SyncManager's encryption handler.
virtual SyncEncryptionHandler* GetEncryptionHandler() = 0;
// Ask the SyncManager to fetch updates for the given types.
virtual void RefreshTypes(DataTypeSet types) = 0;
// Returns any buffered protocol events. Does not clear the buffer.
virtual std::vector<std::unique_ptr<ProtocolEvent>>
GetBufferedProtocolEvents() = 0;
// Updates Sync's tracking of whether the cookie jar has a mismatch with the
// chrome account. See ClientConfigParams proto message for more info.
// Note: this does not trigger a sync cycle. It just updates the sync context.
virtual void OnCookieJarChanged(bool account_mismatch) = 0;
// Updates the invalidation information from known active devices.
virtual void UpdateActiveDevicesInvalidationInfo(
ActiveDevicesInvalidationInfo active_devices_invalidation_info) = 0;
};
} // namespace syncer
#endif // COMPONENTS_SYNC_ENGINE_SYNC_MANAGER_H_
|