OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 to run the syncer on a thread. | 5 // A class to run the syncer on a thread. |
6 // This is the default implementation of SyncerThread whose Stop implementation | 6 // This is the default implementation of SyncerThread whose Stop implementation |
7 // does not support a timeout, but is greatly simplified. | 7 // does not support a timeout, but is greatly simplified. |
8 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ | 8 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
9 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ | 9 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
10 | 10 |
11 #include <list> | 11 #include <list> |
12 #include <map> | 12 #include <map> |
13 #include <queue> | 13 #include <queue> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/condition_variable.h" | 17 #include "base/condition_variable.h" |
18 #include "base/ref_counted.h" | 18 #include "base/ref_counted.h" |
19 #include "base/scoped_ptr.h" | 19 #include "base/scoped_ptr.h" |
20 #include "base/thread.h" | 20 #include "base/thread.h" |
21 #include "base/time.h" | 21 #include "base/time.h" |
22 #include "base/waitable_event.h" | 22 #include "base/waitable_event.h" |
23 #include "chrome/browser/sync/engine/all_status.h" | 23 #include "chrome/browser/sync/engine/all_status.h" |
| 24 #if defined(OS_LINUX) |
| 25 #include "chrome/browser/sync/engine/idle_query_linux.h" |
| 26 #endif |
24 #include "chrome/browser/sync/sessions/sync_session.h" | 27 #include "chrome/browser/sync/sessions/sync_session.h" |
25 #include "chrome/browser/sync/util/event_sys-inl.h" | 28 #include "chrome/browser/sync/util/event_sys-inl.h" |
26 #include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST | 29 #include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST |
27 | 30 |
28 class EventListenerHookup; | 31 class EventListenerHookup; |
29 | 32 |
30 namespace syncable { | 33 namespace syncable { |
31 class DirectoryManager; | 34 class DirectoryManager; |
32 struct DirectoryManagerEvent; | 35 struct DirectoryManagerEvent; |
33 } | 36 } |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // If |was_throttled| was true, this still discards elapsed nudges, but we | 243 // If |was_throttled| was true, this still discards elapsed nudges, but we |
241 // treat the request as a periodic poll rather than a nudge from a source. | 244 // treat the request as a periodic poll rather than a nudge from a source. |
242 // TODO(timsteele/code reviewer): The first poll after a throttle period | 245 // TODO(timsteele/code reviewer): The first poll after a throttle period |
243 // will appear as a periodic request. Do we want to be more specific? | 246 // will appear as a periodic request. Do we want to be more specific? |
244 // Returns true if it determines a nudge actually occurred. | 247 // Returns true if it determines a nudge actually occurred. |
245 bool UpdateNudgeSource(bool was_throttled, bool continue_sync_cycle, | 248 bool UpdateNudgeSource(bool was_throttled, bool continue_sync_cycle, |
246 bool* initial_sync); | 249 bool* initial_sync); |
247 void SetUpdatesSource(bool nudged, NudgeSource nudge_source, | 250 void SetUpdatesSource(bool nudged, NudgeSource nudge_source, |
248 bool* initial_sync); | 251 bool* initial_sync); |
249 | 252 |
| 253 int UserIdleTime(); |
| 254 |
250 // For unit tests only. | 255 // For unit tests only. |
251 virtual void DisableIdleDetection() { disable_idle_detection_ = true; } | 256 virtual void DisableIdleDetection() { disable_idle_detection_ = true; } |
252 | 257 |
253 // State of the notification framework is tracked by these values. | 258 // State of the notification framework is tracked by these values. |
254 bool p2p_authenticated_; | 259 bool p2p_authenticated_; |
255 bool p2p_subscribed_; | 260 bool p2p_subscribed_; |
256 | 261 |
257 scoped_ptr<EventListenerHookup> conn_mgr_hookup_; | 262 scoped_ptr<EventListenerHookup> conn_mgr_hookup_; |
258 const AllStatus* allstatus_; | 263 const AllStatus* allstatus_; |
259 | 264 |
(...skipping 13 matching lines...) Expand all Loading... |
273 | 278 |
274 // This causes syncer to start syncing ASAP. If the rate of requests is too | 279 // This causes syncer to start syncing ASAP. If the rate of requests is too |
275 // high the request will be silently dropped. mutex_ should be held when | 280 // high the request will be silently dropped. mutex_ should be held when |
276 // this is called. | 281 // this is called. |
277 void NudgeSyncImpl(int milliseconds_from_now, NudgeSource source); | 282 void NudgeSyncImpl(int milliseconds_from_now, NudgeSource source); |
278 | 283 |
279 scoped_ptr<EventListenerHookup> talk_mediator_hookup_; | 284 scoped_ptr<EventListenerHookup> talk_mediator_hookup_; |
280 scoped_ptr<EventListenerHookup> directory_manager_hookup_; | 285 scoped_ptr<EventListenerHookup> directory_manager_hookup_; |
281 scoped_ptr<EventListenerHookup> syncer_events_; | 286 scoped_ptr<EventListenerHookup> syncer_events_; |
282 | 287 |
| 288 #if defined(OS_LINUX) |
| 289 // On Linux, we need this information in order to query idle time. |
| 290 scoped_ptr<IdleQueryLinux> idle_query_; |
| 291 #endif |
| 292 |
283 scoped_ptr<sessions::SyncSessionContext> session_context_; | 293 scoped_ptr<sessions::SyncSessionContext> session_context_; |
284 | 294 |
285 // Events from the Syncer's syncer_event_channel are first processed by the | 295 // Events from the Syncer's syncer_event_channel are first processed by the |
286 // SyncerThread and then get relayed onto this channel for consumers. | 296 // SyncerThread and then get relayed onto this channel for consumers. |
287 // TODO(timsteele): Wow did this confused me. I had removed the channel from | 297 // TODO(timsteele): Wow did this confused me. I had removed the channel from |
288 // here thinking there was only one, and then realized this relay was | 298 // here thinking there was only one, and then realized this relay was |
289 // happening. Is this strict event handling order needed?! | 299 // happening. Is this strict event handling order needed?! |
290 scoped_ptr<SyncerEventChannel> syncer_event_relay_channel_; | 300 scoped_ptr<SyncerEventChannel> syncer_event_relay_channel_; |
291 | 301 |
292 // Set whenever the server instructs us to stop sending it requests until | 302 // Set whenever the server instructs us to stop sending it requests until |
293 // a specified time, and reset for each call to SyncShare. (Note that the | 303 // a specified time, and reset for each call to SyncShare. (Note that the |
294 // WaitInterval::THROTTLED contract is such that we don't call SyncShare at | 304 // WaitInterval::THROTTLED contract is such that we don't call SyncShare at |
295 // all until the "silenced until" embargo expires.) | 305 // all until the "silenced until" embargo expires.) |
296 base::TimeTicks silenced_until_; | 306 base::TimeTicks silenced_until_; |
297 | 307 |
298 // Useful for unit tests | 308 // Useful for unit tests |
299 bool disable_idle_detection_; | 309 bool disable_idle_detection_; |
300 | 310 |
301 DISALLOW_COPY_AND_ASSIGN(SyncerThread); | 311 DISALLOW_COPY_AND_ASSIGN(SyncerThread); |
302 }; | 312 }; |
303 | 313 |
304 } // namespace browser_sync | 314 } // namespace browser_sync |
305 | 315 |
306 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ | 316 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
OLD | NEW |