summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync
diff options
context:
space:
mode:
authortim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 19:57:13 +0000
committertim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 19:57:13 +0000
commit1e08c8bf57b4c2a3e465a8446e9f9bfbec267fe4 (patch)
tree2fd2b4ae20367982ee534592f9187239d1b8c33d /chrome/browser/sync
parentab39a625b5c844e1ad9c1409c8bda13bcf2b6ec7 (diff)
downloadchromium_src-1e08c8bf57b4c2a3e465a8446e9f9bfbec267fe4.zip
chromium_src-1e08c8bf57b4c2a3e465a8446e9f9bfbec267fe4.tar.gz
chromium_src-1e08c8bf57b4c2a3e465a8446e9f9bfbec267fe4.tar.bz2
Sync: Remove pthreads from ServerConnectionManager and notifier.
BUG=19895 Review URL: http://codereview.chromium.org/266011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28429 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r--chrome/browser/sync/engine/net/server_connection_manager.cc42
-rw-r--r--chrome/browser/sync/engine/net/server_connection_manager.h34
-rw-r--r--chrome/browser/sync/engine/syncapi.cc4
-rw-r--r--chrome/browser/sync/notifier/listener/mediator_thread_impl.cc4
-rw-r--r--chrome/browser/sync/notifier/listener/talk_mediator_impl.cc22
-rw-r--r--chrome/browser/sync/notifier/listener/talk_mediator_impl.h6
6 files changed, 38 insertions, 74 deletions
diff --git a/chrome/browser/sync/engine/net/server_connection_manager.cc b/chrome/browser/sync/engine/net/server_connection_manager.cc
index c2fadac..e7d6dbd 100644
--- a/chrome/browser/sync/engine/net/server_connection_manager.cc
+++ b/chrome/browser/sync/engine/net/server_connection_manager.cc
@@ -38,15 +38,6 @@ static const ServerConnectionEvent shutdown_event =
{ ServerConnectionEvent::SHUTDOWN, HttpResponse::CONNECTION_UNAVAILABLE,
false };
-typedef PThreadScopedLock<PThreadMutex> MutexLock;
-
-struct ServerConnectionManager::PlatformMembers {
- explicit PlatformMembers(const string& user_agent) { }
- void Kill() { }
- void Reset() { }
- void Reset(MutexLock*) { }
-};
-
bool ServerConnectionManager::Post::ReadBufferResponse(
string* buffer_out, HttpResponse* response, bool require_response) {
if (RC_REQUEST_OK != response->response_code) {
@@ -154,21 +145,12 @@ ServerConnectionManager::ServerConnectionManager(
channel_(new Channel(shutdown_event)),
server_status_(HttpResponse::NONE),
server_reachable_(false),
- platform_(new PlatformMembers(user_agent)),
reset_count_(0),
terminate_all_io_(false) {
}
ServerConnectionManager::~ServerConnectionManager() {
delete channel_;
- delete platform_;
- shutdown_event_mutex_.Lock();
- int result = pthread_cond_broadcast(&shutdown_event_condition_.condvar_);
- shutdown_event_mutex_.Unlock();
- if (result) {
- LOG(ERROR) << "Error signaling shutdown_event_condition_ last error = "
- << result;
- }
}
void ServerConnectionManager::NotifyStatusChanged() {
@@ -281,17 +263,9 @@ bool ServerConnectionManager::CheckServerReachable() {
void ServerConnectionManager::kill() {
{
- MutexLock lock(&terminate_all_io_mutex_);
+ AutoLock lock(terminate_all_io_mutex_);
terminate_all_io_ = true;
}
- platform_->Kill();
- shutdown_event_mutex_.Lock();
- int result = pthread_cond_broadcast(&shutdown_event_condition_.condvar_);
- shutdown_event_mutex_.Unlock();
- if (result) {
- LOG(ERROR) << "Error signaling shutdown_event_condition_ last error = "
- << result;
- }
}
void ServerConnectionManager::ResetAuthStatus() {
@@ -302,12 +276,11 @@ void ServerConnectionManager::ResetAuthStatus() {
void ServerConnectionManager::ResetConnection() {
base::subtle::NoBarrier_AtomicIncrement(&reset_count_, 1);
- platform_->Reset();
}
bool ServerConnectionManager::IncrementErrorCount() {
#ifdef OS_WIN
- error_count_mutex_.Lock();
+ error_count_mutex_.Acquire();
error_count_++;
if (error_count_ > kMaxConnectionErrorsBeforeReset) {
@@ -316,7 +289,7 @@ bool ServerConnectionManager::IncrementErrorCount() {
// Be careful with this mutex because calling out to other methods can
// result in being called back. Unlock it here to prevent any potential
// double-acquisitions.
- error_count_mutex_.Unlock();
+ error_count_mutex_.Release();
if (!IsServerReachable()) {
LOG(WARNING) << "Too many connection failures, server is not reachable. "
@@ -328,7 +301,7 @@ bool ServerConnectionManager::IncrementErrorCount() {
return false;
}
- error_count_mutex_.Unlock();
+ error_count_mutex_.Release();
return true;
#endif
return true;
@@ -337,18 +310,17 @@ bool ServerConnectionManager::IncrementErrorCount() {
void ServerConnectionManager::SetServerParameters(const string& server_url,
int port, bool use_ssl) {
{
- ParametersLock lock(&server_parameters_mutex_);
+ ParametersLock lock(server_parameters_mutex_);
sync_server_ = server_url;
sync_server_port_ = port;
use_ssl_ = use_ssl;
}
- platform_->Reset();
}
// Returns the current server parameters in server_url and port.
void ServerConnectionManager::GetServerParameters(string* server_url,
- int* port, bool* use_ssl) {
- ParametersLock lock(&server_parameters_mutex_);
+ int* port, bool* use_ssl) const {
+ ParametersLock lock(server_parameters_mutex_);
if (server_url != NULL)
*server_url = sync_server_;
if (port != NULL)
diff --git a/chrome/browser/sync/engine/net/server_connection_manager.h b/chrome/browser/sync/engine/net/server_connection_manager.h
index 92b7b28..878c582 100644
--- a/chrome/browser/sync/engine/net/server_connection_manager.h
+++ b/chrome/browser/sync/engine/net/server_connection_manager.h
@@ -10,13 +10,13 @@
#include <vector>
#include "base/atomicops.h"
+#include "base/lock.h"
#include "base/logging.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "chrome/browser/sync/engine/net/http_return.h"
#include "chrome/browser/sync/syncable/syncable_id.h"
#include "chrome/browser/sync/util/event_sys.h"
-#include "chrome/browser/sync/util/pthread_helpers.h"
#include "chrome/browser/sync/util/signin.h"
#include "chrome/browser/sync/util/sync_types.h"
@@ -163,9 +163,9 @@ class ServerConnectionManager {
const std::string& path, bool use_ssl) const;
void GetServerParams(std::string* server, int* server_port,
- bool* use_ssl) {
+ bool* use_ssl) const {
ServerConnectionManager::ParametersLock lock(
- &scm_->server_parameters_mutex_);
+ scm_->server_parameters_mutex_);
server->assign(scm_->sync_server_);
*server_port = scm_->sync_server_port_;
*use_ssl = scm_->use_ssl_;
@@ -239,10 +239,11 @@ class ServerConnectionManager {
bool use_ssl);
// Returns the current server parameters in server_url, port and use_ssl.
- void GetServerParameters(std::string* server_url, int* port, bool* use_ssl);
+ void GetServerParameters(std::string* server_url,
+ int* port, bool* use_ssl) const;
bool terminate_all_io() const {
- PThreadScopedLock<PThreadMutex> lock(&terminate_all_io_mutex_);
+ AutoLock lock(terminate_all_io_mutex_);
return terminate_all_io_;
}
@@ -261,13 +262,9 @@ class ServerConnectionManager {
}
protected:
-
- PThreadMutex shutdown_event_mutex_;
- PThreadCondVar shutdown_event_condition_;
-
// Protects access to sync_server_, sync_server_port_ and use_ssl_:
- mutable PThreadMutex server_parameters_mutex_;
- typedef PThreadScopedLock<PThreadMutex> ParametersLock;
+ mutable Lock server_parameters_mutex_;
+ typedef AutoLock ParametersLock;
// The sync_server_ is the server that requests will be made to.
std::string sync_server_;
@@ -285,8 +282,8 @@ class ServerConnectionManager {
bool use_ssl_;
// The paths we post to.
- mutable PThreadMutex path_mutex_;
- typedef PThreadScopedLock<PThreadMutex> ScopedPathLock;
+ mutable Lock path_mutex_;
+ typedef AutoLock ScopedPathLock;
std::string proto_sync_path_;
std::string get_time_path_;
@@ -295,18 +292,18 @@ class ServerConnectionManager {
std::string auth_token_;
inline std::string proto_sync_path() const {
- ScopedPathLock lock(&path_mutex_);
+ ScopedPathLock lock(path_mutex_);
return proto_sync_path_;
}
std::string get_time_path() const {
- ScopedPathLock lock(&path_mutex_);
+ ScopedPathLock lock(path_mutex_);
return get_time_path_;
}
// Called wherever a failure should be taken as an indication that we may
// be experiencing connection difficulties.
virtual bool IncrementErrorCount();
- mutable PThreadMutex error_count_mutex_; // Protects error_count_
+ Lock error_count_mutex_; // Protects error_count_
int error_count_; // Tracks the number of connection errors.
protected:
@@ -316,9 +313,6 @@ class ServerConnectionManager {
volatile HttpResponse::ServerConnectionCode server_status_;
bool server_reachable_;
- struct PlatformMembers; // Contains platform specific member vars.
- PlatformMembers* const platform_;
-
// A counter that is incremented everytime ResetAuthStatus() is called.
volatile base::subtle::AtomicWord reset_count_;
@@ -330,7 +324,7 @@ class ServerConnectionManager {
const std::string& auth_token);
private:
- mutable PThreadMutex terminate_all_io_mutex_;
+ mutable Lock terminate_all_io_mutex_;
bool terminate_all_io_; // When set to true, terminate all connections asap.
DISALLOW_COPY_AND_ASSIGN(ServerConnectionManager);
};
diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/engine/syncapi.cc
index 35081c5..969b4fb 100644
--- a/chrome/browser/sync/engine/syncapi.cc
+++ b/chrome/browser/sync/engine/syncapi.cc
@@ -18,6 +18,7 @@
#include "base/basictypes.h"
#include "base/command_line.h"
+#include "base/platform_thread.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "chrome/browser/sync/engine/all_status.h"
@@ -40,7 +41,6 @@
#include "chrome/browser/sync/util/crypto_helpers.h"
#include "chrome/browser/sync/util/event_sys.h"
#include "chrome/browser/sync/util/path_helpers.h"
-#include "chrome/browser/sync/util/pthread_helpers.h"
#include "chrome/browser/sync/util/user_settings.h"
#include "googleurl/src/gurl.h"
@@ -83,7 +83,7 @@ struct ThreadParams {
// table that maps IP addresses to interfaces, for example when the user
// unplugs his network cable.
void* AddressWatchThread(void* arg) {
- NameCurrentThreadForDebugging("SyncEngine_AddressWatcher");
+ PlatformThread::SetName("SyncEngine_AddressWatcher");
LOG(INFO) << "starting the address watch thread";
#if defined(OS_WIN)
const ThreadParams* const params = reinterpret_cast<const ThreadParams*>(arg);
diff --git a/chrome/browser/sync/notifier/listener/mediator_thread_impl.cc b/chrome/browser/sync/notifier/listener/mediator_thread_impl.cc
index 473b7be..fd25620 100644
--- a/chrome/browser/sync/notifier/listener/mediator_thread_impl.cc
+++ b/chrome/browser/sync/notifier/listener/mediator_thread_impl.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/sync/notifier/listener/mediator_thread_impl.h"
#include "base/logging.h"
+#include "base/platform_thread.h"
#include "chrome/browser/sync/engine/net/gaia_authenticator.h"
#include "chrome/browser/sync/notifier/base/async_dns_lookup.h"
#include "chrome/browser/sync/notifier/base/task_pump.h"
@@ -15,7 +16,6 @@
#include "chrome/browser/sync/notifier/listener/send_update_task.h"
#include "chrome/browser/sync/notifier/listener/subscribe_task.h"
#include "chrome/browser/sync/protocol/service_constants.h"
-#include "chrome/browser/sync/util/pthread_helpers.h"
#include "talk/base/thread.h"
#ifdef WIN32
#include "talk/base/win32socketserver.h"
@@ -38,7 +38,7 @@ void MediatorThreadImpl::Start() {
}
void MediatorThreadImpl::Run() {
- NameCurrentThreadForDebugging("SyncEngine_MediatorThread");
+ PlatformThread::SetName("SyncEngine_MediatorThread");
// For win32, this sets up the win32socketserver. Note that it needs to
// dispatch windows messages since that is what the win32 socket server uses.
#ifdef WIN32
diff --git a/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc b/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc
index 8f6804d..2433c08 100644
--- a/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc
+++ b/chrome/browser/sync/notifier/listener/talk_mediator_impl.cc
@@ -77,7 +77,7 @@ TalkMediatorImpl::~TalkMediatorImpl() {
void TalkMediatorImpl::AuthWatcherEventHandler(
const AuthWatcherEvent& auth_event) {
- MutexLock lock(&mutex_);
+ AutoLock lock(mutex_);
switch (auth_event.what_happened) {
case AuthWatcherEvent::AUTHWATCHER_DESTROYED:
case AuthWatcherEvent::GAIA_AUTH_FAILED:
@@ -111,7 +111,7 @@ void TalkMediatorImpl::WatchAuthWatcher(AuthWatcher* watcher) {
}
bool TalkMediatorImpl::Login() {
- MutexLock lock(&mutex_);
+ AutoLock lock(mutex_);
return DoLogin();
}
@@ -132,7 +132,7 @@ bool TalkMediatorImpl::DoLogin() {
}
bool TalkMediatorImpl::Logout() {
- MutexLock lock(&mutex_);
+ AutoLock lock(mutex_);
// We do not want to be called back during logout since we may be closing.
if (state_.connected) {
mediator_thread_->SignalStateChange.disconnect(this);
@@ -149,7 +149,7 @@ bool TalkMediatorImpl::Logout() {
}
bool TalkMediatorImpl::SendNotification() {
- MutexLock lock(&mutex_);
+ AutoLock lock(mutex_);
if (state_.logged_in && state_.subscribed) {
mediator_thread_->SendNotification();
return true;
@@ -163,7 +163,7 @@ TalkMediatorChannel* TalkMediatorImpl::channel() const {
bool TalkMediatorImpl::SetAuthToken(const std::string& email,
const std::string& token) {
- MutexLock lock(&mutex_);
+ AutoLock lock(mutex_);
// Verify that we can create a JID from the email provided.
buzz::Jid jid = buzz::Jid(email);
@@ -212,7 +212,7 @@ void TalkMediatorImpl::MediatorThreadMessageHandler(
void TalkMediatorImpl::OnLogin() {
LOG(INFO) << "P2P: Logged in.";
- MutexLock lock(&mutex_);
+ AutoLock lock(mutex_);
// ListenForUpdates enables the ListenTask. This is done before
// SubscribeForUpdates.
mediator_thread_->ListenForUpdates();
@@ -224,7 +224,7 @@ void TalkMediatorImpl::OnLogin() {
void TalkMediatorImpl::OnLogout() {
LOG(INFO) << "P2P: Logged off.";
OnSubscriptionFailure();
- MutexLock lock(&mutex_);
+ AutoLock lock(mutex_);
state_.logged_in = 0;
TalkMediatorEvent event = { TalkMediatorEvent::LOGOUT_SUCCEEDED };
channel_->NotifyListeners(event);
@@ -232,7 +232,7 @@ void TalkMediatorImpl::OnLogout() {
void TalkMediatorImpl::OnSubscriptionSuccess() {
LOG(INFO) << "P2P: Update subscription active.";
- MutexLock lock(&mutex_);
+ AutoLock lock(mutex_);
state_.subscribed = 1;
TalkMediatorEvent event = { TalkMediatorEvent::SUBSCRIPTIONS_ON };
channel_->NotifyListeners(event);
@@ -240,7 +240,7 @@ void TalkMediatorImpl::OnSubscriptionSuccess() {
void TalkMediatorImpl::OnSubscriptionFailure() {
LOG(INFO) << "P2P: Update subscription failure.";
- MutexLock lock(&mutex_);
+ AutoLock lock(mutex_);
state_.subscribed = 0;
TalkMediatorEvent event = { TalkMediatorEvent::SUBSCRIPTIONS_OFF };
channel_->NotifyListeners(event);
@@ -248,7 +248,7 @@ void TalkMediatorImpl::OnSubscriptionFailure() {
void TalkMediatorImpl::OnNotificationReceived() {
LOG(INFO) << "P2P: Updates are available on the server.";
- MutexLock lock(&mutex_);
+ AutoLock lock(mutex_);
TalkMediatorEvent event = { TalkMediatorEvent::NOTIFICATION_RECEIVED };
channel_->NotifyListeners(event);
}
@@ -256,7 +256,7 @@ void TalkMediatorImpl::OnNotificationReceived() {
void TalkMediatorImpl::OnNotificationSent() {
LOG(INFO) <<
"P2P: Peers were notified that updates are available on the server.";
- MutexLock lock(&mutex_);
+ AutoLock lock(mutex_);
TalkMediatorEvent event = { TalkMediatorEvent::NOTIFICATION_SENT };
channel_->NotifyListeners(event);
}
diff --git a/chrome/browser/sync/notifier/listener/talk_mediator_impl.h b/chrome/browser/sync/notifier/listener/talk_mediator_impl.h
index 84c45f2..99bbb79 100644
--- a/chrome/browser/sync/notifier/listener/talk_mediator_impl.h
+++ b/chrome/browser/sync/notifier/listener/talk_mediator_impl.h
@@ -11,11 +11,11 @@
#include <string>
+#include "base/lock.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/sync/engine/auth_watcher.h"
#include "chrome/browser/sync/notifier/listener/mediator_thread.h"
#include "chrome/browser/sync/notifier/listener/talk_mediator.h"
-#include "chrome/browser/sync/util/pthread_helpers.h"
#include "talk/xmpp/xmppclientsettings.h"
#include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST
@@ -60,8 +60,6 @@ class TalkMediatorImpl
unsigned int subscribed : 1; // Subscribed to the xmpp receiving channel.
};
- typedef PThreadScopedLock<PThreadMutex> MutexLock;
-
// Completes common initialization between the constructors. Set should
// connect to true if the talk mediator should connect to the controlled
// mediator thread's SignalStateChange object.
@@ -90,7 +88,7 @@ class TalkMediatorImpl
// sources, Authwatcher and MediatorThread. It can also be called by through
// the TalkMediatorInteface. All these access points are serialized by
// this mutex.
- PThreadMutex mutex_;
+ Lock mutex_;
// Internal state.
TalkMediatorState state_;