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 "chrome/browser/chromeos/proxy_config_service_impl.h" | 5 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/json/json_value_serializer.h" | 9 #include "base/json/json_value_serializer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
25 | 25 |
26 namespace em = enterprise_management; | 26 namespace em = enterprise_management; |
27 | 27 |
28 namespace chromeos { | 28 namespace chromeos { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 // Shoud we try to push this to base? | |
33 // Helper comparator functor for the find_if call in |findIfEqual| | |
34 template <class T> | |
35 class EqualsComparator{ | |
36 public: | |
37 explicit EqualsComparator(const T& key) : key_(key) { } | |
38 bool operator() (const T& element) { | |
39 return element.Equals(key_); | |
40 } | |
41 private: | |
42 const T& key_; | |
43 }; | |
44 | |
45 // Tiny stl helper function to allow using the find_if syntax on objects that | |
Mattias Nissler (ping if slow)
2011/11/14 08:35:45
s/stl/STL/
pastarmovj
2011/11/14 14:20:34
Done.
| |
46 // doesn't use the == operator but implement the Equals function which is the | |
Mattias Nissler (ping if slow)
2011/11/14 08:35:45
s/the == operator/operator==/
pastarmovj
2011/11/14 14:20:34
Done.
| |
47 // quasi standard with the coding style we have. | |
48 template<class InputIterator, class T> | |
49 InputIterator findIfEqual(InputIterator first, InputIterator last, | |
50 const T& key) { | |
Mattias Nissler (ping if slow)
2011/11/14 08:35:45
indentation
pastarmovj
2011/11/14 14:20:34
Done.
| |
51 return std::find_if(first, last, EqualsComparator<T>(key)); | |
52 } | |
53 | |
32 const char* ModeToString(ProxyConfigServiceImpl::ProxyConfig::Mode mode) { | 54 const char* ModeToString(ProxyConfigServiceImpl::ProxyConfig::Mode mode) { |
33 switch (mode) { | 55 switch (mode) { |
34 case ProxyConfigServiceImpl::ProxyConfig::MODE_DIRECT: | 56 case ProxyConfigServiceImpl::ProxyConfig::MODE_DIRECT: |
35 return "direct"; | 57 return "direct"; |
36 case ProxyConfigServiceImpl::ProxyConfig::MODE_AUTO_DETECT: | 58 case ProxyConfigServiceImpl::ProxyConfig::MODE_AUTO_DETECT: |
37 return "auto-detect"; | 59 return "auto-detect"; |
38 case ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT: | 60 case ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT: |
39 return "pacurl"; | 61 return "pacurl"; |
40 case ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY: | 62 case ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY: |
41 return "single-proxy"; | 63 return "single-proxy"; |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 NOTREACHED(); | 486 NOTREACHED(); |
465 VLOG(1) << "Cannot set bypass rules for proxy mode [" | 487 VLOG(1) << "Cannot set bypass rules for proxy mode [" |
466 << current_ui_config_.mode << "]"; | 488 << current_ui_config_.mode << "]"; |
467 return false; | 489 return false; |
468 } | 490 } |
469 current_ui_config_.bypass_rules = bypass_rules; | 491 current_ui_config_.bypass_rules = bypass_rules; |
470 OnUISetProxyConfig(); | 492 OnUISetProxyConfig(); |
471 return true; | 493 return true; |
472 } | 494 } |
473 | 495 |
496 void ProxyConfigServiceImpl::AddNotificationCallback(base::Closure callback) { | |
497 | |
498 std::vector<base::Closure>::iterator iter = | |
499 findIfEqual(callbacks_.begin(), callbacks_.end(), callback); | |
500 if (iter == callbacks_.end()) | |
501 callbacks_.push_back(callback); | |
502 } | |
503 | |
504 void ProxyConfigServiceImpl::RemoveNotificationCallback( | |
505 base::Closure callback) { | |
506 std::vector<base::Closure>::iterator iter = | |
507 findIfEqual(callbacks_.begin(), callbacks_.end(), callback); | |
508 if (iter != callbacks_.end()) | |
509 callbacks_.erase(iter); | |
510 } | |
511 | |
474 void ProxyConfigServiceImpl::OnProxyConfigChanged( | 512 void ProxyConfigServiceImpl::OnProxyConfigChanged( |
475 ProxyPrefs::ConfigState config_state, | 513 ProxyPrefs::ConfigState config_state, |
476 const net::ProxyConfig& config) { | 514 const net::ProxyConfig& config) { |
477 VLOG(1) << this << ": got prefs change: " << ConfigStateToString(config_state) | 515 VLOG(1) << this << ": got prefs change: " << ConfigStateToString(config_state) |
478 << ", mode=" << config.proxy_rules().type; | 516 << ", mode=" << config.proxy_rules().type; |
479 Network* network = NULL; | 517 Network* network = NULL; |
480 if (!active_network_.empty()) { | 518 if (!active_network_.empty()) { |
481 network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( | 519 network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( |
482 active_network_); | 520 active_network_); |
483 if (!network) | 521 if (!network) |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 } | 793 } |
756 | 794 |
757 void ProxyConfigServiceImpl::OnUISetCurrentNetwork(const Network* network) { | 795 void ProxyConfigServiceImpl::OnUISetCurrentNetwork(const Network* network) { |
758 DetermineEffectiveConfig(network, false); | 796 DetermineEffectiveConfig(network, false); |
759 VLOG(1) << this << ": current ui network: " | 797 VLOG(1) << this << ": current ui network: " |
760 << (network->name().empty() ? | 798 << (network->name().empty() ? |
761 current_ui_network_ : network->name()) | 799 current_ui_network_ : network->name()) |
762 << ", " << ModeToString(current_ui_config_.mode) | 800 << ", " << ModeToString(current_ui_config_.mode) |
763 << ", " << ConfigStateToString(current_ui_config_.state) | 801 << ", " << ConfigStateToString(current_ui_config_.state) |
764 << ", modifiable:" << current_ui_config_.user_modifiable; | 802 << ", modifiable:" << current_ui_config_.user_modifiable; |
803 // Notify whoever is interested in this change. | |
804 std::vector<base::Closure>::iterator iter = callbacks_.begin(); | |
805 while (iter != callbacks_.end()) { | |
806 if (iter->is_null()) { | |
807 iter = callbacks_.erase(iter); | |
808 } else { | |
809 iter->Run(); | |
810 ++iter; | |
811 } | |
812 } | |
765 } | 813 } |
766 | 814 |
767 void ProxyConfigServiceImpl::ResetUICache() { | 815 void ProxyConfigServiceImpl::ResetUICache() { |
768 current_ui_network_.clear(); | 816 current_ui_network_.clear(); |
769 current_ui_config_ = ProxyConfig(); | 817 current_ui_config_ = ProxyConfig(); |
770 } | 818 } |
771 | 819 |
772 } // namespace chromeos | 820 } // namespace chromeos |
OLD | NEW |