| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 199 |
| 200 #if defined(USE_GCONF) | 200 #if defined(USE_GCONF) |
| 201 // This setting getter uses gconf, as used in GNOME 2 and some GNOME 3 desktops. | 201 // This setting getter uses gconf, as used in GNOME 2 and some GNOME 3 desktops. |
| 202 class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { | 202 class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { |
| 203 public: | 203 public: |
| 204 SettingGetterImplGConf() | 204 SettingGetterImplGConf() |
| 205 : client_(NULL), system_proxy_id_(0), system_http_proxy_id_(0), | 205 : client_(NULL), system_proxy_id_(0), system_http_proxy_id_(0), |
| 206 notify_delegate_(NULL) { | 206 notify_delegate_(NULL) { |
| 207 } | 207 } |
| 208 | 208 |
| 209 virtual ~SettingGetterImplGConf() { | 209 ~SettingGetterImplGConf() override { |
| 210 // client_ should have been released before now, from | 210 // client_ should have been released before now, from |
| 211 // Delegate::OnDestroy(), while running on the UI thread. However | 211 // Delegate::OnDestroy(), while running on the UI thread. However |
| 212 // on exiting the process, it may happen that Delegate::OnDestroy() | 212 // on exiting the process, it may happen that Delegate::OnDestroy() |
| 213 // task is left pending on the glib loop after the loop was quit, | 213 // task is left pending on the glib loop after the loop was quit, |
| 214 // and pending tasks may then be deleted without being run. | 214 // and pending tasks may then be deleted without being run. |
| 215 if (client_) { | 215 if (client_) { |
| 216 // gconf client was not cleaned up. | 216 // gconf client was not cleaned up. |
| 217 if (task_runner_->BelongsToCurrentThread()) { | 217 if (task_runner_->BelongsToCurrentThread()) { |
| 218 // We are on the UI thread so we can clean it safely. This is | 218 // We are on the UI thread so we can clean it safely. This is |
| 219 // the case at least for ui_tests running under Valgrind in | 219 // the case at least for ui_tests running under Valgrind in |
| 220 // bug 16076. | 220 // bug 16076. |
| 221 VLOG(1) << "~SettingGetterImplGConf: releasing gconf client"; | 221 VLOG(1) << "~SettingGetterImplGConf: releasing gconf client"; |
| 222 ShutDown(); | 222 ShutDown(); |
| 223 } else { | 223 } else { |
| 224 // This is very bad! We are deleting the setting getter but we're not on | 224 // This is very bad! We are deleting the setting getter but we're not on |
| 225 // the UI thread. This is not supposed to happen: the setting getter is | 225 // the UI thread. This is not supposed to happen: the setting getter is |
| 226 // owned by the proxy config service's delegate, which is supposed to be | 226 // owned by the proxy config service's delegate, which is supposed to be |
| 227 // destroyed on the UI thread only. We will get change notifications to | 227 // destroyed on the UI thread only. We will get change notifications to |
| 228 // a deleted object if we continue here, so fail now. | 228 // a deleted object if we continue here, so fail now. |
| 229 LOG(FATAL) << "~SettingGetterImplGConf: deleting on wrong thread!"; | 229 LOG(FATAL) << "~SettingGetterImplGConf: deleting on wrong thread!"; |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 DCHECK(!client_); | 232 DCHECK(!client_); |
| 233 } | 233 } |
| 234 | 234 |
| 235 virtual bool Init( | 235 bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, |
| 236 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, | 236 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| 237 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) | |
| 238 override { | 237 override { |
| 239 DCHECK(glib_task_runner->BelongsToCurrentThread()); | 238 DCHECK(glib_task_runner->BelongsToCurrentThread()); |
| 240 DCHECK(!client_); | 239 DCHECK(!client_); |
| 241 DCHECK(!task_runner_.get()); | 240 DCHECK(!task_runner_.get()); |
| 242 task_runner_ = glib_task_runner; | 241 task_runner_ = glib_task_runner; |
| 243 client_ = gconf_client_get_default(); | 242 client_ = gconf_client_get_default(); |
| 244 if (!client_) { | 243 if (!client_) { |
| 245 // It's not clear whether/when this can return NULL. | 244 // It's not clear whether/when this can return NULL. |
| 246 LOG(ERROR) << "Unable to create a gconf client"; | 245 LOG(ERROR) << "Unable to create a gconf client"; |
| 247 task_runner_ = NULL; | 246 task_runner_ = NULL; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 266 if (added_system_proxy) | 265 if (added_system_proxy) |
| 267 gconf_client_remove_dir(client_, "/system/proxy", NULL); | 266 gconf_client_remove_dir(client_, "/system/proxy", NULL); |
| 268 g_object_unref(client_); | 267 g_object_unref(client_); |
| 269 client_ = NULL; | 268 client_ = NULL; |
| 270 task_runner_ = NULL; | 269 task_runner_ = NULL; |
| 271 return false; | 270 return false; |
| 272 } | 271 } |
| 273 return true; | 272 return true; |
| 274 } | 273 } |
| 275 | 274 |
| 276 virtual void ShutDown() override { | 275 void ShutDown() override { |
| 277 if (client_) { | 276 if (client_) { |
| 278 DCHECK(task_runner_->BelongsToCurrentThread()); | 277 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 279 // We must explicitly disable gconf notifications here, because the gconf | 278 // We must explicitly disable gconf notifications here, because the gconf |
| 280 // client will be shared between all setting getters, and they do not all | 279 // client will be shared between all setting getters, and they do not all |
| 281 // have the same lifetimes. (For instance, incognito sessions get their | 280 // have the same lifetimes. (For instance, incognito sessions get their |
| 282 // own, which is destroyed when the session ends.) | 281 // own, which is destroyed when the session ends.) |
| 283 gconf_client_notify_remove(client_, system_http_proxy_id_); | 282 gconf_client_notify_remove(client_, system_http_proxy_id_); |
| 284 gconf_client_notify_remove(client_, system_proxy_id_); | 283 gconf_client_notify_remove(client_, system_proxy_id_); |
| 285 gconf_client_remove_dir(client_, "/system/http_proxy", NULL); | 284 gconf_client_remove_dir(client_, "/system/http_proxy", NULL); |
| 286 gconf_client_remove_dir(client_, "/system/proxy", NULL); | 285 gconf_client_remove_dir(client_, "/system/proxy", NULL); |
| 287 g_object_unref(client_); | 286 g_object_unref(client_); |
| 288 client_ = NULL; | 287 client_ = NULL; |
| 289 task_runner_ = NULL; | 288 task_runner_ = NULL; |
| 290 } | 289 } |
| 291 } | 290 } |
| 292 | 291 |
| 293 virtual bool SetUpNotifications( | 292 bool SetUpNotifications( |
| 294 ProxyConfigServiceLinux::Delegate* delegate) override { | 293 ProxyConfigServiceLinux::Delegate* delegate) override { |
| 295 DCHECK(client_); | 294 DCHECK(client_); |
| 296 DCHECK(task_runner_->BelongsToCurrentThread()); | 295 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 297 GError* error = NULL; | 296 GError* error = NULL; |
| 298 notify_delegate_ = delegate; | 297 notify_delegate_ = delegate; |
| 299 // We have to keep track of the IDs returned by gconf_client_notify_add() so | 298 // We have to keep track of the IDs returned by gconf_client_notify_add() so |
| 300 // that we can remove them in ShutDown(). (Otherwise, notifications will be | 299 // that we can remove them in ShutDown(). (Otherwise, notifications will be |
| 301 // delivered to this object after it is deleted, which is bad, m'kay?) | 300 // delivered to this object after it is deleted, which is bad, m'kay?) |
| 302 system_proxy_id_ = gconf_client_notify_add( | 301 system_proxy_id_ = gconf_client_notify_add( |
| 303 client_, "/system/proxy", | 302 client_, "/system/proxy", |
| 304 OnGConfChangeNotification, this, | 303 OnGConfChangeNotification, this, |
| 305 NULL, &error); | 304 NULL, &error); |
| 306 if (error == NULL) { | 305 if (error == NULL) { |
| 307 system_http_proxy_id_ = gconf_client_notify_add( | 306 system_http_proxy_id_ = gconf_client_notify_add( |
| 308 client_, "/system/http_proxy", | 307 client_, "/system/http_proxy", |
| 309 OnGConfChangeNotification, this, | 308 OnGConfChangeNotification, this, |
| 310 NULL, &error); | 309 NULL, &error); |
| 311 } | 310 } |
| 312 if (error != NULL) { | 311 if (error != NULL) { |
| 313 LOG(ERROR) << "Error requesting gconf notifications: " << error->message; | 312 LOG(ERROR) << "Error requesting gconf notifications: " << error->message; |
| 314 g_error_free(error); | 313 g_error_free(error); |
| 315 ShutDown(); | 314 ShutDown(); |
| 316 return false; | 315 return false; |
| 317 } | 316 } |
| 318 // Simulate a change to avoid possibly losing updates before this point. | 317 // Simulate a change to avoid possibly losing updates before this point. |
| 319 OnChangeNotification(); | 318 OnChangeNotification(); |
| 320 return true; | 319 return true; |
| 321 } | 320 } |
| 322 | 321 |
| 323 virtual const scoped_refptr<base::SingleThreadTaskRunner>& | 322 const scoped_refptr<base::SingleThreadTaskRunner>& GetNotificationTaskRunner() |
| 324 GetNotificationTaskRunner() override { | 323 override { |
| 325 return task_runner_; | 324 return task_runner_; |
| 326 } | 325 } |
| 327 | 326 |
| 328 virtual ProxyConfigSource GetConfigSource() override { | 327 ProxyConfigSource GetConfigSource() override { |
| 329 return PROXY_CONFIG_SOURCE_GCONF; | 328 return PROXY_CONFIG_SOURCE_GCONF; |
| 330 } | 329 } |
| 331 | 330 |
| 332 virtual bool GetString(StringSetting key, std::string* result) override { | 331 bool GetString(StringSetting key, std::string* result) override { |
| 333 switch (key) { | 332 switch (key) { |
| 334 case PROXY_MODE: | 333 case PROXY_MODE: |
| 335 return GetStringByPath("/system/proxy/mode", result); | 334 return GetStringByPath("/system/proxy/mode", result); |
| 336 case PROXY_AUTOCONF_URL: | 335 case PROXY_AUTOCONF_URL: |
| 337 return GetStringByPath("/system/proxy/autoconfig_url", result); | 336 return GetStringByPath("/system/proxy/autoconfig_url", result); |
| 338 case PROXY_HTTP_HOST: | 337 case PROXY_HTTP_HOST: |
| 339 return GetStringByPath("/system/http_proxy/host", result); | 338 return GetStringByPath("/system/http_proxy/host", result); |
| 340 case PROXY_HTTPS_HOST: | 339 case PROXY_HTTPS_HOST: |
| 341 return GetStringByPath("/system/proxy/secure_host", result); | 340 return GetStringByPath("/system/proxy/secure_host", result); |
| 342 case PROXY_FTP_HOST: | 341 case PROXY_FTP_HOST: |
| 343 return GetStringByPath("/system/proxy/ftp_host", result); | 342 return GetStringByPath("/system/proxy/ftp_host", result); |
| 344 case PROXY_SOCKS_HOST: | 343 case PROXY_SOCKS_HOST: |
| 345 return GetStringByPath("/system/proxy/socks_host", result); | 344 return GetStringByPath("/system/proxy/socks_host", result); |
| 346 } | 345 } |
| 347 return false; // Placate compiler. | 346 return false; // Placate compiler. |
| 348 } | 347 } |
| 349 virtual bool GetBool(BoolSetting key, bool* result) override { | 348 bool GetBool(BoolSetting key, bool* result) override { |
| 350 switch (key) { | 349 switch (key) { |
| 351 case PROXY_USE_HTTP_PROXY: | 350 case PROXY_USE_HTTP_PROXY: |
| 352 return GetBoolByPath("/system/http_proxy/use_http_proxy", result); | 351 return GetBoolByPath("/system/http_proxy/use_http_proxy", result); |
| 353 case PROXY_USE_SAME_PROXY: | 352 case PROXY_USE_SAME_PROXY: |
| 354 return GetBoolByPath("/system/http_proxy/use_same_proxy", result); | 353 return GetBoolByPath("/system/http_proxy/use_same_proxy", result); |
| 355 case PROXY_USE_AUTHENTICATION: | 354 case PROXY_USE_AUTHENTICATION: |
| 356 return GetBoolByPath("/system/http_proxy/use_authentication", result); | 355 return GetBoolByPath("/system/http_proxy/use_authentication", result); |
| 357 } | 356 } |
| 358 return false; // Placate compiler. | 357 return false; // Placate compiler. |
| 359 } | 358 } |
| 360 virtual bool GetInt(IntSetting key, int* result) override { | 359 bool GetInt(IntSetting key, int* result) override { |
| 361 switch (key) { | 360 switch (key) { |
| 362 case PROXY_HTTP_PORT: | 361 case PROXY_HTTP_PORT: |
| 363 return GetIntByPath("/system/http_proxy/port", result); | 362 return GetIntByPath("/system/http_proxy/port", result); |
| 364 case PROXY_HTTPS_PORT: | 363 case PROXY_HTTPS_PORT: |
| 365 return GetIntByPath("/system/proxy/secure_port", result); | 364 return GetIntByPath("/system/proxy/secure_port", result); |
| 366 case PROXY_FTP_PORT: | 365 case PROXY_FTP_PORT: |
| 367 return GetIntByPath("/system/proxy/ftp_port", result); | 366 return GetIntByPath("/system/proxy/ftp_port", result); |
| 368 case PROXY_SOCKS_PORT: | 367 case PROXY_SOCKS_PORT: |
| 369 return GetIntByPath("/system/proxy/socks_port", result); | 368 return GetIntByPath("/system/proxy/socks_port", result); |
| 370 } | 369 } |
| 371 return false; // Placate compiler. | 370 return false; // Placate compiler. |
| 372 } | 371 } |
| 373 virtual bool GetStringList(StringListSetting key, | 372 bool GetStringList(StringListSetting key, |
| 374 std::vector<std::string>* result) override { | 373 std::vector<std::string>* result) override { |
| 375 switch (key) { | 374 switch (key) { |
| 376 case PROXY_IGNORE_HOSTS: | 375 case PROXY_IGNORE_HOSTS: |
| 377 return GetStringListByPath("/system/http_proxy/ignore_hosts", result); | 376 return GetStringListByPath("/system/http_proxy/ignore_hosts", result); |
| 378 } | 377 } |
| 379 return false; // Placate compiler. | 378 return false; // Placate compiler. |
| 380 } | 379 } |
| 381 | 380 |
| 382 virtual bool BypassListIsReversed() override { | 381 bool BypassListIsReversed() override { |
| 383 // This is a KDE-specific setting. | 382 // This is a KDE-specific setting. |
| 384 return false; | 383 return false; |
| 385 } | 384 } |
| 386 | 385 |
| 387 virtual bool MatchHostsUsingSuffixMatching() override { | 386 bool MatchHostsUsingSuffixMatching() override { return false; } |
| 388 return false; | |
| 389 } | |
| 390 | 387 |
| 391 private: | 388 private: |
| 392 bool GetStringByPath(const char* key, std::string* result) { | 389 bool GetStringByPath(const char* key, std::string* result) { |
| 393 DCHECK(client_); | 390 DCHECK(client_); |
| 394 DCHECK(task_runner_->BelongsToCurrentThread()); | 391 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 395 GError* error = NULL; | 392 GError* error = NULL; |
| 396 gchar* value = gconf_client_get_string(client_, key, &error); | 393 gchar* value = gconf_client_get_string(client_, key, &error); |
| 397 if (HandleGError(error, key)) | 394 if (HandleGError(error, key)) |
| 398 return false; | 395 return false; |
| 399 if (!value) | 396 if (!value) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 public: | 519 public: |
| 523 SettingGetterImplGSettings() : | 520 SettingGetterImplGSettings() : |
| 524 client_(NULL), | 521 client_(NULL), |
| 525 http_client_(NULL), | 522 http_client_(NULL), |
| 526 https_client_(NULL), | 523 https_client_(NULL), |
| 527 ftp_client_(NULL), | 524 ftp_client_(NULL), |
| 528 socks_client_(NULL), | 525 socks_client_(NULL), |
| 529 notify_delegate_(NULL) { | 526 notify_delegate_(NULL) { |
| 530 } | 527 } |
| 531 | 528 |
| 532 virtual ~SettingGetterImplGSettings() { | 529 ~SettingGetterImplGSettings() override { |
| 533 // client_ should have been released before now, from | 530 // client_ should have been released before now, from |
| 534 // Delegate::OnDestroy(), while running on the UI thread. However | 531 // Delegate::OnDestroy(), while running on the UI thread. However |
| 535 // on exiting the process, it may happen that | 532 // on exiting the process, it may happen that |
| 536 // Delegate::OnDestroy() task is left pending on the glib loop | 533 // Delegate::OnDestroy() task is left pending on the glib loop |
| 537 // after the loop was quit, and pending tasks may then be deleted | 534 // after the loop was quit, and pending tasks may then be deleted |
| 538 // without being run. | 535 // without being run. |
| 539 if (client_) { | 536 if (client_) { |
| 540 // gconf client was not cleaned up. | 537 // gconf client was not cleaned up. |
| 541 if (task_runner_->BelongsToCurrentThread()) { | 538 if (task_runner_->BelongsToCurrentThread()) { |
| 542 // We are on the UI thread so we can clean it safely. This is | 539 // We are on the UI thread so we can clean it safely. This is |
| (...skipping 15 matching lines...) Expand all Loading... |
| 558 if (strcmp(schema_name, static_cast<const char*>(*schemas)) == 0) | 555 if (strcmp(schema_name, static_cast<const char*>(*schemas)) == 0) |
| 559 return true; | 556 return true; |
| 560 schemas++; | 557 schemas++; |
| 561 } | 558 } |
| 562 return false; | 559 return false; |
| 563 } | 560 } |
| 564 | 561 |
| 565 // LoadAndCheckVersion() must be called *before* Init()! | 562 // LoadAndCheckVersion() must be called *before* Init()! |
| 566 bool LoadAndCheckVersion(base::Environment* env); | 563 bool LoadAndCheckVersion(base::Environment* env); |
| 567 | 564 |
| 568 virtual bool Init( | 565 bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, |
| 569 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, | 566 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| 570 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) | |
| 571 override { | 567 override { |
| 572 DCHECK(glib_task_runner->BelongsToCurrentThread()); | 568 DCHECK(glib_task_runner->BelongsToCurrentThread()); |
| 573 DCHECK(!client_); | 569 DCHECK(!client_); |
| 574 DCHECK(!task_runner_.get()); | 570 DCHECK(!task_runner_.get()); |
| 575 | 571 |
| 576 if (!SchemaExists(kProxyGConfSchema) || | 572 if (!SchemaExists(kProxyGConfSchema) || |
| 577 !(client_ = libgio_loader_.g_settings_new(kProxyGConfSchema))) { | 573 !(client_ = libgio_loader_.g_settings_new(kProxyGConfSchema))) { |
| 578 // It's not clear whether/when this can return NULL. | 574 // It's not clear whether/when this can return NULL. |
| 579 LOG(ERROR) << "Unable to create a gsettings client"; | 575 LOG(ERROR) << "Unable to create a gsettings client"; |
| 580 return false; | 576 return false; |
| 581 } | 577 } |
| 582 task_runner_ = glib_task_runner; | 578 task_runner_ = glib_task_runner; |
| 583 // We assume these all work if the above call worked. | 579 // We assume these all work if the above call worked. |
| 584 http_client_ = libgio_loader_.g_settings_get_child(client_, "http"); | 580 http_client_ = libgio_loader_.g_settings_get_child(client_, "http"); |
| 585 https_client_ = libgio_loader_.g_settings_get_child(client_, "https"); | 581 https_client_ = libgio_loader_.g_settings_get_child(client_, "https"); |
| 586 ftp_client_ = libgio_loader_.g_settings_get_child(client_, "ftp"); | 582 ftp_client_ = libgio_loader_.g_settings_get_child(client_, "ftp"); |
| 587 socks_client_ = libgio_loader_.g_settings_get_child(client_, "socks"); | 583 socks_client_ = libgio_loader_.g_settings_get_child(client_, "socks"); |
| 588 DCHECK(http_client_ && https_client_ && ftp_client_ && socks_client_); | 584 DCHECK(http_client_ && https_client_ && ftp_client_ && socks_client_); |
| 589 return true; | 585 return true; |
| 590 } | 586 } |
| 591 | 587 |
| 592 virtual void ShutDown() override { | 588 void ShutDown() override { |
| 593 if (client_) { | 589 if (client_) { |
| 594 DCHECK(task_runner_->BelongsToCurrentThread()); | 590 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 595 // This also disables gsettings notifications. | 591 // This also disables gsettings notifications. |
| 596 g_object_unref(socks_client_); | 592 g_object_unref(socks_client_); |
| 597 g_object_unref(ftp_client_); | 593 g_object_unref(ftp_client_); |
| 598 g_object_unref(https_client_); | 594 g_object_unref(https_client_); |
| 599 g_object_unref(http_client_); | 595 g_object_unref(http_client_); |
| 600 g_object_unref(client_); | 596 g_object_unref(client_); |
| 601 // We only need to null client_ because it's the only one that we check. | 597 // We only need to null client_ because it's the only one that we check. |
| 602 client_ = NULL; | 598 client_ = NULL; |
| 603 task_runner_ = NULL; | 599 task_runner_ = NULL; |
| 604 } | 600 } |
| 605 } | 601 } |
| 606 | 602 |
| 607 virtual bool SetUpNotifications( | 603 bool SetUpNotifications( |
| 608 ProxyConfigServiceLinux::Delegate* delegate) override { | 604 ProxyConfigServiceLinux::Delegate* delegate) override { |
| 609 DCHECK(client_); | 605 DCHECK(client_); |
| 610 DCHECK(task_runner_->BelongsToCurrentThread()); | 606 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 611 notify_delegate_ = delegate; | 607 notify_delegate_ = delegate; |
| 612 // We could watch for the change-event signal instead of changed, but | 608 // We could watch for the change-event signal instead of changed, but |
| 613 // since we have to watch more than one object, we'd still have to | 609 // since we have to watch more than one object, we'd still have to |
| 614 // debounce change notifications. This is conceptually simpler. | 610 // debounce change notifications. This is conceptually simpler. |
| 615 g_signal_connect(G_OBJECT(client_), "changed", | 611 g_signal_connect(G_OBJECT(client_), "changed", |
| 616 G_CALLBACK(OnGSettingsChangeNotification), this); | 612 G_CALLBACK(OnGSettingsChangeNotification), this); |
| 617 g_signal_connect(G_OBJECT(http_client_), "changed", | 613 g_signal_connect(G_OBJECT(http_client_), "changed", |
| 618 G_CALLBACK(OnGSettingsChangeNotification), this); | 614 G_CALLBACK(OnGSettingsChangeNotification), this); |
| 619 g_signal_connect(G_OBJECT(https_client_), "changed", | 615 g_signal_connect(G_OBJECT(https_client_), "changed", |
| 620 G_CALLBACK(OnGSettingsChangeNotification), this); | 616 G_CALLBACK(OnGSettingsChangeNotification), this); |
| 621 g_signal_connect(G_OBJECT(ftp_client_), "changed", | 617 g_signal_connect(G_OBJECT(ftp_client_), "changed", |
| 622 G_CALLBACK(OnGSettingsChangeNotification), this); | 618 G_CALLBACK(OnGSettingsChangeNotification), this); |
| 623 g_signal_connect(G_OBJECT(socks_client_), "changed", | 619 g_signal_connect(G_OBJECT(socks_client_), "changed", |
| 624 G_CALLBACK(OnGSettingsChangeNotification), this); | 620 G_CALLBACK(OnGSettingsChangeNotification), this); |
| 625 // Simulate a change to avoid possibly losing updates before this point. | 621 // Simulate a change to avoid possibly losing updates before this point. |
| 626 OnChangeNotification(); | 622 OnChangeNotification(); |
| 627 return true; | 623 return true; |
| 628 } | 624 } |
| 629 | 625 |
| 630 virtual const scoped_refptr<base::SingleThreadTaskRunner>& | 626 const scoped_refptr<base::SingleThreadTaskRunner>& GetNotificationTaskRunner() |
| 631 GetNotificationTaskRunner() override { | 627 override { |
| 632 return task_runner_; | 628 return task_runner_; |
| 633 } | 629 } |
| 634 | 630 |
| 635 virtual ProxyConfigSource GetConfigSource() override { | 631 ProxyConfigSource GetConfigSource() override { |
| 636 return PROXY_CONFIG_SOURCE_GSETTINGS; | 632 return PROXY_CONFIG_SOURCE_GSETTINGS; |
| 637 } | 633 } |
| 638 | 634 |
| 639 virtual bool GetString(StringSetting key, std::string* result) override { | 635 bool GetString(StringSetting key, std::string* result) override { |
| 640 DCHECK(client_); | 636 DCHECK(client_); |
| 641 switch (key) { | 637 switch (key) { |
| 642 case PROXY_MODE: | 638 case PROXY_MODE: |
| 643 return GetStringByPath(client_, "mode", result); | 639 return GetStringByPath(client_, "mode", result); |
| 644 case PROXY_AUTOCONF_URL: | 640 case PROXY_AUTOCONF_URL: |
| 645 return GetStringByPath(client_, "autoconfig-url", result); | 641 return GetStringByPath(client_, "autoconfig-url", result); |
| 646 case PROXY_HTTP_HOST: | 642 case PROXY_HTTP_HOST: |
| 647 return GetStringByPath(http_client_, "host", result); | 643 return GetStringByPath(http_client_, "host", result); |
| 648 case PROXY_HTTPS_HOST: | 644 case PROXY_HTTPS_HOST: |
| 649 return GetStringByPath(https_client_, "host", result); | 645 return GetStringByPath(https_client_, "host", result); |
| 650 case PROXY_FTP_HOST: | 646 case PROXY_FTP_HOST: |
| 651 return GetStringByPath(ftp_client_, "host", result); | 647 return GetStringByPath(ftp_client_, "host", result); |
| 652 case PROXY_SOCKS_HOST: | 648 case PROXY_SOCKS_HOST: |
| 653 return GetStringByPath(socks_client_, "host", result); | 649 return GetStringByPath(socks_client_, "host", result); |
| 654 } | 650 } |
| 655 return false; // Placate compiler. | 651 return false; // Placate compiler. |
| 656 } | 652 } |
| 657 virtual bool GetBool(BoolSetting key, bool* result) override { | 653 bool GetBool(BoolSetting key, bool* result) override { |
| 658 DCHECK(client_); | 654 DCHECK(client_); |
| 659 switch (key) { | 655 switch (key) { |
| 660 case PROXY_USE_HTTP_PROXY: | 656 case PROXY_USE_HTTP_PROXY: |
| 661 // Although there is an "enabled" boolean in http_client_, it is not set | 657 // Although there is an "enabled" boolean in http_client_, it is not set |
| 662 // to true by the proxy config utility. We ignore it and return false. | 658 // to true by the proxy config utility. We ignore it and return false. |
| 663 return false; | 659 return false; |
| 664 case PROXY_USE_SAME_PROXY: | 660 case PROXY_USE_SAME_PROXY: |
| 665 // Similarly, although there is a "use-same-proxy" boolean in client_, | 661 // Similarly, although there is a "use-same-proxy" boolean in client_, |
| 666 // it is never set to false by the proxy config utility. We ignore it. | 662 // it is never set to false by the proxy config utility. We ignore it. |
| 667 return false; | 663 return false; |
| 668 case PROXY_USE_AUTHENTICATION: | 664 case PROXY_USE_AUTHENTICATION: |
| 669 // There is also no way to set this in the proxy config utility, but it | 665 // There is also no way to set this in the proxy config utility, but it |
| 670 // doesn't hurt us to get the actual setting (unlike the two above). | 666 // doesn't hurt us to get the actual setting (unlike the two above). |
| 671 return GetBoolByPath(http_client_, "use-authentication", result); | 667 return GetBoolByPath(http_client_, "use-authentication", result); |
| 672 } | 668 } |
| 673 return false; // Placate compiler. | 669 return false; // Placate compiler. |
| 674 } | 670 } |
| 675 virtual bool GetInt(IntSetting key, int* result) override { | 671 bool GetInt(IntSetting key, int* result) override { |
| 676 DCHECK(client_); | 672 DCHECK(client_); |
| 677 switch (key) { | 673 switch (key) { |
| 678 case PROXY_HTTP_PORT: | 674 case PROXY_HTTP_PORT: |
| 679 return GetIntByPath(http_client_, "port", result); | 675 return GetIntByPath(http_client_, "port", result); |
| 680 case PROXY_HTTPS_PORT: | 676 case PROXY_HTTPS_PORT: |
| 681 return GetIntByPath(https_client_, "port", result); | 677 return GetIntByPath(https_client_, "port", result); |
| 682 case PROXY_FTP_PORT: | 678 case PROXY_FTP_PORT: |
| 683 return GetIntByPath(ftp_client_, "port", result); | 679 return GetIntByPath(ftp_client_, "port", result); |
| 684 case PROXY_SOCKS_PORT: | 680 case PROXY_SOCKS_PORT: |
| 685 return GetIntByPath(socks_client_, "port", result); | 681 return GetIntByPath(socks_client_, "port", result); |
| 686 } | 682 } |
| 687 return false; // Placate compiler. | 683 return false; // Placate compiler. |
| 688 } | 684 } |
| 689 virtual bool GetStringList(StringListSetting key, | 685 bool GetStringList(StringListSetting key, |
| 690 std::vector<std::string>* result) override { | 686 std::vector<std::string>* result) override { |
| 691 DCHECK(client_); | 687 DCHECK(client_); |
| 692 switch (key) { | 688 switch (key) { |
| 693 case PROXY_IGNORE_HOSTS: | 689 case PROXY_IGNORE_HOSTS: |
| 694 return GetStringListByPath(client_, "ignore-hosts", result); | 690 return GetStringListByPath(client_, "ignore-hosts", result); |
| 695 } | 691 } |
| 696 return false; // Placate compiler. | 692 return false; // Placate compiler. |
| 697 } | 693 } |
| 698 | 694 |
| 699 virtual bool BypassListIsReversed() override { | 695 bool BypassListIsReversed() override { |
| 700 // This is a KDE-specific setting. | 696 // This is a KDE-specific setting. |
| 701 return false; | 697 return false; |
| 702 } | 698 } |
| 703 | 699 |
| 704 virtual bool MatchHostsUsingSuffixMatching() override { | 700 bool MatchHostsUsingSuffixMatching() override { return false; } |
| 705 return false; | |
| 706 } | |
| 707 | 701 |
| 708 private: | 702 private: |
| 709 bool GetStringByPath(GSettings* client, const char* key, | 703 bool GetStringByPath(GSettings* client, const char* key, |
| 710 std::string* result) { | 704 std::string* result) { |
| 711 DCHECK(task_runner_->BelongsToCurrentThread()); | 705 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 712 gchar* value = libgio_loader_.g_settings_get_string(client, key); | 706 gchar* value = libgio_loader_.g_settings_get_string(client, key); |
| 713 if (!value) | 707 if (!value) |
| 714 return false; | 708 return false; |
| 715 *result = value; | 709 *result = value; |
| 716 g_free(value); | 710 g_free(value); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 } | 903 } |
| 910 if (use_kde4) { | 904 if (use_kde4) { |
| 911 kde_config_dir_ = KDEHomeToConfigPath(kde4_path); | 905 kde_config_dir_ = KDEHomeToConfigPath(kde4_path); |
| 912 } else { | 906 } else { |
| 913 kde_config_dir_ = KDEHomeToConfigPath(kde3_path); | 907 kde_config_dir_ = KDEHomeToConfigPath(kde3_path); |
| 914 } | 908 } |
| 915 } | 909 } |
| 916 } | 910 } |
| 917 } | 911 } |
| 918 | 912 |
| 919 virtual ~SettingGetterImplKDE() { | 913 ~SettingGetterImplKDE() override { |
| 920 // inotify_fd_ should have been closed before now, from | 914 // inotify_fd_ should have been closed before now, from |
| 921 // Delegate::OnDestroy(), while running on the file thread. However | 915 // Delegate::OnDestroy(), while running on the file thread. However |
| 922 // on exiting the process, it may happen that Delegate::OnDestroy() | 916 // on exiting the process, it may happen that Delegate::OnDestroy() |
| 923 // task is left pending on the file loop after the loop was quit, | 917 // task is left pending on the file loop after the loop was quit, |
| 924 // and pending tasks may then be deleted without being run. | 918 // and pending tasks may then be deleted without being run. |
| 925 // Here in the KDE version, we can safely close the file descriptor | 919 // Here in the KDE version, we can safely close the file descriptor |
| 926 // anyway. (Not that it really matters; the process is exiting.) | 920 // anyway. (Not that it really matters; the process is exiting.) |
| 927 if (inotify_fd_ >= 0) | 921 if (inotify_fd_ >= 0) |
| 928 ShutDown(); | 922 ShutDown(); |
| 929 DCHECK(inotify_fd_ < 0); | 923 DCHECK(inotify_fd_ < 0); |
| 930 } | 924 } |
| 931 | 925 |
| 932 virtual bool Init( | 926 bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, |
| 933 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, | 927 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| 934 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) | |
| 935 override { | 928 override { |
| 936 // This has to be called on the UI thread (http://crbug.com/69057). | 929 // This has to be called on the UI thread (http://crbug.com/69057). |
| 937 base::ThreadRestrictions::ScopedAllowIO allow_io; | 930 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 938 DCHECK(inotify_fd_ < 0); | 931 DCHECK(inotify_fd_ < 0); |
| 939 inotify_fd_ = inotify_init(); | 932 inotify_fd_ = inotify_init(); |
| 940 if (inotify_fd_ < 0) { | 933 if (inotify_fd_ < 0) { |
| 941 PLOG(ERROR) << "inotify_init failed"; | 934 PLOG(ERROR) << "inotify_init failed"; |
| 942 return false; | 935 return false; |
| 943 } | 936 } |
| 944 int flags = fcntl(inotify_fd_, F_GETFL); | 937 int flags = fcntl(inotify_fd_, F_GETFL); |
| 945 if (fcntl(inotify_fd_, F_SETFL, flags | O_NONBLOCK) < 0) { | 938 if (fcntl(inotify_fd_, F_SETFL, flags | O_NONBLOCK) < 0) { |
| 946 PLOG(ERROR) << "fcntl failed"; | 939 PLOG(ERROR) << "fcntl failed"; |
| 947 close(inotify_fd_); | 940 close(inotify_fd_); |
| 948 inotify_fd_ = -1; | 941 inotify_fd_ = -1; |
| 949 return false; | 942 return false; |
| 950 } | 943 } |
| 951 file_task_runner_ = file_task_runner; | 944 file_task_runner_ = file_task_runner; |
| 952 // The initial read is done on the current thread, not | 945 // The initial read is done on the current thread, not |
| 953 // |file_task_runner_|, since we will need to have it for | 946 // |file_task_runner_|, since we will need to have it for |
| 954 // SetUpAndFetchInitialConfig(). | 947 // SetUpAndFetchInitialConfig(). |
| 955 UpdateCachedSettings(); | 948 UpdateCachedSettings(); |
| 956 return true; | 949 return true; |
| 957 } | 950 } |
| 958 | 951 |
| 959 virtual void ShutDown() override { | 952 void ShutDown() override { |
| 960 if (inotify_fd_ >= 0) { | 953 if (inotify_fd_ >= 0) { |
| 961 ResetCachedSettings(); | 954 ResetCachedSettings(); |
| 962 inotify_watcher_.StopWatchingFileDescriptor(); | 955 inotify_watcher_.StopWatchingFileDescriptor(); |
| 963 close(inotify_fd_); | 956 close(inotify_fd_); |
| 964 inotify_fd_ = -1; | 957 inotify_fd_ = -1; |
| 965 } | 958 } |
| 966 } | 959 } |
| 967 | 960 |
| 968 virtual bool SetUpNotifications( | 961 bool SetUpNotifications( |
| 969 ProxyConfigServiceLinux::Delegate* delegate) override { | 962 ProxyConfigServiceLinux::Delegate* delegate) override { |
| 970 DCHECK(inotify_fd_ >= 0); | 963 DCHECK(inotify_fd_ >= 0); |
| 971 DCHECK(file_task_runner_->BelongsToCurrentThread()); | 964 DCHECK(file_task_runner_->BelongsToCurrentThread()); |
| 972 // We can't just watch the kioslaverc file directly, since KDE will write | 965 // We can't just watch the kioslaverc file directly, since KDE will write |
| 973 // a new copy of it and then rename it whenever settings are changed and | 966 // a new copy of it and then rename it whenever settings are changed and |
| 974 // inotify watches inodes (so we'll be watching the old deleted file after | 967 // inotify watches inodes (so we'll be watching the old deleted file after |
| 975 // the first change, and it will never change again). So, we watch the | 968 // the first change, and it will never change again). So, we watch the |
| 976 // directory instead. We then act only on changes to the kioslaverc entry. | 969 // directory instead. We then act only on changes to the kioslaverc entry. |
| 977 if (inotify_add_watch(inotify_fd_, kde_config_dir_.value().c_str(), | 970 if (inotify_add_watch(inotify_fd_, kde_config_dir_.value().c_str(), |
| 978 IN_MODIFY | IN_MOVED_TO) < 0) { | 971 IN_MODIFY | IN_MOVED_TO) < 0) { |
| 979 return false; | 972 return false; |
| 980 } | 973 } |
| 981 notify_delegate_ = delegate; | 974 notify_delegate_ = delegate; |
| 982 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( | 975 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 983 inotify_fd_, true, base::MessageLoopForIO::WATCH_READ, | 976 inotify_fd_, true, base::MessageLoopForIO::WATCH_READ, |
| 984 &inotify_watcher_, this)) { | 977 &inotify_watcher_, this)) { |
| 985 return false; | 978 return false; |
| 986 } | 979 } |
| 987 // Simulate a change to avoid possibly losing updates before this point. | 980 // Simulate a change to avoid possibly losing updates before this point. |
| 988 OnChangeNotification(); | 981 OnChangeNotification(); |
| 989 return true; | 982 return true; |
| 990 } | 983 } |
| 991 | 984 |
| 992 virtual const scoped_refptr<base::SingleThreadTaskRunner>& | 985 const scoped_refptr<base::SingleThreadTaskRunner>& GetNotificationTaskRunner() |
| 993 GetNotificationTaskRunner() override { | 986 override { |
| 994 return file_task_runner_; | 987 return file_task_runner_; |
| 995 } | 988 } |
| 996 | 989 |
| 997 // Implement base::MessagePumpLibevent::Watcher. | 990 // Implement base::MessagePumpLibevent::Watcher. |
| 998 virtual void OnFileCanReadWithoutBlocking(int fd) override { | 991 void OnFileCanReadWithoutBlocking(int fd) override { |
| 999 DCHECK_EQ(fd, inotify_fd_); | 992 DCHECK_EQ(fd, inotify_fd_); |
| 1000 DCHECK(file_task_runner_->BelongsToCurrentThread()); | 993 DCHECK(file_task_runner_->BelongsToCurrentThread()); |
| 1001 OnChangeNotification(); | 994 OnChangeNotification(); |
| 1002 } | 995 } |
| 1003 virtual void OnFileCanWriteWithoutBlocking(int fd) override { | 996 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } |
| 1004 NOTREACHED(); | |
| 1005 } | |
| 1006 | 997 |
| 1007 virtual ProxyConfigSource GetConfigSource() override { | 998 ProxyConfigSource GetConfigSource() override { |
| 1008 return PROXY_CONFIG_SOURCE_KDE; | 999 return PROXY_CONFIG_SOURCE_KDE; |
| 1009 } | 1000 } |
| 1010 | 1001 |
| 1011 virtual bool GetString(StringSetting key, std::string* result) override { | 1002 bool GetString(StringSetting key, std::string* result) override { |
| 1012 string_map_type::iterator it = string_table_.find(key); | 1003 string_map_type::iterator it = string_table_.find(key); |
| 1013 if (it == string_table_.end()) | 1004 if (it == string_table_.end()) |
| 1014 return false; | 1005 return false; |
| 1015 *result = it->second; | 1006 *result = it->second; |
| 1016 return true; | 1007 return true; |
| 1017 } | 1008 } |
| 1018 virtual bool GetBool(BoolSetting key, bool* result) override { | 1009 bool GetBool(BoolSetting key, bool* result) override { |
| 1019 // We don't ever have any booleans. | 1010 // We don't ever have any booleans. |
| 1020 return false; | 1011 return false; |
| 1021 } | 1012 } |
| 1022 virtual bool GetInt(IntSetting key, int* result) override { | 1013 bool GetInt(IntSetting key, int* result) override { |
| 1023 // We don't ever have any integers. (See AddProxy() below about ports.) | 1014 // We don't ever have any integers. (See AddProxy() below about ports.) |
| 1024 return false; | 1015 return false; |
| 1025 } | 1016 } |
| 1026 virtual bool GetStringList(StringListSetting key, | 1017 bool GetStringList(StringListSetting key, |
| 1027 std::vector<std::string>* result) override { | 1018 std::vector<std::string>* result) override { |
| 1028 strings_map_type::iterator it = strings_table_.find(key); | 1019 strings_map_type::iterator it = strings_table_.find(key); |
| 1029 if (it == strings_table_.end()) | 1020 if (it == strings_table_.end()) |
| 1030 return false; | 1021 return false; |
| 1031 *result = it->second; | 1022 *result = it->second; |
| 1032 return true; | 1023 return true; |
| 1033 } | 1024 } |
| 1034 | 1025 |
| 1035 virtual bool BypassListIsReversed() override { | 1026 bool BypassListIsReversed() override { return reversed_bypass_list_; } |
| 1036 return reversed_bypass_list_; | |
| 1037 } | |
| 1038 | 1027 |
| 1039 virtual bool MatchHostsUsingSuffixMatching() override { | 1028 bool MatchHostsUsingSuffixMatching() override { return true; } |
| 1040 return true; | |
| 1041 } | |
| 1042 | 1029 |
| 1043 private: | 1030 private: |
| 1044 void ResetCachedSettings() { | 1031 void ResetCachedSettings() { |
| 1045 string_table_.clear(); | 1032 string_table_.clear(); |
| 1046 strings_table_.clear(); | 1033 strings_table_.clear(); |
| 1047 indirect_manual_ = false; | 1034 indirect_manual_ = false; |
| 1048 auto_no_pac_ = false; | 1035 auto_no_pac_ = false; |
| 1049 reversed_bypass_list_ = false; | 1036 reversed_bypass_list_ = false; |
| 1050 } | 1037 } |
| 1051 | 1038 |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1773 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { | 1760 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { |
| 1774 delegate_->RemoveObserver(observer); | 1761 delegate_->RemoveObserver(observer); |
| 1775 } | 1762 } |
| 1776 | 1763 |
| 1777 ProxyConfigService::ConfigAvailability | 1764 ProxyConfigService::ConfigAvailability |
| 1778 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { | 1765 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { |
| 1779 return delegate_->GetLatestProxyConfig(config); | 1766 return delegate_->GetLatestProxyConfig(config); |
| 1780 } | 1767 } |
| 1781 | 1768 |
| 1782 } // namespace net | 1769 } // namespace net |
| OLD | NEW |