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/internal_api/public/base/model_type.h"
24 #include "sync/internal_api/public/engine/model_safe_worker.h"
25 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
26 #include "sync/sessions/status_controller.h"
27 #include "sync/sessions/sync_session_context.h"
30 class ModelSafeWorker;
36 class SYNC_EXPORT_PRIVATE SyncSession {
38 // The Delegate services events that occur during the session requiring an
39 // explicit (and session-global) action, as opposed to events that are simply
40 // recorded in per-session state.
41 class SYNC_EXPORT_PRIVATE Delegate {
43 // The client was throttled and should cease-and-desist syncing activity
44 // until the specified time.
45 virtual void OnThrottled(const base::TimeDelta& throttle_duration) = 0;
47 // Some of the client's types were throttled.
48 virtual void OnTypesThrottled(
50 const base::TimeDelta& throttle_duration) = 0;
52 // Silenced intervals can be out of phase with individual sessions, so the
53 // delegate is the only thing that can give an authoritative answer for
54 // "is syncing silenced right now". This shouldn't be necessary very often
55 // as the delegate ensures no session is started if syncing is silenced.
56 // ** Note ** This will return true if silencing commenced during this
57 // session and the interval has not yet elapsed, but the contract here is
58 // solely based on absolute time values. So, this cannot be used to infer
59 // that any given session _instance_ is silenced. An example of reasonable
60 // use is for UI reporting.
61 virtual bool IsCurrentlyThrottled() = 0;
63 // The client has been instructed to change its short poll interval.
64 virtual void OnReceivedShortPollIntervalUpdate(
65 const base::TimeDelta& new_interval) = 0;
67 // The client has been instructed to change its long poll interval.
68 virtual void OnReceivedLongPollIntervalUpdate(
69 const base::TimeDelta& new_interval) = 0;
71 // The client has been instructed to change its sessions commit
73 virtual void OnReceivedSessionsCommitDelay(
74 const base::TimeDelta& new_delay) = 0;
76 // Called for the syncer to respond to the error sent by the server.
77 virtual void OnSyncProtocolError(
78 const sessions::SyncSessionSnapshot& snapshot) = 0;
80 // Called when the server wants to change the number of hints the client
81 // will buffer locally.
82 virtual void OnReceivedClientInvalidationHintBufferSize(int size) = 0;
84 // Called when server wants to schedule a retry GU.
85 virtual void OnReceivedGuRetryDelay(const base::TimeDelta& delay) = 0;
88 virtual ~Delegate() {}
91 // Build a session without a nudge tracker. Used for poll or configure type
93 static SyncSession* Build(SyncSessionContext* context,
97 // Builds a thread-safe and read-only copy of the current session state.
98 SyncSessionSnapshot TakeSnapshot() const;
99 SyncSessionSnapshot TakeSnapshotWithSource(
100 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source)
103 // Builds and sends a snapshot to the session context's listeners.
104 void SendSyncCycleEndEventNotification(
105 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
106 void SendEventNotification(SyncEngineEvent::EventCause cause);
108 // TODO(akalin): Split this into context() and mutable_context().
109 SyncSessionContext* context() const { return context_; }
110 Delegate* delegate() const { return delegate_; }
111 const StatusController& status_controller() const {
112 return *status_controller_.get();
114 StatusController* mutable_status_controller() {
115 return status_controller_.get();
119 SyncSession(SyncSessionContext* context, Delegate* delegate);
121 // The context for this session, guaranteed to outlive |this|.
122 SyncSessionContext* const context_;
124 // The delegate for this session, must never be NULL.
125 Delegate* const delegate_;
127 // Our controller for various status and error counters.
128 scoped_ptr<StatusController> status_controller_;
130 DISALLOW_COPY_AND_ASSIGN(SyncSession);
133 } // namespace sessions
134 } // namespace syncer
136 #endif // SYNC_SESSIONS_SYNC_SESSION_H_