| OLD | NEW |
| 1 // Copyright (c) 2010 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
| 13 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| 14 #include "chrome/common/json_value_serializer.h" | 17 #include "chrome/common/json_value_serializer.h" |
| 18 #include "chrome/common/pref_names.h" |
| 15 | 19 |
| 16 namespace chromeos { | 20 namespace chromeos { |
| 17 | 21 |
| 18 namespace { | 22 namespace { |
| 19 | 23 |
| 20 const char* SourceToString(ProxyConfigServiceImpl::ProxyConfig::Source source) { | 24 const char* SourceToString(ProxyConfigServiceImpl::ProxyConfig::Source source) { |
| 21 switch (source) { | 25 switch (source) { |
| 22 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_NONE: | 26 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_NONE: |
| 23 return "SOURCE_NONE"; | 27 return "SOURCE_NONE"; |
| 24 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_POLICY: | 28 case ProxyConfigServiceImpl::ProxyConfig::SOURCE_POLICY: |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 return false; | 178 return false; |
| 175 std::string value; | 179 std::string value; |
| 176 if (!dict->GetString(kServer, &value)) | 180 if (!dict->GetString(kServer, &value)) |
| 177 return false; | 181 return false; |
| 178 server = net::ProxyServer::FromURI(value, scheme); | 182 server = net::ProxyServer::FromURI(value, scheme); |
| 179 return true; | 183 return true; |
| 180 } | 184 } |
| 181 | 185 |
| 182 //----------- ProxyConfigServiceImpl::ProxyConfig: public methods -------------- | 186 //----------- ProxyConfigServiceImpl::ProxyConfig: public methods -------------- |
| 183 | 187 |
| 184 void ProxyConfigServiceImpl::ProxyConfig::ToNetProxyConfig( | 188 // static |
| 185 net::ProxyConfig* net_config) { | 189 void ProxyConfigServiceImpl::ProxyConfig::FormatProxySpec( |
| 190 std::string* spec, |
| 191 const std::string& scheme, |
| 192 const net::ProxyServer& server) { |
| 193 DCHECK(spec); |
| 194 |
| 195 if (!server.is_valid()) |
| 196 return; |
| 197 |
| 198 if (!spec->empty()) |
| 199 *spec += ";"; |
| 200 if (!scheme.empty()) { |
| 201 *spec += scheme; |
| 202 *spec += "="; |
| 203 } |
| 204 *spec += server.ToURI(); |
| 205 } |
| 206 |
| 207 DictionaryValue* |
| 208 ProxyConfigServiceImpl::ProxyConfig::ToProxyConfigDictionary() const { |
| 209 std::string proxy_spec; |
| 210 |
| 186 switch (mode) { | 211 switch (mode) { |
| 187 case MODE_DIRECT: | 212 case MODE_DIRECT: |
| 188 *net_config = net::ProxyConfig::CreateDirect(); | 213 return ProxyConfigDictionary::CreateDirect(); |
| 189 break; | |
| 190 case MODE_AUTO_DETECT: | 214 case MODE_AUTO_DETECT: |
| 191 *net_config = net::ProxyConfig::CreateAutoDetect(); | 215 return ProxyConfigDictionary::CreateAutoDetect(); |
| 192 break; | |
| 193 case MODE_PAC_SCRIPT: | 216 case MODE_PAC_SCRIPT: |
| 194 *net_config = net::ProxyConfig::CreateFromCustomPacURL( | 217 return ProxyConfigDictionary::CreatePacScript( |
| 195 automatic_proxy.pac_url); | 218 automatic_proxy.pac_url.spec()); |
| 196 break; | |
| 197 case MODE_SINGLE_PROXY: | 219 case MODE_SINGLE_PROXY: |
| 198 *net_config = net::ProxyConfig(); | 220 FormatProxySpec(&proxy_spec, "", single_proxy.server); |
| 199 net_config->proxy_rules().type = | 221 return ProxyConfigDictionary::CreateFixedServers(proxy_spec, |
| 200 net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; | 222 bypass_rules.ToString()); |
| 201 net_config->proxy_rules().single_proxy = single_proxy.server; | |
| 202 net_config->proxy_rules().bypass_rules = bypass_rules; | |
| 203 break; | |
| 204 case MODE_PROXY_PER_SCHEME: | 223 case MODE_PROXY_PER_SCHEME: |
| 205 *net_config = net::ProxyConfig(); | 224 proxy_spec.reserve(256); |
| 206 net_config->proxy_rules().type = | 225 FormatProxySpec(&proxy_spec, "http", http_proxy.server); |
| 207 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; | 226 FormatProxySpec(&proxy_spec, "https", https_proxy.server); |
| 208 net_config->proxy_rules().proxy_for_http = http_proxy.server; | 227 FormatProxySpec(&proxy_spec, "ftp", ftp_proxy.server); |
| 209 net_config->proxy_rules().proxy_for_https = https_proxy.server; | 228 FormatProxySpec(&proxy_spec, "socks", socks_proxy.server); |
| 210 net_config->proxy_rules().proxy_for_ftp = ftp_proxy.server; | 229 return ProxyConfigDictionary::CreateFixedServers(proxy_spec, |
| 211 net_config->proxy_rules().fallback_proxy = socks_proxy.server; | 230 bypass_rules.ToString()); |
| 212 net_config->proxy_rules().bypass_rules = bypass_rules; | |
| 213 break; | |
| 214 default: | 231 default: |
| 215 NOTREACHED() << "Unrecognized proxy config mode"; | 232 NOTREACHED() << "Unrecognized proxy config mode"; |
| 216 break; | 233 break; |
| 217 } | 234 } |
| 235 |
| 236 return NULL; |
| 218 } | 237 } |
| 219 | 238 |
| 220 bool ProxyConfigServiceImpl::ProxyConfig::CanBeWrittenByUser( | 239 bool ProxyConfigServiceImpl::ProxyConfig::CanBeWrittenByUser( |
| 221 bool user_is_owner, const std::string& scheme) { | 240 bool user_is_owner, const std::string& scheme) { |
| 222 // Setting can only be written by user if user is owner and setting is not | 241 // Setting can only be written by user if user is owner and setting is not |
| 223 // from policy. | 242 // from policy. |
| 224 Setting* setting = NULL; | 243 Setting* setting = NULL; |
| 225 switch (mode) { | 244 switch (mode) { |
| 226 case MODE_DIRECT: | 245 case MODE_DIRECT: |
| 227 case MODE_AUTO_DETECT: | 246 case MODE_AUTO_DETECT: |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 DictionaryValue* dict, const char* key_name, bool ok_if_absent, | 401 DictionaryValue* dict, const char* key_name, bool ok_if_absent, |
| 383 net::ProxyServer::Scheme scheme, ManualProxy* manual_proxy) { | 402 net::ProxyServer::Scheme scheme, ManualProxy* manual_proxy) { |
| 384 DictionaryValue* proxy_dict; | 403 DictionaryValue* proxy_dict; |
| 385 if (!dict->GetDictionary(key_name, &proxy_dict)) | 404 if (!dict->GetDictionary(key_name, &proxy_dict)) |
| 386 return ok_if_absent; | 405 return ok_if_absent; |
| 387 return manual_proxy->Decode(proxy_dict, scheme); | 406 return manual_proxy->Decode(proxy_dict, scheme); |
| 388 } | 407 } |
| 389 | 408 |
| 390 //------------------- ProxyConfigServiceImpl: public methods ------------------- | 409 //------------------- ProxyConfigServiceImpl: public methods ------------------- |
| 391 | 410 |
| 392 ProxyConfigServiceImpl::ProxyConfigServiceImpl() | 411 ProxyConfigServiceImpl::ProxyConfigServiceImpl(PrefService* local_state) |
| 393 : can_post_task_(false), | 412 : can_post_task_(false), |
| 394 has_config_(false), | 413 has_config_(false), |
| 395 persist_to_device_(true), | 414 persist_to_device_(true), |
| 396 persist_to_device_pending_(false) { | 415 persist_to_device_pending_(false), |
| 416 local_state_(local_state) { |
| 417 DCHECK(local_state_); |
| 418 |
| 397 // Start async fetch of proxy config from settings persisted on device. | 419 // Start async fetch of proxy config from settings persisted on device. |
| 398 // TODO(kuan): retrieve config from policy and owner and merge them | 420 // TODO(kuan): retrieve config from policy and owner and merge them |
| 399 bool use_default = true; | 421 bool use_default = true; |
| 400 if (CrosLibrary::Get()->EnsureLoaded()) { | 422 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 401 retrieve_property_op_ = SignedSettings::CreateRetrievePropertyOp( | 423 retrieve_property_op_ = SignedSettings::CreateRetrievePropertyOp( |
| 402 kSettingProxyEverywhere, this); | 424 kSettingProxyEverywhere, this); |
| 403 if (retrieve_property_op_) { | 425 if (retrieve_property_op_) { |
| 404 retrieve_property_op_->Execute(); | 426 retrieve_property_op_->Execute(); |
| 405 VLOG(1) << "Start retrieving proxy setting from device"; | 427 VLOG(1) << "Start retrieving proxy setting from device"; |
| 406 use_default = false; | 428 use_default = false; |
| 407 } else { | 429 } else { |
| 408 VLOG(1) << "Fail to retrieve proxy setting from device"; | 430 VLOG(1) << "Fail to retrieve proxy setting from device"; |
| 409 } | 431 } |
| 410 } | 432 } |
| 411 if (use_default) | 433 if (use_default) |
| 412 InitConfigToDefault(false); | 434 InitConfigToDefault(); |
| 413 can_post_task_ = true; | 435 can_post_task_ = true; |
| 414 } | 436 } |
| 415 | 437 |
| 416 ProxyConfigServiceImpl::ProxyConfigServiceImpl(const ProxyConfig& init_config) | 438 ProxyConfigServiceImpl::ProxyConfigServiceImpl(PrefService* local_state, |
| 439 const ProxyConfig& init_config) |
| 417 : can_post_task_(true), | 440 : can_post_task_(true), |
| 418 has_config_(true), | 441 has_config_(true), |
| 419 persist_to_device_(false), | 442 persist_to_device_(false), |
| 420 persist_to_device_pending_(false) { | 443 persist_to_device_pending_(false), |
| 444 local_state_(local_state) { |
| 445 DCHECK(local_state_); |
| 421 reference_config_ = init_config; | 446 reference_config_ = init_config; |
| 422 // Update the IO-accessible copy in |cached_config_| as well. | 447 OnUISetProxyConfig(false); |
| 423 cached_config_ = reference_config_; | |
| 424 } | 448 } |
| 425 | 449 |
| 426 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { | 450 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { |
| 427 } | 451 } |
| 428 | 452 |
| 429 void ProxyConfigServiceImpl::UIGetProxyConfig(ProxyConfig* config) { | 453 void ProxyConfigServiceImpl::UIGetProxyConfig(ProxyConfig* config) { |
| 430 // Should be called from UI thread. | |
| 431 CheckCurrentlyOnUIThread(); | |
| 432 // Simply returns the copy on the UI thread. | 454 // Simply returns the copy on the UI thread. |
| 433 *config = reference_config_; | 455 *config = reference_config_; |
| 434 } | 456 } |
| 435 | 457 |
| 436 bool ProxyConfigServiceImpl::UISetProxyConfigToDirect() { | 458 bool ProxyConfigServiceImpl::UISetProxyConfigToDirect() { |
| 437 // Should be called from UI thread. | |
| 438 CheckCurrentlyOnUIThread(); | |
| 439 reference_config_.mode = ProxyConfig::MODE_DIRECT; | 459 reference_config_.mode = ProxyConfig::MODE_DIRECT; |
| 440 OnUISetProxyConfig(persist_to_device_); | 460 OnUISetProxyConfig(persist_to_device_); |
| 441 return true; | 461 return true; |
| 442 } | 462 } |
| 443 | 463 |
| 444 bool ProxyConfigServiceImpl::UISetProxyConfigToAutoDetect() { | 464 bool ProxyConfigServiceImpl::UISetProxyConfigToAutoDetect() { |
| 445 // Should be called from UI thread. | |
| 446 CheckCurrentlyOnUIThread(); | |
| 447 reference_config_.mode = ProxyConfig::MODE_AUTO_DETECT; | 465 reference_config_.mode = ProxyConfig::MODE_AUTO_DETECT; |
| 448 OnUISetProxyConfig(persist_to_device_); | 466 OnUISetProxyConfig(persist_to_device_); |
| 449 return true; | 467 return true; |
| 450 } | 468 } |
| 451 | 469 |
| 452 bool ProxyConfigServiceImpl::UISetProxyConfigToPACScript(const GURL& pac_url) { | 470 bool ProxyConfigServiceImpl::UISetProxyConfigToPACScript(const GURL& pac_url) { |
| 453 // Should be called from UI thread. | |
| 454 CheckCurrentlyOnUIThread(); | |
| 455 reference_config_.mode = ProxyConfig::MODE_PAC_SCRIPT; | 471 reference_config_.mode = ProxyConfig::MODE_PAC_SCRIPT; |
| 456 reference_config_.automatic_proxy.pac_url = pac_url; | 472 reference_config_.automatic_proxy.pac_url = pac_url; |
| 457 OnUISetProxyConfig(persist_to_device_); | 473 OnUISetProxyConfig(persist_to_device_); |
| 458 return true; | 474 return true; |
| 459 } | 475 } |
| 460 | 476 |
| 461 bool ProxyConfigServiceImpl::UISetProxyConfigToSingleProxy( | 477 bool ProxyConfigServiceImpl::UISetProxyConfigToSingleProxy( |
| 462 const net::ProxyServer& server) { | 478 const net::ProxyServer& server) { |
| 463 // Should be called from UI thread. | |
| 464 CheckCurrentlyOnUIThread(); | |
| 465 reference_config_.mode = ProxyConfig::MODE_SINGLE_PROXY; | 479 reference_config_.mode = ProxyConfig::MODE_SINGLE_PROXY; |
| 466 reference_config_.single_proxy.server = server; | 480 reference_config_.single_proxy.server = server; |
| 467 OnUISetProxyConfig(persist_to_device_); | 481 OnUISetProxyConfig(persist_to_device_); |
| 468 return true; | 482 return true; |
| 469 } | 483 } |
| 470 | 484 |
| 471 bool ProxyConfigServiceImpl::UISetProxyConfigToProxyPerScheme( | 485 bool ProxyConfigServiceImpl::UISetProxyConfigToProxyPerScheme( |
| 472 const std::string& scheme, const net::ProxyServer& server) { | 486 const std::string& scheme, const net::ProxyServer& server) { |
| 473 // Should be called from UI thread. | |
| 474 CheckCurrentlyOnUIThread(); | |
| 475 ProxyConfig::ManualProxy* proxy = reference_config_.MapSchemeToProxy(scheme); | 487 ProxyConfig::ManualProxy* proxy = reference_config_.MapSchemeToProxy(scheme); |
| 476 if (!proxy) { | 488 if (!proxy) { |
| 477 NOTREACHED() << "Cannot set proxy: invalid scheme [" << scheme << "]"; | 489 NOTREACHED() << "Cannot set proxy: invalid scheme [" << scheme << "]"; |
| 478 return false; | 490 return false; |
| 479 } | 491 } |
| 480 reference_config_.mode = ProxyConfig::MODE_PROXY_PER_SCHEME; | 492 reference_config_.mode = ProxyConfig::MODE_PROXY_PER_SCHEME; |
| 481 proxy->server = server; | 493 proxy->server = server; |
| 482 OnUISetProxyConfig(persist_to_device_); | 494 OnUISetProxyConfig(persist_to_device_); |
| 483 return true; | 495 return true; |
| 484 } | 496 } |
| 485 | 497 |
| 486 bool ProxyConfigServiceImpl::UISetProxyConfigBypassRules( | 498 bool ProxyConfigServiceImpl::UISetProxyConfigBypassRules( |
| 487 const net::ProxyBypassRules& bypass_rules) { | 499 const net::ProxyBypassRules& bypass_rules) { |
| 488 // Should be called from UI thread. | |
| 489 CheckCurrentlyOnUIThread(); | |
| 490 DCHECK(reference_config_.mode == ProxyConfig::MODE_SINGLE_PROXY || | 500 DCHECK(reference_config_.mode == ProxyConfig::MODE_SINGLE_PROXY || |
| 491 reference_config_.mode == ProxyConfig::MODE_PROXY_PER_SCHEME); | 501 reference_config_.mode == ProxyConfig::MODE_PROXY_PER_SCHEME); |
| 492 if (reference_config_.mode != ProxyConfig::MODE_SINGLE_PROXY && | 502 if (reference_config_.mode != ProxyConfig::MODE_SINGLE_PROXY && |
| 493 reference_config_.mode != ProxyConfig::MODE_PROXY_PER_SCHEME) { | 503 reference_config_.mode != ProxyConfig::MODE_PROXY_PER_SCHEME) { |
| 494 VLOG(1) << "Cannot set bypass rules for proxy mode [" | 504 VLOG(1) << "Cannot set bypass rules for proxy mode [" |
| 495 << reference_config_.mode << "]"; | 505 << reference_config_.mode << "]"; |
| 496 return false; | 506 return false; |
| 497 } | 507 } |
| 498 reference_config_.bypass_rules = bypass_rules; | 508 reference_config_.bypass_rules = bypass_rules; |
| 499 OnUISetProxyConfig(persist_to_device_); | 509 OnUISetProxyConfig(persist_to_device_); |
| 500 return true; | 510 return true; |
| 501 } | 511 } |
| 502 | 512 |
| 503 void ProxyConfigServiceImpl::AddObserver( | |
| 504 net::ProxyConfigService::Observer* observer) { | |
| 505 // Should be called from IO thread. | |
| 506 CheckCurrentlyOnIOThread(); | |
| 507 observers_.AddObserver(observer); | |
| 508 } | |
| 509 | |
| 510 void ProxyConfigServiceImpl::RemoveObserver( | |
| 511 net::ProxyConfigService::Observer* observer) { | |
| 512 // Should be called from IO thread. | |
| 513 CheckCurrentlyOnIOThread(); | |
| 514 observers_.RemoveObserver(observer); | |
| 515 } | |
| 516 | |
| 517 bool ProxyConfigServiceImpl::IOGetProxyConfig(net::ProxyConfig* net_config) { | |
| 518 // Should be called from IO thread. | |
| 519 CheckCurrentlyOnIOThread(); | |
| 520 if (has_config_) { | |
| 521 // Simply return the last cached proxy configuration. | |
| 522 cached_config_.ToNetProxyConfig(net_config); | |
| 523 return true; | |
| 524 } | |
| 525 return false; | |
| 526 } | |
| 527 | |
| 528 void ProxyConfigServiceImpl::OnSettingsOpCompleted( | 513 void ProxyConfigServiceImpl::OnSettingsOpCompleted( |
| 529 SignedSettings::ReturnCode code, | 514 SignedSettings::ReturnCode code, |
| 530 bool value) { | 515 bool value) { |
| 531 if (SignedSettings::SUCCESS == code) | 516 if (SignedSettings::SUCCESS == code) |
| 532 VLOG(1) << "Stored proxy setting to device"; | 517 VLOG(1) << "Stored proxy setting to device"; |
| 533 else | 518 else |
| 534 LOG(WARNING) << "Error storing proxy setting to device"; | 519 LOG(WARNING) << "Error storing proxy setting to device"; |
| 535 store_property_op_ = NULL; | 520 store_property_op_ = NULL; |
| 536 if (persist_to_device_pending_) | 521 if (persist_to_device_pending_) |
| 537 PersistConfigToDevice(); | 522 PersistConfigToDevice(); |
| 538 } | 523 } |
| 539 | 524 |
| 540 void ProxyConfigServiceImpl::OnSettingsOpCompleted( | 525 void ProxyConfigServiceImpl::OnSettingsOpCompleted( |
| 541 SignedSettings::ReturnCode code, | 526 SignedSettings::ReturnCode code, |
| 542 std::string value) { | 527 std::string value) { |
| 543 if (SignedSettings::SUCCESS == code) { | 528 if (SignedSettings::SUCCESS == code) { |
| 544 VLOG(1) << "Retrieved proxy setting from device, value=[" << value << "]"; | 529 VLOG(1) << "Retrieved proxy setting from device, value=[" << value << "]"; |
| 545 if (reference_config_.Deserialize(value)) { | 530 if (reference_config_.Deserialize(value)) { |
| 546 OnUISetProxyConfig(false); | 531 OnUISetProxyConfig(false); |
| 547 } else { | 532 } else { |
| 548 LOG(WARNING) << "Error deserializing device's proxy setting"; | 533 LOG(WARNING) << "Error deserializing device's proxy setting"; |
| 549 InitConfigToDefault(true); | 534 InitConfigToDefault(); |
| 550 } | 535 } |
| 551 } else { | 536 } else { |
| 552 LOG(WARNING) << "Error retrieving proxy setting from device"; | 537 LOG(WARNING) << "Error retrieving proxy setting from device"; |
| 553 InitConfigToDefault(true); | 538 InitConfigToDefault(); |
| 554 } | 539 } |
| 555 retrieve_property_op_ = NULL; | 540 retrieve_property_op_ = NULL; |
| 556 } | 541 } |
| 557 | 542 |
| 558 //------------------ ProxyConfigServiceImpl: private methods ------------------- | 543 //------------------ ProxyConfigServiceImpl: private methods ------------------- |
| 559 | 544 |
| 560 void ProxyConfigServiceImpl::InitConfigToDefault(bool post_to_io_thread) { | 545 void ProxyConfigServiceImpl::InitConfigToDefault() { |
| 561 VLOG(1) << "Using default proxy config: auto-detect"; | 546 VLOG(1) << "Using default proxy config: auto-detect"; |
| 562 reference_config_.mode = ProxyConfig::MODE_AUTO_DETECT; | 547 reference_config_.mode = ProxyConfig::MODE_AUTO_DETECT; |
| 563 reference_config_.automatic_proxy.source = ProxyConfig::SOURCE_OWNER; | 548 reference_config_.automatic_proxy.source = ProxyConfig::SOURCE_OWNER; |
| 564 if (post_to_io_thread && can_post_task_) { | 549 OnUISetProxyConfig(false); |
| 565 OnUISetProxyConfig(false); | |
| 566 } else { | |
| 567 // Update the IO-accessible copy in |cached_config_| as well. | |
| 568 cached_config_ = reference_config_; | |
| 569 has_config_ = true; | |
| 570 } | |
| 571 } | 550 } |
| 572 | 551 |
| 573 void ProxyConfigServiceImpl::PersistConfigToDevice() { | 552 void ProxyConfigServiceImpl::PersistConfigToDevice() { |
| 574 DCHECK(!store_property_op_); | 553 DCHECK(!store_property_op_); |
| 575 persist_to_device_pending_ = false; | 554 persist_to_device_pending_ = false; |
| 576 std::string value; | 555 std::string value; |
| 577 if (!reference_config_.Serialize(&value)) { | 556 if (!reference_config_.Serialize(&value)) { |
| 578 LOG(WARNING) << "Error serializing proxy config"; | 557 LOG(WARNING) << "Error serializing proxy config"; |
| 579 return; | 558 return; |
| 580 } | 559 } |
| 581 store_property_op_ = SignedSettings::CreateStorePropertyOp( | 560 store_property_op_ = SignedSettings::CreateStorePropertyOp( |
| 582 kSettingProxyEverywhere, value, this); | 561 kSettingProxyEverywhere, value, this); |
| 583 store_property_op_->Execute(); | 562 store_property_op_->Execute(); |
| 584 VLOG(1) << "Start storing proxy setting to device, value=" << value; | 563 VLOG(1) << "Start storing proxy setting to device, value=" << value; |
| 585 } | 564 } |
| 586 | 565 |
| 587 void ProxyConfigServiceImpl::OnUISetProxyConfig(bool persist_to_device) { | 566 void ProxyConfigServiceImpl::OnUISetProxyConfig(bool persist_to_device) { |
| 588 // Posts a task to IO thread with the new config, so it can update | 567 scoped_ptr<DictionaryValue> proxy_dict( |
| 589 // |cached_config_|. | 568 reference_config_.ToProxyConfigDictionary()); |
| 590 Task* task = NewRunnableMethod(this, | 569 if (proxy_dict.get()) |
| 591 &ProxyConfigServiceImpl::IOSetProxyConfig, reference_config_); | 570 local_state_->Set(prefs::kProxy, *proxy_dict); |
| 592 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task)) { | 571 else |
| 593 VLOG(1) << "Couldn't post task to IO thread to set new proxy config"; | 572 local_state_->ClearPref(prefs::kProxy); |
| 594 delete task; | |
| 595 } | |
| 596 | 573 |
| 597 if (persist_to_device && CrosLibrary::Get()->EnsureLoaded()) { | 574 if (persist_to_device && CrosLibrary::Get()->EnsureLoaded()) { |
| 598 if (store_property_op_) { | 575 if (store_property_op_) { |
| 599 persist_to_device_pending_ = true; | 576 persist_to_device_pending_ = true; |
| 600 VLOG(1) << "Pending persisting proxy setting to device"; | 577 VLOG(1) << "Pending persisting proxy setting to device"; |
| 601 } else { | 578 } else { |
| 602 PersistConfigToDevice(); | 579 PersistConfigToDevice(); |
| 603 } | 580 } |
| 604 } | 581 } |
| 605 } | 582 } |
| 606 | 583 |
| 607 void ProxyConfigServiceImpl::CheckCurrentlyOnIOThread() { | |
| 608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 609 } | |
| 610 | |
| 611 void ProxyConfigServiceImpl::CheckCurrentlyOnUIThread() { | |
| 612 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 613 } | |
| 614 | |
| 615 void ProxyConfigServiceImpl::IOSetProxyConfig(const ProxyConfig& new_config) { | |
| 616 // This is called on the IO thread (posted from UI thread). | |
| 617 CheckCurrentlyOnIOThread(); | |
| 618 VLOG(1) << "Proxy configuration changed"; | |
| 619 has_config_ = true; | |
| 620 cached_config_ = new_config; | |
| 621 // Notify observers of new proxy config. | |
| 622 net::ProxyConfig net_config; | |
| 623 cached_config_.ToNetProxyConfig(&net_config); | |
| 624 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, | |
| 625 OnProxyConfigChanged(net_config)); | |
| 626 } | |
| 627 | |
| 628 } // namespace chromeos | 584 } // namespace chromeos |
| OLD | NEW |