#include "net/proxy/proxy_config_service_linux.h"
-// glib >=2.40 deprecate g_settings_list_schemas in favor of
-// g_settings_schema_source_list_schemas. This function is not available on
-// earlier versions that we still need to support (specifically, 2.32), so
-// disable the warning.
-// TODO(mgiuca): Remove this suppression when we drop support for Ubuntu 13.10
-// (saucy) and earlier. Update the code to use
-// g_settings_schema_source_list_schemas instead.
-#define GLIB_DISABLE_DEPRECATION_WARNINGS
-
#include <errno.h>
#include <fcntl.h>
#if defined(USE_GCONF)
#include "base/compiler_specific.h"
#include "base/debug/leak_annotations.h"
#include "base/environment.h"
-#include "base/file_util.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
DCHECK(!client_);
}
- virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner,
- base::MessageLoopForIO* file_loop) OVERRIDE {
- DCHECK(glib_thread_task_runner->BelongsToCurrentThread());
+ virtual bool Init(
+ const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
+ const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
+ OVERRIDE {
+ DCHECK(glib_task_runner->BelongsToCurrentThread());
DCHECK(!client_);
DCHECK(!task_runner_.get());
- task_runner_ = glib_thread_task_runner;
+ task_runner_ = glib_task_runner;
client_ = gconf_client_get_default();
if (!client_) {
// It's not clear whether/when this can return NULL.
return true;
}
- virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE {
- return task_runner_.get();
+ virtual const scoped_refptr<base::SingleThreadTaskRunner>&
+ GetNotificationTaskRunner() OVERRIDE {
+ return task_runner_;
}
virtual ProxyConfigSource GetConfigSource() OVERRIDE {
// LoadAndCheckVersion() must be called *before* Init()!
bool LoadAndCheckVersion(base::Environment* env);
- virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner,
- base::MessageLoopForIO* file_loop) OVERRIDE {
- DCHECK(glib_thread_task_runner->BelongsToCurrentThread());
+ virtual bool Init(
+ const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
+ const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
+ OVERRIDE {
+ DCHECK(glib_task_runner->BelongsToCurrentThread());
DCHECK(!client_);
DCHECK(!task_runner_.get());
LOG(ERROR) << "Unable to create a gsettings client";
return false;
}
- task_runner_ = glib_thread_task_runner;
+ task_runner_ = glib_task_runner;
// We assume these all work if the above call worked.
http_client_ = libgio_loader_.g_settings_get_child(client_, "http");
https_client_ = libgio_loader_.g_settings_get_child(client_, "https");
return true;
}
- virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE {
- return task_runner_.get();
+ virtual const scoped_refptr<base::SingleThreadTaskRunner>&
+ GetNotificationTaskRunner() OVERRIDE {
+ return task_runner_;
}
virtual ProxyConfigSource GetConfigSource() OVERRIDE {
explicit SettingGetterImplKDE(base::Environment* env_var_getter)
: inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false),
auto_no_pac_(false), reversed_bypass_list_(false),
- env_var_getter_(env_var_getter), file_loop_(NULL) {
+ env_var_getter_(env_var_getter), file_task_runner_(NULL) {
// This has to be called on the UI thread (http://crbug.com/69057).
base::ThreadRestrictions::ScopedAllowIO allow_io;
DCHECK(inotify_fd_ < 0);
}
- virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner,
- base::MessageLoopForIO* file_loop) OVERRIDE {
+ virtual bool Init(
+ const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
+ const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
+ OVERRIDE {
// This has to be called on the UI thread (http://crbug.com/69057).
base::ThreadRestrictions::ScopedAllowIO allow_io;
DCHECK(inotify_fd_ < 0);
inotify_fd_ = -1;
return false;
}
- file_loop_ = file_loop;
- // The initial read is done on the current thread, not |file_loop_|,
- // since we will need to have it for SetUpAndFetchInitialConfig().
+ file_task_runner_ = file_task_runner;
+ // The initial read is done on the current thread, not
+ // |file_task_runner_|, since we will need to have it for
+ // SetUpAndFetchInitialConfig().
UpdateCachedSettings();
return true;
}
virtual bool SetUpNotifications(
ProxyConfigServiceLinux::Delegate* delegate) OVERRIDE {
DCHECK(inotify_fd_ >= 0);
- DCHECK(base::MessageLoop::current() == file_loop_);
+ DCHECK(file_task_runner_->BelongsToCurrentThread());
// We can't just watch the kioslaverc file directly, since KDE will write
// a new copy of it and then rename it whenever settings are changed and
// inotify watches inodes (so we'll be watching the old deleted file after
// the first change, and it will never change again). So, we watch the
// directory instead. We then act only on changes to the kioslaverc entry.
if (inotify_add_watch(inotify_fd_, kde_config_dir_.value().c_str(),
- IN_MODIFY | IN_MOVED_TO) < 0)
+ IN_MODIFY | IN_MOVED_TO) < 0) {
return false;
+ }
notify_delegate_ = delegate;
- if (!file_loop_->WatchFileDescriptor(inotify_fd_,
- true,
- base::MessageLoopForIO::WATCH_READ,
- &inotify_watcher_,
- this))
+ if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
+ inotify_fd_, true, base::MessageLoopForIO::WATCH_READ,
+ &inotify_watcher_, this)) {
return false;
+ }
// Simulate a change to avoid possibly losing updates before this point.
OnChangeNotification();
return true;
}
- virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE {
- return file_loop_ ? file_loop_->message_loop_proxy().get() : NULL;
+ virtual const scoped_refptr<base::SingleThreadTaskRunner>&
+ GetNotificationTaskRunner() OVERRIDE {
+ return file_task_runner_;
}
// Implement base::MessagePumpLibevent::Watcher.
virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE {
DCHECK_EQ(fd, inotify_fd_);
- DCHECK(base::MessageLoop::current() == file_loop_);
+ DCHECK(file_task_runner_->BelongsToCurrentThread());
OnChangeNotification();
}
virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE {
// This is the callback from the debounce timer.
void OnDebouncedNotification() {
- DCHECK(base::MessageLoop::current() == file_loop_);
+ DCHECK(file_task_runner_->BelongsToCurrentThread());
VLOG(1) << "inotify change notification for kioslaverc";
UpdateCachedSettings();
CHECK(notify_delegate_);
// an event for kioslaverc is seen.
void OnChangeNotification() {
DCHECK_GE(inotify_fd_, 0);
- DCHECK(base::MessageLoop::current() == file_loop_);
+ DCHECK(file_task_runner_->BelongsToCurrentThread());
char event_buf[(sizeof(inotify_event) + NAME_MAX + 1) * 4];
bool kioslaverc_touched = false;
ssize_t r;
string_map_type string_table_;
strings_map_type strings_table_;
- // Message loop of the file thread, for reading kioslaverc. If NULL,
+ // Task runner of the file thread, for reading kioslaverc. If NULL,
// just read it directly (for testing). We also handle inotify events
// on this thread.
- base::MessageLoopForIO* file_loop_;
+ scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
DISALLOW_COPY_AND_ASSIGN(SettingGetterImplKDE);
};
}
void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig(
- base::SingleThreadTaskRunner* glib_thread_task_runner,
- base::SingleThreadTaskRunner* io_thread_task_runner,
- base::MessageLoopForIO* file_loop) {
+ const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
+ const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) {
// We should be running on the default glib main loop thread right
// now. gconf can only be accessed from this thread.
- DCHECK(glib_thread_task_runner->BelongsToCurrentThread());
- glib_thread_task_runner_ = glib_thread_task_runner;
- io_thread_task_runner_ = io_thread_task_runner;
-
- // If we are passed a NULL |io_thread_task_runner| or |file_loop|,
- // then we don't set up proxy setting change notifications. This
- // should not be the usual case but is intended to simplify test
- // setups.
- if (!io_thread_task_runner_.get() || !file_loop)
+ DCHECK(glib_task_runner->BelongsToCurrentThread());
+ glib_task_runner_ = glib_task_runner;
+ io_task_runner_ = io_task_runner;
+
+ // If we are passed a NULL |io_task_runner| or |file_task_runner|, then we
+ // don't set up proxy setting change notifications. This should not be the
+ // usual case but is intended to/ simplify test setups.
+ if (!io_task_runner_.get() || !file_task_runner.get())
VLOG(1) << "Monitoring of proxy setting changes is disabled";
// Fetch and cache the current proxy config. The config is left in
bool got_config = false;
if (setting_getter_.get() &&
- setting_getter_->Init(glib_thread_task_runner, file_loop) &&
+ setting_getter_->Init(glib_task_runner, file_task_runner) &&
GetConfigFromSettings(&cached_config_)) {
cached_config_.set_id(1); // Mark it as valid.
cached_config_.set_source(setting_getter_->GetConfigSource());
// that we won't lose any updates that may have happened after the initial
// fetch and before setting up notifications. We'll detect the common case
// of no changes in OnCheckProxyConfigSettings() (or sooner) and ignore it.
- if (io_thread_task_runner && file_loop) {
+ if (io_task_runner.get() && file_task_runner.get()) {
scoped_refptr<base::SingleThreadTaskRunner> required_loop =
setting_getter_->GetNotificationTaskRunner();
if (!required_loop.get() || required_loop->BelongsToCurrentThread()) {
ProxyConfigServiceLinux::Delegate::GetLatestProxyConfig(
ProxyConfig* config) {
// This is called from the IO thread.
- DCHECK(!io_thread_task_runner_.get() ||
- io_thread_task_runner_->BelongsToCurrentThread());
+ DCHECK(!io_task_runner_.get() ||
+ io_task_runner_->BelongsToCurrentThread());
// Simply return the last proxy configuration that glib_default_loop
// notified us of.
!new_config.Equals(reference_config_)) {
// Post a task to the IO thread with the new configuration, so it can
// update |cached_config_|.
- io_thread_task_runner_->PostTask(FROM_HERE, base::Bind(
+ io_task_runner_->PostTask(FROM_HERE, base::Bind(
&ProxyConfigServiceLinux::Delegate::SetNewProxyConfig,
this, new_config));
// Update the thread-private copy in |reference_config_| as well.
void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig(
const ProxyConfig& new_config) {
- DCHECK(io_thread_task_runner_->BelongsToCurrentThread());
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
VLOG(1) << "Proxy configuration changed";
cached_config_ = new_config;
FOR_EACH_OBSERVER(