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

Unified Diff: chromeos/network/proxy/ui_proxy_config_service.cc

Issue 2446893008: NetworkHandler: Add ui_proxy_config_service (Closed)
Patch Set: Add NetworkHandler::ShutdownPrefServices Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/network/proxy/ui_proxy_config_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/network/proxy/ui_proxy_config_service.cc
diff --git a/chromeos/network/proxy/ui_proxy_config_service.cc b/chromeos/network/proxy/ui_proxy_config_service.cc
index 810d85a0449cc511cbc1dfe1dccbe9ef5c211030..9665a6ff50a6febdfb93c417b076e7c609936870 100644
--- a/chromeos/network/proxy/ui_proxy_config_service.cc
+++ b/chromeos/network/proxy/ui_proxy_config_service.cc
@@ -6,6 +6,8 @@
#include <memory>
+#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/values.h"
#include "chromeos/network/network_state.h"
@@ -14,6 +16,7 @@
#include "chromeos/network/proxy/proxy_config_service_impl.h"
#include "components/device_event_log/device_event_log.h"
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
+#include "components/proxy_config/proxy_config_pref_names.h"
#include "net/proxy/proxy_config.h"
namespace chromeos {
@@ -62,32 +65,46 @@ bool IsNetworkProxySettingsEditable(const onc::ONCSource onc_source) {
} // namespace
-UIProxyConfigService::UIProxyConfigService()
- : profile_prefs_(nullptr), local_state_prefs_(nullptr) {}
-
-UIProxyConfigService::~UIProxyConfigService() {}
+UIProxyConfigService::UIProxyConfigService(PrefService* profile_prefs,
+ PrefService* local_state_prefs)
+ : profile_prefs_(profile_prefs), local_state_prefs_(local_state_prefs) {
+ if (profile_prefs_) {
+ profile_registrar_.Init(profile_prefs_);
+ profile_registrar_.Add(
+ ::proxy_config::prefs::kProxy,
+ base::Bind(&UIProxyConfigService::OnPreferenceChanged,
+ base::Unretained(this)));
+ profile_registrar_.Add(
+ ::proxy_config::prefs::kUseSharedProxies,
+ base::Bind(&UIProxyConfigService::OnPreferenceChanged,
+ base::Unretained(this)));
+ }
-void UIProxyConfigService::SetPrefs(PrefService* profile_prefs,
- PrefService* local_state_prefs) {
- profile_prefs_ = profile_prefs;
- local_state_prefs_ = local_state_prefs;
+ DCHECK(local_state_prefs_);
+ local_state_registrar_.Init(local_state_prefs_);
+ local_state_registrar_.Add(
+ ::proxy_config::prefs::kProxy,
+ base::Bind(&UIProxyConfigService::OnPreferenceChanged,
+ base::Unretained(this)));
}
-void UIProxyConfigService::SetCurrentNetworkGuid(
- const std::string& current_guid) {
- current_ui_network_guid_ = current_guid;
-}
+UIProxyConfigService::~UIProxyConfigService() {}
-void UIProxyConfigService::UpdateFromPrefs() {
+void UIProxyConfigService::UpdateFromPrefs(const std::string& network_guid) {
+ current_ui_network_guid_ = network_guid;
const NetworkState* network = nullptr;
- if (!current_ui_network_guid_.empty()) {
+ if (!network_guid.empty()) {
network =
NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid(
- current_ui_network_guid_);
+ network_guid);
+ if (!network) {
+ NET_LOG(ERROR) << "No NetworkState for guid: " << network_guid;
+ } else if (!network->IsInProfile()) {
+ NET_LOG(ERROR) << "Network not in profile: " << network_guid;
+ network = nullptr;
+ }
}
- if (!network || !network->IsInProfile()) {
- NET_LOG(ERROR) << "No configured NetworkState for guid: "
- << current_ui_network_guid_;
+ if (!network) {
current_ui_network_guid_.clear();
current_ui_config_ = UIProxyConfig();
return;
@@ -100,11 +117,16 @@ void UIProxyConfigService::UpdateFromPrefs() {
<< ", modifiable:" << current_ui_config_.user_modifiable;
}
-void UIProxyConfigService::GetProxyConfig(UIProxyConfig* config) const {
+void UIProxyConfigService::GetProxyConfig(const std::string& network_guid,
+ UIProxyConfig* config) {
+ if (network_guid != current_ui_network_guid_)
+ UpdateFromPrefs(network_guid);
*config = current_ui_config_;
}
-void UIProxyConfigService::SetProxyConfig(const UIProxyConfig& config) {
+void UIProxyConfigService::SetProxyConfig(const std::string& network_guid,
+ const UIProxyConfig& config) {
+ current_ui_network_guid_ = network_guid;
current_ui_config_ = config;
if (current_ui_network_guid_.empty())
return;
@@ -177,4 +199,9 @@ void UIProxyConfigService::DetermineEffectiveConfig(
}
}
+void UIProxyConfigService::OnPreferenceChanged(const std::string& pref_name) {
+ if (!current_ui_network_guid_.empty())
+ UpdateFromPrefs(current_ui_network_guid_);
+}
+
} // namespace chromeos
« no previous file with comments | « chromeos/network/proxy/ui_proxy_config_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698