diff options
-rw-r--r-- | net/proxy/proxy_config_service_linux.cc | 26 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_linux_unittest.cc | 18 |
2 files changed, 38 insertions, 6 deletions
diff --git a/net/proxy/proxy_config_service_linux.cc b/net/proxy/proxy_config_service_linux.cc index ad17b36..cd7102b 100644 --- a/net/proxy/proxy_config_service_linux.cc +++ b/net/proxy/proxy_config_service_linux.cc @@ -433,21 +433,35 @@ class GConfSettingGetterImplKDE kde_config_dir_ = KDEHomeToConfigPath(kde_path); } else { // Some distributions patch KDE4 to use .kde4 instead of .kde, so that - // both can be installed side-by-side. They will probably continue to - // use .kde4, even when they no longer provide KDE3, for backwards- - // compatibility. So if there is a .kde4 directory, use that instead of - // .kde for the proxy config. + // both can be installed side-by-side. Sadly they don't all do this, and + // they don't always do this: some distributions have started switching + // back as well. So if there is a .kde4 directory, check the timestamps + // of the config directories within and use the newest one. // Note that we should currently be running in the UI thread, because in // the gconf version, that is the only thread that can access the proxy // settings (a gconf restriction). As noted below, the initial read of // the proxy settings will be done in this thread anyway, so we check // for .kde4 here in this thread as well. + FilePath kde3_path = FilePath(home).Append(".kde"); + FilePath kde3_config = KDEHomeToConfigPath(kde3_path); FilePath kde4_path = FilePath(home).Append(".kde4"); + FilePath kde4_config = KDEHomeToConfigPath(kde4_path); + bool use_kde4 = false; if (file_util::DirectoryExists(kde4_path)) { + file_util::FileInfo kde3_info; + file_util::FileInfo kde4_info; + if (file_util::GetFileInfo(kde4_config, &kde4_info)) { + if (file_util::GetFileInfo(kde3_config, &kde3_info)) { + use_kde4 = kde4_info.last_modified >= kde3_info.last_modified; + } else { + use_kde4 = true; + } + } + } + if (use_kde4) { kde_config_dir_ = KDEHomeToConfigPath(kde4_path); } else { - FilePath kde_path = FilePath(home).Append(".kde"); - kde_config_dir_ = KDEHomeToConfigPath(kde_path); + kde_config_dir_ = KDEHomeToConfigPath(kde3_path); } } } diff --git a/net/proxy/proxy_config_service_linux_unittest.cc b/net/proxy/proxy_config_service_linux_unittest.cc index fb1b016..5a09275 100644 --- a/net/proxy/proxy_config_service_linux_unittest.cc +++ b/net/proxy/proxy_config_service_linux_unittest.cc @@ -1309,6 +1309,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEHomePicker) { } // Now create .kde4 and put a kioslaverc in the config directory. + // Note that its timestamp will be at least as new as the .kde one. file_util::CreateDirectory(kde4_config_); file_util::WriteFile(kioslaverc4_, slaverc4.c_str(), slaverc4.length()); CHECK(file_util::PathExists(kioslaverc4_)); @@ -1352,6 +1353,23 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEHomePicker) { EXPECT_TRUE(config.auto_detect()); EXPECT_EQ(GURL(), config.pac_url()); } + + // Finally, make the .kde4 config directory older than the .kde directory + // and make sure we then use .kde instead of .kde4 since it's newer. + file_util::SetLastModifiedTime(kde4_config_, base::Time()); + + { SCOPED_TRACE("KDE4, very old .kde4 directory present, use .kde"); + MockEnvVarGetter* env_getter = new MockEnvVarGetter; + env_getter->values.DESKTOP_SESSION = "kde4"; + env_getter->values.HOME = user_home_.value().c_str(); + SynchConfigGetter sync_config_getter( + new ProxyConfigServiceLinux(env_getter)); + ProxyConfig config; + sync_config_getter.SetupAndInitialFetch(); + sync_config_getter.SyncGetProxyConfig(&config); + EXPECT_TRUE(config.auto_detect()); + EXPECT_EQ(GURL(), config.pac_url()); + } } } // namespace net |