| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/proxy/proxy_config_service_linux.h" | 5 #include "net/proxy/proxy_config_service_linux.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #if defined(USE_GCONF) | 9 #if defined(USE_GCONF) |
| 10 #include <gconf/gconf-client.h> | 10 #include <gconf/gconf-client.h> |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 } | 515 } |
| 516 DCHECK(!client_); | 516 DCHECK(!client_); |
| 517 #if defined(DLOPEN_GSETTINGS) | 517 #if defined(DLOPEN_GSETTINGS) |
| 518 if (gio_handle_) { | 518 if (gio_handle_) { |
| 519 dlclose(gio_handle_); | 519 dlclose(gio_handle_); |
| 520 gio_handle_ = NULL; | 520 gio_handle_ = NULL; |
| 521 } | 521 } |
| 522 #endif | 522 #endif |
| 523 } | 523 } |
| 524 | 524 |
| 525 bool SchemaExists(const char* schema_name) { |
| 526 const gchar* const* schemas = g_settings_list_schemas(); |
| 527 while (*schemas) { |
| 528 if (strcmp(schema_name, reinterpret_cast<const char*>(schemas)) == 0) |
| 529 return true; |
| 530 schemas++; |
| 531 } |
| 532 return false; |
| 533 } |
| 534 |
| 525 // LoadAndCheckVersion() must be called *before* Init()! | 535 // LoadAndCheckVersion() must be called *before* Init()! |
| 526 bool LoadAndCheckVersion(base::Environment* env); | 536 bool LoadAndCheckVersion(base::Environment* env); |
| 527 | 537 |
| 528 virtual bool Init(MessageLoop* glib_default_loop, | 538 virtual bool Init(MessageLoop* glib_default_loop, |
| 529 MessageLoopForIO* file_loop) { | 539 MessageLoopForIO* file_loop) { |
| 530 DCHECK(MessageLoop::current() == glib_default_loop); | 540 DCHECK(MessageLoop::current() == glib_default_loop); |
| 531 DCHECK(!client_); | 541 DCHECK(!client_); |
| 532 DCHECK(!loop_); | 542 DCHECK(!loop_); |
| 533 client_ = g_settings_new("org.gnome.system.proxy"); | 543 |
| 534 if (!client_) { | 544 if (!SchemaExists("org.gnome.system.proxy") || |
| 545 !(client_ = g_settings_new("org.gnome.system.proxy"))) { |
| 535 // It's not clear whether/when this can return NULL. | 546 // It's not clear whether/when this can return NULL. |
| 536 LOG(ERROR) << "Unable to create a gsettings client"; | 547 LOG(ERROR) << "Unable to create a gsettings client"; |
| 537 return false; | 548 return false; |
| 538 } | 549 } |
| 539 loop_ = glib_default_loop; | 550 loop_ = glib_default_loop; |
| 540 // We assume these all work if the above call worked. | 551 // We assume these all work if the above call worked. |
| 541 http_client_ = g_settings_get_child(client_, "http"); | 552 http_client_ = g_settings_get_child(client_, "http"); |
| 542 https_client_ = g_settings_get_child(client_, "https"); | 553 https_client_ = g_settings_get_child(client_, "https"); |
| 543 ftp_client_ = g_settings_get_child(client_, "ftp"); | 554 ftp_client_ = g_settings_get_child(client_, "ftp"); |
| 544 socks_client_ = g_settings_get_child(client_, "socks"); | 555 socks_client_ = g_settings_get_child(client_, "socks"); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 // conflict both because they are identical and also due to scoping. The | 681 // conflict both because they are identical and also due to scoping. The |
| 671 // scoping will also ensure that these get used instead of the global ones. | 682 // scoping will also ensure that these get used instead of the global ones. |
| 672 struct _GSettings; | 683 struct _GSettings; |
| 673 typedef struct _GSettings GSettings; | 684 typedef struct _GSettings GSettings; |
| 674 GSettings* (*g_settings_new)(const gchar* schema); | 685 GSettings* (*g_settings_new)(const gchar* schema); |
| 675 GSettings* (*g_settings_get_child)(GSettings* settings, const gchar* name); | 686 GSettings* (*g_settings_get_child)(GSettings* settings, const gchar* name); |
| 676 gboolean (*g_settings_get_boolean)(GSettings* settings, const gchar* key); | 687 gboolean (*g_settings_get_boolean)(GSettings* settings, const gchar* key); |
| 677 gchar* (*g_settings_get_string)(GSettings* settings, const gchar* key); | 688 gchar* (*g_settings_get_string)(GSettings* settings, const gchar* key); |
| 678 gint (*g_settings_get_int)(GSettings* settings, const gchar* key); | 689 gint (*g_settings_get_int)(GSettings* settings, const gchar* key); |
| 679 gchar** (*g_settings_get_strv)(GSettings* settings, const gchar* key); | 690 gchar** (*g_settings_get_strv)(GSettings* settings, const gchar* key); |
| 691 const gchar* const* (*g_settings_list_schemas)(); |
| 680 | 692 |
| 681 // The library handle. | 693 // The library handle. |
| 682 void* gio_handle_; | 694 void* gio_handle_; |
| 683 | 695 |
| 684 // Load a symbol from |gio_handle_| and store it into |*func_ptr|. | 696 // Load a symbol from |gio_handle_| and store it into |*func_ptr|. |
| 685 bool LoadSymbol(const char* name, void** func_ptr) { | 697 bool LoadSymbol(const char* name, void** func_ptr) { |
| 686 dlerror(); | 698 dlerror(); |
| 687 *func_ptr = dlsym(gio_handle_, name); | 699 *func_ptr = dlsym(gio_handle_, name); |
| 688 const char* error = dlerror(); | 700 const char* error = dlerror(); |
| 689 if (error) { | 701 if (error) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 reinterpret_cast<void**>(&g_settings_new)) || | 810 reinterpret_cast<void**>(&g_settings_new)) || |
| 799 !LoadSymbol("g_settings_get_child", | 811 !LoadSymbol("g_settings_get_child", |
| 800 reinterpret_cast<void**>(&g_settings_get_child)) || | 812 reinterpret_cast<void**>(&g_settings_get_child)) || |
| 801 !LoadSymbol("g_settings_get_string", | 813 !LoadSymbol("g_settings_get_string", |
| 802 reinterpret_cast<void**>(&g_settings_get_string)) || | 814 reinterpret_cast<void**>(&g_settings_get_string)) || |
| 803 !LoadSymbol("g_settings_get_boolean", | 815 !LoadSymbol("g_settings_get_boolean", |
| 804 reinterpret_cast<void**>(&g_settings_get_boolean)) || | 816 reinterpret_cast<void**>(&g_settings_get_boolean)) || |
| 805 !LoadSymbol("g_settings_get_int", | 817 !LoadSymbol("g_settings_get_int", |
| 806 reinterpret_cast<void**>(&g_settings_get_int)) || | 818 reinterpret_cast<void**>(&g_settings_get_int)) || |
| 807 !LoadSymbol("g_settings_get_strv", | 819 !LoadSymbol("g_settings_get_strv", |
| 808 reinterpret_cast<void**>(&g_settings_get_strv))) { | 820 reinterpret_cast<void**>(&g_settings_get_strv)) || |
| 821 !LoadSymbol("g_settings_list_schemas", |
| 822 reinterpret_cast<void**>(&g_settings_list_schemas))) { |
| 809 VLOG(1) << "Cannot load gsettings API. Will fall back to gconf."; | 823 VLOG(1) << "Cannot load gsettings API. Will fall back to gconf."; |
| 810 dlclose(gio_handle_); | 824 dlclose(gio_handle_); |
| 811 gio_handle_ = NULL; | 825 gio_handle_ = NULL; |
| 812 return false; | 826 return false; |
| 813 } | 827 } |
| 814 #endif | 828 #endif |
| 815 | 829 |
| 816 GSettings* client = g_settings_new("org.gnome.system.proxy"); | 830 GSettings* client; |
| 817 if (!client) { | 831 if (!SchemaExists("org.gnome.system.proxy") || |
| 832 !(client = g_settings_new("org.gnome.system.proxy"))) { |
| 818 VLOG(1) << "Cannot create gsettings client. Will fall back to gconf."; | 833 VLOG(1) << "Cannot create gsettings client. Will fall back to gconf."; |
| 819 return false; | 834 return false; |
| 820 } | 835 } |
| 821 g_object_unref(client); | 836 g_object_unref(client); |
| 822 | 837 |
| 823 std::string path; | 838 std::string path; |
| 824 if (!env->GetVar("PATH", &path)) { | 839 if (!env->GetVar("PATH", &path)) { |
| 825 LOG(ERROR) << "No $PATH variable. Assuming no gnome-network-properties."; | 840 LOG(ERROR) << "No $PATH variable. Assuming no gnome-network-properties."; |
| 826 } else { | 841 } else { |
| 827 // Yes, we're on the UI thread. Yes, we're accessing the file system. | 842 // Yes, we're on the UI thread. Yes, we're accessing the file system. |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1741 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { | 1756 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { |
| 1742 delegate_->RemoveObserver(observer); | 1757 delegate_->RemoveObserver(observer); |
| 1743 } | 1758 } |
| 1744 | 1759 |
| 1745 ProxyConfigService::ConfigAvailability | 1760 ProxyConfigService::ConfigAvailability |
| 1746 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { | 1761 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { |
| 1747 return delegate_->GetLatestProxyConfig(config); | 1762 return delegate_->GetLatestProxyConfig(config); |
| 1748 } | 1763 } |
| 1749 | 1764 |
| 1750 } // namespace net | 1765 } // namespace net |
| OLD | NEW |