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

Side by Side Diff: components/sync/sessions_impl/sync_session.h

Issue 2258873003: [Sync] Move sessions/ to engine/cycle/ and rename things to match. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 4 months 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
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.
9
10 #ifndef COMPONENTS_SYNC_SESSIONS_IMPL_SYNC_SESSION_H_
11 #define COMPONENTS_SYNC_SESSIONS_IMPL_SYNC_SESSION_H_
12
13 #include <map>
14 #include <memory>
15 #include <set>
16 #include <string>
17 #include <utility>
18 #include <vector>
19
20 #include "base/macros.h"
21 #include "base/time/time.h"
22 #include "components/sync/base/model_type.h"
23 #include "components/sync/engine/model_safe_worker.h"
24 #include "components/sync/engine_impl/sync_cycle_event.h"
25 #include "components/sync/protocol/sync_protocol_error.h"
26 #include "components/sync/sessions/sync_session_snapshot.h"
27 #include "components/sync/sessions_impl/status_controller.h"
28 #include "components/sync/sessions_impl/sync_session_context.h"
29
30 namespace syncer {
31 class ModelSafeWorker;
32 class ProtocolEvent;
33
34 namespace sessions {
35
36 class NudgeTracker;
37
38 class SyncSession {
39 public:
40 // The Delegate services events that occur during the session requiring an
41 // explicit (and session-global) action, as opposed to events that are simply
42 // recorded in per-session state.
43 class Delegate {
44 public:
45 // The client was throttled and should cease-and-desist syncing activity
46 // until the specified time.
47 virtual void OnThrottled(const base::TimeDelta& throttle_duration) = 0;
48
49 // Some of the client's types were throttled.
50 virtual void OnTypesThrottled(ModelTypeSet types,
51 const base::TimeDelta& throttle_duration) = 0;
52
53 // Silenced intervals can be out of phase with individual sessions, so the
54 // delegate is the only thing that can give an authoritative answer for
55 // "is syncing silenced right now". This shouldn't be necessary very often
56 // as the delegate ensures no session is started if syncing is silenced.
57 // ** Note ** This will return true if silencing commenced during this
58 // session and the interval has not yet elapsed, but the contract here is
59 // solely based on absolute time values. So, this cannot be used to infer
60 // that any given session _instance_ is silenced. An example of reasonable
61 // use is for UI reporting.
62 virtual bool IsCurrentlyThrottled() = 0;
63
64 // The client has been instructed to change its short poll interval.
65 virtual void OnReceivedShortPollIntervalUpdate(
66 const base::TimeDelta& new_interval) = 0;
67
68 // The client has been instructed to change its long poll interval.
69 virtual void OnReceivedLongPollIntervalUpdate(
70 const base::TimeDelta& new_interval) = 0;
71
72 // The client has been instructed to change a nudge delay.
73 virtual void OnReceivedCustomNudgeDelays(
74 const std::map<ModelType, base::TimeDelta>& nudge_delays) = 0;
75
76 // Called for the syncer to respond to the error sent by the server.
77 virtual void OnSyncProtocolError(
78 const SyncProtocolError& sync_protocol_error) = 0;
79
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;
83
84 // Called when server wants to schedule a retry GU.
85 virtual void OnReceivedGuRetryDelay(const base::TimeDelta& delay) = 0;
86
87 // Called when server requests a migration.
88 virtual void OnReceivedMigrationRequest(ModelTypeSet types) = 0;
89
90 protected:
91 virtual ~Delegate() {}
92 };
93
94 // Build a session without a nudge tracker. Used for poll or configure type
95 // sync cycles.
96 static SyncSession* Build(SyncSessionContext* context, Delegate* delegate);
97 ~SyncSession();
98
99 // Builds a thread-safe and read-only copy of the current session state.
100 SyncSessionSnapshot TakeSnapshot() const;
101 SyncSessionSnapshot TakeSnapshotWithSource(
102 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source)
103 const;
104
105 // Builds and sends a snapshot to the session context's listeners.
106 void SendSyncCycleEndEventNotification(
107 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
108 void SendEventNotification(SyncCycleEvent::EventCause cause);
109
110 void SendProtocolEvent(const ProtocolEvent& event);
111
112 // TODO(akalin): Split this into context() and mutable_context().
113 SyncSessionContext* context() const { return context_; }
114 Delegate* delegate() const { return delegate_; }
115 const StatusController& status_controller() const {
116 return *status_controller_.get();
117 }
118 StatusController* mutable_status_controller() {
119 return status_controller_.get();
120 }
121
122 private:
123 SyncSession(SyncSessionContext* context, Delegate* delegate);
124
125 // The context for this session, guaranteed to outlive |this|.
126 SyncSessionContext* const context_;
127
128 // The delegate for this session, must never be NULL.
129 Delegate* const delegate_;
130
131 // Our controller for various status and error counters.
132 std::unique_ptr<StatusController> status_controller_;
133
134 DISALLOW_COPY_AND_ASSIGN(SyncSession);
135 };
136
137 } // namespace sessions
138 } // namespace syncer
139
140 #endif // COMPONENTS_SYNC_SESSIONS_IMPL_SYNC_SESSION_H_
OLDNEW
« no previous file with comments | « components/sync/sessions_impl/status_controller_unittest.cc ('k') | components/sync/sessions_impl/sync_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698