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

Side by Side Diff: components/sync/engine_impl/cycle/sync_cycle.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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // A class representing an attempt to synchronize the local syncable data 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 6 // store with a sync server. A SyncCycle instance is passed as a stateful
7 // bundle throughout the sync cycle. The SyncSession is not reused across 7 // bundle throughout the sync cycle. The SyncCycle is not reused across
8 // sync cycles; each cycle starts with a new one. 8 // sync cycles; each cycle starts with a new one.
9 9
10 #ifndef COMPONENTS_SYNC_SESSIONS_IMPL_SYNC_SESSION_H_ 10 #ifndef COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_SYNC_CYCLE_H_
11 #define COMPONENTS_SYNC_SESSIONS_IMPL_SYNC_SESSION_H_ 11 #define COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_SYNC_CYCLE_H_
12 12
13 #include <map> 13 #include <map>
14 #include <memory> 14 #include <memory>
15 #include <set> 15 #include <set>
16 #include <string> 16 #include <string>
17 #include <utility> 17 #include <utility>
18 #include <vector> 18 #include <vector>
19 19
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "components/sync/base/model_type.h" 22 #include "components/sync/base/model_type.h"
23 #include "components/sync/engine/cycle/sync_cycle_snapshot.h"
23 #include "components/sync/engine/model_safe_worker.h" 24 #include "components/sync/engine/model_safe_worker.h"
25 #include "components/sync/engine_impl/cycle/status_controller.h"
26 #include "components/sync/engine_impl/cycle/sync_cycle_context.h"
24 #include "components/sync/engine_impl/sync_cycle_event.h" 27 #include "components/sync/engine_impl/sync_cycle_event.h"
25 #include "components/sync/protocol/sync_protocol_error.h" 28 #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 29
30 namespace syncer { 30 namespace syncer {
31
31 class ModelSafeWorker; 32 class ModelSafeWorker;
33 class NudgeTracker;
32 class ProtocolEvent; 34 class ProtocolEvent;
33 35
34 namespace sessions { 36 class SyncCycle {
35
36 class NudgeTracker;
37
38 class SyncSession {
39 public: 37 public:
40 // The Delegate services events that occur during the session requiring an 38 // The Delegate services events that occur during the cycle requiring an
41 // explicit (and session-global) action, as opposed to events that are simply 39 // explicit (and cycle-global) action, as opposed to events that are simply
42 // recorded in per-session state. 40 // recorded in per-cycle state.
43 class Delegate { 41 class Delegate {
44 public: 42 public:
45 // The client was throttled and should cease-and-desist syncing activity 43 // The client was throttled and should cease-and-desist syncing activity
46 // until the specified time. 44 // until the specified time.
47 virtual void OnThrottled(const base::TimeDelta& throttle_duration) = 0; 45 virtual void OnThrottled(const base::TimeDelta& throttle_duration) = 0;
48 46
49 // Some of the client's types were throttled. 47 // Some of the client's types were throttled.
50 virtual void OnTypesThrottled(ModelTypeSet types, 48 virtual void OnTypesThrottled(ModelTypeSet types,
51 const base::TimeDelta& throttle_duration) = 0; 49 const base::TimeDelta& throttle_duration) = 0;
52 50
53 // Silenced intervals can be out of phase with individual sessions, so the 51 // Silenced intervals can be out of phase with individual cycles, so the
54 // delegate is the only thing that can give an authoritative answer for 52 // 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 53 // "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. 54 // as the delegate ensures no cycle is started if syncing is silenced.
57 // ** Note ** This will return true if silencing commenced during this 55 // ** Note ** This will return true if silencing commenced during this
58 // session and the interval has not yet elapsed, but the contract here is 56 // cycle 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 57 // 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 58 // that any given cycle _instance_ is silenced. An example of reasonable
61 // use is for UI reporting. 59 // use is for UI reporting.
62 virtual bool IsCurrentlyThrottled() = 0; 60 virtual bool IsCurrentlyThrottled() = 0;
63 61
64 // The client has been instructed to change its short poll interval. 62 // The client has been instructed to change its short poll interval.
65 virtual void OnReceivedShortPollIntervalUpdate( 63 virtual void OnReceivedShortPollIntervalUpdate(
66 const base::TimeDelta& new_interval) = 0; 64 const base::TimeDelta& new_interval) = 0;
67 65
68 // The client has been instructed to change its long poll interval. 66 // The client has been instructed to change its long poll interval.
69 virtual void OnReceivedLongPollIntervalUpdate( 67 virtual void OnReceivedLongPollIntervalUpdate(
70 const base::TimeDelta& new_interval) = 0; 68 const base::TimeDelta& new_interval) = 0;
(...skipping 13 matching lines...) Expand all
84 // Called when server wants to schedule a retry GU. 82 // Called when server wants to schedule a retry GU.
85 virtual void OnReceivedGuRetryDelay(const base::TimeDelta& delay) = 0; 83 virtual void OnReceivedGuRetryDelay(const base::TimeDelta& delay) = 0;
86 84
87 // Called when server requests a migration. 85 // Called when server requests a migration.
88 virtual void OnReceivedMigrationRequest(ModelTypeSet types) = 0; 86 virtual void OnReceivedMigrationRequest(ModelTypeSet types) = 0;
89 87
90 protected: 88 protected:
91 virtual ~Delegate() {} 89 virtual ~Delegate() {}
92 }; 90 };
93 91
94 // Build a session without a nudge tracker. Used for poll or configure type 92 // Build a cycle without a nudge tracker. Used for poll or configure type
95 // sync cycles. 93 // sync cycles.
96 static SyncSession* Build(SyncSessionContext* context, Delegate* delegate); 94 static SyncCycle* Build(SyncCycleContext* context, Delegate* delegate);
97 ~SyncSession(); 95 ~SyncCycle();
98 96
99 // Builds a thread-safe and read-only copy of the current session state. 97 // Builds a thread-safe and read-only copy of the current cycle state.
100 SyncSessionSnapshot TakeSnapshot() const; 98 SyncCycleSnapshot TakeSnapshot() const;
101 SyncSessionSnapshot TakeSnapshotWithSource( 99 SyncCycleSnapshot TakeSnapshotWithSource(
102 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source) 100 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource legacy_updates_source)
103 const; 101 const;
104 102
105 // Builds and sends a snapshot to the session context's listeners. 103 // Builds and sends a snapshot to the cycle context's listeners.
106 void SendSyncCycleEndEventNotification( 104 void SendSyncCycleEndEventNotification(
107 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); 105 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
108 void SendEventNotification(SyncCycleEvent::EventCause cause); 106 void SendEventNotification(SyncCycleEvent::EventCause cause);
109 107
110 void SendProtocolEvent(const ProtocolEvent& event); 108 void SendProtocolEvent(const ProtocolEvent& event);
111 109
112 // TODO(akalin): Split this into context() and mutable_context(). 110 // TODO(akalin): Split this into context() and mutable_context().
113 SyncSessionContext* context() const { return context_; } 111 SyncCycleContext* context() const { return context_; }
114 Delegate* delegate() const { return delegate_; } 112 Delegate* delegate() const { return delegate_; }
115 const StatusController& status_controller() const { 113 const StatusController& status_controller() const {
116 return *status_controller_.get(); 114 return *status_controller_.get();
117 } 115 }
118 StatusController* mutable_status_controller() { 116 StatusController* mutable_status_controller() {
119 return status_controller_.get(); 117 return status_controller_.get();
120 } 118 }
121 119
122 private: 120 private:
123 SyncSession(SyncSessionContext* context, Delegate* delegate); 121 SyncCycle(SyncCycleContext* context, Delegate* delegate);
124 122
125 // The context for this session, guaranteed to outlive |this|. 123 // The context for this cycle, guaranteed to outlive |this|.
126 SyncSessionContext* const context_; 124 SyncCycleContext* const context_;
127 125
128 // The delegate for this session, must never be NULL. 126 // The delegate for this cycle, must never be NULL.
129 Delegate* const delegate_; 127 Delegate* const delegate_;
130 128
131 // Our controller for various status and error counters. 129 // Our controller for various status and error counters.
132 std::unique_ptr<StatusController> status_controller_; 130 std::unique_ptr<StatusController> status_controller_;
133 131
134 DISALLOW_COPY_AND_ASSIGN(SyncSession); 132 DISALLOW_COPY_AND_ASSIGN(SyncCycle);
135 }; 133 };
136 134
137 } // namespace sessions
138 } // namespace syncer 135 } // namespace syncer
139 136
140 #endif // COMPONENTS_SYNC_SESSIONS_IMPL_SYNC_SESSION_H_ 137 #endif // COMPONENTS_SYNC_ENGINE_IMPL_CYCLE_SYNC_CYCLE_H_
OLDNEW
« no previous file with comments | « components/sync/engine_impl/cycle/status_controller_unittest.cc ('k') | components/sync/engine_impl/cycle/sync_cycle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698