OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 |
11 // server updates, and access the SyncSessionContext for the current session | 11 // server updates, and access the SyncSessionContext for the current session |
12 // via SyncSession instances. | 12 // via SyncSession instances. |
13 | 13 |
14 #ifndef CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ | 14 #ifndef CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ |
15 #define CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ | 15 #define CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ |
16 #pragma once | 16 #pragma once |
17 | 17 |
18 #include <utility> | 18 #include <utility> |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
21 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
22 #include "base/ref_counted.h" | |
22 #include "base/scoped_ptr.h" | 23 #include "base/scoped_ptr.h" |
23 #include "base/time.h" | 24 #include "base/time.h" |
24 #include "chrome/browser/sync/sessions/ordered_commit_set.h" | 25 #include "chrome/browser/sync/sessions/ordered_commit_set.h" |
25 #include "chrome/browser/sync/sessions/session_state.h" | 26 #include "chrome/browser/sync/sessions/session_state.h" |
26 #include "chrome/browser/sync/sessions/status_controller.h" | 27 #include "chrome/browser/sync/sessions/status_controller.h" |
27 #include "chrome/browser/sync/sessions/sync_session_context.h" | 28 #include "chrome/browser/sync/sessions/sync_session_context.h" |
28 #include "chrome/browser/sync/util/extensions_activity_monitor.h" | 29 #include "chrome/browser/sync/util/extensions_activity_monitor.h" |
29 | 30 |
30 namespace syncable { | 31 namespace syncable { |
31 class WriteTransaction; | 32 class WriteTransaction; |
32 } | 33 } |
33 | 34 |
34 namespace browser_sync { | 35 namespace browser_sync { |
35 class ModelSafeWorker; | 36 class ModelSafeWorker; |
36 | 37 |
37 namespace sessions { | 38 namespace sessions { |
38 typedef std::pair<sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, | 39 typedef std::pair<sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, |
39 syncable::ModelTypeBitSet> SyncSourceInfo; | 40 syncable::ModelTypeBitSet> SyncSourceInfo; |
40 | 41 |
41 class SyncSession { | 42 class SyncSession : public base::RefCountedThreadSafe<SyncSession> { |
akalin
2011/01/13 00:36:34
Why does this have to be refcounted?
tim (not reviewing)
2011/01/13 18:26:56
I discussed this tradeoff in the design doc (linke
| |
42 public: | 43 public: |
43 // The Delegate services events that occur during the session requiring an | 44 // The Delegate services events that occur during the session requiring an |
44 // explicit (and session-global) action, as opposed to events that are simply | 45 // explicit (and session-global) action, as opposed to events that are simply |
45 // recorded in per-session state. | 46 // recorded in per-session state. |
46 class Delegate { | 47 class Delegate { |
47 public: | 48 public: |
48 // The client was throttled and should cease-and-desist syncing activity | 49 // The client was throttled and should cease-and-desist syncing activity |
49 // until the specified time. | 50 // until the specified time. |
50 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) = 0; | 51 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) = 0; |
51 | 52 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 const std::vector<ModelSafeWorker*>& workers); | 86 const std::vector<ModelSafeWorker*>& workers); |
86 ~SyncSession(); | 87 ~SyncSession(); |
87 | 88 |
88 // Builds a thread-safe and read-only copy of the current session state. | 89 // Builds a thread-safe and read-only copy of the current session state. |
89 SyncSessionSnapshot TakeSnapshot() const; | 90 SyncSessionSnapshot TakeSnapshot() const; |
90 | 91 |
91 // Returns true if this session contains data that should go through the sync | 92 // Returns true if this session contains data that should go through the sync |
92 // engine again. | 93 // engine again. |
93 bool HasMoreToSync() const; | 94 bool HasMoreToSync() const; |
94 | 95 |
95 SyncSessionContext* context() { return context_; } | 96 // Collects all state pertaining to how and why |s| originated and unions it |
96 Delegate* delegate() { return delegate_; } | 97 // with corresponding state in |this|, leaving |s| unchanged. Allows |this| |
98 // to take on the responsibilities |s| had (e.g. certain data types) in the | |
99 // next SyncShare operation using |this|, rather than needed two separate | |
100 // sessions. | |
101 void Coalesce(const SyncSession* s); | |
102 | |
103 // Should be called any time |this| is being re-used in a new call to | |
104 // SyncShare (e.g., HasMoreToSync returned true). | |
105 void ResetTransientState(); | |
106 | |
107 SyncSessionContext* context() const { return context_; } | |
108 Delegate* delegate() const { return delegate_; } | |
97 syncable::WriteTransaction* write_transaction() { return write_transaction_; } | 109 syncable::WriteTransaction* write_transaction() { return write_transaction_; } |
98 StatusController* status_controller() { return status_controller_.get(); } | 110 StatusController* status_controller() { return status_controller_.get(); } |
99 | 111 |
100 const ExtensionsActivityMonitor::Records& extensions_activity() const { | 112 const ExtensionsActivityMonitor::Records& extensions_activity() const { |
101 return extensions_activity_; | 113 return extensions_activity_; |
102 } | 114 } |
103 ExtensionsActivityMonitor::Records* mutable_extensions_activity() { | 115 ExtensionsActivityMonitor::Records* mutable_extensions_activity() { |
104 return &extensions_activity_; | 116 return &extensions_activity_; |
105 } | 117 } |
106 | 118 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 | 175 |
164 private: | 176 private: |
165 SyncSession* session_; | 177 SyncSession* session_; |
166 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); | 178 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction); |
167 }; | 179 }; |
168 | 180 |
169 } // namespace sessions | 181 } // namespace sessions |
170 } // namespace browser_sync | 182 } // namespace browser_sync |
171 | 183 |
172 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ | 184 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_ |
OLD | NEW |