1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // A class representing an attempt to synchronize the local syncable data
6 // store with a sync server. A SyncSession instance is passed as a stateful
7 // bundle throughout the sync cycle. The SyncSession is not reused across
8 // sync cycles; each cycle starts with a new one.
10 #ifndef SYNC_SESSIONS_SYNC_SESSION_H_
11 #define SYNC_SESSIONS_SYNC_SESSION_H_
19 #include "base/basictypes.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "base/time/time.h"
22 #include "sync/base/sync_export.h"
23 #include "sync/engine/sync_cycle_event.h"
24 #include "sync/internal_api/public/base/model_type.h"
25 #include "sync/internal_api/public/engine/model_safe_worker.h"
26 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
27 #include "sync/protocol/sync_protocol_error.h"
28 #include "sync/sessions/status_controller.h"
29 #include "sync/sessions/sync_session_context.h"
32 class ModelSafeWorker
;
39 class SYNC_EXPORT_PRIVATE SyncSession
{
41 // The Delegate services events that occur during the session requiring an
42 // explicit (and session-global) action, as opposed to events that are simply
43 // recorded in per-session state.
44 class SYNC_EXPORT_PRIVATE Delegate
{
46 // The client was throttled and should cease-and-desist syncing activity
47 // until the specified time.
48 virtual void OnThrottled(const base::TimeDelta
& throttle_duration
) = 0;
50 // Some of the client's types were throttled.
51 virtual void OnTypesThrottled(
53 const base::TimeDelta
& throttle_duration
) = 0;
55 // Silenced intervals can be out of phase with individual sessions, so the
56 // delegate is the only thing that can give an authoritative answer for
57 // "is syncing silenced right now". This shouldn't be necessary very often
58 // as the delegate ensures no session is started if syncing is silenced.
59 // ** Note ** This will return true if silencing commenced during this
60 // session and the interval has not yet elapsed, but the contract here is
61 // solely based on absolute time values. So, this cannot be used to infer
62 // that any given session _instance_ is silenced. An example of reasonable
63 // use is for UI reporting.
64 virtual bool IsCurrentlyThrottled() = 0;
66 // The client has been instructed to change its short poll interval.
67 virtual void OnReceivedShortPollIntervalUpdate(
68 const base::TimeDelta
& new_interval
) = 0;
70 // The client has been instructed to change its long poll interval.
71 virtual void OnReceivedLongPollIntervalUpdate(
72 const base::TimeDelta
& new_interval
) = 0;
74 // The client has been instructed to change its sessions commit
76 virtual void OnReceivedSessionsCommitDelay(
77 const base::TimeDelta
& new_delay
) = 0;
79 // Called for the syncer to respond to the error sent by the server.
80 virtual void OnSyncProtocolError(
81 const SyncProtocolError
& sync_protocol_error
) = 0;
83 // Called when the server wants to change the number of hints the client
84 // will buffer locally.
85 virtual void OnReceivedClientInvalidationHintBufferSize(int size
) = 0;
87 // Called when server wants to schedule a retry GU.
88 virtual void OnReceivedGuRetryDelay(const base::TimeDelta
& delay
) = 0;
90 // Called when server requests a migration.
91 virtual void OnReceivedMigrationRequest(ModelTypeSet types
) = 0;
94 virtual ~Delegate() {}
97 // Build a session without a nudge tracker. Used for poll or configure type
99 static SyncSession
* Build(SyncSessionContext
* context
,
103 // Builds a thread-safe and read-only copy of the current session state.
104 SyncSessionSnapshot
TakeSnapshot() const;
105 SyncSessionSnapshot
TakeSnapshotWithSource(
106 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source
)
109 // Builds and sends a snapshot to the session context's listeners.
110 void SendSyncCycleEndEventNotification(
111 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source
);
112 void SendEventNotification(SyncCycleEvent::EventCause cause
);
114 void SendProtocolEvent(const ProtocolEvent
& event
);
116 // TODO(akalin): Split this into context() and mutable_context().
117 SyncSessionContext
* context() const { return context_
; }
118 Delegate
* delegate() const { return delegate_
; }
119 const StatusController
& status_controller() const {
120 return *status_controller_
.get();
122 StatusController
* mutable_status_controller() {
123 return status_controller_
.get();
127 SyncSession(SyncSessionContext
* context
, Delegate
* delegate
);
129 // The context for this session, guaranteed to outlive |this|.
130 SyncSessionContext
* const context_
;
132 // The delegate for this session, must never be NULL.
133 Delegate
* const delegate_
;
135 // Our controller for various status and error counters.
136 scoped_ptr
<StatusController
> status_controller_
;
138 DISALLOW_COPY_AND_ASSIGN(SyncSession
);
141 } // namespace sessions
142 } // namespace syncer
144 #endif // SYNC_SESSIONS_SYNC_SESSION_H_