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

Side by Side Diff: chrome/browser/sync/engine/all_status.h

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 years, 3 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-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 //
6 // The all status object watches various sync engine components and aggregates
7 // the status of all of them into one place.
8 //
9 #ifndef CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_
10 #define CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_
11
12 #include <map>
13
14 #include "base/atomicops.h"
15 #include "base/scoped_ptr.h"
16 #include "chrome/browser/sync/engine/syncer_status.h"
17 #include "chrome/browser/sync/util/event_sys.h"
18 #include "chrome/browser/sync/util/pthread_helpers.h"
19
20 namespace browser_sync {
21 class AuthWatcher;
22 class GaiaAuthenticator;
23 class ScopedStatusLockWithNotify;
24 class ServerConnectionManager;
25 class Syncer;
26 class SyncerThread;
27 class TalkMediator;
28 struct AllStatusEvent;
29 struct AuthWatcherEvent;
30 struct GaiaAuthEvent;
31 struct ServerConnectionEvent;
32 struct SyncerEvent;
33 struct TalkMediatorEvent;
34
35 class AllStatus {
36 friend class ScopedStatusLockWithNotify;
37 public:
38 typedef EventChannel<AllStatusEvent, PThreadMutex> Channel;
39
40 // Status of the entire sync process distilled into a single enum.
41 enum SyncStatus {
42 // Can't connect to server, but there are no pending changes in
43 // our local dataase.
44 OFFLINE,
45 // Can't connect to server, and there are pending changes in our
46 // local cache.
47 OFFLINE_UNSYNCED,
48 // Connected and syncing.
49 SYNCING,
50 // Connected, no pending changes.
51 READY,
52 // Internal sync error.
53 CONFLICT,
54 // Can't connect to server, and we haven't completed the initial
55 // sync yet. So there's nothing we can do but wait for the server.
56 OFFLINE_UNUSABLE,
57 // For array sizing, etc.
58 ICON_STATUS_COUNT
59 };
60
61 struct Status {
62 SyncStatus icon;
63 int unsynced_count;
64 int conflicting_count;
65 bool syncing;
66 bool authenticated; // Successfully authenticated via gaia
67 // True if we have received at least one good reply from the server.
68 bool server_up;
69 bool server_reachable;
70 // True after a client has done a first sync.
71 bool initial_sync_ended;
72 // True if any syncer is stuck.
73 bool syncer_stuck;
74 // True if any syncer is stopped because of server issues.
75 bool server_broken;
76 // True only if the notification listener has subscribed.
77 bool notifications_enabled;
78 // Notifications counters updated by the actions in synapi.
79 int notifications_received;
80 int notifications_sent;
81 // The max number of consecutive errors from any component.
82 int max_consecutive_errors;
83 bool disk_full;
84
85 // Contains current transfer item meta handle
86 int64 current_item_meta_handle;
87 // The next two values will be equal if all updates have been received.
88 // total updates available.
89 int64 updates_available;
90 // total updates received.
91 int64 updates_received;
92 };
93
94 // Maximum interval for exponential backoff.
95 static const int kMaxBackoffSeconds = 60 * 60 * 4; // 4 hours.
96
97 AllStatus();
98 ~AllStatus();
99
100 void WatchConnectionManager(ServerConnectionManager* conn_mgr);
101 void HandleServerConnectionEvent(const ServerConnectionEvent& event);
102
103 // Both WatchAuthenticator/HandleGaiaAuthEvent and WatchAuthWatcher/
104 // HandleAuthWatcherEventachieve have the same goal; use only one of the
105 // following two. (The AuthWatcher is watched under Windows; the
106 // GaiaAuthenticator is watched under Mac/Linux.)
107 void WatchAuthenticator(GaiaAuthenticator* gaia);
108 void HandleGaiaAuthEvent(const GaiaAuthEvent& event);
109
110 void WatchAuthWatcher(AuthWatcher* auth_watcher);
111 void HandleAuthWatcherEvent(const AuthWatcherEvent& event);
112
113 void WatchSyncerThread(SyncerThread* syncer_thread);
114 void HandleSyncerEvent(const SyncerEvent& event);
115
116 void WatchTalkMediator(
117 const browser_sync::TalkMediator* talk_mediator);
118 void HandleTalkMediatorEvent(
119 const browser_sync::TalkMediatorEvent& event);
120
121 // Returns a string description of the SyncStatus (currently just the ascii
122 // version of the enum). Will LOG(FATAL) if the status us out of range.
123 static const char* GetSyncStatusString(SyncStatus status);
124
125 Channel* channel() const { return channel_; }
126
127 Status status() const;
128
129 // DDOS avoidance function. The argument and return value is in seconds
130 static int GetRecommendedDelaySeconds(int base_delay_seconds);
131
132 // This uses AllStatus' max_consecutive_errors as the error count
133 int GetRecommendedDelay(int base_delay) const;
134
135 protected:
136 typedef PThreadScopedLock<PThreadMutex> MutexLock;
137 typedef std::map<Syncer*, EventListenerHookup*> Syncers;
138
139 // Examines syncer to calculate syncing and the unsynced count,
140 // and returns a Status with new values.
141 Status CalcSyncing() const;
142 Status CalcSyncing(const SyncerEvent& event) const;
143 Status CreateBlankStatus() const;
144
145 // Examines status to see what has changed, updates old_status in place.
146 int CalcStatusChanges(Status* old_status);
147
148 Status status_;
149 Channel* const channel_;
150 scoped_ptr<EventListenerHookup> conn_mgr_hookup_;
151 scoped_ptr<EventListenerHookup> gaia_hookup_;
152 scoped_ptr<EventListenerHookup> authwatcher_hookup_;
153 scoped_ptr<EventListenerHookup> syncer_thread_hookup_;
154 scoped_ptr<EventListenerHookup> diskfull_hookup_;
155 scoped_ptr<EventListenerHookup> talk_mediator_hookup_;
156
157 mutable PThreadMutex mutex_; // Protects all data members.
158 };
159
160 struct AllStatusEvent {
161 enum { // A bit mask of which members have changed.
162 SHUTDOWN = 0x0000,
163 ICON = 0x0001,
164 UNSYNCED_COUNT = 0x0002,
165 AUTHENTICATED = 0x0004,
166 SYNCING = 0x0008,
167 SERVER_UP = 0x0010,
168 NOTIFICATIONS_ENABLED = 0x0020,
169 INITIAL_SYNC_ENDED = 0x0080,
170 SERVER_REACHABLE = 0x0100,
171 DISK_FULL = 0x0200,
172 OVER_QUOTA = 0x0400,
173 NOTIFICATIONS_RECEIVED = 0x0800,
174 NOTIFICATIONS_SENT = 0x1000,
175 TRASH_WARNING = 0x40000,
176 };
177 int what_changed;
178 AllStatus::Status status;
179
180 typedef AllStatusEvent EventType;
181 static inline bool IsChannelShutdownEvent(const AllStatusEvent& e) {
182 return SHUTDOWN == e.what_changed;
183 }
184 };
185
186 enum StatusNotifyPlan {
187 NOTIFY_IF_STATUS_CHANGED,
188 // A small optimization, don't do the big compare when we know
189 // nothing has changed.
190 DONT_NOTIFY,
191 };
192
193 class ScopedStatusLockWithNotify {
194 public:
195 explicit ScopedStatusLockWithNotify(AllStatus* allstatus);
196 ~ScopedStatusLockWithNotify();
197 // Defaults to true, but can be explicitly reset so we don't have to
198 // do the big compare in the destructor. Small optimization.
199
200 inline void set_notify_plan(StatusNotifyPlan plan) { plan_ = plan; }
201 void NotifyOverQuota();
202 protected:
203 AllStatusEvent event_;
204 AllStatus* const allstatus_;
205 StatusNotifyPlan plan_;
206 };
207
208 } // namespace browser_sync
209
210 #endif // CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/engine/all_status.cc » ('j') | chrome/browser/sync/engine/apply_updates_command_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698