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/bind.h" | |
9 #include "base/json/json_value_serializer.h" | 10 #include "base/json/json_value_serializer.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "chrome/browser/chromeos/cros/cros_library.h" | 13 #include "chrome/browser/chromeos/cros/cros_library.h" |
14 #include "chrome/browser/chromeos/cros_settings.h" | |
13 #include "chrome/browser/chromeos/cros_settings_names.h" | 15 #include "chrome/browser/chromeos/cros_settings_names.h" |
14 #include "chrome/browser/chromeos/login/user_manager.h" | 16 #include "chrome/browser/chromeos/login/user_manager.h" |
15 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" | 17 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 19 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
18 #include "chrome/browser/prefs/proxy_prefs.h" | 20 #include "chrome/browser/prefs/proxy_prefs.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
22 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 *spec += scheme; | 347 *spec += scheme; |
346 *spec += "="; | 348 *spec += "="; |
347 } | 349 } |
348 *spec += server.ToURI(); | 350 *spec += server.ToURI(); |
349 } | 351 } |
350 | 352 |
351 //------------------- ProxyConfigServiceImpl: public methods ------------------- | 353 //------------------- ProxyConfigServiceImpl: public methods ------------------- |
352 | 354 |
353 ProxyConfigServiceImpl::ProxyConfigServiceImpl(PrefService* pref_service) | 355 ProxyConfigServiceImpl::ProxyConfigServiceImpl(PrefService* pref_service) |
354 : PrefProxyConfigTrackerImpl(pref_service), | 356 : PrefProxyConfigTrackerImpl(pref_service), |
355 active_config_state_(ProxyPrefs::CONFIG_UNSET) { | 357 active_config_state_(ProxyPrefs::CONFIG_UNSET), |
358 pointer_factory_(this) { | |
356 | 359 |
357 // Register for notification when user logs in, so that we can activate the | 360 // Register for notification when user logs in, so that we can activate the |
358 // new proxy config. | 361 // new proxy config. |
359 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 362 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
360 content::NotificationService::AllSources()); | 363 content::NotificationService::AllSources()); |
361 | 364 |
362 // Register for notifications of UseSharedProxies user preference. | 365 // Register for notifications of UseSharedProxies user preference. |
363 if (pref_service->FindPreference(prefs::kUseSharedProxies)) | 366 if (pref_service->FindPreference(prefs::kUseSharedProxies)) |
364 use_shared_proxies_.Init(prefs::kUseSharedProxies, pref_service, this); | 367 use_shared_proxies_.Init(prefs::kUseSharedProxies, pref_service, this); |
365 | 368 |
366 // Start async fetch of proxy config from settings persisted on device. | 369 if (CrosSettings::Get()->GetTrusted( |
367 if (CrosLibrary::Get()->libcros_loaded()) { | 370 kSettingProxyEverywhere, |
368 retrieve_property_op_ = SignedSettings::CreateRetrievePropertyOp( | 371 base::Bind(&ProxyConfigServiceImpl::FetchProxyPolicy, |
369 kSettingProxyEverywhere, this); | 372 pointer_factory_.GetWeakPtr()))) { |
370 if (retrieve_property_op_) { | 373 FetchProxyPolicy(); |
371 retrieve_property_op_->Execute(); | |
372 VLOG(1) << this << ": Start retrieving proxy setting from device"; | |
373 } else { | |
374 VLOG(1) << this << ": Fail to retrieve proxy setting from device"; | |
375 } | |
376 } | 374 } |
377 | 375 |
378 // Register for flimflam network notifications. | 376 // Register for flimflam network notifications. |
379 NetworkLibrary* network_lib = CrosLibrary::Get()->GetNetworkLibrary(); | 377 NetworkLibrary* network_lib = CrosLibrary::Get()->GetNetworkLibrary(); |
380 OnActiveNetworkChanged(network_lib, network_lib->active_network()); | 378 OnActiveNetworkChanged(network_lib, network_lib->active_network()); |
381 network_lib->AddNetworkManagerObserver(this); | 379 network_lib->AddNetworkManagerObserver(this); |
382 } | 380 } |
383 | 381 |
384 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { | 382 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { |
385 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); | 383 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 Network* network = NULL; | 515 Network* network = NULL; |
518 if (!active_network_.empty()) { | 516 if (!active_network_.empty()) { |
519 network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( | 517 network = CrosLibrary::Get()->GetNetworkLibrary()->FindNetworkByPath( |
520 active_network_); | 518 active_network_); |
521 if (!network) | 519 if (!network) |
522 LOG(ERROR) << "can't find requested network " << active_network_; | 520 LOG(ERROR) << "can't find requested network " << active_network_; |
523 } | 521 } |
524 DetermineEffectiveConfig(network, true); | 522 DetermineEffectiveConfig(network, true); |
525 } | 523 } |
526 | 524 |
527 void ProxyConfigServiceImpl::OnSettingsOpCompleted( | |
528 SignedSettings::ReturnCode code, | |
529 const base::Value* value) { | |
530 retrieve_property_op_ = NULL; | |
531 if (code != SignedSettings::SUCCESS) { | |
532 LOG(WARNING) << this << ": Error retrieving proxy setting from device"; | |
533 device_config_.clear(); | |
534 return; | |
535 } | |
536 std::string policy_value; | |
537 value->GetAsString(&policy_value); | |
538 VLOG(1) << "Retrieved proxy setting from device, value=[" | |
539 << policy_value << "]"; | |
540 ProxyConfig device_config; | |
541 if (!device_config.DeserializeForDevice(policy_value) || | |
542 !device_config.SerializeForNetwork(&device_config_)) { | |
543 LOG(WARNING) << "Can't deserialize device setting or serialize for network"; | |
544 device_config_.clear(); | |
545 return; | |
546 } | |
547 if (!active_network_.empty()) { | |
548 VLOG(1) << this << ": try migrating device config to " << active_network_; | |
549 SetProxyConfigForNetwork(active_network_, device_config_, true); | |
550 } | |
551 } | |
552 | |
553 void ProxyConfigServiceImpl::OnNetworkManagerChanged( | 525 void ProxyConfigServiceImpl::OnNetworkManagerChanged( |
554 NetworkLibrary* network_lib) { | 526 NetworkLibrary* network_lib) { |
555 VLOG(1) << this << " OnNetworkManagerChanged: use-shared-proxies=" | 527 VLOG(1) << this << " OnNetworkManagerChanged: use-shared-proxies=" |
556 << GetUseSharedProxies(); | 528 << GetUseSharedProxies(); |
557 OnActiveNetworkChanged(network_lib, network_lib->active_network()); | 529 OnActiveNetworkChanged(network_lib, network_lib->active_network()); |
558 } | 530 } |
559 | 531 |
560 void ProxyConfigServiceImpl::OnNetworkChanged(NetworkLibrary* network_lib, | 532 void ProxyConfigServiceImpl::OnNetworkChanged(NetworkLibrary* network_lib, |
561 const Network* network) { | 533 const Network* network) { |
562 if (!network) | 534 if (!network) |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 ++iter; | 784 ++iter; |
813 } | 785 } |
814 } | 786 } |
815 } | 787 } |
816 | 788 |
817 void ProxyConfigServiceImpl::ResetUICache() { | 789 void ProxyConfigServiceImpl::ResetUICache() { |
818 current_ui_network_.clear(); | 790 current_ui_network_.clear(); |
819 current_ui_config_ = ProxyConfig(); | 791 current_ui_config_ = ProxyConfig(); |
820 } | 792 } |
821 | 793 |
794 void ProxyConfigServiceImpl::FetchProxyPolicy() { | |
795 std::string policy_value = ""; | |
Denis Lagno
2011/12/01 00:38:12
nit: just std::string policy_value; without = "" d
pastarmovj
2011/12/01 10:07:17
Done.
| |
796 if (!CrosSettings::Get()->GetString(kSettingProxyEverywhere, | |
797 &policy_value)) { | |
798 LOG(WARNING) << this << ": Error retrieving proxy setting from device"; | |
799 device_config_.clear(); | |
800 return; | |
801 } | |
802 | |
803 VLOG(1) << "Retrieved proxy setting from device, value=[" | |
804 << policy_value << "]"; | |
805 ProxyConfig device_config; | |
806 if (!device_config.DeserializeForDevice(policy_value) || | |
807 !device_config.SerializeForNetwork(&device_config_)) { | |
808 LOG(WARNING) << "Can't deserialize device setting or serialize for network"; | |
809 device_config_.clear(); | |
810 return; | |
811 } | |
812 if (!active_network_.empty()) { | |
813 VLOG(1) << this << ": try migrating device config to " << active_network_; | |
814 SetProxyConfigForNetwork(active_network_, device_config_, true); | |
815 } | |
816 } | |
817 | |
822 } // namespace chromeos | 818 } // namespace chromeos |
OLD | NEW |