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
|
// Copyright 2012 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_ENGINE_IMPL_CYCLE_SYNC_CYCLE_H_
#define COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_SYNC_CYCLE_H_
#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "base/macros.h"
#include "base/time/time.h"
#include "components/sync/base/model_type.h"
#include "components/sync/engine/cycle/sync_cycle_snapshot.h"
#include "components/sync/engine/model_safe_worker.h"
#include "components/sync/engine_impl/cycle/status_controller.h"
#include "components/sync/engine_impl/cycle/sync_cycle_context.h"
#include "components/sync/engine_impl/sync_cycle_event.h"
#include "components/sync/protocol/sync_protocol_error.h"
namespace syncer {
class ProtocolEvent;
// A class representing an attempt to synchronize the local syncable data
// store with a sync server. A SyncCycle instance is passed as a stateful
// bundle throughout the sync cycle. The SyncCycle is not reused across
// sync cycles; each cycle starts with a new one.
class SyncCycle {
public:
// The Delegate services events that occur during the cycle requiring an
// explicit (and cycle-global) action, as opposed to events that are simply
// recorded in per-cycle state.
class Delegate {
public:
// The client was throttled and should cease-and-desist syncing activity
// until the specified time.
virtual void OnThrottled(const base::TimeDelta& throttle_duration) = 0;
// Some of the client's types were throttled.
virtual void OnTypesThrottled(ModelTypeSet types,
const base::TimeDelta& throttle_duration) = 0;
// Some of the client's types were backed off.
virtual void OnTypesBackedOff(ModelTypeSet types) = 0;
// Silenced intervals can be out of phase with individual cycles, so the
// delegate is the only thing that can give an authoritative answer for
// "is syncing silenced right now". This shouldn't be necessary very often
// as the delegate ensures no cycle is started if syncing is silenced.
// ** Note ** This will return true if silencing commenced during this
// cycle and the interval has not yet elapsed, but the contract here is
// solely based on absolute time values. So, this cannot be used to infer
// that any given cycle _instance_ is silenced. An example of reasonable
// use is for UI reporting.
virtual bool IsCurrentlyThrottled() = 0;
// The client has been instructed to change its short poll interval.
virtual void OnReceivedShortPollIntervalUpdate(
const base::TimeDelta& new_interval) = 0;
// The client has been instructed to change its long poll interval.
virtual void OnReceivedLongPollIntervalUpdate(
const base::TimeDelta& new_interval) = 0;
// The client has been instructed to change a nudge delay.
virtual void OnReceivedCustomNudgeDelays(
const std::map<ModelType, base::TimeDelta>& nudge_delays) = 0;
// Called for the syncer to respond to the error sent by the server.
virtual void OnSyncProtocolError(
const SyncProtocolError& sync_protocol_error) = 0;
// Called when the server wants to change the number of hints the client
// will buffer locally.
virtual void OnReceivedClientInvalidationHintBufferSize(int size) = 0;
// Called when server wants to schedule a retry GU.
virtual void OnReceivedGuRetryDelay(const base::TimeDelta& delay) = 0;
// Called when server requests a migration.
virtual void OnReceivedMigrationRequest(ModelTypeSet types) = 0;
protected:
virtual ~Delegate() {}
};
// Build a cycle without a nudge tracker. Used for poll or configure type
// sync cycles.
static SyncCycle* Build(SyncCycleContext* context, Delegate* delegate);
~SyncCycle();
// Builds a thread-safe and read-only copy of the current cycle state.
SyncCycleSnapshot TakeSnapshot() const;
SyncCycleSnapshot TakeSnapshotWithSource(
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source)
const;
// Builds and sends a snapshot to the cycle context's listeners.
void SendSyncCycleEndEventNotification(
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
void SendEventNotification(SyncCycleEvent::EventCause cause);
void SendProtocolEvent(const ProtocolEvent& event);
// TODO(akalin): Split this into context() and mutable_context().
SyncCycleContext* context() const { return context_; }
Delegate* delegate() const { return delegate_; }
const StatusController& status_controller() const {
return *status_controller_.get();
}
StatusController* mutable_status_controller() {
return status_controller_.get();
}
private:
SyncCycle(SyncCycleContext* context, Delegate* delegate);
// The context for this cycle, guaranteed to outlive |this|.
SyncCycleContext* const context_;
// The delegate for this cycle, must never be null.
Delegate* const delegate_;
// Our controller for various status and error counters.
std::unique_ptr<StatusController> status_controller_;
DISALLOW_COPY_AND_ASSIGN(SyncCycle);
};
} // namespace syncer
#endif // COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_SYNC_CYCLE_H_
|