OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 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 | 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 // The AllStatus object watches various sync engine components and aggregates | 5 // The AllStatus object watches various sync engine components and aggregates |
6 // the status of all of them into one place. | 6 // the status of all of them into one place. |
7 | 7 |
8 #ifndef CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ | 8 #ifndef CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ |
9 #define CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ | 9 #define CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 | 12 |
13 #include "base/atomicops.h" | 13 #include "base/atomicops.h" |
14 #include "base/lock.h" | 14 #include "base/lock.h" |
15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 16 #include "chrome/browser/sync/util/channel.h" |
16 #include "chrome/common/deprecated/event_sys.h" | 17 #include "chrome/common/deprecated/event_sys.h" |
17 | 18 |
18 namespace browser_sync { | 19 namespace browser_sync { |
19 | 20 |
20 class ScopedStatusLockWithNotify; | 21 class ScopedStatusLockWithNotify; |
21 class ServerConnectionManager; | 22 class ServerConnectionManager; |
22 class Syncer; | 23 class Syncer; |
23 class SyncerThread; | 24 class SyncerThread; |
24 struct AllStatusEvent; | 25 struct AllStatusEvent; |
25 struct AuthWatcherEvent; | 26 struct AuthWatcherEvent; |
26 struct ServerConnectionEvent; | 27 struct ServerConnectionEvent; |
27 struct SyncerEvent; | 28 struct SyncerEvent; |
28 | 29 |
29 class AllStatus { | 30 class AllStatus : public ChannelEventHandler<SyncerEvent> { |
30 friend class ScopedStatusLockWithNotify; | 31 friend class ScopedStatusLockWithNotify; |
31 public: | 32 public: |
32 typedef EventChannel<AllStatusEvent, Lock> Channel; | 33 typedef EventChannel<AllStatusEvent, Lock> Channel; |
33 | 34 |
34 // Status of the entire sync process distilled into a single enum. | 35 // Status of the entire sync process distilled into a single enum. |
35 enum SyncStatus { | 36 enum SyncStatus { |
36 // Can't connect to server, but there are no pending changes in | 37 // Can't connect to server, but there are no pending changes in |
37 // our local dataase. | 38 // our local dataase. |
38 OFFLINE, | 39 OFFLINE, |
39 // Can't connect to server, and there are pending changes in our | 40 // Can't connect to server, and there are pending changes in our |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 91 |
91 AllStatus(); | 92 AllStatus(); |
92 ~AllStatus(); | 93 ~AllStatus(); |
93 | 94 |
94 void WatchConnectionManager(ServerConnectionManager* conn_mgr); | 95 void WatchConnectionManager(ServerConnectionManager* conn_mgr); |
95 void HandleServerConnectionEvent(const ServerConnectionEvent& event); | 96 void HandleServerConnectionEvent(const ServerConnectionEvent& event); |
96 | 97 |
97 void HandleAuthWatcherEvent(const AuthWatcherEvent& event); | 98 void HandleAuthWatcherEvent(const AuthWatcherEvent& event); |
98 | 99 |
99 void WatchSyncerThread(SyncerThread* syncer_thread); | 100 void WatchSyncerThread(SyncerThread* syncer_thread); |
100 void HandleSyncerEvent(const SyncerEvent& event); | 101 void HandleChannelEvent(const SyncerEvent& event); |
101 | 102 |
102 // Returns a string description of the SyncStatus (currently just the ascii | 103 // Returns a string description of the SyncStatus (currently just the ascii |
103 // version of the enum). Will LOG(FATAL) if the status us out of range. | 104 // version of the enum). Will LOG(FATAL) if the status us out of range. |
104 static const char* GetSyncStatusString(SyncStatus status); | 105 static const char* GetSyncStatusString(SyncStatus status); |
105 | 106 |
106 Channel* channel() const { return channel_; } | 107 Channel* channel() const { return channel_; } |
107 | 108 |
108 Status status() const; | 109 Status status() const; |
109 | 110 |
110 // DDOS avoidance function. The argument and return value is in seconds | 111 // DDOS avoidance function. The argument and return value is in seconds |
(...skipping 16 matching lines...) Expand all Loading... |
127 Status CalcSyncing() const; | 128 Status CalcSyncing() const; |
128 Status CalcSyncing(const SyncerEvent& event) const; | 129 Status CalcSyncing(const SyncerEvent& event) const; |
129 Status CreateBlankStatus() const; | 130 Status CreateBlankStatus() const; |
130 | 131 |
131 // Examines status to see what has changed, updates old_status in place. | 132 // Examines status to see what has changed, updates old_status in place. |
132 int CalcStatusChanges(Status* old_status); | 133 int CalcStatusChanges(Status* old_status); |
133 | 134 |
134 Status status_; | 135 Status status_; |
135 Channel* const channel_; | 136 Channel* const channel_; |
136 scoped_ptr<EventListenerHookup> conn_mgr_hookup_; | 137 scoped_ptr<EventListenerHookup> conn_mgr_hookup_; |
137 scoped_ptr<EventListenerHookup> syncer_thread_hookup_; | 138 scoped_ptr<ChannelHookup<SyncerEvent> > syncer_thread_hookup_; |
138 scoped_ptr<EventListenerHookup> diskfull_hookup_; | 139 scoped_ptr<EventListenerHookup> diskfull_hookup_; |
139 scoped_ptr<EventListenerHookup> talk_mediator_hookup_; | 140 scoped_ptr<EventListenerHookup> talk_mediator_hookup_; |
140 | 141 |
141 mutable Lock mutex_; // Protects all data members. | 142 mutable Lock mutex_; // Protects all data members. |
142 DISALLOW_COPY_AND_ASSIGN(AllStatus); | 143 DISALLOW_COPY_AND_ASSIGN(AllStatus); |
143 }; | 144 }; |
144 | 145 |
145 struct AllStatusEvent { | 146 struct AllStatusEvent { |
146 enum { // A bit mask of which members have changed. | 147 enum { // A bit mask of which members have changed. |
147 SHUTDOWN = 0x0000, | 148 SHUTDOWN = 0x0000, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 void NotifyOverQuota(); | 187 void NotifyOverQuota(); |
187 protected: | 188 protected: |
188 AllStatusEvent event_; | 189 AllStatusEvent event_; |
189 AllStatus* const allstatus_; | 190 AllStatus* const allstatus_; |
190 StatusNotifyPlan plan_; | 191 StatusNotifyPlan plan_; |
191 }; | 192 }; |
192 | 193 |
193 } // namespace browser_sync | 194 } // namespace browser_sync |
194 | 195 |
195 #endif // CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ | 196 #endif // CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ |
OLD | NEW |