X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fnet%2Fproxy%2Fproxy_config_service_linux.cc;h=4e9065e1cce928ac3f89ad28911bc0910e230e95;hb=3545e9f2671f595d2a2f3ee75ca0393b01e35ef6;hp=158fd5c1ff72d405eacec058b746d97065f7317b;hpb=7d210d4c7e9ba36e635eabc5b5780495f8a63292;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/net/proxy/proxy_config_service_linux.cc b/src/net/proxy/proxy_config_service_linux.cc index 158fd5c..4e9065e 100644 --- a/src/net/proxy/proxy_config_service_linux.cc +++ b/src/net/proxy/proxy_config_service_linux.cc @@ -4,15 +4,6 @@ #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 #include #if defined(USE_GCONF) @@ -30,8 +21,8 @@ #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" @@ -241,12 +232,14 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { 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& glib_task_runner, + const scoped_refptr& 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. @@ -327,8 +320,9 @@ class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { return true; } - virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { - return task_runner_.get(); + virtual const scoped_refptr& + GetNotificationTaskRunner() OVERRIDE { + return task_runner_; } virtual ProxyConfigSource GetConfigSource() OVERRIDE { @@ -571,9 +565,11 @@ class SettingGetterImplGSettings // 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& glib_task_runner, + const scoped_refptr& file_task_runner) + OVERRIDE { + DCHECK(glib_task_runner->BelongsToCurrentThread()); DCHECK(!client_); DCHECK(!task_runner_.get()); @@ -583,7 +579,7 @@ class SettingGetterImplGSettings 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"); @@ -631,8 +627,9 @@ class SettingGetterImplGSettings return true; } - virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { - return task_runner_.get(); + virtual const scoped_refptr& + GetNotificationTaskRunner() OVERRIDE { + return task_runner_; } virtual ProxyConfigSource GetConfigSource() OVERRIDE { @@ -863,7 +860,7 @@ class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, 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; @@ -932,8 +929,10 @@ class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, DCHECK(inotify_fd_ < 0); } - virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, - base::MessageLoopForIO* file_loop) OVERRIDE { + virtual bool Init( + const scoped_refptr& glib_task_runner, + const scoped_refptr& 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); @@ -949,9 +948,10 @@ class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, 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; } @@ -968,35 +968,36 @@ class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, 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& + 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 { @@ -1262,7 +1263,7 @@ class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, // 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_); @@ -1275,7 +1276,7 @@ class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, // 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; @@ -1345,10 +1346,10 @@ class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, 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 file_task_runner_; DISALLOW_COPY_AND_ASSIGN(SettingGetterImplKDE); }; @@ -1565,20 +1566,19 @@ ProxyConfigServiceLinux::Delegate::Delegate( } void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig( - base::SingleThreadTaskRunner* glib_thread_task_runner, - base::SingleThreadTaskRunner* io_thread_task_runner, - base::MessageLoopForIO* file_loop) { + const scoped_refptr& glib_task_runner, + const scoped_refptr& io_task_runner, + const scoped_refptr& 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 @@ -1595,7 +1595,7 @@ void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig( 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()); @@ -1620,7 +1620,7 @@ void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig( // 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 required_loop = setting_getter_->GetNotificationTaskRunner(); if (!required_loop.get() || required_loop->BelongsToCurrentThread()) { @@ -1669,8 +1669,8 @@ ProxyConfigService::ConfigAvailability 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. @@ -1705,7 +1705,7 @@ void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() { !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. @@ -1717,7 +1717,7 @@ void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() { 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(