Index: chrome/browser/sync/engine/syncer_thread_pthreads.h |
=================================================================== |
--- chrome/browser/sync/engine/syncer_thread_pthreads.h (revision 26372) |
+++ chrome/browser/sync/engine/syncer_thread_pthreads.h (working copy) |
@@ -2,10 +2,13 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
// |
-// A class to run the syncer on a thread. |
+// *THIS EXISTS FOR EXPERIMENTATION AND TESTING WHILE WE REPLACE PTHREADS |
+// WITH CHROME THREADS IN SYNC CODE* |
-#ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
-#define CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
+// A class to run the syncer on a thread. Uses PIMPL to wrap the old, original |
+// pthreads implementation of SyncerThread. |
+#ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_PTHREADS_H_ |
+#define CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_PTHREADS_H_ |
#include <list> |
#include <map> |
@@ -18,6 +21,7 @@ |
#include "chrome/browser/sync/engine/client_command_channel.h" |
#include "chrome/browser/sync/util/event_sys-inl.h" |
#include "chrome/browser/sync/util/pthread_helpers.h" |
+#include "chrome/browser/sync/engine/syncer_thread.h" |
#include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST |
class EventListenerHookup; |
@@ -39,57 +43,41 @@ |
struct SyncerShutdownEvent; |
struct TalkMediatorEvent; |
-class SyncerThread { |
- FRIEND_TEST(SyncerThreadTest, CalculateSyncWaitTime); |
- FRIEND_TEST(SyncerThreadTest, CalculatePollingWaitTime); |
- |
+// The legacy implementation of SyncerThread using pthreads, kept around for |
+// historical experimentation until a new version is finalized. |
+class SyncerThreadPthreadImpl { |
public: |
- friend class SyncerThreadTest; |
+ virtual ~SyncerThreadPthreadImpl(); |
- enum NudgeSource { |
- kUnknown = 0, |
- kNotification, |
- kLocal, |
- kContinuation |
- }; |
- |
- // Server can overwrite these values via client commands. |
- // Standard short poll. This is used when XMPP is off. |
- static const int kDefaultShortPollIntervalSeconds = 60; |
- // Long poll is used when XMPP is on. |
- static const int kDefaultLongPollIntervalSeconds = 3600; |
- // 30 minutes by default. If exponential backoff kicks in, this is the |
- // longest possible poll interval. |
- static const int kDefaultMaxPollIntervalMs = 30 * 60 * 1000; |
- |
- SyncerThread(ClientCommandChannel* command_channel, |
- syncable::DirectoryManager* mgr, |
- ServerConnectionManager* connection_manager, AllStatus* all_status, |
- ModelSafeWorker* model_safe_worker); |
- ~SyncerThread(); |
- |
- void WatchConnectionManager(ServerConnectionManager* conn_mgr); |
+ virtual void WatchConnectionManager(ServerConnectionManager* conn_mgr); |
// Creates and starts a syncer thread. |
// Returns true if it creates a thread or if there's currently a thread |
// running and false otherwise. |
- bool Start(); |
+ virtual bool Start(); |
// Stop processing. A max wait of at least 2*server RTT time is recommended. |
// returns true if we stopped, false otherwise. |
- bool Stop(int max_wait); |
+ virtual bool Stop(int max_wait); |
// Nudges the syncer to sync with a delay specified. This API is for access |
// from the SyncerThread's controller and will cause a mutex lock. |
- bool NudgeSyncer(int milliseconds_from_now, NudgeSource source); |
+ virtual bool NudgeSyncer(int milliseconds_from_now, |
+ SyncerThread::NudgeSource source); |
// Registers this thread to watch talk mediator events. |
- void WatchTalkMediator(TalkMediator* talk_mediator); |
+ virtual void WatchTalkMediator(TalkMediator* talk_mediator); |
- void WatchClientCommands(ClientCommandChannel* channel); |
+ virtual void WatchClientCommands(ClientCommandChannel* channel); |
- SyncerEventChannel* channel(); |
+ virtual SyncerEventChannel* channel(); |
private: |
+ friend class SyncerThreadPthreads; |
+ SyncerThreadPthreadImpl(ClientCommandChannel* command_channel, |
+ syncable::DirectoryManager* mgr, |
+ ServerConnectionManager* connection_manager, AllStatus* all_status, |
+ ModelSafeWorker* model_safe_worker); |
+ |
// A few members to gate the rate at which we nudge the syncer. |
enum { |
kNudgeRateLimitCount = 6, |
@@ -98,7 +86,7 @@ |
// A queue of all scheduled nudges. One insertion for every call to |
// NudgeQueue(). |
- typedef std::pair<timespec, NudgeSource> NudgeObject; |
+ typedef std::pair<timespec, SyncerThread::NudgeSource> NudgeObject; |
struct IsTimeSpecGreater { |
inline bool operator() (const NudgeObject& lhs, const NudgeObject& rhs) { |
@@ -150,7 +138,7 @@ |
// two methods work in concert to achieve this goal. |
void UpdateNudgeSource(const timespec& now, bool* continue_sync_cycle, |
bool* initial_sync); |
- void SetUpdatesSource(bool nudged, NudgeSource nudge_source, |
+ void SetUpdatesSource(bool nudged, SyncerThread::NudgeSource nudge_source, |
bool* initial_sync); |
// For unit tests only. |
@@ -206,7 +194,8 @@ |
// This causes syncer to start syncing ASAP. If the rate of requests is too |
// high the request will be silently dropped. mutex_ should be held when |
// this is called. |
- void NudgeSyncImpl(int milliseconds_from_now, NudgeSource source); |
+ void NudgeSyncImpl(int milliseconds_from_now, |
+ SyncerThread::NudgeSource source); |
NudgeQueue nudge_queue_; |
@@ -223,9 +212,73 @@ |
// Useful for unit tests |
bool disable_idle_detection_; |
- DISALLOW_COPY_AND_ASSIGN(SyncerThread); |
+ DISALLOW_COPY_AND_ASSIGN(SyncerThreadPthreadImpl); |
}; |
+// A new-version SyncerThread pimpl wrapper for the old legacy implementation. |
+class SyncerThreadPthreads : public SyncerThread { |
+ FRIEND_TEST(SyncerThreadTest, CalculateSyncWaitTime); |
+ FRIEND_TEST(SyncerThreadTest, CalculatePollingWaitTime); |
+ FRIEND_TEST(SyncerThreadWithSyncerTest, Polling); |
+ FRIEND_TEST(SyncerThreadWithSyncerTest, Nudge); |
+ friend class SyncerThreadWithSyncerTest; |
+ friend class SyncerThreadFactory; |
+ public: |
+ virtual ~SyncerThreadPthreads() {} |
+ |
+ virtual void WatchConnectionManager(ServerConnectionManager* conn_mgr) { |
+ impl_->WatchConnectionManager(conn_mgr); |
+ } |
+ virtual bool Start() { |
+ return impl_->Start(); |
+ } |
+ virtual bool Stop(int max_wait) { |
+ return impl_->Stop(max_wait); |
+ } |
+ virtual bool NudgeSyncer(int milliseconds_from_now, NudgeSource source) { |
+ return impl_->NudgeSyncer(milliseconds_from_now, source); |
+ } |
+ virtual void WatchTalkMediator(TalkMediator* talk_mediator) { |
+ impl_->WatchTalkMediator(talk_mediator); |
+ } |
+ virtual void WatchClientCommands(ClientCommandChannel* channel) { |
+ impl_->WatchClientCommands(channel); |
+ } |
+ virtual SyncerEventChannel* channel() { |
+ return impl_->channel(); |
+ } |
+ protected: |
+ SyncerThreadPthreads(ClientCommandChannel* command_channel, |
+ syncable::DirectoryManager* mgr, |
+ ServerConnectionManager* connection_manager, AllStatus* all_status, |
+ ModelSafeWorker* model_safe_worker); |
+ virtual void SetConnected(bool connected) { |
+ impl_->connected_ = connected; |
+ } |
+ virtual void SetSyncerPollingInterval(int interval) { |
+ impl_->syncer_polling_interval_ = interval; |
+ } |
+ virtual void SetSyncerShortPollInterval(base::TimeDelta interval) { |
+ impl_->syncer_short_poll_interval_seconds_ = static_cast<int>( |
+ interval.InSeconds()); |
+ } |
+ virtual void DisableIdleDetection() { impl_->disable_idle_detection_ = true; } |
+ virtual int CalculateSyncWaitTime(int last_wait, int user_idle_ms) { |
+ return impl_->CalculateSyncWaitTime(last_wait, user_idle_ms); |
+ } |
+ virtual int CalculatePollingWaitTime( |
+ const AllStatus::Status& status, |
+ int last_poll_wait, // in s |
+ int* user_idle_milliseconds, |
+ bool* continue_sync_cycle) { |
+ return impl_->CalculatePollingWaitTime(status, last_poll_wait, |
+ user_idle_milliseconds, continue_sync_cycle); |
+ } |
+ private: |
+ scoped_ptr<SyncerThreadPthreadImpl> impl_; |
+ DISALLOW_COPY_AND_ASSIGN(SyncerThreadPthreads); |
+}; |
+ |
} // namespace browser_sync |
-#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ |
+#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_PTHREADS_H_ |