OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/proxy/proxy_config_service_linux.h" | 5 #include "net/proxy/proxy_config_service_linux.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 &values.ignore_hosts; | 168 &values.ignore_hosts; |
169 Reset(); | 169 Reset(); |
170 } | 170 } |
171 | 171 |
172 // Zeros all environment values. | 172 // Zeros all environment values. |
173 void Reset() { | 173 void Reset() { |
174 GConfValues zero_values = { 0 }; | 174 GConfValues zero_values = { 0 }; |
175 values = zero_values; | 175 values = zero_values; |
176 } | 176 } |
177 | 177 |
178 virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, | 178 virtual bool Init( |
179 base::MessageLoopForIO* file_loop) OVERRIDE { | 179 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, |
| 180 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| 181 OVERRIDE { |
| 182 task_runner_ = glib_task_runner; |
180 return true; | 183 return true; |
181 } | 184 } |
182 | 185 |
183 virtual void ShutDown() OVERRIDE {} | 186 virtual void ShutDown() OVERRIDE {} |
184 | 187 |
185 virtual bool SetUpNotifications(ProxyConfigServiceLinux::Delegate* delegate) | 188 virtual bool SetUpNotifications(ProxyConfigServiceLinux::Delegate* delegate) |
186 OVERRIDE { | 189 OVERRIDE { |
187 return true; | 190 return true; |
188 } | 191 } |
189 | 192 |
190 virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { | 193 virtual const scoped_refptr<base::SingleThreadTaskRunner>& |
191 return NULL; | 194 GetNotificationTaskRunner() OVERRIDE { |
| 195 return task_runner_; |
192 } | 196 } |
193 | 197 |
194 virtual ProxyConfigSource GetConfigSource() OVERRIDE { | 198 virtual ProxyConfigSource GetConfigSource() OVERRIDE { |
195 return PROXY_CONFIG_SOURCE_TEST; | 199 return PROXY_CONFIG_SOURCE_TEST; |
196 } | 200 } |
197 | 201 |
198 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { | 202 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { |
199 const char* value = strings_table.Get(key); | 203 const char* value = strings_table.Get(key); |
200 if (value) { | 204 if (value) { |
201 *result = value; | 205 *result = value; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 240 } |
237 | 241 |
238 virtual bool MatchHostsUsingSuffixMatching() OVERRIDE { | 242 virtual bool MatchHostsUsingSuffixMatching() OVERRIDE { |
239 return false; | 243 return false; |
240 } | 244 } |
241 | 245 |
242 // Intentionally public, for convenience when setting up a test. | 246 // Intentionally public, for convenience when setting up a test. |
243 GConfValues values; | 247 GConfValues values; |
244 | 248 |
245 private: | 249 private: |
| 250 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
246 SettingsTable<StringSetting, const char*> strings_table; | 251 SettingsTable<StringSetting, const char*> strings_table; |
247 SettingsTable<BoolSetting, BoolSettingValue> bools_table; | 252 SettingsTable<BoolSetting, BoolSettingValue> bools_table; |
248 SettingsTable<IntSetting, int> ints_table; | 253 SettingsTable<IntSetting, int> ints_table; |
249 SettingsTable<StringListSetting, | 254 SettingsTable<StringListSetting, |
250 std::vector<std::string> > string_lists_table; | 255 std::vector<std::string> > string_lists_table; |
251 }; | 256 }; |
252 | 257 |
253 } // namespace | 258 } // namespace |
254 } // namespace net | 259 } // namespace net |
255 | 260 |
(...skipping 25 matching lines...) Expand all Loading... |
281 // Clean up the IO thread. | 286 // Clean up the IO thread. |
282 io_thread_.message_loop()->PostTask(FROM_HERE, | 287 io_thread_.message_loop()->PostTask(FROM_HERE, |
283 base::Bind(&SynchConfigGetter::CleanUp, base::Unretained(this))); | 288 base::Bind(&SynchConfigGetter::CleanUp, base::Unretained(this))); |
284 Wait(); | 289 Wait(); |
285 } | 290 } |
286 | 291 |
287 // Does gconf setup and initial fetch of the proxy config, | 292 // Does gconf setup and initial fetch of the proxy config, |
288 // all on the calling thread (meant to be the thread with the | 293 // all on the calling thread (meant to be the thread with the |
289 // default glib main loop, which is the UI thread). | 294 // default glib main loop, which is the UI thread). |
290 void SetupAndInitialFetch() { | 295 void SetupAndInitialFetch() { |
291 base::MessageLoop* file_loop = io_thread_.message_loop(); | |
292 DCHECK_EQ(base::MessageLoop::TYPE_IO, file_loop->type()); | |
293 // We pass the mock IO thread as both the IO and file threads. | 296 // We pass the mock IO thread as both the IO and file threads. |
294 config_service_->SetupAndFetchInitialConfig( | 297 config_service_->SetupAndFetchInitialConfig( |
295 base::MessageLoopProxy::current().get(), | 298 base::MessageLoopProxy::current(), |
296 io_thread_.message_loop_proxy().get(), | 299 io_thread_.message_loop_proxy(), |
297 static_cast<base::MessageLoopForIO*>(file_loop)); | 300 io_thread_.message_loop_proxy()); |
298 } | 301 } |
299 // Synchronously gets the proxy config. | 302 // Synchronously gets the proxy config. |
300 net::ProxyConfigService::ConfigAvailability SyncGetLatestProxyConfig( | 303 net::ProxyConfigService::ConfigAvailability SyncGetLatestProxyConfig( |
301 net::ProxyConfig* config) { | 304 net::ProxyConfig* config) { |
302 io_thread_.message_loop()->PostTask(FROM_HERE, | 305 io_thread_.message_loop()->PostTask(FROM_HERE, |
303 base::Bind(&SynchConfigGetter::GetLatestConfigOnIOThread, | 306 base::Bind(&SynchConfigGetter::GetLatestConfigOnIOThread, |
304 base::Unretained(this))); | 307 base::Unretained(this))); |
305 Wait(); | 308 Wait(); |
306 *config = proxy_config_; | 309 *config = proxy_config_; |
307 return get_latest_config_result_; | 310 return get_latest_config_result_; |
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 ProxyConfig config; | 1611 ProxyConfig config; |
1609 sync_config_getter.SetupAndInitialFetch(); | 1612 sync_config_getter.SetupAndInitialFetch(); |
1610 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, | 1613 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
1611 sync_config_getter.SyncGetLatestProxyConfig(&config)); | 1614 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
1612 EXPECT_TRUE(config.auto_detect()); | 1615 EXPECT_TRUE(config.auto_detect()); |
1613 EXPECT_EQ(GURL(), config.pac_url()); | 1616 EXPECT_EQ(GURL(), config.pac_url()); |
1614 } | 1617 } |
1615 } | 1618 } |
1616 | 1619 |
1617 } // namespace net | 1620 } // namespace net |
OLD | NEW |