Chromium Code Reviews| Index: net/proxy/polling_proxy_config_service.cc |
| diff --git a/net/proxy/polling_proxy_config_service.cc b/net/proxy/polling_proxy_config_service.cc |
| index 7526c192c0375db0129144e388269ca47fe89d7e..aee5abfe1aeb8226d17ce6cf483b83aa8227fbae 100644 |
| --- a/net/proxy/polling_proxy_config_service.cc |
| +++ b/net/proxy/polling_proxy_config_service.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -24,7 +24,7 @@ class PollingProxyConfigService::Core |
| : get_config_func_(get_config_func), |
| poll_interval_(poll_interval), |
| have_initialized_origin_loop_(false), |
| - has_config_(false), |
| + config_availability_(ProxyConfigService::CONFIG_PENDING), |
| poll_task_outstanding_(false), |
| poll_task_queued_(false) { |
| } |
| @@ -36,7 +36,8 @@ class PollingProxyConfigService::Core |
| origin_loop_proxy_ = NULL; |
| } |
| - bool GetLatestProxyConfig(ProxyConfig* config) { |
| + ProxyConfigService::ConfigAvailability GetLatestProxyConfig( |
| + ProxyConfig* config) { |
| LazyInitializeOriginLoop(); |
| DCHECK(origin_loop_proxy_->BelongsToCurrentThread()); |
| @@ -44,11 +45,10 @@ class PollingProxyConfigService::Core |
| // If we have already retrieved the proxy settings (on worker thread) |
| // then return what we last saw. |
| - if (has_config_) { |
| + if (config_availability_ == ProxyConfigService::CONFIG_VALID) |
| *config = last_config_; |
| - return true; |
| - } |
| - return false; |
| + |
| + return config_availability_; |
| } |
| void AddObserver(Observer* observer) { |
| @@ -97,18 +97,21 @@ class PollingProxyConfigService::Core |
| private: |
| void PollOnWorkerThread(GetConfigFunction func) { |
| ProxyConfig config; |
| - func(&config); |
| + ProxyConfigService::ConfigAvailability available = func(&config); |
|
eroman
2011/03/16 01:30:00
Please add a DCHECK/CHECK that |available| != CONF
Mattias Nissler (ping if slow)
2011/03/16 17:40:00
Done.
|
| base::AutoLock l(lock_); |
| if (origin_loop_proxy_) { |
| origin_loop_proxy_->PostTask( |
| FROM_HERE, |
| - NewRunnableMethod(this, &Core::GetConfigCompleted, config)); |
| + NewRunnableMethod(this, &Core::GetConfigCompleted, |
| + config, available)); |
| } |
| } |
| // Called after the worker thread has finished retrieving a configuration. |
| - void GetConfigCompleted(const ProxyConfig& config) { |
| + void GetConfigCompleted( |
| + const ProxyConfig& config, |
| + ProxyConfigService::ConfigAvailability available) { |
| DCHECK(poll_task_outstanding_); |
| poll_task_outstanding_ = false; |
| @@ -117,11 +120,15 @@ class PollingProxyConfigService::Core |
| DCHECK(origin_loop_proxy_->BelongsToCurrentThread()); |
| - if (!has_config_ || !last_config_.Equals(config)) { |
| + if (config_availability_ != available || |
| + (available == ProxyConfigService::CONFIG_VALID && |
| + !last_config_.Equals(config))) { |
| // If the configuration has changed, notify the observers. |
| - has_config_ = true; |
| + config_availability_ = available; |
| last_config_ = config; |
| - FOR_EACH_OBSERVER(Observer, observers_, OnProxyConfigChanged(config)); |
| + FOR_EACH_OBSERVER(Observer, observers_, |
| + OnProxyConfigChanged(last_config_, |
| + config_availability_)); |
| } |
| if (poll_task_queued_) |
| @@ -149,7 +156,7 @@ class PollingProxyConfigService::Core |
| scoped_refptr<base::MessageLoopProxy> origin_loop_proxy_; |
| bool have_initialized_origin_loop_; |
| - bool has_config_; |
| + ProxyConfigService::ConfigAvailability config_availability_; |
| bool poll_task_outstanding_; |
| bool poll_task_queued_; |
| }; |
| @@ -162,7 +169,8 @@ void PollingProxyConfigService::RemoveObserver(Observer* observer) { |
| core_->RemoveObserver(observer); |
| } |
| -bool PollingProxyConfigService::GetLatestProxyConfig(ProxyConfig* config) { |
| +ProxyConfigService::ConfigAvailability |
| + PollingProxyConfigService::GetLatestProxyConfig(ProxyConfig* config) { |
| return core_->GetLatestProxyConfig(config); |
| } |