OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
11 #endif | 11 #endif |
12 #include <limits.h> | 12 #include <limits.h> |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include <stdlib.h> | 14 #include <stdlib.h> |
15 #include <sys/inotify.h> | 15 #include <sys/inotify.h> |
16 #include <unistd.h> | 16 #include <unistd.h> |
17 | 17 |
18 #include <map> | 18 #include <map> |
19 | 19 |
20 #include "base/environment.h" | 20 #include "base/environment.h" |
21 #include "base/file_path.h" | 21 #include "base/file_path.h" |
22 #include "base/file_util.h" | 22 #include "base/file_util.h" |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "base/message_loop.h" | 24 #include "base/message_loop.h" |
25 #include "base/string_number_conversions.h" | 25 #include "base/string_number_conversions.h" |
26 #include "base/string_tokenizer.h" | 26 #include "base/string_tokenizer.h" |
27 #include "base/string_util.h" | 27 #include "base/string_util.h" |
28 #include "base/task.h" | 28 #include "base/task.h" |
29 #include "base/threading/thread_restrictions.h" | |
29 #include "base/timer.h" | 30 #include "base/timer.h" |
30 #include "base/nix/xdg_util.h" | 31 #include "base/nix/xdg_util.h" |
31 #include "googleurl/src/url_canon.h" | 32 #include "googleurl/src/url_canon.h" |
32 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
33 #include "net/http/http_util.h" | 34 #include "net/http/http_util.h" |
34 #include "net/proxy/proxy_config.h" | 35 #include "net/proxy/proxy_config.h" |
35 #include "net/proxy/proxy_server.h" | 36 #include "net/proxy/proxy_server.h" |
36 | 37 |
37 namespace net { | 38 namespace net { |
38 | 39 |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 // Doing this allows the main Delegate code, as well as the unit tests | 429 // Doing this allows the main Delegate code, as well as the unit tests |
429 // for it, to stay the same - and the settings map fairly well besides. | 430 // for it, to stay the same - and the settings map fairly well besides. |
430 class GConfSettingGetterImplKDE | 431 class GConfSettingGetterImplKDE |
431 : public ProxyConfigServiceLinux::GConfSettingGetter, | 432 : public ProxyConfigServiceLinux::GConfSettingGetter, |
432 public base::MessagePumpLibevent::Watcher { | 433 public base::MessagePumpLibevent::Watcher { |
433 public: | 434 public: |
434 explicit GConfSettingGetterImplKDE(base::Environment* env_var_getter) | 435 explicit GConfSettingGetterImplKDE(base::Environment* env_var_getter) |
435 : inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false), | 436 : inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false), |
436 auto_no_pac_(false), reversed_bypass_list_(false), | 437 auto_no_pac_(false), reversed_bypass_list_(false), |
437 env_var_getter_(env_var_getter), file_loop_(NULL) { | 438 env_var_getter_(env_var_getter), file_loop_(NULL) { |
439 // This has to be called on the UI thread (bug 69057). | |
eroman
2011/01/20 23:17:25
nit: I recommend providing URLs to bugs, as in "ht
battre
2011/01/24 17:47:18
Done.
| |
440 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
441 | |
438 // Derive the location of the kde config dir from the environment. | 442 // Derive the location of the kde config dir from the environment. |
439 std::string home; | 443 std::string home; |
440 if (env_var_getter->GetVar("KDEHOME", &home) && !home.empty()) { | 444 if (env_var_getter->GetVar("KDEHOME", &home) && !home.empty()) { |
441 // $KDEHOME is set. Use it unconditionally. | 445 // $KDEHOME is set. Use it unconditionally. |
442 kde_config_dir_ = KDEHomeToConfigPath(FilePath(home)); | 446 kde_config_dir_ = KDEHomeToConfigPath(FilePath(home)); |
443 } else { | 447 } else { |
444 // $KDEHOME is unset. Try to figure out what to use. This seems to be | 448 // $KDEHOME is unset. Try to figure out what to use. This seems to be |
445 // the common case on most distributions. | 449 // the common case on most distributions. |
446 if (!env_var_getter->GetVar(base::env_vars::kHome, &home)) | 450 if (!env_var_getter->GetVar(base::env_vars::kHome, &home)) |
447 // User has no $HOME? Give up. Later we'll report the failure. | 451 // User has no $HOME? Give up. Later we'll report the failure. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 // and pending tasks may then be deleted without being run. | 499 // and pending tasks may then be deleted without being run. |
496 // Here in the KDE version, we can safely close the file descriptor | 500 // Here in the KDE version, we can safely close the file descriptor |
497 // anyway. (Not that it really matters; the process is exiting.) | 501 // anyway. (Not that it really matters; the process is exiting.) |
498 if (inotify_fd_ >= 0) | 502 if (inotify_fd_ >= 0) |
499 Shutdown(); | 503 Shutdown(); |
500 DCHECK(inotify_fd_ < 0); | 504 DCHECK(inotify_fd_ < 0); |
501 } | 505 } |
502 | 506 |
503 virtual bool Init(MessageLoop* glib_default_loop, | 507 virtual bool Init(MessageLoop* glib_default_loop, |
504 MessageLoopForIO* file_loop) { | 508 MessageLoopForIO* file_loop) { |
509 // This has to be called on the UI thread (bug 69057). | |
510 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
505 DCHECK(inotify_fd_ < 0); | 511 DCHECK(inotify_fd_ < 0); |
506 inotify_fd_ = inotify_init(); | 512 inotify_fd_ = inotify_init(); |
507 if (inotify_fd_ < 0) { | 513 if (inotify_fd_ < 0) { |
508 PLOG(ERROR) << "inotify_init failed"; | 514 PLOG(ERROR) << "inotify_init failed"; |
509 return false; | 515 return false; |
510 } | 516 } |
511 int flags = fcntl(inotify_fd_, F_GETFL); | 517 int flags = fcntl(inotify_fd_, F_GETFL); |
512 if (fcntl(inotify_fd_, F_SETFL, flags | O_NONBLOCK) < 0) { | 518 if (fcntl(inotify_fd_, F_SETFL, flags | O_NONBLOCK) < 0) { |
513 PLOG(ERROR) << "fcntl failed"; | 519 PLOG(ERROR) << "fcntl failed"; |
514 close(inotify_fd_); | 520 close(inotify_fd_); |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1261 | 1267 |
1262 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { | 1268 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { |
1263 delegate_->RemoveObserver(observer); | 1269 delegate_->RemoveObserver(observer); |
1264 } | 1270 } |
1265 | 1271 |
1266 bool ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { | 1272 bool ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { |
1267 return delegate_->GetLatestProxyConfig(config); | 1273 return delegate_->GetLatestProxyConfig(config); |
1268 } | 1274 } |
1269 | 1275 |
1270 } // namespace net | 1276 } // namespace net |
OLD | NEW |