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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // Call this when a directory is opened | 144 // Call this when a directory is opened |
145 void CreateSyncer(const std::string& dirname); | 145 void CreateSyncer(const std::string& dirname); |
146 | 146 |
147 // DDOS avoidance function. The argument and return value is in seconds | 147 // DDOS avoidance function. The argument and return value is in seconds |
148 static int GetRecommendedDelaySeconds(int base_delay_seconds); | 148 static int GetRecommendedDelaySeconds(int base_delay_seconds); |
149 | 149 |
150 protected: | 150 protected: |
151 virtual void ThreadMain(); | 151 virtual void ThreadMain(); |
152 void ThreadMainLoop(); | 152 void ThreadMainLoop(); |
153 | 153 |
154 virtual void SetConnected(bool connected) { | 154 virtual void SetConnected(bool connected); |
155 DCHECK(!thread_.IsRunning()); | |
156 vault_.connected_ = connected; | |
157 } | |
158 | 155 |
159 virtual void SetSyncerPollingInterval(base::TimeDelta interval) { | 156 virtual void SetSyncerPollingInterval(base::TimeDelta interval); |
160 // TODO(timsteele): Use TimeDelta internally. | 157 virtual void SetSyncerShortPollInterval(base::TimeDelta interval); |
161 syncer_polling_interval_ = static_cast<int>(interval.InSeconds()); | |
162 } | |
163 virtual void SetSyncerShortPollInterval(base::TimeDelta interval) { | |
164 // TODO(timsteele): Use TimeDelta internally. | |
165 syncer_short_poll_interval_seconds_ = | |
166 static_cast<int>(interval.InSeconds()); | |
167 } | |
168 | 158 |
169 // Needed to emulate the behavior of pthread_create, which synchronously | 159 // Needed to emulate the behavior of pthread_create, which synchronously |
170 // started the thread and set the value of thread_running_ to true. | 160 // started the thread and set the value of thread_running_ to true. |
171 // We can't quite match that because we asynchronously post the task, | 161 // We can't quite match that because we asynchronously post the task, |
172 // which opens a window for Stop to get called before the task actually | 162 // which opens a window for Stop to get called before the task actually |
173 // makes it. To prevent this, we block Start() until we're sure it's ok. | 163 // makes it. To prevent this, we block Start() until we're sure it's ok. |
174 base::WaitableEvent thread_main_started_; | 164 base::WaitableEvent thread_main_started_; |
175 | 165 |
176 // Handle of the running thread. | 166 // Handle of the running thread. |
177 base::Thread thread_; | 167 base::Thread thread_; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 288 |
299 // The thread will remain in this method until a resume is requested | 289 // The thread will remain in this method until a resume is requested |
300 // or shutdown is started. | 290 // or shutdown is started. |
301 void PauseUntilResumedOrQuit(); | 291 void PauseUntilResumedOrQuit(); |
302 | 292 |
303 void EnterPausedState(); | 293 void EnterPausedState(); |
304 | 294 |
305 void ExitPausedState(); | 295 void ExitPausedState(); |
306 | 296 |
307 // For unit tests only. | 297 // For unit tests only. |
308 virtual void DisableIdleDetection() { disable_idle_detection_ = true; } | 298 virtual void DisableIdleDetection(); |
309 | 299 |
310 // This sets all conditions for syncer thread termination but does not | 300 // This sets all conditions for syncer thread termination but does not |
311 // actually join threads. It is expected that Stop will be called at some | 301 // actually join threads. It is expected that Stop will be called at some |
312 // time after to fully stop and clean up. | 302 // time after to fully stop and clean up. |
313 void RequestSyncerExitAndSetThreadStopConditions(); | 303 void RequestSyncerExitAndSetThreadStopConditions(); |
314 | 304 |
315 void Notify(SyncEngineEvent::EventCause cause); | 305 void Notify(SyncEngineEvent::EventCause cause); |
316 | 306 |
317 scoped_ptr<EventListenerHookup> conn_mgr_hookup_; | 307 scoped_ptr<EventListenerHookup> conn_mgr_hookup_; |
318 | 308 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 343 |
354 // Useful for unit tests | 344 // Useful for unit tests |
355 bool disable_idle_detection_; | 345 bool disable_idle_detection_; |
356 | 346 |
357 DISALLOW_COPY_AND_ASSIGN(SyncerThread); | 347 DISALLOW_COPY_AND_ASSIGN(SyncerThread); |
358 }; | 348 }; |
359 | 349 |
360 } // namespace browser_sync | 350 } // namespace browser_sync |
361 | 351 |
362 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ | 352 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
OLD | NEW |