| 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 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 #pragma once | 10 #pragma once |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/time.h" | 22 #include "base/time.h" |
| 23 #include "base/waitable_event.h" | 23 #include "base/waitable_event.h" |
| 24 #if defined(OS_LINUX) | 24 #if defined(OS_LINUX) |
| 25 #include "chrome/browser/sync/engine/idle_query_linux.h" | 25 #include "chrome/browser/sync/engine/idle_query_linux.h" |
| 26 #endif | 26 #endif |
| 27 #include "chrome/browser/sync/sessions/sync_session.h" | 27 #include "chrome/browser/sync/sessions/sync_session.h" |
| 28 #include "chrome/common/deprecated/event_sys-inl.h" | 28 #include "chrome/common/deprecated/event_sys-inl.h" |
| 29 | 29 |
| 30 class EventListenerHookup; | 30 class EventListenerHookup; |
| 31 | 31 |
| 32 namespace syncable { | |
| 33 class DirectoryManager; | |
| 34 struct DirectoryManagerEvent; | |
| 35 } | |
| 36 | |
| 37 namespace browser_sync { | 32 namespace browser_sync { |
| 38 | 33 |
| 39 class ModelSafeWorker; | 34 class ModelSafeWorker; |
| 40 class ServerConnectionManager; | 35 class ServerConnectionManager; |
| 41 class Syncer; | 36 class Syncer; |
| 42 class URLFactory; | 37 class URLFactory; |
| 43 struct ServerConnectionEvent; | 38 struct ServerConnectionEvent; |
| 44 struct SyncerEvent; | 39 struct SyncerEvent; |
| 45 struct SyncerShutdownEvent; | 40 struct SyncerShutdownEvent; |
| 46 | 41 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 virtual bool RequestResume(); | 126 virtual bool RequestResume(); |
| 132 | 127 |
| 133 // Nudges the syncer to sync with a delay specified. This API is for access | 128 // Nudges the syncer to sync with a delay specified. This API is for access |
| 134 // from the SyncerThread's controller and will cause a mutex lock. | 129 // from the SyncerThread's controller and will cause a mutex lock. |
| 135 virtual void NudgeSyncer(int milliseconds_from_now, NudgeSource source); | 130 virtual void NudgeSyncer(int milliseconds_from_now, NudgeSource source); |
| 136 | 131 |
| 137 void SetNotificationsEnabled(bool notifications_enabled); | 132 void SetNotificationsEnabled(bool notifications_enabled); |
| 138 | 133 |
| 139 virtual SyncerEventChannel* relay_channel(); | 134 virtual SyncerEventChannel* relay_channel(); |
| 140 | 135 |
| 136 // Call this when a directory is opened |
| 137 void CreateSyncer(const std::string& dirname); |
| 138 |
| 141 // DDOS avoidance function. The argument and return value is in seconds | 139 // DDOS avoidance function. The argument and return value is in seconds |
| 142 static int GetRecommendedDelaySeconds(int base_delay_seconds); | 140 static int GetRecommendedDelaySeconds(int base_delay_seconds); |
| 143 | 141 |
| 144 protected: | 142 protected: |
| 145 virtual void ThreadMain(); | 143 virtual void ThreadMain(); |
| 146 void ThreadMainLoop(); | 144 void ThreadMainLoop(); |
| 147 | 145 |
| 148 virtual void SetConnected(bool connected) { | 146 virtual void SetConnected(bool connected) { |
| 149 DCHECK(!thread_.IsRunning()); | 147 DCHECK(!thread_.IsRunning()); |
| 150 vault_.connected_ = connected; | 148 vault_.connected_ = connected; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 221 |
| 224 // Used to lock everything in |vault_|. | 222 // Used to lock everything in |vault_|. |
| 225 Lock lock_; | 223 Lock lock_; |
| 226 | 224 |
| 227 private: | 225 private: |
| 228 // Threshold multipler for how long before user should be considered idle. | 226 // Threshold multipler for how long before user should be considered idle. |
| 229 static const int kPollBackoffThresholdMultiplier = 10; | 227 static const int kPollBackoffThresholdMultiplier = 10; |
| 230 | 228 |
| 231 friend void* RunSyncerThread(void* syncer_thread); | 229 friend void* RunSyncerThread(void* syncer_thread); |
| 232 void* Run(); | 230 void* Run(); |
| 233 void HandleDirectoryManagerEvent( | |
| 234 const syncable::DirectoryManagerEvent& event); | |
| 235 void HandleChannelEvent(const SyncerEvent& event); | 231 void HandleChannelEvent(const SyncerEvent& event); |
| 236 | 232 |
| 237 // SyncSession::Delegate implementation. | 233 // SyncSession::Delegate implementation. |
| 238 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until); | 234 virtual void OnSilencedUntil(const base::TimeTicks& silenced_until); |
| 239 virtual bool IsSyncingCurrentlySilenced(); | 235 virtual bool IsSyncingCurrentlySilenced(); |
| 240 virtual void OnReceivedShortPollIntervalUpdate( | 236 virtual void OnReceivedShortPollIntervalUpdate( |
| 241 const base::TimeDelta& new_interval); | 237 const base::TimeDelta& new_interval); |
| 242 virtual void OnReceivedLongPollIntervalUpdate( | 238 virtual void OnReceivedLongPollIntervalUpdate( |
| 243 const base::TimeDelta& new_interval); | 239 const base::TimeDelta& new_interval); |
| 244 virtual void OnShouldStopSyncingPermanently(); | 240 virtual void OnShouldStopSyncingPermanently(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // The upper bound on the nominal wait between polls in seconds. Note that | 312 // The upper bound on the nominal wait between polls in seconds. Note that |
| 317 // this bounds the "nominal" poll interval, while the the actual interval | 313 // this bounds the "nominal" poll interval, while the the actual interval |
| 318 // also takes previous failures into account. | 314 // also takes previous failures into account. |
| 319 int syncer_max_interval_; | 315 int syncer_max_interval_; |
| 320 | 316 |
| 321 // This causes syncer to start syncing ASAP. If the rate of requests is too | 317 // This causes syncer to start syncing ASAP. If the rate of requests is too |
| 322 // high the request will be silently dropped. mutex_ should be held when | 318 // high the request will be silently dropped. mutex_ should be held when |
| 323 // this is called. | 319 // this is called. |
| 324 void NudgeSyncImpl(int milliseconds_from_now, NudgeSource source); | 320 void NudgeSyncImpl(int milliseconds_from_now, NudgeSource source); |
| 325 | 321 |
| 326 scoped_ptr<EventListenerHookup> directory_manager_hookup_; | |
| 327 scoped_ptr<ChannelHookup<SyncerEvent> > syncer_events_; | 322 scoped_ptr<ChannelHookup<SyncerEvent> > syncer_events_; |
| 328 | 323 |
| 329 #if defined(OS_LINUX) | 324 #if defined(OS_LINUX) |
| 330 // On Linux, we need this information in order to query idle time. | 325 // On Linux, we need this information in order to query idle time. |
| 331 scoped_ptr<IdleQueryLinux> idle_query_; | 326 scoped_ptr<IdleQueryLinux> idle_query_; |
| 332 #endif | 327 #endif |
| 333 | 328 |
| 334 scoped_ptr<sessions::SyncSessionContext> session_context_; | 329 scoped_ptr<sessions::SyncSessionContext> session_context_; |
| 335 | 330 |
| 336 // Events from the Syncer's syncer_event_channel are first processed by the | 331 // Events from the Syncer's syncer_event_channel are first processed by the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 348 | 343 |
| 349 // Useful for unit tests | 344 // Useful for unit tests |
| 350 bool disable_idle_detection_; | 345 bool disable_idle_detection_; |
| 351 | 346 |
| 352 DISALLOW_COPY_AND_ASSIGN(SyncerThread); | 347 DISALLOW_COPY_AND_ASSIGN(SyncerThread); |
| 353 }; | 348 }; |
| 354 | 349 |
| 355 } // namespace browser_sync | 350 } // namespace browser_sync |
| 356 | 351 |
| 357 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ | 352 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
| OLD | NEW |