Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 SyncSession instance is passed as a stateful |
| 7 // bundle to and from various SyncerCommands with the goal of converging the | 7 // bundle to and from various SyncerCommands with the goal of converging the |
| 8 // client view of data with that of the server. The commands twiddle with | 8 // client view of data with that of the server. The commands twiddle with |
| 9 // session status in response to events and hiccups along the way, set and | 9 // session status in response to events and hiccups along the way, set and |
| 10 // query session progress with regards to conflict resolution and applying | 10 // query session progress with regards to conflict resolution and applying |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 29 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
| 30 #include "sync/sessions/ordered_commit_set.h" | 30 #include "sync/sessions/ordered_commit_set.h" |
| 31 #include "sync/sessions/status_controller.h" | 31 #include "sync/sessions/status_controller.h" |
| 32 #include "sync/sessions/sync_session_context.h" | 32 #include "sync/sessions/sync_session_context.h" |
| 33 | 33 |
| 34 namespace syncer { | 34 namespace syncer { |
| 35 class ModelSafeWorker; | 35 class ModelSafeWorker; |
| 36 | 36 |
| 37 namespace sessions { | 37 namespace sessions { |
| 38 | 38 |
| 39 class NudgeTracker; | |
| 40 | |
| 39 class SYNC_EXPORT_PRIVATE SyncSession { | 41 class SYNC_EXPORT_PRIVATE SyncSession { |
| 40 public: | 42 public: |
| 41 // The Delegate services events that occur during the session requiring an | 43 // The Delegate services events that occur during the session requiring an |
| 42 // explicit (and session-global) action, as opposed to events that are simply | 44 // explicit (and session-global) action, as opposed to events that are simply |
| 43 // recorded in per-session state. | 45 // recorded in per-session state. |
| 44 class SYNC_EXPORT_PRIVATE Delegate { | 46 class SYNC_EXPORT_PRIVATE Delegate { |
| 45 public: | 47 public: |
| 46 // The client was throttled and should cease-and-desist syncing activity | 48 // The client was throttled and should cease-and-desist syncing activity |
| 47 // until the specified time. | 49 // until the specified time. |
| 48 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) = 0; | 50 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) = 0; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 virtual void OnShouldStopSyncingPermanently() = 0; | 85 virtual void OnShouldStopSyncingPermanently() = 0; |
| 84 | 86 |
| 85 // Called for the syncer to respond to the error sent by the server. | 87 // Called for the syncer to respond to the error sent by the server. |
| 86 virtual void OnSyncProtocolError( | 88 virtual void OnSyncProtocolError( |
| 87 const sessions::SyncSessionSnapshot& snapshot) = 0; | 89 const sessions::SyncSessionSnapshot& snapshot) = 0; |
| 88 | 90 |
| 89 protected: | 91 protected: |
| 90 virtual ~Delegate() {} | 92 virtual ~Delegate() {} |
| 91 }; | 93 }; |
| 92 | 94 |
| 93 SyncSession(SyncSessionContext* context, | 95 // Build a session with a nudge tracker. Used for sync cycles with origin of |
| 94 Delegate* delegate, | 96 // GU_TRIGGER (ie. notification, local change, and/or refresh request) |
| 95 const SyncSourceInfo& source); | 97 static SyncSession* BuildForNudge(SyncSessionContext* context, |
| 98 Delegate* delegate, | |
| 99 const SyncSourceInfo& source, | |
| 100 const NudgeTracker* nudge_tracker); | |
| 101 | |
| 102 // Build a session without a nudge tracker. Used for poll or configure type | |
| 103 // sync cycles. | |
| 104 static SyncSession* BuildForNonNudge(SyncSessionContext* context, | |
|
tim (not reviewing)
2013/05/07 20:34:13
Build() and BuildForNudge() wouldn't be horrible,
rlarocque
2013/05/07 21:50:57
Done.
| |
| 105 Delegate* delegate, | |
| 106 const SyncSourceInfo& source); | |
| 107 | |
| 96 ~SyncSession(); | 108 ~SyncSession(); |
| 97 | 109 |
| 98 // Builds a thread-safe and read-only copy of the current session state. | 110 // Builds a thread-safe and read-only copy of the current session state. |
| 99 SyncSessionSnapshot TakeSnapshot() const; | 111 SyncSessionSnapshot TakeSnapshot() const; |
| 100 | 112 |
| 101 // Builds and sends a snapshot to the session context's listeners. | 113 // Builds and sends a snapshot to the session context's listeners. |
| 102 void SendEventNotification(SyncEngineEvent::EventCause cause); | 114 void SendEventNotification(SyncEngineEvent::EventCause cause); |
| 103 | 115 |
| 104 // TODO(akalin): Split this into context() and mutable_context(). | 116 // TODO(akalin): Split this into context() and mutable_context(). |
| 105 SyncSessionContext* context() const { return context_; } | 117 SyncSessionContext* context() const { return context_; } |
| 106 Delegate* delegate() const { return delegate_; } | 118 Delegate* delegate() const { return delegate_; } |
| 107 const StatusController& status_controller() const { | 119 const StatusController& status_controller() const { |
| 108 return *status_controller_.get(); | 120 return *status_controller_.get(); |
| 109 } | 121 } |
| 110 StatusController* mutable_status_controller() { | 122 StatusController* mutable_status_controller() { |
| 111 return status_controller_.get(); | 123 return status_controller_.get(); |
| 112 } | 124 } |
| 113 | 125 |
| 114 const SyncSourceInfo& source() const { return source_; } | 126 const SyncSourceInfo& source() const { return source_; } |
| 115 | 127 |
| 128 const NudgeTracker* nudge_tracker() const { return nudge_tracker_; } | |
| 129 | |
| 116 private: | 130 private: |
| 131 SyncSession(SyncSessionContext* context, | |
| 132 Delegate* delegate, | |
| 133 const SyncSourceInfo& source, | |
| 134 const NudgeTracker* nudge_tracker); | |
| 135 | |
| 117 // The context for this session, guaranteed to outlive |this|. | 136 // The context for this session, guaranteed to outlive |this|. |
| 118 SyncSessionContext* const context_; | 137 SyncSessionContext* const context_; |
| 119 | 138 |
| 120 // The source for initiating this sync session. | 139 // The source for initiating this sync session. |
| 121 SyncSourceInfo source_; | 140 SyncSourceInfo source_; |
| 122 | 141 |
| 123 // The delegate for this session, must never be NULL. | 142 // The delegate for this session, must never be NULL. |
| 124 Delegate* const delegate_; | 143 Delegate* const delegate_; |
| 125 | 144 |
| 126 // Our controller for various status and error counters. | 145 // Our controller for various status and error counters. |
| 127 scoped_ptr<StatusController> status_controller_; | 146 scoped_ptr<StatusController> status_controller_; |
| 128 | 147 |
| 148 const NudgeTracker* nudge_tracker_; | |
| 149 | |
| 129 DISALLOW_COPY_AND_ASSIGN(SyncSession); | 150 DISALLOW_COPY_AND_ASSIGN(SyncSession); |
| 130 }; | 151 }; |
| 131 | 152 |
| 132 } // namespace sessions | 153 } // namespace sessions |
| 133 } // namespace syncer | 154 } // namespace syncer |
| 134 | 155 |
| 135 #endif // SYNC_SESSIONS_SYNC_SESSION_H_ | 156 #endif // SYNC_SESSIONS_SYNC_SESSION_H_ |
| OLD | NEW |