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

Side by Side Diff: chrome/browser/sync/sessions/sync_session.h

Issue 386030: Relieve SyncerSession,SyncCycleState, SyncProcessState, SyncerSession, Syncer... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 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
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
11 // server updates, and access the SyncSessionContext for the current session
12 // via SyncSession instances.
13
14 #ifndef CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_
15 #define CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_
16
17 #include <string>
18
19 #include "base/basictypes.h"
20 #include "base/scoped_ptr.h"
21 #include "base/time.h"
22 #include "chrome/browser/sync/sessions/session_state.h"
23 #include "chrome/browser/sync/sessions/status_controller.h"
24 #include "chrome/browser/sync/sessions/sync_session_context.h"
25 #include "chrome/browser/sync/util/extensions_activity_monitor.h"
26
27 namespace syncable {
28 class WriteTransaction;
29 }
30
31 namespace browser_sync {
32 namespace sessions {
33
34 class SyncSession {
35 public:
36 // The Delegate services events that occur during the session requiring an
37 // explicit (and session-global) action, as opposed to events that are simply
38 // recorded in per-session state.
39 class Delegate {
40 public:
41 // The client was throttled and should cease-and-desist syncing activity
42 // until the specified time.
43 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until) = 0;
44
45 // Silenced intervals can be out of phase with individual sessions, so the
46 // delegate is the only thing that can give an authoritative answer for
47 // "is syncing silenced right now". This shouldn't be necessary very often
48 // as the delegate ensures no session is started if syncing is silenced.
49 // ** Note ** This will return true if silencing commenced during this
50 // session and the interval has not yet elapsed, but the contract here is
51 // solely based on absolute time values. So, this cannot be used to infer
52 // that any given session _instance_ is silenced. An example of reasonable
53 // use is for UI reporting.
54 virtual bool IsSyncingCurrentlySilenced() = 0;
55
56 // The client has been instructed to change its short poll interval.
57 virtual void OnReceivedShortPollIntervalUpdate(
58 const base::TimeDelta& new_interval) = 0;
59
60 // The client has been instructed to change its long poll interval.
61 virtual void OnReceivedLongPollIntervalUpdate(
62 const base::TimeDelta& new_interval) = 0;
63
64 protected:
65 virtual ~Delegate() {}
66 };
67
68 // Creates a new SyncSession with mandatory context and delegate.
69 SyncSession(SyncSessionContext* context, Delegate* delegate);
70
71 // Builds a thread-safe and read-only copy of the current session state.
72 SyncSessionSnapshot TakeSnapshot() const;
73
74 // Returns true if this session contains data that should go through the sync
75 // engine again.
76 bool HasMoreToSync() const;
77
78 SyncSessionContext* context() { return context_; }
79 Delegate* delegate() { return delegate_; }
80 syncable::WriteTransaction* write_transaction() { return write_transaction_; }
81 StatusController* status_controller() { return &status_controller_; }
82
83 const ExtensionsActivityMonitor::Records& extensions_activity() const {
84 return extensions_activity_;
85 }
86 ExtensionsActivityMonitor::Records* mutable_extensions_activity() {
87 return &extensions_activity_;
88 }
89
90 bool auth_failure_occurred() const { return auth_failure_occurred_; }
91 void set_auth_failure_occurred() { auth_failure_occurred_ = true; }
92 void clear_auth_failure_occurred() { auth_failure_occurred_ = false; }
93
94 // Volatile reader for the source member of the sync session object. The
95 // value is set to the SYNC_CYCLE_CONTINUATION value to signal that it has
96 // been read.
97 sync_pb::GetUpdatesCallerInfo::GET_UPDATES_SOURCE TestAndSetSource();
98 void set_source(sync_pb::GetUpdatesCallerInfo::GET_UPDATES_SOURCE source) {
99 source_ = source;
100 }
101
102 private:
103 // Extend the encapsulation boundary to utilities for internal member
104 // assignments. This way, the scope of these actions is explicit, they can't
105 // be overridden, and assigning is always accompanied by unassigning.
106 friend class ScopedSetSessionWriteTransaction;
107
108 // The context for this session, guaranteed to outlive |this|.
109 SyncSessionContext* const context_;
110
111 // The source for initiating this sync session.
112 sync_pb::GetUpdatesCallerInfo::GET_UPDATES_SOURCE source_;
113
114 // Information about extensions activity since the last successful commit.
115 ExtensionsActivityMonitor::Records extensions_activity_;
116
117 // Used to allow various steps to share a transaction. Can be NULL.
118 syncable::WriteTransaction* write_transaction_;
119
120 // The delegate for this session, must never be NULL.
121 Delegate* delegate_;
122
123 // Our controller for various status and error counters.
124 StatusController status_controller_;
125
126 // Used to determine if an auth error notification should be sent out.
127 bool auth_failure_occurred_;
128
129 DISALLOW_COPY_AND_ASSIGN(SyncSession);
130 };
131
132 // Installs a WriteTransaction to a given session and later clears it when the
133 // utility falls out of scope. Transactions are not nestable, so it is an error
134 // to try and use one of these if the session already has a transaction.
135 class ScopedSetSessionWriteTransaction {
136 public:
137 ScopedSetSessionWriteTransaction(SyncSession* session,
138 syncable::WriteTransaction* trans)
139 : session_(session) {
140 DCHECK(!session_->write_transaction_);
141 session_->write_transaction_ = trans;
142 }
143 ~ScopedSetSessionWriteTransaction() { session_->write_transaction_ = NULL; }
144
145 private:
146 SyncSession* session_;
147 DISALLOW_COPY_AND_ASSIGN(ScopedSetSessionWriteTransaction);
148 };
149
150 } // namespace sessions
151 } // namespace browser_sync
152
153 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSION_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/status_controller_unittest.cc ('k') | chrome/browser/sync/sessions/sync_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698