Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 |
| 43 class SyncerThread : public base::RefCountedThreadSafe<SyncerThread>, | 43 class SyncerThread : public base::RefCountedThreadSafe<SyncerThread>, |
| 44 public sessions::SyncSession::Delegate { | 44 public sessions::SyncSession::Delegate { |
| 45 FRIEND_TEST_ALL_PREFIXES(SyncerThreadTest, CalculateSyncWaitTime); | 45 FRIEND_TEST_ALL_PREFIXES(SyncerThreadTest, CalculateSyncWaitTime); |
| 46 FRIEND_TEST_ALL_PREFIXES(SyncerThreadTest, CalculatePollingWaitTime); | 46 FRIEND_TEST_ALL_PREFIXES(SyncerThreadTest, CalculatePollingWaitTime); |
| 47 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, Polling); | 47 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, Polling); |
| 48 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, Nudge); | 48 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, Nudge); |
| 49 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, NudgeWithDataTypes); | 49 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, NudgeWithDataTypes); |
| 50 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, | 50 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, |
| 51 NudgeWithDataTypesCoalesced); | 51 NudgeWithDataTypesCoalesced); |
| 52 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, NudgeWithPayloads); | |
| 53 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, | |
| 54 NudgeWithPayloadsCoalesced); | |
| 52 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, Throttling); | 55 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, Throttling); |
| 53 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, AuthInvalid); | 56 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, AuthInvalid); |
| 54 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, Pause); | 57 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, Pause); |
| 55 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, StartWhenNotConnected); | 58 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, StartWhenNotConnected); |
| 56 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, PauseWhenNotConnected); | 59 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, PauseWhenNotConnected); |
| 57 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, StopSyncPermanently); | 60 FRIEND_TEST_ALL_PREFIXES(SyncerThreadWithSyncerTest, StopSyncPermanently); |
| 58 friend class SyncerThreadWithSyncerTest; | 61 friend class SyncerThreadWithSyncerTest; |
| 59 friend class SyncerThreadFactory; | 62 friend class SyncerThreadFactory; |
| 60 public: | 63 public: |
| 61 // Encapsulates the parameters that make up an interval on which the | 64 // Encapsulates the parameters that make up an interval on which the |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 // request can not be completed (e.g. the thread is not running or | 129 // request can not be completed (e.g. the thread is not running or |
| 127 // is not currently paused). When the thread actually resumes, a | 130 // is not currently paused). When the thread actually resumes, a |
| 128 // SyncEngineEvent::RESUMED event notification will be sent to the relay | 131 // SyncEngineEvent::RESUMED event notification will be sent to the relay |
| 129 // channel. | 132 // channel. |
| 130 virtual bool RequestResume(); | 133 virtual bool RequestResume(); |
| 131 | 134 |
| 132 // Nudges the syncer to sync with a delay specified. This API is for access | 135 // Nudges the syncer to sync with a delay specified. This API is for access |
| 133 // from the SyncerThread's controller and will cause a mutex lock. | 136 // from the SyncerThread's controller and will cause a mutex lock. |
| 134 virtual void NudgeSyncer(int milliseconds_from_now, NudgeSource source); | 137 virtual void NudgeSyncer(int milliseconds_from_now, NudgeSource source); |
| 135 | 138 |
| 136 // Same as |NudgeSyncer|, but supports tracking the datatypes that caused | 139 // Same as |NudgeSyncer|, but supports tracking the datatypes that caused |
|
akalin
2011/01/12 09:55:19
I think we can combine these two Nudge functions i
Nicolas Zea
2011/01/13 19:17:30
My only hesitancy with this is that it then fully
akalin
2011/01/13 19:47:41
Fair point. I'm fine with two different methods.
Nicolas Zea
2011/01/18 06:07:23
Done.
| |
| 137 // the nudge to occur. | 140 // the nudge to occur. |
| 138 virtual void NudgeSyncerWithDataTypes( | 141 virtual void NudgeSyncerWithDataTypes( |
| 139 int milliseconds_from_now, | 142 int milliseconds_from_now, |
| 140 NudgeSource source, | 143 NudgeSource source, |
| 141 const syncable::ModelTypeBitSet& model_type); | 144 const syncable::ModelTypeBitSet& model_type); |
| 142 | 145 |
| 146 virtual void NudgeSyncerWithPayloads( | |
| 147 int milliseconds_from_now, | |
| 148 NudgeSource source, | |
| 149 const std::vector<std::string>& payloads); | |
| 150 | |
| 151 | |
| 143 void SetNotificationsEnabled(bool notifications_enabled); | 152 void SetNotificationsEnabled(bool notifications_enabled); |
| 144 | 153 |
| 145 // Call this when a directory is opened | 154 // Call this when a directory is opened |
| 146 void CreateSyncer(const std::string& dirname); | 155 void CreateSyncer(const std::string& dirname); |
| 147 | 156 |
| 148 // DDOS avoidance function. The argument and return value is in seconds | 157 // DDOS avoidance function. The argument and return value is in seconds |
| 149 static int GetRecommendedDelaySeconds(int base_delay_seconds); | 158 static int GetRecommendedDelaySeconds(int base_delay_seconds); |
| 150 | 159 |
| 151 protected: | 160 protected: |
| 152 virtual void ThreadMain(); | 161 virtual void ThreadMain(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 195 |
| 187 // kUnknown if there is no pending nudge. (Theoretically, there | 196 // kUnknown if there is no pending nudge. (Theoretically, there |
| 188 // could be a pending nudge of type kUnknown, so it's better to | 197 // could be a pending nudge of type kUnknown, so it's better to |
| 189 // check pending_nudge_time_.) | 198 // check pending_nudge_time_.) |
| 190 NudgeSource pending_nudge_source_; | 199 NudgeSource pending_nudge_source_; |
| 191 | 200 |
| 192 // BitSet of the datatypes that have triggered the current nudge | 201 // BitSet of the datatypes that have triggered the current nudge |
| 193 // (can be union of various bitsets when multiple nudges are coalesced) | 202 // (can be union of various bitsets when multiple nudges are coalesced) |
| 194 syncable::ModelTypeBitSet pending_nudge_types_; | 203 syncable::ModelTypeBitSet pending_nudge_types_; |
| 195 | 204 |
| 205 // Payloads associated with each of the datatypes we're polling on. | |
| 206 // These payloads are used by the download updates command and can contain | |
| 207 // datatype specific information the server might use. | |
| 208 std::vector<std::string> datatype_payloads_; | |
| 209 | |
| 196 // null iff there is no pending nudge. | 210 // null iff there is no pending nudge. |
| 197 base::TimeTicks pending_nudge_time_; | 211 base::TimeTicks pending_nudge_time_; |
| 198 | 212 |
| 199 // The wait interval for to the current iteration of our main loop. This is | 213 // The wait interval for to the current iteration of our main loop. This is |
| 200 // only written to by the syncer thread, and since the only reader from a | 214 // only written to by the syncer thread, and since the only reader from a |
| 201 // different thread (NudgeSync) is called at totally random times, we don't | 215 // different thread (NudgeSync) is called at totally random times, we don't |
| 202 // really need to access mutually exclusively as the data races that exist | 216 // really need to access mutually exclusively as the data races that exist |
| 203 // are intrinsic, but do so anyway and avoid using 'volatile'. | 217 // are intrinsic, but do so anyway and avoid using 'volatile'. |
| 204 WaitInterval current_wait_interval_; | 218 WaitInterval current_wait_interval_; |
| 205 | 219 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 // |was_nudged| parameter. | 288 // |was_nudged| parameter. |
| 275 sessions::SyncSourceInfo GetAndResetNudgeSource(bool was_throttled, | 289 sessions::SyncSourceInfo GetAndResetNudgeSource(bool was_throttled, |
| 276 bool continue_sync_cycle, | 290 bool continue_sync_cycle, |
| 277 bool* initial_sync, | 291 bool* initial_sync, |
| 278 bool* was_nudged); | 292 bool* was_nudged); |
| 279 | 293 |
| 280 sessions::SyncSourceInfo MakeSyncSourceInfo( | 294 sessions::SyncSourceInfo MakeSyncSourceInfo( |
| 281 bool nudged, | 295 bool nudged, |
| 282 NudgeSource nudge_source, | 296 NudgeSource nudge_source, |
| 283 const syncable::ModelTypeBitSet& nudge_types, | 297 const syncable::ModelTypeBitSet& nudge_types, |
| 298 const std::vector<std::string>& payloads, | |
| 284 bool* initial_sync); | 299 bool* initial_sync); |
| 285 | 300 |
| 286 int UserIdleTime(); | 301 int UserIdleTime(); |
| 287 | 302 |
| 288 void WaitUntilConnectedOrQuit(); | 303 void WaitUntilConnectedOrQuit(); |
| 289 | 304 |
| 290 // The thread will remain in this method until a resume is requested | 305 // The thread will remain in this method until a resume is requested |
| 291 // or shutdown is started. | 306 // or shutdown is started. |
| 292 void PauseUntilResumedOrQuit(); | 307 void PauseUntilResumedOrQuit(); |
| 293 | 308 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 320 // this bounds the "nominal" poll interval, while the the actual interval | 335 // this bounds the "nominal" poll interval, while the the actual interval |
| 321 // also takes previous failures into account. | 336 // also takes previous failures into account. |
| 322 int syncer_max_interval_; | 337 int syncer_max_interval_; |
| 323 | 338 |
| 324 // This causes syncer to start syncing ASAP. If the rate of requests is too | 339 // This causes syncer to start syncing ASAP. If the rate of requests is too |
| 325 // high the request will be silently dropped. mutex_ should be held when | 340 // high the request will be silently dropped. mutex_ should be held when |
| 326 // this is called. | 341 // this is called. |
| 327 void NudgeSyncImpl( | 342 void NudgeSyncImpl( |
| 328 int milliseconds_from_now, | 343 int milliseconds_from_now, |
| 329 NudgeSource source, | 344 NudgeSource source, |
| 330 const syncable::ModelTypeBitSet& model_types); | 345 const syncable::ModelTypeBitSet& model_types, |
| 346 const std::vector<std::string>& payloads); | |
| 331 | 347 |
| 332 #if defined(OS_LINUX) | 348 #if defined(OS_LINUX) |
| 333 // On Linux, we need this information in order to query idle time. | 349 // On Linux, we need this information in order to query idle time. |
| 334 scoped_ptr<IdleQueryLinux> idle_query_; | 350 scoped_ptr<IdleQueryLinux> idle_query_; |
| 335 #endif | 351 #endif |
| 336 | 352 |
| 337 scoped_ptr<sessions::SyncSessionContext> session_context_; | 353 scoped_ptr<sessions::SyncSessionContext> session_context_; |
| 338 | 354 |
| 339 // Set whenever the server instructs us to stop sending it requests until | 355 // Set whenever the server instructs us to stop sending it requests until |
| 340 // a specified time, and reset for each call to SyncShare. (Note that the | 356 // a specified time, and reset for each call to SyncShare. (Note that the |
| 341 // WaitInterval::THROTTLED contract is such that we don't call SyncShare at | 357 // WaitInterval::THROTTLED contract is such that we don't call SyncShare at |
| 342 // all until the "silenced until" embargo expires.) | 358 // all until the "silenced until" embargo expires.) |
| 343 base::TimeTicks silenced_until_; | 359 base::TimeTicks silenced_until_; |
| 344 | 360 |
| 345 // Useful for unit tests | 361 // Useful for unit tests |
| 346 bool disable_idle_detection_; | 362 bool disable_idle_detection_; |
| 347 | 363 |
| 348 DISALLOW_COPY_AND_ASSIGN(SyncerThread); | 364 DISALLOW_COPY_AND_ASSIGN(SyncerThread); |
| 349 }; | 365 }; |
| 350 | 366 |
| 351 } // namespace browser_sync | 367 } // namespace browser_sync |
| 352 | 368 |
| 353 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ | 369 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
| OLD | NEW |