Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: net/proxy/proxy_config_service_linux.cc

Issue 623213004: replace OVERRIDE and FINAL with override and final in net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: undo unwanted change in comment Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 virtual bool Init(
236 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, 236 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
237 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) 237 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
238 OVERRIDE { 238 override {
239 DCHECK(glib_task_runner->BelongsToCurrentThread()); 239 DCHECK(glib_task_runner->BelongsToCurrentThread());
240 DCHECK(!client_); 240 DCHECK(!client_);
241 DCHECK(!task_runner_.get()); 241 DCHECK(!task_runner_.get());
242 task_runner_ = glib_task_runner; 242 task_runner_ = glib_task_runner;
243 client_ = gconf_client_get_default(); 243 client_ = gconf_client_get_default();
244 if (!client_) { 244 if (!client_) {
245 // It's not clear whether/when this can return NULL. 245 // It's not clear whether/when this can return NULL.
246 LOG(ERROR) << "Unable to create a gconf client"; 246 LOG(ERROR) << "Unable to create a gconf client";
247 task_runner_ = NULL; 247 task_runner_ = NULL;
248 return false; 248 return false;
(...skipping 17 matching lines...) Expand all
266 if (added_system_proxy) 266 if (added_system_proxy)
267 gconf_client_remove_dir(client_, "/system/proxy", NULL); 267 gconf_client_remove_dir(client_, "/system/proxy", NULL);
268 g_object_unref(client_); 268 g_object_unref(client_);
269 client_ = NULL; 269 client_ = NULL;
270 task_runner_ = NULL; 270 task_runner_ = NULL;
271 return false; 271 return false;
272 } 272 }
273 return true; 273 return true;
274 } 274 }
275 275
276 virtual void ShutDown() OVERRIDE { 276 virtual void ShutDown() override {
277 if (client_) { 277 if (client_) {
278 DCHECK(task_runner_->BelongsToCurrentThread()); 278 DCHECK(task_runner_->BelongsToCurrentThread());
279 // We must explicitly disable gconf notifications here, because the gconf 279 // We must explicitly disable gconf notifications here, because the gconf
280 // client will be shared between all setting getters, and they do not all 280 // client will be shared between all setting getters, and they do not all
281 // have the same lifetimes. (For instance, incognito sessions get their 281 // have the same lifetimes. (For instance, incognito sessions get their
282 // own, which is destroyed when the session ends.) 282 // own, which is destroyed when the session ends.)
283 gconf_client_notify_remove(client_, system_http_proxy_id_); 283 gconf_client_notify_remove(client_, system_http_proxy_id_);
284 gconf_client_notify_remove(client_, system_proxy_id_); 284 gconf_client_notify_remove(client_, system_proxy_id_);
285 gconf_client_remove_dir(client_, "/system/http_proxy", NULL); 285 gconf_client_remove_dir(client_, "/system/http_proxy", NULL);
286 gconf_client_remove_dir(client_, "/system/proxy", NULL); 286 gconf_client_remove_dir(client_, "/system/proxy", NULL);
287 g_object_unref(client_); 287 g_object_unref(client_);
288 client_ = NULL; 288 client_ = NULL;
289 task_runner_ = NULL; 289 task_runner_ = NULL;
290 } 290 }
291 } 291 }
292 292
293 virtual bool SetUpNotifications( 293 virtual bool SetUpNotifications(
294 ProxyConfigServiceLinux::Delegate* delegate) OVERRIDE { 294 ProxyConfigServiceLinux::Delegate* delegate) override {
295 DCHECK(client_); 295 DCHECK(client_);
296 DCHECK(task_runner_->BelongsToCurrentThread()); 296 DCHECK(task_runner_->BelongsToCurrentThread());
297 GError* error = NULL; 297 GError* error = NULL;
298 notify_delegate_ = delegate; 298 notify_delegate_ = delegate;
299 // We have to keep track of the IDs returned by gconf_client_notify_add() so 299 // 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 300 // 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?) 301 // delivered to this object after it is deleted, which is bad, m'kay?)
302 system_proxy_id_ = gconf_client_notify_add( 302 system_proxy_id_ = gconf_client_notify_add(
303 client_, "/system/proxy", 303 client_, "/system/proxy",
304 OnGConfChangeNotification, this, 304 OnGConfChangeNotification, this,
305 NULL, &error); 305 NULL, &error);
306 if (error == NULL) { 306 if (error == NULL) {
307 system_http_proxy_id_ = gconf_client_notify_add( 307 system_http_proxy_id_ = gconf_client_notify_add(
308 client_, "/system/http_proxy", 308 client_, "/system/http_proxy",
309 OnGConfChangeNotification, this, 309 OnGConfChangeNotification, this,
310 NULL, &error); 310 NULL, &error);
311 } 311 }
312 if (error != NULL) { 312 if (error != NULL) {
313 LOG(ERROR) << "Error requesting gconf notifications: " << error->message; 313 LOG(ERROR) << "Error requesting gconf notifications: " << error->message;
314 g_error_free(error); 314 g_error_free(error);
315 ShutDown(); 315 ShutDown();
316 return false; 316 return false;
317 } 317 }
318 // Simulate a change to avoid possibly losing updates before this point. 318 // Simulate a change to avoid possibly losing updates before this point.
319 OnChangeNotification(); 319 OnChangeNotification();
320 return true; 320 return true;
321 } 321 }
322 322
323 virtual const scoped_refptr<base::SingleThreadTaskRunner>& 323 virtual const scoped_refptr<base::SingleThreadTaskRunner>&
324 GetNotificationTaskRunner() OVERRIDE { 324 GetNotificationTaskRunner() override {
325 return task_runner_; 325 return task_runner_;
326 } 326 }
327 327
328 virtual ProxyConfigSource GetConfigSource() OVERRIDE { 328 virtual ProxyConfigSource GetConfigSource() override {
329 return PROXY_CONFIG_SOURCE_GCONF; 329 return PROXY_CONFIG_SOURCE_GCONF;
330 } 330 }
331 331
332 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { 332 virtual bool GetString(StringSetting key, std::string* result) override {
333 switch (key) { 333 switch (key) {
334 case PROXY_MODE: 334 case PROXY_MODE:
335 return GetStringByPath("/system/proxy/mode", result); 335 return GetStringByPath("/system/proxy/mode", result);
336 case PROXY_AUTOCONF_URL: 336 case PROXY_AUTOCONF_URL:
337 return GetStringByPath("/system/proxy/autoconfig_url", result); 337 return GetStringByPath("/system/proxy/autoconfig_url", result);
338 case PROXY_HTTP_HOST: 338 case PROXY_HTTP_HOST:
339 return GetStringByPath("/system/http_proxy/host", result); 339 return GetStringByPath("/system/http_proxy/host", result);
340 case PROXY_HTTPS_HOST: 340 case PROXY_HTTPS_HOST:
341 return GetStringByPath("/system/proxy/secure_host", result); 341 return GetStringByPath("/system/proxy/secure_host", result);
342 case PROXY_FTP_HOST: 342 case PROXY_FTP_HOST:
343 return GetStringByPath("/system/proxy/ftp_host", result); 343 return GetStringByPath("/system/proxy/ftp_host", result);
344 case PROXY_SOCKS_HOST: 344 case PROXY_SOCKS_HOST:
345 return GetStringByPath("/system/proxy/socks_host", result); 345 return GetStringByPath("/system/proxy/socks_host", result);
346 } 346 }
347 return false; // Placate compiler. 347 return false; // Placate compiler.
348 } 348 }
349 virtual bool GetBool(BoolSetting key, bool* result) OVERRIDE { 349 virtual bool GetBool(BoolSetting key, bool* result) override {
350 switch (key) { 350 switch (key) {
351 case PROXY_USE_HTTP_PROXY: 351 case PROXY_USE_HTTP_PROXY:
352 return GetBoolByPath("/system/http_proxy/use_http_proxy", result); 352 return GetBoolByPath("/system/http_proxy/use_http_proxy", result);
353 case PROXY_USE_SAME_PROXY: 353 case PROXY_USE_SAME_PROXY:
354 return GetBoolByPath("/system/http_proxy/use_same_proxy", result); 354 return GetBoolByPath("/system/http_proxy/use_same_proxy", result);
355 case PROXY_USE_AUTHENTICATION: 355 case PROXY_USE_AUTHENTICATION:
356 return GetBoolByPath("/system/http_proxy/use_authentication", result); 356 return GetBoolByPath("/system/http_proxy/use_authentication", result);
357 } 357 }
358 return false; // Placate compiler. 358 return false; // Placate compiler.
359 } 359 }
360 virtual bool GetInt(IntSetting key, int* result) OVERRIDE { 360 virtual bool GetInt(IntSetting key, int* result) override {
361 switch (key) { 361 switch (key) {
362 case PROXY_HTTP_PORT: 362 case PROXY_HTTP_PORT:
363 return GetIntByPath("/system/http_proxy/port", result); 363 return GetIntByPath("/system/http_proxy/port", result);
364 case PROXY_HTTPS_PORT: 364 case PROXY_HTTPS_PORT:
365 return GetIntByPath("/system/proxy/secure_port", result); 365 return GetIntByPath("/system/proxy/secure_port", result);
366 case PROXY_FTP_PORT: 366 case PROXY_FTP_PORT:
367 return GetIntByPath("/system/proxy/ftp_port", result); 367 return GetIntByPath("/system/proxy/ftp_port", result);
368 case PROXY_SOCKS_PORT: 368 case PROXY_SOCKS_PORT:
369 return GetIntByPath("/system/proxy/socks_port", result); 369 return GetIntByPath("/system/proxy/socks_port", result);
370 } 370 }
371 return false; // Placate compiler. 371 return false; // Placate compiler.
372 } 372 }
373 virtual bool GetStringList(StringListSetting key, 373 virtual bool GetStringList(StringListSetting key,
374 std::vector<std::string>* result) OVERRIDE { 374 std::vector<std::string>* result) override {
375 switch (key) { 375 switch (key) {
376 case PROXY_IGNORE_HOSTS: 376 case PROXY_IGNORE_HOSTS:
377 return GetStringListByPath("/system/http_proxy/ignore_hosts", result); 377 return GetStringListByPath("/system/http_proxy/ignore_hosts", result);
378 } 378 }
379 return false; // Placate compiler. 379 return false; // Placate compiler.
380 } 380 }
381 381
382 virtual bool BypassListIsReversed() OVERRIDE { 382 virtual bool BypassListIsReversed() override {
383 // This is a KDE-specific setting. 383 // This is a KDE-specific setting.
384 return false; 384 return false;
385 } 385 }
386 386
387 virtual bool MatchHostsUsingSuffixMatching() OVERRIDE { 387 virtual bool MatchHostsUsingSuffixMatching() override {
388 return false; 388 return false;
389 } 389 }
390 390
391 private: 391 private:
392 bool GetStringByPath(const char* key, std::string* result) { 392 bool GetStringByPath(const char* key, std::string* result) {
393 DCHECK(client_); 393 DCHECK(client_);
394 DCHECK(task_runner_->BelongsToCurrentThread()); 394 DCHECK(task_runner_->BelongsToCurrentThread());
395 GError* error = NULL; 395 GError* error = NULL;
396 gchar* value = gconf_client_get_string(client_, key, &error); 396 gchar* value = gconf_client_get_string(client_, key, &error);
397 if (HandleGError(error, key)) 397 if (HandleGError(error, key))
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 } 561 }
562 return false; 562 return false;
563 } 563 }
564 564
565 // LoadAndCheckVersion() must be called *before* Init()! 565 // LoadAndCheckVersion() must be called *before* Init()!
566 bool LoadAndCheckVersion(base::Environment* env); 566 bool LoadAndCheckVersion(base::Environment* env);
567 567
568 virtual bool Init( 568 virtual bool Init(
569 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, 569 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
570 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) 570 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
571 OVERRIDE { 571 override {
572 DCHECK(glib_task_runner->BelongsToCurrentThread()); 572 DCHECK(glib_task_runner->BelongsToCurrentThread());
573 DCHECK(!client_); 573 DCHECK(!client_);
574 DCHECK(!task_runner_.get()); 574 DCHECK(!task_runner_.get());
575 575
576 if (!SchemaExists(kProxyGConfSchema) || 576 if (!SchemaExists(kProxyGConfSchema) ||
577 !(client_ = libgio_loader_.g_settings_new(kProxyGConfSchema))) { 577 !(client_ = libgio_loader_.g_settings_new(kProxyGConfSchema))) {
578 // It's not clear whether/when this can return NULL. 578 // It's not clear whether/when this can return NULL.
579 LOG(ERROR) << "Unable to create a gsettings client"; 579 LOG(ERROR) << "Unable to create a gsettings client";
580 return false; 580 return false;
581 } 581 }
582 task_runner_ = glib_task_runner; 582 task_runner_ = glib_task_runner;
583 // We assume these all work if the above call worked. 583 // We assume these all work if the above call worked.
584 http_client_ = libgio_loader_.g_settings_get_child(client_, "http"); 584 http_client_ = libgio_loader_.g_settings_get_child(client_, "http");
585 https_client_ = libgio_loader_.g_settings_get_child(client_, "https"); 585 https_client_ = libgio_loader_.g_settings_get_child(client_, "https");
586 ftp_client_ = libgio_loader_.g_settings_get_child(client_, "ftp"); 586 ftp_client_ = libgio_loader_.g_settings_get_child(client_, "ftp");
587 socks_client_ = libgio_loader_.g_settings_get_child(client_, "socks"); 587 socks_client_ = libgio_loader_.g_settings_get_child(client_, "socks");
588 DCHECK(http_client_ && https_client_ && ftp_client_ && socks_client_); 588 DCHECK(http_client_ && https_client_ && ftp_client_ && socks_client_);
589 return true; 589 return true;
590 } 590 }
591 591
592 virtual void ShutDown() OVERRIDE { 592 virtual void ShutDown() override {
593 if (client_) { 593 if (client_) {
594 DCHECK(task_runner_->BelongsToCurrentThread()); 594 DCHECK(task_runner_->BelongsToCurrentThread());
595 // This also disables gsettings notifications. 595 // This also disables gsettings notifications.
596 g_object_unref(socks_client_); 596 g_object_unref(socks_client_);
597 g_object_unref(ftp_client_); 597 g_object_unref(ftp_client_);
598 g_object_unref(https_client_); 598 g_object_unref(https_client_);
599 g_object_unref(http_client_); 599 g_object_unref(http_client_);
600 g_object_unref(client_); 600 g_object_unref(client_);
601 // We only need to null client_ because it's the only one that we check. 601 // We only need to null client_ because it's the only one that we check.
602 client_ = NULL; 602 client_ = NULL;
603 task_runner_ = NULL; 603 task_runner_ = NULL;
604 } 604 }
605 } 605 }
606 606
607 virtual bool SetUpNotifications( 607 virtual bool SetUpNotifications(
608 ProxyConfigServiceLinux::Delegate* delegate) OVERRIDE { 608 ProxyConfigServiceLinux::Delegate* delegate) override {
609 DCHECK(client_); 609 DCHECK(client_);
610 DCHECK(task_runner_->BelongsToCurrentThread()); 610 DCHECK(task_runner_->BelongsToCurrentThread());
611 notify_delegate_ = delegate; 611 notify_delegate_ = delegate;
612 // We could watch for the change-event signal instead of changed, but 612 // 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 613 // since we have to watch more than one object, we'd still have to
614 // debounce change notifications. This is conceptually simpler. 614 // debounce change notifications. This is conceptually simpler.
615 g_signal_connect(G_OBJECT(client_), "changed", 615 g_signal_connect(G_OBJECT(client_), "changed",
616 G_CALLBACK(OnGSettingsChangeNotification), this); 616 G_CALLBACK(OnGSettingsChangeNotification), this);
617 g_signal_connect(G_OBJECT(http_client_), "changed", 617 g_signal_connect(G_OBJECT(http_client_), "changed",
618 G_CALLBACK(OnGSettingsChangeNotification), this); 618 G_CALLBACK(OnGSettingsChangeNotification), this);
619 g_signal_connect(G_OBJECT(https_client_), "changed", 619 g_signal_connect(G_OBJECT(https_client_), "changed",
620 G_CALLBACK(OnGSettingsChangeNotification), this); 620 G_CALLBACK(OnGSettingsChangeNotification), this);
621 g_signal_connect(G_OBJECT(ftp_client_), "changed", 621 g_signal_connect(G_OBJECT(ftp_client_), "changed",
622 G_CALLBACK(OnGSettingsChangeNotification), this); 622 G_CALLBACK(OnGSettingsChangeNotification), this);
623 g_signal_connect(G_OBJECT(socks_client_), "changed", 623 g_signal_connect(G_OBJECT(socks_client_), "changed",
624 G_CALLBACK(OnGSettingsChangeNotification), this); 624 G_CALLBACK(OnGSettingsChangeNotification), this);
625 // Simulate a change to avoid possibly losing updates before this point. 625 // Simulate a change to avoid possibly losing updates before this point.
626 OnChangeNotification(); 626 OnChangeNotification();
627 return true; 627 return true;
628 } 628 }
629 629
630 virtual const scoped_refptr<base::SingleThreadTaskRunner>& 630 virtual const scoped_refptr<base::SingleThreadTaskRunner>&
631 GetNotificationTaskRunner() OVERRIDE { 631 GetNotificationTaskRunner() override {
632 return task_runner_; 632 return task_runner_;
633 } 633 }
634 634
635 virtual ProxyConfigSource GetConfigSource() OVERRIDE { 635 virtual ProxyConfigSource GetConfigSource() override {
636 return PROXY_CONFIG_SOURCE_GSETTINGS; 636 return PROXY_CONFIG_SOURCE_GSETTINGS;
637 } 637 }
638 638
639 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { 639 virtual bool GetString(StringSetting key, std::string* result) override {
640 DCHECK(client_); 640 DCHECK(client_);
641 switch (key) { 641 switch (key) {
642 case PROXY_MODE: 642 case PROXY_MODE:
643 return GetStringByPath(client_, "mode", result); 643 return GetStringByPath(client_, "mode", result);
644 case PROXY_AUTOCONF_URL: 644 case PROXY_AUTOCONF_URL:
645 return GetStringByPath(client_, "autoconfig-url", result); 645 return GetStringByPath(client_, "autoconfig-url", result);
646 case PROXY_HTTP_HOST: 646 case PROXY_HTTP_HOST:
647 return GetStringByPath(http_client_, "host", result); 647 return GetStringByPath(http_client_, "host", result);
648 case PROXY_HTTPS_HOST: 648 case PROXY_HTTPS_HOST:
649 return GetStringByPath(https_client_, "host", result); 649 return GetStringByPath(https_client_, "host", result);
650 case PROXY_FTP_HOST: 650 case PROXY_FTP_HOST:
651 return GetStringByPath(ftp_client_, "host", result); 651 return GetStringByPath(ftp_client_, "host", result);
652 case PROXY_SOCKS_HOST: 652 case PROXY_SOCKS_HOST:
653 return GetStringByPath(socks_client_, "host", result); 653 return GetStringByPath(socks_client_, "host", result);
654 } 654 }
655 return false; // Placate compiler. 655 return false; // Placate compiler.
656 } 656 }
657 virtual bool GetBool(BoolSetting key, bool* result) OVERRIDE { 657 virtual bool GetBool(BoolSetting key, bool* result) override {
658 DCHECK(client_); 658 DCHECK(client_);
659 switch (key) { 659 switch (key) {
660 case PROXY_USE_HTTP_PROXY: 660 case PROXY_USE_HTTP_PROXY:
661 // Although there is an "enabled" boolean in http_client_, it is not set 661 // 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. 662 // to true by the proxy config utility. We ignore it and return false.
663 return false; 663 return false;
664 case PROXY_USE_SAME_PROXY: 664 case PROXY_USE_SAME_PROXY:
665 // Similarly, although there is a "use-same-proxy" boolean in client_, 665 // 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. 666 // it is never set to false by the proxy config utility. We ignore it.
667 return false; 667 return false;
668 case PROXY_USE_AUTHENTICATION: 668 case PROXY_USE_AUTHENTICATION:
669 // There is also no way to set this in the proxy config utility, but it 669 // 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). 670 // doesn't hurt us to get the actual setting (unlike the two above).
671 return GetBoolByPath(http_client_, "use-authentication", result); 671 return GetBoolByPath(http_client_, "use-authentication", result);
672 } 672 }
673 return false; // Placate compiler. 673 return false; // Placate compiler.
674 } 674 }
675 virtual bool GetInt(IntSetting key, int* result) OVERRIDE { 675 virtual bool GetInt(IntSetting key, int* result) override {
676 DCHECK(client_); 676 DCHECK(client_);
677 switch (key) { 677 switch (key) {
678 case PROXY_HTTP_PORT: 678 case PROXY_HTTP_PORT:
679 return GetIntByPath(http_client_, "port", result); 679 return GetIntByPath(http_client_, "port", result);
680 case PROXY_HTTPS_PORT: 680 case PROXY_HTTPS_PORT:
681 return GetIntByPath(https_client_, "port", result); 681 return GetIntByPath(https_client_, "port", result);
682 case PROXY_FTP_PORT: 682 case PROXY_FTP_PORT:
683 return GetIntByPath(ftp_client_, "port", result); 683 return GetIntByPath(ftp_client_, "port", result);
684 case PROXY_SOCKS_PORT: 684 case PROXY_SOCKS_PORT:
685 return GetIntByPath(socks_client_, "port", result); 685 return GetIntByPath(socks_client_, "port", result);
686 } 686 }
687 return false; // Placate compiler. 687 return false; // Placate compiler.
688 } 688 }
689 virtual bool GetStringList(StringListSetting key, 689 virtual bool GetStringList(StringListSetting key,
690 std::vector<std::string>* result) OVERRIDE { 690 std::vector<std::string>* result) override {
691 DCHECK(client_); 691 DCHECK(client_);
692 switch (key) { 692 switch (key) {
693 case PROXY_IGNORE_HOSTS: 693 case PROXY_IGNORE_HOSTS:
694 return GetStringListByPath(client_, "ignore-hosts", result); 694 return GetStringListByPath(client_, "ignore-hosts", result);
695 } 695 }
696 return false; // Placate compiler. 696 return false; // Placate compiler.
697 } 697 }
698 698
699 virtual bool BypassListIsReversed() OVERRIDE { 699 virtual bool BypassListIsReversed() override {
700 // This is a KDE-specific setting. 700 // This is a KDE-specific setting.
701 return false; 701 return false;
702 } 702 }
703 703
704 virtual bool MatchHostsUsingSuffixMatching() OVERRIDE { 704 virtual bool MatchHostsUsingSuffixMatching() override {
705 return false; 705 return false;
706 } 706 }
707 707
708 private: 708 private:
709 bool GetStringByPath(GSettings* client, const char* key, 709 bool GetStringByPath(GSettings* client, const char* key,
710 std::string* result) { 710 std::string* result) {
711 DCHECK(task_runner_->BelongsToCurrentThread()); 711 DCHECK(task_runner_->BelongsToCurrentThread());
712 gchar* value = libgio_loader_.g_settings_get_string(client, key); 712 gchar* value = libgio_loader_.g_settings_get_string(client, key);
713 if (!value) 713 if (!value)
714 return false; 714 return false;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 // Here in the KDE version, we can safely close the file descriptor 925 // Here in the KDE version, we can safely close the file descriptor
926 // anyway. (Not that it really matters; the process is exiting.) 926 // anyway. (Not that it really matters; the process is exiting.)
927 if (inotify_fd_ >= 0) 927 if (inotify_fd_ >= 0)
928 ShutDown(); 928 ShutDown();
929 DCHECK(inotify_fd_ < 0); 929 DCHECK(inotify_fd_ < 0);
930 } 930 }
931 931
932 virtual bool Init( 932 virtual bool Init(
933 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, 933 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
934 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) 934 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
935 OVERRIDE { 935 override {
936 // This has to be called on the UI thread (http://crbug.com/69057). 936 // This has to be called on the UI thread (http://crbug.com/69057).
937 base::ThreadRestrictions::ScopedAllowIO allow_io; 937 base::ThreadRestrictions::ScopedAllowIO allow_io;
938 DCHECK(inotify_fd_ < 0); 938 DCHECK(inotify_fd_ < 0);
939 inotify_fd_ = inotify_init(); 939 inotify_fd_ = inotify_init();
940 if (inotify_fd_ < 0) { 940 if (inotify_fd_ < 0) {
941 PLOG(ERROR) << "inotify_init failed"; 941 PLOG(ERROR) << "inotify_init failed";
942 return false; 942 return false;
943 } 943 }
944 int flags = fcntl(inotify_fd_, F_GETFL); 944 int flags = fcntl(inotify_fd_, F_GETFL);
945 if (fcntl(inotify_fd_, F_SETFL, flags | O_NONBLOCK) < 0) { 945 if (fcntl(inotify_fd_, F_SETFL, flags | O_NONBLOCK) < 0) {
946 PLOG(ERROR) << "fcntl failed"; 946 PLOG(ERROR) << "fcntl failed";
947 close(inotify_fd_); 947 close(inotify_fd_);
948 inotify_fd_ = -1; 948 inotify_fd_ = -1;
949 return false; 949 return false;
950 } 950 }
951 file_task_runner_ = file_task_runner; 951 file_task_runner_ = file_task_runner;
952 // The initial read is done on the current thread, not 952 // The initial read is done on the current thread, not
953 // |file_task_runner_|, since we will need to have it for 953 // |file_task_runner_|, since we will need to have it for
954 // SetUpAndFetchInitialConfig(). 954 // SetUpAndFetchInitialConfig().
955 UpdateCachedSettings(); 955 UpdateCachedSettings();
956 return true; 956 return true;
957 } 957 }
958 958
959 virtual void ShutDown() OVERRIDE { 959 virtual void ShutDown() override {
960 if (inotify_fd_ >= 0) { 960 if (inotify_fd_ >= 0) {
961 ResetCachedSettings(); 961 ResetCachedSettings();
962 inotify_watcher_.StopWatchingFileDescriptor(); 962 inotify_watcher_.StopWatchingFileDescriptor();
963 close(inotify_fd_); 963 close(inotify_fd_);
964 inotify_fd_ = -1; 964 inotify_fd_ = -1;
965 } 965 }
966 } 966 }
967 967
968 virtual bool SetUpNotifications( 968 virtual bool SetUpNotifications(
969 ProxyConfigServiceLinux::Delegate* delegate) OVERRIDE { 969 ProxyConfigServiceLinux::Delegate* delegate) override {
970 DCHECK(inotify_fd_ >= 0); 970 DCHECK(inotify_fd_ >= 0);
971 DCHECK(file_task_runner_->BelongsToCurrentThread()); 971 DCHECK(file_task_runner_->BelongsToCurrentThread());
972 // We can't just watch the kioslaverc file directly, since KDE will write 972 // 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 973 // 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 974 // 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 975 // 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. 976 // 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(), 977 if (inotify_add_watch(inotify_fd_, kde_config_dir_.value().c_str(),
978 IN_MODIFY | IN_MOVED_TO) < 0) { 978 IN_MODIFY | IN_MOVED_TO) < 0) {
979 return false; 979 return false;
980 } 980 }
981 notify_delegate_ = delegate; 981 notify_delegate_ = delegate;
982 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( 982 if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
983 inotify_fd_, true, base::MessageLoopForIO::WATCH_READ, 983 inotify_fd_, true, base::MessageLoopForIO::WATCH_READ,
984 &inotify_watcher_, this)) { 984 &inotify_watcher_, this)) {
985 return false; 985 return false;
986 } 986 }
987 // Simulate a change to avoid possibly losing updates before this point. 987 // Simulate a change to avoid possibly losing updates before this point.
988 OnChangeNotification(); 988 OnChangeNotification();
989 return true; 989 return true;
990 } 990 }
991 991
992 virtual const scoped_refptr<base::SingleThreadTaskRunner>& 992 virtual const scoped_refptr<base::SingleThreadTaskRunner>&
993 GetNotificationTaskRunner() OVERRIDE { 993 GetNotificationTaskRunner() override {
994 return file_task_runner_; 994 return file_task_runner_;
995 } 995 }
996 996
997 // Implement base::MessagePumpLibevent::Watcher. 997 // Implement base::MessagePumpLibevent::Watcher.
998 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE { 998 virtual void OnFileCanReadWithoutBlocking(int fd) override {
999 DCHECK_EQ(fd, inotify_fd_); 999 DCHECK_EQ(fd, inotify_fd_);
1000 DCHECK(file_task_runner_->BelongsToCurrentThread()); 1000 DCHECK(file_task_runner_->BelongsToCurrentThread());
1001 OnChangeNotification(); 1001 OnChangeNotification();
1002 } 1002 }
1003 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE { 1003 virtual void OnFileCanWriteWithoutBlocking(int fd) override {
1004 NOTREACHED(); 1004 NOTREACHED();
1005 } 1005 }
1006 1006
1007 virtual ProxyConfigSource GetConfigSource() OVERRIDE { 1007 virtual ProxyConfigSource GetConfigSource() override {
1008 return PROXY_CONFIG_SOURCE_KDE; 1008 return PROXY_CONFIG_SOURCE_KDE;
1009 } 1009 }
1010 1010
1011 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { 1011 virtual bool GetString(StringSetting key, std::string* result) override {
1012 string_map_type::iterator it = string_table_.find(key); 1012 string_map_type::iterator it = string_table_.find(key);
1013 if (it == string_table_.end()) 1013 if (it == string_table_.end())
1014 return false; 1014 return false;
1015 *result = it->second; 1015 *result = it->second;
1016 return true; 1016 return true;
1017 } 1017 }
1018 virtual bool GetBool(BoolSetting key, bool* result) OVERRIDE { 1018 virtual bool GetBool(BoolSetting key, bool* result) override {
1019 // We don't ever have any booleans. 1019 // We don't ever have any booleans.
1020 return false; 1020 return false;
1021 } 1021 }
1022 virtual bool GetInt(IntSetting key, int* result) OVERRIDE { 1022 virtual bool GetInt(IntSetting key, int* result) override {
1023 // We don't ever have any integers. (See AddProxy() below about ports.) 1023 // We don't ever have any integers. (See AddProxy() below about ports.)
1024 return false; 1024 return false;
1025 } 1025 }
1026 virtual bool GetStringList(StringListSetting key, 1026 virtual bool GetStringList(StringListSetting key,
1027 std::vector<std::string>* result) OVERRIDE { 1027 std::vector<std::string>* result) override {
1028 strings_map_type::iterator it = strings_table_.find(key); 1028 strings_map_type::iterator it = strings_table_.find(key);
1029 if (it == strings_table_.end()) 1029 if (it == strings_table_.end())
1030 return false; 1030 return false;
1031 *result = it->second; 1031 *result = it->second;
1032 return true; 1032 return true;
1033 } 1033 }
1034 1034
1035 virtual bool BypassListIsReversed() OVERRIDE { 1035 virtual bool BypassListIsReversed() override {
1036 return reversed_bypass_list_; 1036 return reversed_bypass_list_;
1037 } 1037 }
1038 1038
1039 virtual bool MatchHostsUsingSuffixMatching() OVERRIDE { 1039 virtual bool MatchHostsUsingSuffixMatching() override {
1040 return true; 1040 return true;
1041 } 1041 }
1042 1042
1043 private: 1043 private:
1044 void ResetCachedSettings() { 1044 void ResetCachedSettings() {
1045 string_table_.clear(); 1045 string_table_.clear();
1046 strings_table_.clear(); 1046 strings_table_.clear();
1047 indirect_manual_ = false; 1047 indirect_manual_ = false;
1048 auto_no_pac_ = false; 1048 auto_no_pac_ = false;
1049 reversed_bypass_list_ = false; 1049 reversed_bypass_list_ = false;
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { 1773 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) {
1774 delegate_->RemoveObserver(observer); 1774 delegate_->RemoveObserver(observer);
1775 } 1775 }
1776 1776
1777 ProxyConfigService::ConfigAvailability 1777 ProxyConfigService::ConfigAvailability
1778 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { 1778 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) {
1779 return delegate_->GetLatestProxyConfig(config); 1779 return delegate_->GetLatestProxyConfig(config);
1780 } 1780 }
1781 1781
1782 } // namespace net 1782 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_config_service_linux.h ('k') | net/proxy/proxy_config_service_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698