Index: chrome/browser/sync/engine/syncer_thread_pthreads.cc |
=================================================================== |
--- chrome/browser/sync/engine/syncer_thread_pthreads.cc (revision 26372) |
+++ chrome/browser/sync/engine/syncer_thread_pthreads.cc (working copy) |
@@ -1,9 +1,8 @@ |
// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "chrome/browser/sync/engine/syncer_thread_pthreads.h" |
-#include "chrome/browser/sync/engine/syncer_thread.h" |
- |
#include "build/build_config.h" |
#ifdef OS_MACOSX |
@@ -108,7 +107,18 @@ |
namespace browser_sync { |
-bool SyncerThread::NudgeSyncer(int milliseconds_from_now, NudgeSource source) { |
+SyncerThreadPthreads::SyncerThreadPthreads( |
+ ClientCommandChannel* command_channel, |
+ syncable::DirectoryManager* mgr, |
+ ServerConnectionManager* connection_manager, |
+ AllStatus* all_status, ModelSafeWorker* model_safe_worker) |
+ : SyncerThread() { |
+ impl_.reset(new SyncerThreadPthreadImpl(command_channel, mgr, |
+ connection_manager, all_status, model_safe_worker)); |
+} |
+ |
+bool SyncerThreadPthreadImpl::NudgeSyncer(int milliseconds_from_now, |
+ SyncerThread::NudgeSource source) { |
MutexLock lock(&mutex_); |
if (syncer_ == NULL) { |
return false; |
@@ -118,10 +128,11 @@ |
} |
void* RunSyncerThread(void* syncer_thread) { |
- return (reinterpret_cast<SyncerThread*>(syncer_thread))->ThreadMain(); |
+ return (reinterpret_cast<SyncerThreadPthreadImpl*>( |
+ syncer_thread))->ThreadMain(); |
} |
-SyncerThread::SyncerThread( |
+SyncerThreadPthreadImpl::SyncerThreadPthreadImpl( |
ClientCommandChannel* command_channel, |
syncable::DirectoryManager* mgr, |
ServerConnectionManager* connection_manager, |
@@ -129,10 +140,12 @@ |
ModelSafeWorker* model_safe_worker) |
: dirman_(mgr), scm_(connection_manager), |
syncer_(NULL), syncer_events_(NULL), thread_running_(false), |
- syncer_short_poll_interval_seconds_(kDefaultShortPollIntervalSeconds), |
- syncer_long_poll_interval_seconds_(kDefaultLongPollIntervalSeconds), |
- syncer_polling_interval_(kDefaultShortPollIntervalSeconds), |
- syncer_max_interval_(kDefaultMaxPollIntervalMs), |
+ syncer_short_poll_interval_seconds_( |
+ SyncerThread::kDefaultShortPollIntervalSeconds), |
+ syncer_long_poll_interval_seconds_( |
+ SyncerThread::kDefaultLongPollIntervalSeconds), |
+ syncer_polling_interval_(SyncerThread::kDefaultShortPollIntervalSeconds), |
+ syncer_max_interval_(SyncerThread::kDefaultMaxPollIntervalMs), |
stop_syncer_thread_(false), connected_(false), conn_mgr_hookup_(NULL), |
p2p_authenticated_(false), p2p_subscribed_(false), |
allstatus_(all_status), talk_mediator_hookup_(NULL), |
@@ -145,7 +158,8 @@ |
if (dirman_) { |
directory_manager_hookup_.reset(NewEventListenerHookup( |
- dirman_->channel(), this, &SyncerThread::HandleDirectoryManagerEvent)); |
+ dirman_->channel(), this, |
+ &SyncerThreadPthreadImpl::HandleDirectoryManagerEvent)); |
} |
if (scm_) { |
@@ -157,7 +171,7 @@ |
} |
} |
-SyncerThread::~SyncerThread() { |
+SyncerThreadPthreadImpl::~SyncerThreadPthreadImpl() { |
client_command_hookup_.reset(); |
conn_mgr_hookup_.reset(); |
syncer_event_channel_.reset(); |
@@ -171,7 +185,7 @@ |
// 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 SyncerThread::Start() { |
+bool SyncerThreadPthreadImpl::Start() { |
MutexLock lock(&mutex_); |
if (thread_running_) { |
return true; |
@@ -186,7 +200,7 @@ |
// Stop processing. A max wait of at least 2*server RTT time is recommended. |
// Returns true if we stopped, false otherwise. |
-bool SyncerThread::Stop(int max_wait) { |
+bool SyncerThreadPthreadImpl::Stop(int max_wait) { |
MutexLock lock(&mutex_); |
if (!thread_running_) |
return true; |
@@ -210,13 +224,15 @@ |
return true; |
} |
-void SyncerThread::WatchClientCommands(ClientCommandChannel* channel) { |
+void SyncerThreadPthreadImpl::WatchClientCommands( |
+ ClientCommandChannel* channel) { |
PThreadScopedLock<PThreadMutex> lock(&mutex_); |
client_command_hookup_.reset(NewEventListenerHookup(channel, this, |
- &SyncerThread::HandleClientCommand)); |
+ &SyncerThreadPthreadImpl::HandleClientCommand)); |
} |
-void SyncerThread::HandleClientCommand(ClientCommandChannel::EventType event) { |
+void SyncerThreadPthreadImpl::HandleClientCommand( |
+ ClientCommandChannel::EventType event) { |
if (!event) { |
return; |
} |
@@ -231,7 +247,7 @@ |
} |
} |
-void SyncerThread::ThreadMainLoop() { |
+void SyncerThreadPthreadImpl::ThreadMainLoop() { |
// Use the short poll value by default. |
int poll_seconds = syncer_short_poll_interval_seconds_; |
int user_idle_milliseconds = 0; |
@@ -290,7 +306,7 @@ |
// We check how long the user's been idle and sync less often if the machine is |
// not in use. The aim is to reduce server load. |
-int SyncerThread::CalculatePollingWaitTime( |
+int SyncerThreadPthreadImpl::CalculatePollingWaitTime( |
const AllStatus::Status& status, |
int last_poll_wait, // in s |
int* user_idle_milliseconds, |
@@ -343,7 +359,7 @@ |
return actual_next_wait; |
} |
-void* SyncerThread::ThreadMain() { |
+void* SyncerThreadPthreadImpl::ThreadMain() { |
NameCurrentThreadForDebugging("SyncEngine_SyncerThread"); |
mutex_.Lock(); |
ThreadMainLoop(); |
@@ -354,7 +370,7 @@ |
return 0; |
} |
-void SyncerThread::SyncMain(Syncer* syncer) { |
+void SyncerThreadPthreadImpl::SyncMain(Syncer* syncer) { |
CHECK(syncer); |
mutex_.Unlock(); |
while (syncer->SyncShare()) { |
@@ -365,14 +381,14 @@ |
mutex_.Lock(); |
} |
-void SyncerThread::UpdateNudgeSource(const timespec& now, |
+void SyncerThreadPthreadImpl::UpdateNudgeSource(const timespec& now, |
bool* continue_sync_cycle, |
bool* initial_sync) { |
bool nudged = false; |
- NudgeSource nudge_source = kUnknown; |
+ SyncerThread::NudgeSource nudge_source = SyncerThread::kUnknown; |
// Has the previous sync cycle completed? |
if (continue_sync_cycle) { |
- nudge_source = kContinuation; |
+ nudge_source = SyncerThread::kContinuation; |
} |
// Update the nudge source if a new nudge has come through during the |
// previous sync cycle. |
@@ -387,8 +403,8 @@ |
SetUpdatesSource(nudged, nudge_source, initial_sync); |
} |
-void SyncerThread::SetUpdatesSource(bool nudged, NudgeSource nudge_source, |
- bool* initial_sync) { |
+void SyncerThreadPthreadImpl::SetUpdatesSource(bool nudged, |
+ SyncerThread::NudgeSource nudge_source, bool* initial_sync) { |
sync_pb::GetUpdatesCallerInfo::GET_UPDATES_SOURCE updates_source = |
sync_pb::GetUpdatesCallerInfo::UNKNOWN; |
if (*initial_sync) { |
@@ -398,16 +414,16 @@ |
updates_source = sync_pb::GetUpdatesCallerInfo::PERIODIC; |
} else { |
switch (nudge_source) { |
- case kNotification: |
+ case SyncerThread::kNotification: |
updates_source = sync_pb::GetUpdatesCallerInfo::NOTIFICATION; |
break; |
- case kLocal: |
+ case SyncerThread::kLocal: |
updates_source = sync_pb::GetUpdatesCallerInfo::LOCAL; |
break; |
- case kContinuation: |
+ case SyncerThread::kContinuation: |
updates_source = sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; |
break; |
- case kUnknown: |
+ case SyncerThread::kUnknown: |
default: |
updates_source = sync_pb::GetUpdatesCallerInfo::UNKNOWN; |
break; |
@@ -416,16 +432,16 @@ |
syncer_->set_updates_source(updates_source); |
} |
-void SyncerThread::HandleSyncerEvent(const SyncerEvent& event) { |
+void SyncerThreadPthreadImpl::HandleSyncerEvent(const SyncerEvent& event) { |
MutexLock lock(&mutex_); |
channel()->NotifyListeners(event); |
if (SyncerEvent::REQUEST_SYNC_NUDGE != event.what_happened) { |
return; |
} |
- NudgeSyncImpl(event.nudge_delay_milliseconds, kUnknown); |
+ NudgeSyncImpl(event.nudge_delay_milliseconds, SyncerThread::kUnknown); |
} |
-void SyncerThread::HandleDirectoryManagerEvent( |
+void SyncerThreadPthreadImpl::HandleDirectoryManagerEvent( |
const syncable::DirectoryManagerEvent& event) { |
LOG(INFO) << "Handling a directory manager event"; |
if (syncable::DirectoryManagerEvent::OPENED == event.what_happened) { |
@@ -439,7 +455,7 @@ |
syncer_->set_command_channel(command_channel_); |
syncer_events_.reset(NewEventListenerHookup( |
- syncer_->channel(), this, &SyncerThread::HandleSyncerEvent)); |
+ syncer_->channel(), this, &SyncerThreadPthreadImpl::HandleSyncerEvent)); |
pthread_cond_broadcast(&changed_.condvar_); |
} |
} |
@@ -460,14 +476,15 @@ |
} |
} |
-void SyncerThread::WatchConnectionManager(ServerConnectionManager* conn_mgr) { |
+void SyncerThreadPthreadImpl::WatchConnectionManager( |
+ ServerConnectionManager* conn_mgr) { |
conn_mgr_hookup_.reset(NewEventListenerHookup(conn_mgr->channel(), this, |
- &SyncerThread::HandleServerConnectionEvent)); |
+ &SyncerThreadPthreadImpl::HandleServerConnectionEvent)); |
CheckConnected(&connected_, conn_mgr->server_status(), |
&changed_.condvar_); |
} |
-void SyncerThread::HandleServerConnectionEvent( |
+void SyncerThreadPthreadImpl::HandleServerConnectionEvent( |
const ServerConnectionEvent& event) { |
if (ServerConnectionEvent::STATUS_CHANGED == event.what_happened) { |
MutexLock lock(&mutex_); |
@@ -476,12 +493,13 @@ |
} |
} |
-SyncerEventChannel* SyncerThread::channel() { |
+SyncerEventChannel* SyncerThreadPthreadImpl::channel() { |
return syncer_event_channel_.get(); |
} |
// Inputs and return value in milliseconds. |
-int SyncerThread::CalculateSyncWaitTime(int last_interval, int user_idle_ms) { |
+int SyncerThreadPthreadImpl::CalculateSyncWaitTime(int last_interval, |
+ int user_idle_ms) { |
// syncer_polling_interval_ is in seconds |
int syncer_polling_interval_ms = syncer_polling_interval_ * 1000; |
@@ -502,23 +520,24 @@ |
} |
// Called with mutex_ already locked. |
-void SyncerThread::NudgeSyncImpl(int milliseconds_from_now, |
- NudgeSource source) { |
+void SyncerThreadPthreadImpl::NudgeSyncImpl(int milliseconds_from_now, |
+ SyncerThread::NudgeSource source) { |
const timespec nudge_time = GetPThreadAbsoluteTime(milliseconds_from_now); |
NudgeObject nudge_object(nudge_time, source); |
nudge_queue_.push(nudge_object); |
pthread_cond_broadcast(&changed_.condvar_); |
} |
-void SyncerThread::WatchTalkMediator(TalkMediator* mediator) { |
+void SyncerThreadPthreadImpl::WatchTalkMediator(TalkMediator* mediator) { |
talk_mediator_hookup_.reset( |
NewEventListenerHookup( |
mediator->channel(), |
this, |
- &SyncerThread::HandleTalkMediatorEvent)); |
+ &SyncerThreadPthreadImpl::HandleTalkMediatorEvent)); |
} |
-void SyncerThread::HandleTalkMediatorEvent(const TalkMediatorEvent& event) { |
+void SyncerThreadPthreadImpl::HandleTalkMediatorEvent( |
+ const TalkMediatorEvent& event) { |
MutexLock lock(&mutex_); |
switch (event.what_happened) { |
case TalkMediatorEvent::LOGIN_SUCCEEDED: |
@@ -534,7 +553,7 @@ |
p2p_subscribed_ = true; |
if (NULL != syncer_) { |
LOG(INFO) << "Subscriptions on. Nudging syncer for initial push."; |
- NudgeSyncImpl(0, kLocal); |
+ NudgeSyncImpl(0, SyncerThread::kLocal); |
} |
break; |
case TalkMediatorEvent::SUBSCRIPTIONS_OFF: |
@@ -544,7 +563,7 @@ |
case TalkMediatorEvent::NOTIFICATION_RECEIVED: |
LOG(INFO) << "P2P: Updates on server, pushing syncer"; |
if (NULL != syncer_) { |
- NudgeSyncImpl(0, kNotification); |
+ NudgeSyncImpl(0, SyncerThread::kNotification); |
} |
break; |
default: |
@@ -556,4 +575,4 @@ |
} |
} |
-} // namespace browser_sync |
+} // namespace browser_sync |