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 #include "chrome/browser/sync/engine/syncer_thread.h" | 4 #include "chrome/browser/sync/engine/syncer_thread.h" |
5 | 5 |
6 #include "build/build_config.h" | 6 #include "build/build_config.h" |
7 | 7 |
8 #if defined(OS_MACOSX) | 8 #if defined(OS_MACOSX) |
9 #include <CoreFoundation/CFNumber.h> | 9 #include <CoreFoundation/CFNumber.h> |
10 #include <IOKit/IOTypes.h> | 10 #include <IOKit/IOTypes.h> |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 VLOG(1) << "Updating the next polling time after SyncMain"; | 357 VLOG(1) << "Updating the next polling time after SyncMain"; |
358 vault_.current_wait_interval_ = CalculatePollingWaitTime( | 358 vault_.current_wait_interval_ = CalculatePollingWaitTime( |
359 static_cast<int>(vault_.current_wait_interval_.poll_delta.InSeconds()), | 359 static_cast<int>(vault_.current_wait_interval_.poll_delta.InSeconds()), |
360 &user_idle_milliseconds, &continue_sync_cycle, nudged); | 360 &user_idle_milliseconds, &continue_sync_cycle, nudged); |
361 } | 361 } |
362 #if defined(OS_LINUX) | 362 #if defined(OS_LINUX) |
363 idle_query_.reset(); | 363 idle_query_.reset(); |
364 #endif | 364 #endif |
365 } | 365 } |
366 | 366 |
| 367 void SyncerThread::SetConnected(bool connected) { |
| 368 DCHECK(!thread_.IsRunning()); |
| 369 vault_.connected_ = connected; |
| 370 } |
| 371 |
| 372 void SyncerThread::SetSyncerPollingInterval(base::TimeDelta interval) { |
| 373 // TODO(timsteele): Use TimeDelta internally. |
| 374 syncer_polling_interval_ = static_cast<int>(interval.InSeconds()); |
| 375 } |
| 376 |
| 377 void SyncerThread::SetSyncerShortPollInterval(base::TimeDelta interval) { |
| 378 // TODO(timsteele): Use TimeDelta internally. |
| 379 syncer_short_poll_interval_seconds_ = |
| 380 static_cast<int>(interval.InSeconds()); |
| 381 } |
| 382 |
367 void SyncerThread::WaitUntilConnectedOrQuit() { | 383 void SyncerThread::WaitUntilConnectedOrQuit() { |
368 VLOG(1) << "Syncer thread waiting for connection."; | 384 VLOG(1) << "Syncer thread waiting for connection."; |
369 Notify(SyncEngineEvent::SYNCER_THREAD_WAITING_FOR_CONNECTION); | 385 Notify(SyncEngineEvent::SYNCER_THREAD_WAITING_FOR_CONNECTION); |
370 | 386 |
371 bool is_paused = vault_.paused_; | 387 bool is_paused = vault_.paused_; |
372 | 388 |
373 while (!vault_.connected_ && !vault_.stop_syncer_thread_) { | 389 while (!vault_.connected_ && !vault_.stop_syncer_thread_) { |
374 if (!is_paused && vault_.pause_requested_) { | 390 if (!is_paused && vault_.pause_requested_) { |
375 // If we get a pause request while waiting for a connection, | 391 // If we get a pause request while waiting for a connection, |
376 // enter the paused state. | 392 // enter the paused state. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 Notify(SyncEngineEvent::SYNCER_THREAD_PAUSED); | 437 Notify(SyncEngineEvent::SYNCER_THREAD_PAUSED); |
422 } | 438 } |
423 | 439 |
424 void SyncerThread::ExitPausedState() { | 440 void SyncerThread::ExitPausedState() { |
425 lock_.AssertAcquired(); | 441 lock_.AssertAcquired(); |
426 vault_.paused_ = false; | 442 vault_.paused_ = false; |
427 vault_field_changed_.Broadcast(); | 443 vault_field_changed_.Broadcast(); |
428 Notify(SyncEngineEvent::SYNCER_THREAD_RESUMED); | 444 Notify(SyncEngineEvent::SYNCER_THREAD_RESUMED); |
429 } | 445 } |
430 | 446 |
| 447 void SyncerThread::DisableIdleDetection() { |
| 448 disable_idle_detection_ = true; |
| 449 } |
| 450 |
431 // We check how long the user's been idle and sync less often if the machine is | 451 // We check how long the user's been idle and sync less often if the machine is |
432 // not in use. The aim is to reduce server load. | 452 // not in use. The aim is to reduce server load. |
433 SyncerThread::WaitInterval SyncerThread::CalculatePollingWaitTime( | 453 SyncerThread::WaitInterval SyncerThread::CalculatePollingWaitTime( |
434 int last_poll_wait, // Time in seconds. | 454 int last_poll_wait, // Time in seconds. |
435 int* user_idle_milliseconds, | 455 int* user_idle_milliseconds, |
436 bool* continue_sync_cycle, | 456 bool* continue_sync_cycle, |
437 bool was_nudged) { | 457 bool was_nudged) { |
438 lock_.AssertAcquired(); // We access 'vault' in here, so we need the lock. | 458 lock_.AssertAcquired(); // We access 'vault' in here, so we need the lock. |
439 WaitInterval return_interval; | 459 WaitInterval return_interval; |
440 | 460 |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 was_logged = true; | 843 was_logged = true; |
824 VLOG(1) << "UserIdleTime unimplemented on this platform, synchronization " | 844 VLOG(1) << "UserIdleTime unimplemented on this platform, synchronization " |
825 "will not throttle when user idle"; | 845 "will not throttle when user idle"; |
826 } | 846 } |
827 #endif | 847 #endif |
828 | 848 |
829 return 0; | 849 return 0; |
830 } | 850 } |
831 | 851 |
832 } // namespace browser_sync | 852 } // namespace browser_sync |
OLD | NEW |