| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include <list> | 5 #include <list> |
| 6 #include <map> | 6 #include <map> |
| 7 | 7 |
| 8 #include "base/lock.h" | |
| 9 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 9 #include "base/synchronization/lock.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "chrome/browser/sync/engine/model_safe_worker.h" | 12 #include "chrome/browser/sync/engine/model_safe_worker.h" |
| 13 #include "chrome/browser/sync/engine/syncer_thread.h" | 13 #include "chrome/browser/sync/engine/syncer_thread.h" |
| 14 #include "chrome/browser/sync/engine/syncer_types.h" | 14 #include "chrome/browser/sync/engine/syncer_types.h" |
| 15 #include "chrome/browser/sync/sessions/sync_session_context.h" | 15 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| 16 #include "chrome/browser/sync/util/channel.h" | 16 #include "chrome/browser/sync/util/channel.h" |
| 17 #include "chrome/test/sync/engine/mock_connection_manager.h" | 17 #include "chrome/test/sync/engine/mock_connection_manager.h" |
| 18 #include "chrome/test/sync/engine/test_directory_setter_upper.h" | 18 #include "chrome/test/sync/engine/test_directory_setter_upper.h" |
| 19 #include "chrome/test/sync/sessions/test_scoped_session_event_listener.h" | 19 #include "chrome/test/sync/sessions/test_scoped_session_event_listener.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 sync_cycle_ended_event_.TimedWait(max_wait_time_); | 106 sync_cycle_ended_event_.TimedWait(max_wait_time_); |
| 107 max_cycles--; | 107 max_cycles--; |
| 108 } | 108 } |
| 109 | 109 |
| 110 return syncer_thread()->IsSyncingCurrentlySilenced(); | 110 return syncer_thread()->IsSyncingCurrentlySilenced(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void WaitForDisconnect() { | 113 void WaitForDisconnect() { |
| 114 // Wait for the SyncerThread to detect loss of connection, up to a max of | 114 // Wait for the SyncerThread to detect loss of connection, up to a max of |
| 115 // 10 seconds to timeout the test. | 115 // 10 seconds to timeout the test. |
| 116 AutoLock lock(syncer_thread()->lock_); | 116 base::AutoLock lock(syncer_thread()->lock_); |
| 117 TimeTicks start = TimeTicks::Now(); | 117 TimeTicks start = TimeTicks::Now(); |
| 118 TimeDelta ten_seconds = TimeDelta::FromSeconds(10); | 118 TimeDelta ten_seconds = TimeDelta::FromSeconds(10); |
| 119 while (syncer_thread()->vault_.connected_) { | 119 while (syncer_thread()->vault_.connected_) { |
| 120 syncer_thread()->vault_field_changed_.TimedWait(ten_seconds); | 120 syncer_thread()->vault_field_changed_.TimedWait(ten_seconds); |
| 121 if (TimeTicks::Now() - start > ten_seconds) | 121 if (TimeTicks::Now() - start > ten_seconds) |
| 122 break; | 122 break; |
| 123 } | 123 } |
| 124 EXPECT_FALSE(syncer_thread()->vault_.connected_); | 124 EXPECT_FALSE(syncer_thread()->vault_.connected_); |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool Pause(ListenerMock* listener) { | 127 bool Pause(ListenerMock* listener) { |
| 128 WaitableEvent event(false, false); | 128 WaitableEvent event(false, false); |
| 129 { | 129 { |
| 130 AutoLock lock(syncer_thread()->lock_); | 130 base::AutoLock lock(syncer_thread()->lock_); |
| 131 EXPECT_CALL(*listener, OnSyncEngineEvent( | 131 EXPECT_CALL(*listener, OnSyncEngineEvent( |
| 132 Field(&SyncEngineEvent::what_happened, | 132 Field(&SyncEngineEvent::what_happened, |
| 133 SyncEngineEvent::SYNCER_THREAD_PAUSED))). | 133 SyncEngineEvent::SYNCER_THREAD_PAUSED))). |
| 134 WillOnce(SignalEvent(&event)); | 134 WillOnce(SignalEvent(&event)); |
| 135 } | 135 } |
| 136 if (!syncer_thread()->RequestPause()) | 136 if (!syncer_thread()->RequestPause()) |
| 137 return false; | 137 return false; |
| 138 return event.TimedWait(max_wait_time_); | 138 return event.TimedWait(max_wait_time_); |
| 139 } | 139 } |
| 140 | 140 |
| 141 bool Resume(ListenerMock* listener) { | 141 bool Resume(ListenerMock* listener) { |
| 142 WaitableEvent event(false, false); | 142 WaitableEvent event(false, false); |
| 143 { | 143 { |
| 144 AutoLock lock(syncer_thread()->lock_); | 144 base::AutoLock lock(syncer_thread()->lock_); |
| 145 EXPECT_CALL(*listener, OnSyncEngineEvent( | 145 EXPECT_CALL(*listener, OnSyncEngineEvent( |
| 146 Field(&SyncEngineEvent::what_happened, | 146 Field(&SyncEngineEvent::what_happened, |
| 147 SyncEngineEvent::SYNCER_THREAD_RESUMED))). | 147 SyncEngineEvent::SYNCER_THREAD_RESUMED))). |
| 148 WillOnce(SignalEvent(&event)); | 148 WillOnce(SignalEvent(&event)); |
| 149 } | 149 } |
| 150 if (!syncer_thread()->RequestResume()) | 150 if (!syncer_thread()->RequestResume()) |
| 151 return false; | 151 return false; |
| 152 return event.TimedWait(max_wait_time_); | 152 return event.TimedWait(max_wait_time_); |
| 153 } | 153 } |
| 154 | 154 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 311 } |
| 312 | 312 |
| 313 TEST_F(SyncerThreadTest, CalculatePollingWaitTime) { | 313 TEST_F(SyncerThreadTest, CalculatePollingWaitTime) { |
| 314 // Set up the environment. | 314 // Set up the environment. |
| 315 int user_idle_milliseconds_param = 0; | 315 int user_idle_milliseconds_param = 0; |
| 316 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL, | 316 SyncSessionContext* context = new SyncSessionContext(NULL, NULL, NULL, |
| 317 std::vector<SyncEngineEventListener*>()); | 317 std::vector<SyncEngineEventListener*>()); |
| 318 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context)); | 318 scoped_refptr<SyncerThread> syncer_thread(new SyncerThread(context)); |
| 319 syncer_thread->DisableIdleDetection(); | 319 syncer_thread->DisableIdleDetection(); |
| 320 // Hold the lock to appease asserts in code. | 320 // Hold the lock to appease asserts in code. |
| 321 AutoLock lock(syncer_thread->lock_); | 321 base::AutoLock lock(syncer_thread->lock_); |
| 322 | 322 |
| 323 // Notifications disabled should result in a polling interval of | 323 // Notifications disabled should result in a polling interval of |
| 324 // kDefaultShortPollInterval. | 324 // kDefaultShortPollInterval. |
| 325 { | 325 { |
| 326 context->set_notifications_enabled(false); | 326 context->set_notifications_enabled(false); |
| 327 bool continue_sync_cycle_param = false; | 327 bool continue_sync_cycle_param = false; |
| 328 | 328 |
| 329 // No work and no backoff. | 329 // No work and no backoff. |
| 330 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( | 330 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( |
| 331 0, | 331 0, |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 EXPECT_CALL(listener, OnSyncEngineEvent( | 1114 EXPECT_CALL(listener, OnSyncEngineEvent( |
| 1115 Field(&SyncEngineEvent::what_happened, | 1115 Field(&SyncEngineEvent::what_happened, |
| 1116 SyncEngineEvent::SYNCER_THREAD_EXITING))); | 1116 SyncEngineEvent::SYNCER_THREAD_EXITING))); |
| 1117 | 1117 |
| 1118 ASSERT_TRUE(Resume(&listener)); | 1118 ASSERT_TRUE(Resume(&listener)); |
| 1119 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); | 1119 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); |
| 1120 EXPECT_TRUE(syncer_thread()->Stop(2000)); | 1120 EXPECT_TRUE(syncer_thread()->Stop(2000)); |
| 1121 } | 1121 } |
| 1122 | 1122 |
| 1123 } // namespace browser_sync | 1123 } // namespace browser_sync |
| OLD | NEW |