summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-24 21:13:28 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-24 21:13:28 +0000
commit434fff8b3cd14b1c41aea1788d33f0543eff6ad1 (patch)
tree38bb5641357159ea91452092c9bebe241a15d5a7 /net
parent31ae7abec500e5d497079745490d8ba4986b1ba2 (diff)
downloadchromium_src-434fff8b3cd14b1c41aea1788d33f0543eff6ad1.zip
chromium_src-434fff8b3cd14b1c41aea1788d33f0543eff6ad1.tar.gz
chromium_src-434fff8b3cd14b1c41aea1788d33f0543eff6ad1.tar.bz2
Use base::MessageLoopProxy instead of MessageLoop in ProxyConfigServiceLinux.
This will allow using that class on the main NPAPI plugin thread in chromoting. BUG=124728 Review URL: http://codereview.chromium.org/10140010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133767 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/proxy/proxy_config_service_linux.cc89
-rw-r--r--net/proxy/proxy_config_service_linux.h25
-rw-r--r--net/proxy/proxy_config_service_linux_unittest.cc6
-rw-r--r--net/proxy/proxy_service.cc4
4 files changed, 69 insertions, 55 deletions
diff --git a/net/proxy/proxy_config_service_linux.cc b/net/proxy/proxy_config_service_linux.cc
index 1ac2f09..af0e4cd 100644
--- a/net/proxy/proxy_config_service_linux.cc
+++ b/net/proxy/proxy_config_service_linux.cc
@@ -30,6 +30,7 @@
#include "base/file_util.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "base/nix/xdg_util.h"
#include "base/string_number_conversions.h"
#include "base/string_tokenizer.h"
@@ -212,7 +213,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
// and pending tasks may then be deleted without being run.
if (client_) {
// gconf client was not cleaned up.
- if (MessageLoop::current() == loop_) {
+ if (loop_->BelongsToCurrentThread()) {
// We are on the UI thread so we can clean it safely. This is
// the case at least for ui_tests running under Valgrind in
// bug 16076.
@@ -230,9 +231,9 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
DCHECK(!client_);
}
- virtual bool Init(MessageLoop* glib_default_loop,
+ virtual bool Init(base::MessageLoopProxy* glib_default_loop,
MessageLoopForIO* file_loop) OVERRIDE {
- DCHECK(MessageLoop::current() == glib_default_loop);
+ DCHECK(glib_default_loop->BelongsToCurrentThread());
DCHECK(!client_);
DCHECK(!loop_);
loop_ = glib_default_loop;
@@ -271,7 +272,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
void ShutDown() {
if (client_) {
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
// We must explicitly disable gconf notifications here, because the gconf
// client will be shared between all setting getters, and they do not all
// have the same lifetimes. (For instance, incognito sessions get their
@@ -288,7 +289,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
bool SetUpNotifications(ProxyConfigServiceLinux::Delegate* delegate) {
DCHECK(client_);
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
GError* error = NULL;
notify_delegate_ = delegate;
// We have to keep track of the IDs returned by gconf_client_notify_add() so
@@ -315,7 +316,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
return true;
}
- virtual MessageLoop* GetNotificationLoop() OVERRIDE {
+ virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE {
return loop_;
}
@@ -385,7 +386,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
private:
bool GetStringByPath(const char* key, std::string* result) {
DCHECK(client_);
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
GError* error = NULL;
gchar* value = gconf_client_get_string(client_, key, &error);
if (HandleGError(error, key))
@@ -398,7 +399,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
}
bool GetBoolByPath(const char* key, bool* result) {
DCHECK(client_);
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
GError* error = NULL;
// We want to distinguish unset values from values defaulting to
// false. For that we need to use the type-generic
@@ -421,7 +422,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
}
bool GetIntByPath(const char* key, int* result) {
DCHECK(client_);
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
GError* error = NULL;
int value = gconf_client_get_int(client_, key, &error);
if (HandleGError(error, key))
@@ -433,7 +434,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
}
bool GetStringListByPath(const char* key, std::vector<std::string>* result) {
DCHECK(client_);
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
GError* error = NULL;
GSList* list = gconf_client_get_list(client_, key,
GCONF_VALUE_STRING, &error);
@@ -463,7 +464,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
// This is the callback from the debounce timer.
void OnDebouncedNotification() {
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
CHECK(notify_delegate_);
// Forward to a method on the proxy config service delegate object.
notify_delegate_->OnCheckProxyConfigSettings();
@@ -501,7 +502,7 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
// Message loop of the thread that we make gconf calls on. It should
// be the UI thread and all our methods should be called on this
// thread. Only for assertions.
- MessageLoop* loop_;
+ scoped_refptr<base::MessageLoopProxy> loop_;
DISALLOW_COPY_AND_ASSIGN(SettingGetterImplGConf);
};
@@ -541,7 +542,7 @@ class SettingGetterImplGSettings
// without being run.
if (client_) {
// gconf client was not cleaned up.
- if (MessageLoop::current() == loop_) {
+ if (loop_->BelongsToCurrentThread()) {
// We are on the UI thread so we can clean it safely. This is
// the case at least for ui_tests running under Valgrind in
// bug 16076.
@@ -574,9 +575,9 @@ class SettingGetterImplGSettings
// LoadAndCheckVersion() must be called *before* Init()!
bool LoadAndCheckVersion(base::Environment* env);
- virtual bool Init(MessageLoop* glib_default_loop,
+ virtual bool Init(base::MessageLoopProxy* glib_default_loop,
MessageLoopForIO* file_loop) OVERRIDE {
- DCHECK(MessageLoop::current() == glib_default_loop);
+ DCHECK(glib_default_loop->BelongsToCurrentThread());
DCHECK(!client_);
DCHECK(!loop_);
@@ -598,7 +599,7 @@ class SettingGetterImplGSettings
void ShutDown() {
if (client_) {
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
// This also disables gsettings notifications.
g_object_unref(socks_client_);
g_object_unref(ftp_client_);
@@ -613,7 +614,7 @@ class SettingGetterImplGSettings
bool SetUpNotifications(ProxyConfigServiceLinux::Delegate* delegate) {
DCHECK(client_);
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
notify_delegate_ = delegate;
// We could watch for the change-event signal instead of changed, but
// since we have to watch more than one object, we'd still have to
@@ -633,7 +634,7 @@ class SettingGetterImplGSettings
return true;
}
- virtual MessageLoop* GetNotificationLoop() OVERRIDE {
+ virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE {
return loop_;
}
@@ -744,7 +745,7 @@ class SettingGetterImplGSettings
bool GetStringByPath(GSettings* client, const char* key,
std::string* result) {
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
gchar* value = g_settings_get_string(client, key);
if (!value)
return false;
@@ -753,18 +754,18 @@ class SettingGetterImplGSettings
return true;
}
bool GetBoolByPath(GSettings* client, const char* key, bool* result) {
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
*result = static_cast<bool>(g_settings_get_boolean(client, key));
return true;
}
bool GetIntByPath(GSettings* client, const char* key, int* result) {
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
*result = g_settings_get_int(client, key);
return true;
}
bool GetStringListByPath(GSettings* client, const char* key,
std::vector<std::string>* result) {
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
gchar** list = g_settings_get_strv(client, key);
if (!list)
return false;
@@ -778,7 +779,7 @@ class SettingGetterImplGSettings
// This is the callback from the debounce timer.
void OnDebouncedNotification() {
- DCHECK(MessageLoop::current() == loop_);
+ DCHECK(loop_->BelongsToCurrentThread());
CHECK(notify_delegate_);
// Forward to a method on the proxy config service delegate object.
notify_delegate_->OnCheckProxyConfigSettings();
@@ -814,7 +815,7 @@ class SettingGetterImplGSettings
// Message loop of the thread that we make gsettings calls on. It should
// be the UI thread and all our methods should be called on this
// thread. Only for assertions.
- MessageLoop* loop_;
+ scoped_refptr<base::MessageLoopProxy> loop_;
DISALLOW_COPY_AND_ASSIGN(SettingGetterImplGSettings);
};
@@ -978,7 +979,7 @@ class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter,
DCHECK(inotify_fd_ < 0);
}
- virtual bool Init(MessageLoop* glib_default_loop,
+ virtual bool Init(base::MessageLoopProxy* glib_default_loop,
MessageLoopForIO* file_loop) OVERRIDE {
// This has to be called on the UI thread (http://crbug.com/69057).
base::ThreadRestrictions::ScopedAllowIO allow_io;
@@ -1031,8 +1032,8 @@ class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter,
return true;
}
- virtual MessageLoop* GetNotificationLoop() OVERRIDE {
- return file_loop_;
+ virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE {
+ return file_loop_->message_loop_proxy();
}
// Implement base::MessagePumpLibevent::Watcher.
@@ -1595,11 +1596,12 @@ ProxyConfigServiceLinux::Delegate::Delegate(
}
void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig(
- MessageLoop* glib_default_loop, MessageLoop* io_loop,
+ base::MessageLoopProxy* glib_default_loop,
+ base::MessageLoopProxy* io_loop,
MessageLoopForIO* file_loop) {
// We should be running on the default glib main loop thread right
// now. gconf can only be accessed from this thread.
- DCHECK(MessageLoop::current() == glib_default_loop);
+ DCHECK(glib_default_loop->BelongsToCurrentThread());
glib_default_loop_ = glib_default_loop;
io_loop_ = io_loop;
@@ -1648,8 +1650,9 @@ void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig(
// fetch and before setting up notifications. We'll detect the common case
// of no changes in OnCheckProxyConfigSettings() (or sooner) and ignore it.
if (io_loop && file_loop) {
- MessageLoop* required_loop = setting_getter_->GetNotificationLoop();
- if (!required_loop || MessageLoop::current() == required_loop) {
+ scoped_refptr<base::MessageLoopProxy> required_loop =
+ setting_getter_->GetNotificationLoop();
+ if (!required_loop || required_loop->BelongsToCurrentThread()) {
// In this case we are already on an acceptable thread.
SetUpNotifications();
} else {
@@ -1675,8 +1678,9 @@ void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig(
// Depending on the SettingGetter in use, this method will be called
// on either the UI thread (GConf) or the file thread (KDE).
void ProxyConfigServiceLinux::Delegate::SetUpNotifications() {
- MessageLoop* required_loop = setting_getter_->GetNotificationLoop();
- DCHECK(!required_loop || MessageLoop::current() == required_loop);
+ scoped_refptr<base::MessageLoopProxy> required_loop =
+ setting_getter_->GetNotificationLoop();
+ DCHECK(!required_loop || required_loop->BelongsToCurrentThread());
if (!setting_getter_->SetUpNotifications(this))
LOG(ERROR) << "Unable to set up proxy configuration change notifications";
}
@@ -1693,7 +1697,7 @@ ProxyConfigService::ConfigAvailability
ProxyConfigServiceLinux::Delegate::GetLatestProxyConfig(
ProxyConfig* config) {
// This is called from the IO thread.
- DCHECK(!io_loop_ || MessageLoop::current() == io_loop_);
+ DCHECK(!io_loop_ || io_loop_->BelongsToCurrentThread());
// Simply return the last proxy configuration that glib_default_loop
// notified us of.
@@ -1711,8 +1715,9 @@ ProxyConfigService::ConfigAvailability
// Depending on the SettingGetter in use, this method will be called
// on either the UI thread (GConf) or the file thread (KDE).
void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() {
- MessageLoop* required_loop = setting_getter_->GetNotificationLoop();
- DCHECK(!required_loop || MessageLoop::current() == required_loop);
+ scoped_refptr<base::MessageLoopProxy> required_loop =
+ setting_getter_->GetNotificationLoop();
+ DCHECK(!required_loop || required_loop->BelongsToCurrentThread());
ProxyConfig new_config;
bool valid = GetConfigFromSettings(&new_config);
if (valid)
@@ -1735,7 +1740,7 @@ void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() {
void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig(
const ProxyConfig& new_config) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(io_loop_->BelongsToCurrentThread());
VLOG(1) << "Proxy configuration changed";
cached_config_ = new_config;
FOR_EACH_OBSERVER(
@@ -1746,8 +1751,9 @@ void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig(
void ProxyConfigServiceLinux::Delegate::PostDestroyTask() {
if (!setting_getter_.get())
return;
- MessageLoop* shutdown_loop = setting_getter_->GetNotificationLoop();
- if (!shutdown_loop || MessageLoop::current() == shutdown_loop) {
+ scoped_refptr<base::MessageLoopProxy> shutdown_loop =
+ setting_getter_->GetNotificationLoop();
+ if (!shutdown_loop || shutdown_loop->BelongsToCurrentThread()) {
// Already on the right thread, call directly.
// This is the case for the unittests.
OnDestroy();
@@ -1759,8 +1765,9 @@ void ProxyConfigServiceLinux::Delegate::PostDestroyTask() {
}
}
void ProxyConfigServiceLinux::Delegate::OnDestroy() {
- MessageLoop* shutdown_loop = setting_getter_->GetNotificationLoop();
- DCHECK(!shutdown_loop || MessageLoop::current() == shutdown_loop);
+ scoped_refptr<base::MessageLoopProxy> shutdown_loop =
+ setting_getter_->GetNotificationLoop();
+ DCHECK(!shutdown_loop || shutdown_loop->BelongsToCurrentThread());
setting_getter_->ShutDown();
}
diff --git a/net/proxy/proxy_config_service_linux.h b/net/proxy/proxy_config_service_linux.h
index 94eef7e..ffaa988 100644
--- a/net/proxy/proxy_config_service_linux.h
+++ b/net/proxy/proxy_config_service_linux.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -14,13 +14,18 @@
#include "base/environment.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop.h"
#include "base/observer_list.h"
#include "net/base/net_export.h"
#include "net/proxy/proxy_config.h"
#include "net/proxy/proxy_config_service.h"
#include "net/proxy/proxy_server.h"
+class MessageLoopForIO;
+
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace net {
// Implementation of ProxyConfigService that retrieves the system proxy
@@ -47,7 +52,7 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService {
// One of |glib_default_loop| and |file_loop| will be used for
// gconf/gsettings calls or reading necessary files, depending on the
// implementation.
- virtual bool Init(MessageLoop* glib_default_loop,
+ virtual bool Init(base::MessageLoopProxy* glib_default_loop,
MessageLoopForIO* file_loop) = 0;
// Releases the gconf/gsettings client, which clears cached directories and
@@ -61,7 +66,7 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService {
// Returns the message loop for the thread on which this object
// handles notifications, and also on which it must be destroyed.
// Returns NULL if it does not matter.
- virtual MessageLoop* GetNotificationLoop() = 0;
+ virtual base::MessageLoopProxy* GetNotificationLoop() = 0;
// Returns the data source's name (e.g. "gconf", "gsettings", "KDE",
// "test"). Used only for diagnostic purposes (e.g. VLOG(1) etc.).
@@ -177,8 +182,8 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService {
// thread is specified so that notifications can post tasks to it
// (and for assertions). The message loop for the file thread is
// used to read any files needed to determine proxy settings.
- void SetUpAndFetchInitialConfig(MessageLoop* glib_default_loop,
- MessageLoop* io_loop,
+ void SetUpAndFetchInitialConfig(base::MessageLoopProxy* glib_default_loop,
+ base::MessageLoopProxy* io_loop,
MessageLoopForIO* file_loop);
// Handler for setting change notifications: fetches a new proxy
@@ -255,10 +260,10 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService {
// timeouts and idles and possibly other callbacks that will all be
// dispatched on this thread. Since gconf is not thread safe, any use of
// gconf must be done on the thread running this loop.
- MessageLoop* glib_default_loop_;
+ scoped_refptr<base::MessageLoopProxy> glib_default_loop_;
// MessageLoop for the IO thread. GetLatestProxyConfig() is called from
// the thread running this loop.
- MessageLoop* io_loop_;
+ scoped_refptr<base::MessageLoopProxy> io_loop_;
ObserverList<Observer> observers_;
@@ -276,8 +281,8 @@ class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService {
virtual ~ProxyConfigServiceLinux();
- void SetupAndFetchInitialConfig(MessageLoop* glib_default_loop,
- MessageLoop* io_loop,
+ void SetupAndFetchInitialConfig(base::MessageLoopProxy* glib_default_loop,
+ base::MessageLoopProxy* io_loop,
MessageLoopForIO* file_loop) {
delegate_->SetUpAndFetchInitialConfig(glib_default_loop, io_loop,
file_loop);
diff --git a/net/proxy/proxy_config_service_linux_unittest.cc b/net/proxy/proxy_config_service_linux_unittest.cc
index f8e2238..ad12ea6 100644
--- a/net/proxy/proxy_config_service_linux_unittest.cc
+++ b/net/proxy/proxy_config_service_linux_unittest.cc
@@ -175,7 +175,7 @@ class MockSettingGetter
values = zero_values;
}
- virtual bool Init(MessageLoop* glib_default_loop,
+ virtual bool Init(base::MessageLoopProxy* glib_default_loop,
MessageLoopForIO* file_loop) OVERRIDE {
return true;
}
@@ -187,7 +187,7 @@ class MockSettingGetter
return true;
}
- virtual MessageLoop* GetNotificationLoop() OVERRIDE {
+ virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE {
return NULL;
}
@@ -292,7 +292,7 @@ class SynchConfigGetter {
DCHECK_EQ(MessageLoop::TYPE_IO, file_loop->type());
// We pass the mock IO thread as both the IO and file threads.
config_service_->SetupAndFetchInitialConfig(
- MessageLoop::current(), io_thread_.message_loop(),
+ base::MessageLoopProxy::current(), io_thread_.message_loop_proxy(),
static_cast<MessageLoopForIO*>(file_loop));
}
// Synchronously gets the proxy config.
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index 39638e2..6df9ce9 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -1424,7 +1424,9 @@ ProxyConfigService* ProxyService::CreateSystemProxyConfigService(
// running on glib_default_loop). Additionally register for
// notifications (delivered in either |glib_default_loop| or
// |file_loop|) to keep us updated when the proxy config changes.
- linux_config_service->SetupAndFetchInitialConfig(glib_default_loop, io_loop,
+ linux_config_service->SetupAndFetchInitialConfig(
+ glib_default_loop->message_loop_proxy(),
+ io_loop->message_loop_proxy(),
static_cast<MessageLoopForIO*>(file_loop));
return linux_config_service;