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

Side by Side Diff: components/proxy_config/pref_proxy_config_tracker_impl.cc

Issue 2972223002: Revert https://codereview.chromium.org/2860033003 (Closed)
Patch Set: Created 3 years, 5 months 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 unified diff | Download patch
OLDNEW
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 "components/proxy_config/pref_proxy_config_tracker_impl.h" 5 #include "components/proxy_config/pref_proxy_config_tracker_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "components/pref_registry/pref_registry_syncable.h" 16 #include "components/pref_registry/pref_registry_syncable.h"
17 #include "components/prefs/pref_registry_simple.h" 17 #include "components/prefs/pref_registry_simple.h"
18 #include "components/prefs/pref_service.h" 18 #include "components/prefs/pref_service.h"
19 #include "components/proxy_config/proxy_config_dictionary.h" 19 #include "components/proxy_config/proxy_config_dictionary.h"
20 #include "components/proxy_config/proxy_config_pref_names.h" 20 #include "components/proxy_config/proxy_config_pref_names.h"
21 #include "net/proxy/proxy_server.h" 21 #include "net/proxy/proxy_server.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 //============================= ProxyConfigServiceImpl ======================= 24 //============================= ProxyConfigServiceImpl =======================
25 25
26 ProxyConfigServiceImpl::ProxyConfigServiceImpl( 26 ProxyConfigServiceImpl::ProxyConfigServiceImpl(
27 std::unique_ptr<net::ProxyConfigService> base_service, 27 net::ProxyConfigService* base_service)
28 ProxyPrefs::ConfigState initial_config_state, 28 : base_service_(base_service),
29 const net::ProxyConfig& initial_config) 29 pref_config_state_(ProxyPrefs::CONFIG_UNSET),
30 : base_service_(std::move(base_service)), 30 pref_config_read_pending_(true),
31 pref_config_state_(initial_config_state),
32 pref_config_(initial_config),
33 registered_observer_(false) { 31 registered_observer_(false) {
34 // ProxyConfigServiceImpl is created on the UI thread, but used on the network 32 // ProxyConfigServiceImpl is created on the UI thread, but used on the network
35 // thread. 33 // thread.
36 thread_checker_.DetachFromThread(); 34 thread_checker_.DetachFromThread();
37 } 35 }
38 36
39 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() { 37 ProxyConfigServiceImpl::~ProxyConfigServiceImpl() {
40 if (registered_observer_ && base_service_.get()) 38 if (registered_observer_ && base_service_.get())
41 base_service_->RemoveObserver(this); 39 base_service_->RemoveObserver(this);
42 } 40 }
43 41
44 void ProxyConfigServiceImpl::AddObserver( 42 void ProxyConfigServiceImpl::AddObserver(
45 net::ProxyConfigService::Observer* observer) { 43 net::ProxyConfigService::Observer* observer) {
46 RegisterObserver(); 44 RegisterObserver();
47 observers_.AddObserver(observer); 45 observers_.AddObserver(observer);
48 } 46 }
49 47
50 void ProxyConfigServiceImpl::RemoveObserver( 48 void ProxyConfigServiceImpl::RemoveObserver(
51 net::ProxyConfigService::Observer* observer) { 49 net::ProxyConfigService::Observer* observer) {
52 observers_.RemoveObserver(observer); 50 observers_.RemoveObserver(observer);
53 } 51 }
54 52
55 net::ProxyConfigService::ConfigAvailability 53 net::ProxyConfigService::ConfigAvailability
56 ProxyConfigServiceImpl::GetLatestProxyConfig(net::ProxyConfig* config) { 54 ProxyConfigServiceImpl::GetLatestProxyConfig(net::ProxyConfig* config) {
57 RegisterObserver(); 55 RegisterObserver();
58 56
57 if (pref_config_read_pending_)
58 return net::ProxyConfigService::CONFIG_PENDING;
59
59 // Ask the base service if available. 60 // Ask the base service if available.
60 net::ProxyConfig system_config; 61 net::ProxyConfig system_config;
61 ConfigAvailability system_availability = 62 ConfigAvailability system_availability =
62 net::ProxyConfigService::CONFIG_UNSET; 63 net::ProxyConfigService::CONFIG_UNSET;
63 if (base_service_.get()) 64 if (base_service_.get())
64 system_availability = base_service_->GetLatestProxyConfig(&system_config); 65 system_availability = base_service_->GetLatestProxyConfig(&system_config);
65 66
66 ProxyPrefs::ConfigState config_state; 67 ProxyPrefs::ConfigState config_state;
67 return PrefProxyConfigTrackerImpl::GetEffectiveProxyConfig( 68 return PrefProxyConfigTrackerImpl::GetEffectiveProxyConfig(
68 pref_config_state_, pref_config_, system_availability, system_config, 69 pref_config_state_, pref_config_, system_availability, system_config,
69 false, &config_state, config); 70 false, &config_state, config);
70 } 71 }
71 72
72 void ProxyConfigServiceImpl::OnLazyPoll() { 73 void ProxyConfigServiceImpl::OnLazyPoll() {
73 if (base_service_.get()) 74 if (base_service_.get())
74 base_service_->OnLazyPoll(); 75 base_service_->OnLazyPoll();
75 } 76 }
76 77
77 void ProxyConfigServiceImpl::UpdateProxyConfig( 78 void ProxyConfigServiceImpl::UpdateProxyConfig(
78 ProxyPrefs::ConfigState config_state, 79 ProxyPrefs::ConfigState config_state,
79 const net::ProxyConfig& config) { 80 const net::ProxyConfig& config) {
80 DCHECK(thread_checker_.CalledOnValidThread()); 81 DCHECK(thread_checker_.CalledOnValidThread());
82 pref_config_read_pending_ = false;
81 pref_config_state_ = config_state; 83 pref_config_state_ = config_state;
82 pref_config_ = config; 84 pref_config_ = config;
83 85
84 if (!observers_.might_have_observers()) 86 if (!observers_.might_have_observers())
85 return; 87 return;
86 88
87 // Evaluate the proxy configuration. If GetLatestProxyConfig returns 89 // Evaluate the proxy configuration. If GetLatestProxyConfig returns
88 // CONFIG_PENDING, we are using the system proxy service, but it doesn't have 90 // CONFIG_PENDING, we are using the system proxy service, but it doesn't have
89 // a valid configuration yet. Once it is ready, OnProxyConfigChanged() will be 91 // a valid configuration yet. Once it is ready, OnProxyConfigChanged() will be
90 // called and broadcast the proxy configuration. 92 // called and broadcast the proxy configuration.
91 // Note: If a switch between a preference proxy configuration and the system 93 // Note: If a switch between a preference proxy configuration and the system
92 // proxy configuration occurs an unnecessary notification might get send if 94 // proxy configuration occurs an unnecessary notification might get send if
93 // the two configurations agree. This case should be rare however, so we don't 95 // the two configurations agree. This case should be rare however, so we don't
94 // handle that case specially. 96 // handle that case specially.
95 net::ProxyConfig new_config; 97 net::ProxyConfig new_config;
96 ConfigAvailability availability = GetLatestProxyConfig(&new_config); 98 ConfigAvailability availability = GetLatestProxyConfig(&new_config);
97 if (availability != CONFIG_PENDING) { 99 if (availability != CONFIG_PENDING) {
98 for (net::ProxyConfigService::Observer& observer : observers_) 100 for (net::ProxyConfigService::Observer& observer : observers_)
99 observer.OnProxyConfigChanged(new_config, availability); 101 observer.OnProxyConfigChanged(new_config, availability);
100 } 102 }
101 } 103 }
102 104
103 void ProxyConfigServiceImpl::OnProxyConfigChanged( 105 void ProxyConfigServiceImpl::OnProxyConfigChanged(
104 const net::ProxyConfig& config, 106 const net::ProxyConfig& config,
105 ConfigAvailability availability) { 107 ConfigAvailability availability) {
106 DCHECK(thread_checker_.CalledOnValidThread()); 108 DCHECK(thread_checker_.CalledOnValidThread());
107 109
108 // Check whether there is a proxy configuration defined by preferences. In 110 // Check whether there is a proxy configuration defined by preferences. In
109 // this case that proxy configuration takes precedence and the change event 111 // this case that proxy configuration takes precedence and the change event
110 // from the delegate proxy config service can be disregarded. 112 // from the delegate proxy service can be disregarded.
111 if (!PrefProxyConfigTrackerImpl::PrefPrecedes(pref_config_state_)) { 113 if (!PrefProxyConfigTrackerImpl::PrefPrecedes(pref_config_state_)) {
112 net::ProxyConfig actual_config; 114 net::ProxyConfig actual_config;
113 availability = GetLatestProxyConfig(&actual_config); 115 availability = GetLatestProxyConfig(&actual_config);
114 for (net::ProxyConfigService::Observer& observer : observers_) 116 for (net::ProxyConfigService::Observer& observer : observers_)
115 observer.OnProxyConfigChanged(actual_config, availability); 117 observer.OnProxyConfigChanged(actual_config, availability);
116 } 118 }
117 } 119 }
118 120
119 void ProxyConfigServiceImpl::RegisterObserver() { 121 void ProxyConfigServiceImpl::RegisterObserver() {
120 DCHECK(thread_checker_.CalledOnValidThread()); 122 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 19 matching lines...) Expand all
140 base::Unretained(this))); 142 base::Unretained(this)));
141 } 143 }
142 144
143 PrefProxyConfigTrackerImpl::~PrefProxyConfigTrackerImpl() { 145 PrefProxyConfigTrackerImpl::~PrefProxyConfigTrackerImpl() {
144 DCHECK(pref_service_ == NULL); 146 DCHECK(pref_service_ == NULL);
145 } 147 }
146 148
147 std::unique_ptr<net::ProxyConfigService> 149 std::unique_ptr<net::ProxyConfigService>
148 PrefProxyConfigTrackerImpl::CreateTrackingProxyConfigService( 150 PrefProxyConfigTrackerImpl::CreateTrackingProxyConfigService(
149 std::unique_ptr<net::ProxyConfigService> base_service) { 151 std::unique_ptr<net::ProxyConfigService> base_service) {
150 DCHECK(!proxy_config_service_impl_); 152 proxy_config_service_impl_ =
151 proxy_config_service_impl_ = new ProxyConfigServiceImpl( 153 new ProxyConfigServiceImpl(base_service.release());
152 std::move(base_service), config_state_, pref_config_);
153 VLOG(1) << this << ": set chrome proxy config service to " 154 VLOG(1) << this << ": set chrome proxy config service to "
154 << proxy_config_service_impl_; 155 << proxy_config_service_impl_;
155 update_pending_ = false; 156 if (proxy_config_service_impl_ && update_pending_)
157 OnProxyConfigChanged(config_state_, pref_config_);
156 158
157 return std::unique_ptr<net::ProxyConfigService>(proxy_config_service_impl_); 159 return std::unique_ptr<net::ProxyConfigService>(proxy_config_service_impl_);
158 } 160 }
159 161
160 void PrefProxyConfigTrackerImpl::DetachFromPrefService() { 162 void PrefProxyConfigTrackerImpl::DetachFromPrefService() {
161 DCHECK(thread_checker_.CalledOnValidThread()); 163 DCHECK(thread_checker_.CalledOnValidThread());
162 // Stop notifications. 164 // Stop notifications.
163 proxy_prefs_.RemoveAll(); 165 proxy_prefs_.RemoveAll();
164 pref_service_ = NULL; 166 pref_service_ = NULL;
165 proxy_config_service_impl_ = NULL; 167 proxy_config_service_impl_ = NULL;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 (config_state_ != ProxyPrefs::CONFIG_UNSET && 352 (config_state_ != ProxyPrefs::CONFIG_UNSET &&
351 !pref_config_.Equals(new_config))) { 353 !pref_config_.Equals(new_config))) {
352 config_state_ = config_state; 354 config_state_ = config_state;
353 if (config_state_ != ProxyPrefs::CONFIG_UNSET) 355 if (config_state_ != ProxyPrefs::CONFIG_UNSET)
354 pref_config_ = new_config; 356 pref_config_ = new_config;
355 update_pending_ = true; 357 update_pending_ = true;
356 } 358 }
357 if (update_pending_) 359 if (update_pending_)
358 OnProxyConfigChanged(config_state, new_config); 360 OnProxyConfigChanged(config_state, new_config);
359 } 361 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698