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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // which opens a window for Stop to get called before the task actually | 174 // which opens a window for Stop to get called before the task actually |
175 // makes it. To prevent this, we block Start() until we're sure it's ok. | 175 // makes it. To prevent this, we block Start() until we're sure it's ok. |
176 base::WaitableEvent thread_main_started_; | 176 base::WaitableEvent thread_main_started_; |
177 | 177 |
178 // Handle of the running thread. | 178 // Handle of the running thread. |
179 base::Thread thread_; | 179 base::Thread thread_; |
180 | 180 |
181 // Fields that are modified / accessed by multiple threads go in this struct | 181 // Fields that are modified / accessed by multiple threads go in this struct |
182 // for clarity and explicitness. | 182 // for clarity and explicitness. |
183 struct ProtectedFields { | 183 struct ProtectedFields { |
| 184 ProtectedFields(); |
| 185 ~ProtectedFields(); |
| 186 |
184 // False when we want to stop the thread. | 187 // False when we want to stop the thread. |
185 bool stop_syncer_thread_; | 188 bool stop_syncer_thread_; |
186 | 189 |
187 // True when a pause was requested. | 190 // True when a pause was requested. |
188 bool pause_requested_; | 191 bool pause_requested_; |
189 | 192 |
190 // True when the thread is paused. | 193 // True when the thread is paused. |
191 bool paused_; | 194 bool paused_; |
192 | 195 |
193 Syncer* syncer_; | 196 Syncer* syncer_; |
(...skipping 16 matching lines...) Expand all Loading... |
210 | 213 |
211 // null iff there is no pending nudge. | 214 // null iff there is no pending nudge. |
212 base::TimeTicks pending_nudge_time_; | 215 base::TimeTicks pending_nudge_time_; |
213 | 216 |
214 // The wait interval for to the current iteration of our main loop. This is | 217 // The wait interval for to the current iteration of our main loop. This is |
215 // only written to by the syncer thread, and since the only reader from a | 218 // only written to by the syncer thread, and since the only reader from a |
216 // different thread (NudgeSync) is called at totally random times, we don't | 219 // different thread (NudgeSync) is called at totally random times, we don't |
217 // really need to access mutually exclusively as the data races that exist | 220 // really need to access mutually exclusively as the data races that exist |
218 // are intrinsic, but do so anyway and avoid using 'volatile'. | 221 // are intrinsic, but do so anyway and avoid using 'volatile'. |
219 WaitInterval current_wait_interval_; | 222 WaitInterval current_wait_interval_; |
220 | |
221 ProtectedFields() | |
222 : stop_syncer_thread_(false), | |
223 pause_requested_(false), | |
224 paused_(false), | |
225 syncer_(NULL), | |
226 connected_(false), | |
227 pending_nudge_source_(kUnknown) {} | |
228 } vault_; | 223 } vault_; |
229 | 224 |
230 // Gets signaled whenever a thread outside of the syncer thread changes a | 225 // Gets signaled whenever a thread outside of the syncer thread changes a |
231 // protected field in the vault_. | 226 // protected field in the vault_. |
232 base::ConditionVariable vault_field_changed_; | 227 base::ConditionVariable vault_field_changed_; |
233 | 228 |
234 // Used to lock everything in |vault_|. | 229 // Used to lock everything in |vault_|. |
235 base::Lock lock_; | 230 base::Lock lock_; |
236 | 231 |
237 private: | 232 private: |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 354 |
360 // Useful for unit tests | 355 // Useful for unit tests |
361 bool disable_idle_detection_; | 356 bool disable_idle_detection_; |
362 | 357 |
363 DISALLOW_COPY_AND_ASSIGN(SyncerThread); | 358 DISALLOW_COPY_AND_ASSIGN(SyncerThread); |
364 }; | 359 }; |
365 | 360 |
366 } // namespace browser_sync | 361 } // namespace browser_sync |
367 | 362 |
368 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ | 363 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
OLD | NEW |