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

Side by Side Diff: net/proxy/proxy_config_service_linux.cc

Issue 2094913002: Make base::Environment::Create() return unique_ptrs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit, rebase Created 4 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) 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 <errno.h> 7 #include <errno.h>
8 #if defined(USE_GCONF) 8 #if defined(USE_GCONF)
9 #include <gconf/gconf-client.h> 9 #include <gconf/gconf-client.h>
10 #endif // defined(USE_GCONF) 10 #endif // defined(USE_GCONF)
11 #include <limits.h> 11 #include <limits.h>
12 #include <stdio.h> 12 #include <stdio.h>
13 #include <stdlib.h> 13 #include <stdlib.h>
14 #include <sys/inotify.h> 14 #include <sys/inotify.h>
15 #include <unistd.h> 15 #include <unistd.h>
16 16
17 #include <map> 17 #include <map>
18 #include <utility>
18 19
19 #include "base/bind.h" 20 #include "base/bind.h"
20 #include "base/compiler_specific.h" 21 #include "base/compiler_specific.h"
21 #include "base/debug/leak_annotations.h" 22 #include "base/debug/leak_annotations.h"
22 #include "base/files/file_path.h" 23 #include "base/files/file_path.h"
23 #include "base/files/file_util.h" 24 #include "base/files/file_util.h"
24 #include "base/files/scoped_file.h" 25 #include "base/files/scoped_file.h"
25 #include "base/logging.h" 26 #include "base/logging.h"
26 #include "base/macros.h" 27 #include "base/macros.h"
27 #include "base/message_loop/message_loop.h" 28 #include "base/message_loop/message_loop.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 host.resize(host.length() - 1); 88 host.resize(host.length() - 1);
88 return host; 89 return host;
89 } 90 }
90 91
91 } // namespace 92 } // namespace
92 93
93 ProxyConfigServiceLinux::Delegate::~Delegate() { 94 ProxyConfigServiceLinux::Delegate::~Delegate() {
94 } 95 }
95 96
96 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme( 97 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme(
97 const char* variable, ProxyServer::Scheme scheme, 98 base::StringPiece variable,
99 ProxyServer::Scheme scheme,
98 ProxyServer* result_server) { 100 ProxyServer* result_server) {
99 std::string env_value; 101 std::string env_value;
100 if (env_var_getter_->GetVar(variable, &env_value)) { 102 if (!env_var_getter_->GetVar(variable, &env_value))
101 if (!env_value.empty()) { 103 return false;
102 env_value = FixupProxyHostScheme(scheme, env_value); 104
103 ProxyServer proxy_server = 105 if (env_value.empty())
104 ProxyServer::FromURI(env_value, ProxyServer::SCHEME_HTTP); 106 return false;
105 if (proxy_server.is_valid() && !proxy_server.is_direct()) { 107
106 *result_server = proxy_server; 108 env_value = FixupProxyHostScheme(scheme, env_value);
107 return true; 109 ProxyServer proxy_server =
108 } else { 110 ProxyServer::FromURI(env_value, ProxyServer::SCHEME_HTTP);
109 LOG(ERROR) << "Failed to parse environment variable " << variable; 111 if (proxy_server.is_valid() && !proxy_server.is_direct()) {
110 } 112 *result_server = proxy_server;
111 } 113 return true;
112 } 114 }
115 LOG(ERROR) << "Failed to parse environment variable " << variable;
113 return false; 116 return false;
114 } 117 }
115 118
116 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVar( 119 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVar(
117 const char* variable, ProxyServer* result_server) { 120 base::StringPiece variable,
121 ProxyServer* result_server) {
118 return GetProxyFromEnvVarForScheme(variable, ProxyServer::SCHEME_HTTP, 122 return GetProxyFromEnvVarForScheme(variable, ProxyServer::SCHEME_HTTP,
119 result_server); 123 result_server);
120 } 124 }
121 125
122 bool ProxyConfigServiceLinux::Delegate::GetConfigFromEnv(ProxyConfig* config) { 126 bool ProxyConfigServiceLinux::Delegate::GetConfigFromEnv(ProxyConfig* config) {
123 // Check for automatic configuration first, in 127 // Check for automatic configuration first, in
124 // "auto_proxy". Possibly only the "environment_proxy" firefox 128 // "auto_proxy". Possibly only the "environment_proxy" firefox
125 // extension has ever used this, but it still sounds like a good 129 // extension has ever used this, but it still sounds like a good
126 // idea. 130 // idea.
127 std::string auto_proxy; 131 std::string auto_proxy;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 199
196 namespace { 200 namespace {
197 201
198 const int kDebounceTimeoutMilliseconds = 250; 202 const int kDebounceTimeoutMilliseconds = 250;
199 203
200 #if defined(USE_GCONF) 204 #if defined(USE_GCONF)
201 // This setting getter uses gconf, as used in GNOME 2 and some GNOME 3 desktops. 205 // This setting getter uses gconf, as used in GNOME 2 and some GNOME 3 desktops.
202 class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter { 206 class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
203 public: 207 public:
204 SettingGetterImplGConf() 208 SettingGetterImplGConf()
205 : client_(NULL), 209 : client_(nullptr),
206 system_proxy_id_(0), 210 system_proxy_id_(0),
207 system_http_proxy_id_(0), 211 system_http_proxy_id_(0),
208 notify_delegate_(NULL), 212 notify_delegate_(nullptr),
209 debounce_timer_(new base::OneShotTimer()) {} 213 debounce_timer_(new base::OneShotTimer()) {}
210 214
211 ~SettingGetterImplGConf() override { 215 ~SettingGetterImplGConf() override {
212 // client_ should have been released before now, from 216 // client_ should have been released before now, from
213 // Delegate::OnDestroy(), while running on the UI thread. However 217 // Delegate::OnDestroy(), while running on the UI thread. However
214 // on exiting the process, it may happen that Delegate::OnDestroy() 218 // on exiting the process, it may happen that Delegate::OnDestroy()
215 // task is left pending on the glib loop after the loop was quit, 219 // task is left pending on the glib loop after the loop was quit,
216 // and pending tasks may then be deleted without being run. 220 // and pending tasks may then be deleted without being run.
217 if (client_) { 221 if (client_) {
218 // gconf client was not cleaned up. 222 // gconf client was not cleaned up.
(...skipping 20 matching lines...) Expand all
239 override { 243 override {
240 DCHECK(glib_task_runner->BelongsToCurrentThread()); 244 DCHECK(glib_task_runner->BelongsToCurrentThread());
241 DCHECK(!client_); 245 DCHECK(!client_);
242 DCHECK(!task_runner_.get()); 246 DCHECK(!task_runner_.get());
243 task_runner_ = glib_task_runner; 247 task_runner_ = glib_task_runner;
244 248
245 client_ = gconf_client_get_default(); 249 client_ = gconf_client_get_default();
246 if (!client_) { 250 if (!client_) {
247 // It's not clear whether/when this can return NULL. 251 // It's not clear whether/when this can return NULL.
248 LOG(ERROR) << "Unable to create a gconf client"; 252 LOG(ERROR) << "Unable to create a gconf client";
249 task_runner_ = NULL; 253 task_runner_ = nullptr;
250 return false; 254 return false;
251 } 255 }
252 GError* error = NULL; 256 GError* error = nullptr;
253 bool added_system_proxy = false; 257 bool added_system_proxy = false;
254 // We need to add the directories for which we'll be asking 258 // We need to add the directories for which we'll be asking
255 // for notifications, and we might as well ask to preload them. 259 // for notifications, and we might as well ask to preload them.
256 // These need to be removed again in ShutDown(); we are careful 260 // These need to be removed again in ShutDown(); we are careful
257 // here to only leave client_ non-NULL if both have been added. 261 // here to only leave client_ non-NULL if both have been added.
258 gconf_client_add_dir(client_, "/system/proxy", 262 gconf_client_add_dir(client_, "/system/proxy",
259 GCONF_CLIENT_PRELOAD_ONELEVEL, &error); 263 GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
260 if (error == NULL) { 264 if (!error) {
261 added_system_proxy = true; 265 added_system_proxy = true;
262 gconf_client_add_dir(client_, "/system/http_proxy", 266 gconf_client_add_dir(client_, "/system/http_proxy",
263 GCONF_CLIENT_PRELOAD_ONELEVEL, &error); 267 GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
264 } 268 }
265 if (error != NULL) { 269 if (!error)
266 LOG(ERROR) << "Error requesting gconf directory: " << error->message; 270 return true;
267 g_error_free(error); 271
268 if (added_system_proxy) 272 LOG(ERROR) << "Error requesting gconf directory: " << error->message;
269 gconf_client_remove_dir(client_, "/system/proxy", NULL); 273 g_error_free(error);
270 g_object_unref(client_); 274 if (added_system_proxy)
271 client_ = NULL; 275 gconf_client_remove_dir(client_, "/system/proxy", nullptr);
272 task_runner_ = NULL; 276 g_object_unref(client_);
273 return false; 277 client_ = nullptr;
274 } 278 task_runner_ = nullptr;
275 return true; 279 return false;
276 } 280 }
277 281
278 void ShutDown() override { 282 void ShutDown() override {
279 if (client_) { 283 if (client_) {
280 DCHECK(task_runner_->BelongsToCurrentThread()); 284 DCHECK(task_runner_->BelongsToCurrentThread());
281 // We must explicitly disable gconf notifications here, because the gconf 285 // We must explicitly disable gconf notifications here, because the gconf
282 // client will be shared between all setting getters, and they do not all 286 // client will be shared between all setting getters, and they do not all
283 // have the same lifetimes. (For instance, incognito sessions get their 287 // have the same lifetimes. (For instance, incognito sessions get their
284 // own, which is destroyed when the session ends.) 288 // own, which is destroyed when the session ends.)
285 gconf_client_notify_remove(client_, system_http_proxy_id_); 289 gconf_client_notify_remove(client_, system_http_proxy_id_);
286 gconf_client_notify_remove(client_, system_proxy_id_); 290 gconf_client_notify_remove(client_, system_proxy_id_);
287 gconf_client_remove_dir(client_, "/system/http_proxy", NULL); 291 gconf_client_remove_dir(client_, "/system/http_proxy", nullptr);
288 gconf_client_remove_dir(client_, "/system/proxy", NULL); 292 gconf_client_remove_dir(client_, "/system/proxy", nullptr);
289 g_object_unref(client_); 293 g_object_unref(client_);
290 client_ = NULL; 294 client_ = nullptr;
291 task_runner_ = NULL; 295 task_runner_ = nullptr;
292 } 296 }
293 debounce_timer_.reset(); 297 debounce_timer_.reset();
294 } 298 }
295 299
296 bool SetUpNotifications( 300 bool SetUpNotifications(
297 ProxyConfigServiceLinux::Delegate* delegate) override { 301 ProxyConfigServiceLinux::Delegate* delegate) override {
298 DCHECK(client_); 302 DCHECK(client_);
299 DCHECK(task_runner_->BelongsToCurrentThread()); 303 DCHECK(task_runner_->BelongsToCurrentThread());
300 GError* error = NULL; 304 GError* error = nullptr;
301 notify_delegate_ = delegate; 305 notify_delegate_ = delegate;
302 // We have to keep track of the IDs returned by gconf_client_notify_add() so 306 // We have to keep track of the IDs returned by gconf_client_notify_add() so
303 // that we can remove them in ShutDown(). (Otherwise, notifications will be 307 // that we can remove them in ShutDown(). (Otherwise, notifications will be
304 // delivered to this object after it is deleted, which is bad, m'kay?) 308 // delivered to this object after it is deleted, which is bad, m'kay?)
305 system_proxy_id_ = gconf_client_notify_add( 309 system_proxy_id_ = gconf_client_notify_add(client_, "/system/proxy",
306 client_, "/system/proxy", 310 OnGConfChangeNotification, this,
307 OnGConfChangeNotification, this, 311 nullptr, &error);
308 NULL, &error); 312 if (!error) {
309 if (error == NULL) {
310 system_http_proxy_id_ = gconf_client_notify_add( 313 system_http_proxy_id_ = gconf_client_notify_add(
311 client_, "/system/http_proxy", 314 client_, "/system/http_proxy", OnGConfChangeNotification, this,
312 OnGConfChangeNotification, this, 315 nullptr, &error);
313 NULL, &error);
314 } 316 }
315 if (error != NULL) { 317 if (!error) {
316 LOG(ERROR) << "Error requesting gconf notifications: " << error->message; 318 // Simulate a change to avoid possibly losing updates before this point.
317 g_error_free(error); 319 OnChangeNotification();
318 ShutDown(); 320 return true;
319 return false;
320 } 321 }
321 // Simulate a change to avoid possibly losing updates before this point. 322
322 OnChangeNotification(); 323 LOG(ERROR) << "Error requesting gconf notifications: " << error->message;
323 return true; 324 g_error_free(error);
325 ShutDown();
326 return false;
324 } 327 }
325 328
326 const scoped_refptr<base::SingleThreadTaskRunner>& GetNotificationTaskRunner() 329 const scoped_refptr<base::SingleThreadTaskRunner>& GetNotificationTaskRunner()
327 override { 330 override {
328 return task_runner_; 331 return task_runner_;
329 } 332 }
330 333
331 ProxyConfigSource GetConfigSource() override { 334 ProxyConfigSource GetConfigSource() override {
332 return PROXY_CONFIG_SOURCE_GCONF; 335 return PROXY_CONFIG_SOURCE_GCONF;
333 } 336 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 386 }
384 387
385 bool BypassListIsReversed() override { 388 bool BypassListIsReversed() override {
386 // This is a KDE-specific setting. 389 // This is a KDE-specific setting.
387 return false; 390 return false;
388 } 391 }
389 392
390 bool MatchHostsUsingSuffixMatching() override { return false; } 393 bool MatchHostsUsingSuffixMatching() override { return false; }
391 394
392 private: 395 private:
393 bool GetStringByPath(const char* key, std::string* result) { 396 bool GetStringByPath(base::StringPiece key, std::string* result) {
394 DCHECK(client_); 397 DCHECK(client_);
395 DCHECK(task_runner_->BelongsToCurrentThread()); 398 DCHECK(task_runner_->BelongsToCurrentThread());
396 GError* error = NULL; 399 GError* error = nullptr;
397 gchar* value = gconf_client_get_string(client_, key, &error); 400 gchar* value = gconf_client_get_string(client_, key.data(), &error);
398 if (HandleGError(error, key)) 401 if (HandleGError(error, key.data()))
399 return false; 402 return false;
400 if (!value) 403 if (!value)
401 return false; 404 return false;
402 *result = value; 405 *result = value;
403 g_free(value); 406 g_free(value);
404 return true; 407 return true;
405 } 408 }
406 bool GetBoolByPath(const char* key, bool* result) { 409 bool GetBoolByPath(base::StringPiece key, bool* result) {
407 DCHECK(client_); 410 DCHECK(client_);
408 DCHECK(task_runner_->BelongsToCurrentThread()); 411 DCHECK(task_runner_->BelongsToCurrentThread());
409 GError* error = NULL; 412 GError* error = nullptr;
410 // We want to distinguish unset values from values defaulting to 413 // We want to distinguish unset values from values defaulting to
411 // false. For that we need to use the type-generic 414 // false. For that we need to use the type-generic
412 // gconf_client_get() rather than gconf_client_get_bool(). 415 // gconf_client_get() rather than gconf_client_get_bool().
413 GConfValue* gconf_value = gconf_client_get(client_, key, &error); 416 GConfValue* gconf_value = gconf_client_get(client_, key.data(), &error);
414 if (HandleGError(error, key)) 417 if (HandleGError(error, key.data()))
415 return false; 418 return false;
416 if (!gconf_value) { 419 if (!gconf_value) {
417 // Unset. 420 // Unset.
418 return false; 421 return false;
419 } 422 }
420 if (gconf_value->type != GCONF_VALUE_BOOL) { 423 if (gconf_value->type != GCONF_VALUE_BOOL) {
421 gconf_value_free(gconf_value); 424 gconf_value_free(gconf_value);
422 return false; 425 return false;
423 } 426 }
424 gboolean bool_value = gconf_value_get_bool(gconf_value); 427 gboolean bool_value = gconf_value_get_bool(gconf_value);
425 *result = static_cast<bool>(bool_value); 428 *result = static_cast<bool>(bool_value);
426 gconf_value_free(gconf_value); 429 gconf_value_free(gconf_value);
427 return true; 430 return true;
428 } 431 }
429 bool GetIntByPath(const char* key, int* result) { 432 bool GetIntByPath(base::StringPiece key, int* result) {
430 DCHECK(client_); 433 DCHECK(client_);
431 DCHECK(task_runner_->BelongsToCurrentThread()); 434 DCHECK(task_runner_->BelongsToCurrentThread());
432 GError* error = NULL; 435 GError* error = nullptr;
433 int value = gconf_client_get_int(client_, key, &error); 436 int value = gconf_client_get_int(client_, key.data(), &error);
434 if (HandleGError(error, key)) 437 if (HandleGError(error, key.data()))
435 return false; 438 return false;
436 // We don't bother to distinguish an unset value because callers 439 // We don't bother to distinguish an unset value because callers
437 // don't care. 0 is returned if unset. 440 // don't care. 0 is returned if unset.
438 *result = value; 441 *result = value;
439 return true; 442 return true;
440 } 443 }
441 bool GetStringListByPath(const char* key, std::vector<std::string>* result) { 444 bool GetStringListByPath(base::StringPiece key,
445 std::vector<std::string>* result) {
442 DCHECK(client_); 446 DCHECK(client_);
443 DCHECK(task_runner_->BelongsToCurrentThread()); 447 DCHECK(task_runner_->BelongsToCurrentThread());
444 GError* error = NULL; 448 GError* error = nullptr;
445 GSList* list = gconf_client_get_list(client_, key, 449 GSList* list =
446 GCONF_VALUE_STRING, &error); 450 gconf_client_get_list(client_, key.data(), GCONF_VALUE_STRING, &error);
447 if (HandleGError(error, key)) 451 if (HandleGError(error, key.data()))
448 return false; 452 return false;
449 if (!list) 453 if (!list)
450 return false; 454 return false;
451 for (GSList *it = list; it; it = it->next) { 455 for (GSList *it = list; it; it = it->next) {
452 result->push_back(static_cast<char*>(it->data)); 456 result->push_back(static_cast<char*>(it->data));
453 g_free(it->data); 457 g_free(it->data);
454 } 458 }
455 g_slist_free(list); 459 g_slist_free(list);
456 return true; 460 return true;
457 } 461 }
458 462
459 // Logs and frees a glib error. Returns false if there was no error 463 // Logs and frees a glib error. Returns false if there was no error
460 // (error is NULL). 464 // (error is NULL).
461 bool HandleGError(GError* error, const char* key) { 465 bool HandleGError(GError* error, base::StringPiece key) {
462 if (error != NULL) { 466 if (!error)
463 LOG(ERROR) << "Error getting gconf value for " << key 467 return false;
464 << ": " << error->message; 468
465 g_error_free(error); 469 LOG(ERROR) << "Error getting gconf value for " << key << ": "
466 return true; 470 << error->message;
467 } 471 g_error_free(error);
468 return false; 472 return true;
469 } 473 }
470 474
471 // This is the callback from the debounce timer. 475 // This is the callback from the debounce timer.
472 void OnDebouncedNotification() { 476 void OnDebouncedNotification() {
473 DCHECK(task_runner_->BelongsToCurrentThread()); 477 DCHECK(task_runner_->BelongsToCurrentThread());
474 CHECK(notify_delegate_); 478 CHECK(notify_delegate_);
475 // Forward to a method on the proxy config service delegate object. 479 // Forward to a method on the proxy config service delegate object.
476 notify_delegate_->OnCheckProxyConfigSettings(); 480 notify_delegate_->OnCheckProxyConfigSettings();
477 } 481 }
478 482
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 #endif // defined(USE_GCONF) 519 #endif // defined(USE_GCONF)
516 520
517 #if defined(USE_GIO) 521 #if defined(USE_GIO)
518 const char kProxyGConfSchema[] = "org.gnome.system.proxy"; 522 const char kProxyGConfSchema[] = "org.gnome.system.proxy";
519 523
520 // This setting getter uses gsettings, as used in most GNOME 3 desktops. 524 // This setting getter uses gsettings, as used in most GNOME 3 desktops.
521 class SettingGetterImplGSettings 525 class SettingGetterImplGSettings
522 : public ProxyConfigServiceLinux::SettingGetter { 526 : public ProxyConfigServiceLinux::SettingGetter {
523 public: 527 public:
524 SettingGetterImplGSettings() 528 SettingGetterImplGSettings()
525 : client_(NULL), 529 : client_(nullptr),
526 http_client_(NULL), 530 http_client_(nullptr),
527 https_client_(NULL), 531 https_client_(nullptr),
528 ftp_client_(NULL), 532 ftp_client_(nullptr),
529 socks_client_(NULL), 533 socks_client_(nullptr),
530 notify_delegate_(NULL), 534 notify_delegate_(nullptr),
531 debounce_timer_(new base::OneShotTimer()) {} 535 debounce_timer_(new base::OneShotTimer()) {}
532 536
533 ~SettingGetterImplGSettings() override { 537 ~SettingGetterImplGSettings() override {
534 // client_ should have been released before now, from 538 // client_ should have been released before now, from
535 // Delegate::OnDestroy(), while running on the UI thread. However 539 // Delegate::OnDestroy(), while running on the UI thread. However
536 // on exiting the process, it may happen that 540 // on exiting the process, it may happen that
537 // Delegate::OnDestroy() task is left pending on the glib loop 541 // Delegate::OnDestroy() task is left pending on the glib loop
538 // after the loop was quit, and pending tasks may then be deleted 542 // after the loop was quit, and pending tasks may then be deleted
539 // without being run. 543 // without being run.
540 if (client_) { 544 if (client_) {
541 // gconf client was not cleaned up. 545 // gconf client was not cleaned up.
542 if (task_runner_->BelongsToCurrentThread()) { 546 if (task_runner_->BelongsToCurrentThread()) {
543 // We are on the UI thread so we can clean it safely. This is 547 // We are on the UI thread so we can clean it safely. This is
544 // the case at least for ui_tests running under Valgrind in 548 // the case at least for ui_tests running under Valgrind in
545 // bug 16076. 549 // bug 16076.
546 VLOG(1) << "~SettingGetterImplGSettings: releasing gsettings client"; 550 VLOG(1) << "~SettingGetterImplGSettings: releasing gsettings client";
547 ShutDown(); 551 ShutDown();
548 } else { 552 } else {
549 LOG(WARNING) << "~SettingGetterImplGSettings: leaking gsettings client"; 553 LOG(WARNING) << "~SettingGetterImplGSettings: leaking gsettings client";
550 client_ = NULL; 554 client_ = nullptr;
551 } 555 }
552 } 556 }
553 DCHECK(!client_); 557 DCHECK(!client_);
554 } 558 }
555 559
556 bool SchemaExists(const char* schema_name) { 560 bool SchemaExists(base::StringPiece schema_name) {
557 const gchar* const* schemas = libgio_loader_.g_settings_list_schemas(); 561 const gchar* const* schemas = libgio_loader_.g_settings_list_schemas();
558 while (*schemas) { 562 while (*schemas) {
559 if (strcmp(schema_name, static_cast<const char*>(*schemas)) == 0) 563 if (!strcmp(schema_name.data(), static_cast<const char*>(*schemas)))
560 return true; 564 return true;
561 schemas++; 565 schemas++;
562 } 566 }
563 return false; 567 return false;
564 } 568 }
565 569
566 // LoadAndCheckVersion() must be called *before* Init()! 570 // LoadAndCheckVersion() must be called *before* Init()!
567 bool LoadAndCheckVersion(base::Environment* env); 571 bool LoadAndCheckVersion(base::Environment* env);
568 572
569 bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, 573 bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
(...skipping 22 matching lines...) Expand all
592 void ShutDown() override { 596 void ShutDown() override {
593 if (client_) { 597 if (client_) {
594 DCHECK(task_runner_->BelongsToCurrentThread()); 598 DCHECK(task_runner_->BelongsToCurrentThread());
595 // This also disables gsettings notifications. 599 // This also disables gsettings notifications.
596 g_object_unref(socks_client_); 600 g_object_unref(socks_client_);
597 g_object_unref(ftp_client_); 601 g_object_unref(ftp_client_);
598 g_object_unref(https_client_); 602 g_object_unref(https_client_);
599 g_object_unref(http_client_); 603 g_object_unref(http_client_);
600 g_object_unref(client_); 604 g_object_unref(client_);
601 // We only need to null client_ because it's the only one that we check. 605 // We only need to null client_ because it's the only one that we check.
602 client_ = NULL; 606 client_ = nullptr;
603 task_runner_ = NULL; 607 task_runner_ = nullptr;
604 } 608 }
605 debounce_timer_.reset(); 609 debounce_timer_.reset();
606 } 610 }
607 611
608 bool SetUpNotifications( 612 bool SetUpNotifications(
609 ProxyConfigServiceLinux::Delegate* delegate) override { 613 ProxyConfigServiceLinux::Delegate* delegate) override {
610 DCHECK(client_); 614 DCHECK(client_);
611 DCHECK(task_runner_->BelongsToCurrentThread()); 615 DCHECK(task_runner_->BelongsToCurrentThread());
612 notify_delegate_ = delegate; 616 notify_delegate_ = delegate;
613 // We could watch for the change-event signal instead of changed, but 617 // We could watch for the change-event signal instead of changed, but
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 } 702 }
699 703
700 bool BypassListIsReversed() override { 704 bool BypassListIsReversed() override {
701 // This is a KDE-specific setting. 705 // This is a KDE-specific setting.
702 return false; 706 return false;
703 } 707 }
704 708
705 bool MatchHostsUsingSuffixMatching() override { return false; } 709 bool MatchHostsUsingSuffixMatching() override { return false; }
706 710
707 private: 711 private:
708 bool GetStringByPath(GSettings* client, const char* key, 712 bool GetStringByPath(GSettings* client,
713 base::StringPiece key,
709 std::string* result) { 714 std::string* result) {
710 DCHECK(task_runner_->BelongsToCurrentThread()); 715 DCHECK(task_runner_->BelongsToCurrentThread());
711 gchar* value = libgio_loader_.g_settings_get_string(client, key); 716 gchar* value = libgio_loader_.g_settings_get_string(client, key.data());
712 if (!value) 717 if (!value)
713 return false; 718 return false;
714 *result = value; 719 *result = value;
715 g_free(value); 720 g_free(value);
716 return true; 721 return true;
717 } 722 }
718 bool GetBoolByPath(GSettings* client, const char* key, bool* result) { 723 bool GetBoolByPath(GSettings* client, base::StringPiece key, bool* result) {
719 DCHECK(task_runner_->BelongsToCurrentThread()); 724 DCHECK(task_runner_->BelongsToCurrentThread());
720 *result = static_cast<bool>( 725 *result = static_cast<bool>(
721 libgio_loader_.g_settings_get_boolean(client, key)); 726 libgio_loader_.g_settings_get_boolean(client, key.data()));
722 return true; 727 return true;
723 } 728 }
724 bool GetIntByPath(GSettings* client, const char* key, int* result) { 729 bool GetIntByPath(GSettings* client, base::StringPiece key, int* result) {
725 DCHECK(task_runner_->BelongsToCurrentThread()); 730 DCHECK(task_runner_->BelongsToCurrentThread());
726 *result = libgio_loader_.g_settings_get_int(client, key); 731 *result = libgio_loader_.g_settings_get_int(client, key.data());
727 return true; 732 return true;
728 } 733 }
729 bool GetStringListByPath(GSettings* client, const char* key, 734 bool GetStringListByPath(GSettings* client,
735 base::StringPiece key,
730 std::vector<std::string>* result) { 736 std::vector<std::string>* result) {
731 DCHECK(task_runner_->BelongsToCurrentThread()); 737 DCHECK(task_runner_->BelongsToCurrentThread());
732 gchar** list = libgio_loader_.g_settings_get_strv(client, key); 738 gchar** list = libgio_loader_.g_settings_get_strv(client, key.data());
733 if (!list) 739 if (!list)
734 return false; 740 return false;
735 for (size_t i = 0; list[i]; ++i) { 741 for (size_t i = 0; list[i]; ++i) {
736 result->push_back(static_cast<char*>(list[i])); 742 result->push_back(static_cast<char*>(list[i]));
737 g_free(list[i]); 743 g_free(list[i]);
738 } 744 }
739 g_free(list); 745 g_free(list);
740 return true; 746 return true;
741 } 747 }
742 748
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 } 820 }
815 821
816 // g_type_init will be deprecated in 2.36. 2.35 is the development 822 // g_type_init will be deprecated in 2.36. 2.35 is the development
817 // version for 2.36, hence do not call g_type_init starting 2.35. 823 // version for 2.36, hence do not call g_type_init starting 2.35.
818 // http://developer.gnome.org/gobject/unstable/gobject-Type-Information.html #g-type-init 824 // http://developer.gnome.org/gobject/unstable/gobject-Type-Information.html #g-type-init
819 if (libgio_loader_.glib_check_version(2, 35, 0)) { 825 if (libgio_loader_.glib_check_version(2, 35, 0)) {
820 libgio_loader_.g_type_init(); 826 libgio_loader_.g_type_init();
821 } 827 }
822 } 828 }
823 829
824 GSettings* client = NULL; 830 GSettings* client = nullptr;
825 if (SchemaExists(kProxyGConfSchema)) { 831 if (SchemaExists(kProxyGConfSchema)) {
826 ANNOTATE_SCOPED_MEMORY_LEAK; // http://crbug.com/380782 832 ANNOTATE_SCOPED_MEMORY_LEAK; // http://crbug.com/380782
827 client = libgio_loader_.g_settings_new(kProxyGConfSchema); 833 client = libgio_loader_.g_settings_new(kProxyGConfSchema);
828 } 834 }
829 if (!client) { 835 if (!client) {
830 VLOG(1) << "Cannot create gsettings client. Will fall back to gconf."; 836 VLOG(1) << "Cannot create gsettings client. Will fall back to gconf.";
831 return false; 837 return false;
832 } 838 }
833 g_object_unref(client); 839 g_object_unref(client);
834 840
835 // Yes, we're on the UI thread. Yes, we're accessing the file system. 841 // Yes, we're on the UI thread. Yes, we're accessing the file system.
836 // Sadly, we don't have much choice. We need the proxy settings and we 842 // Sadly, we don't have much choice. We need the proxy settings and we
(...skipping 13 matching lines...) Expand all
850 #endif // defined(USE_GIO) 856 #endif // defined(USE_GIO)
851 857
852 // This is the KDE version that reads kioslaverc and simulates gconf. 858 // This is the KDE version that reads kioslaverc and simulates gconf.
853 // Doing this allows the main Delegate code, as well as the unit tests 859 // Doing this allows the main Delegate code, as well as the unit tests
854 // for it, to stay the same - and the settings map fairly well besides. 860 // for it, to stay the same - and the settings map fairly well besides.
855 class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter, 861 class SettingGetterImplKDE : public ProxyConfigServiceLinux::SettingGetter,
856 public base::MessagePumpLibevent::Watcher { 862 public base::MessagePumpLibevent::Watcher {
857 public: 863 public:
858 explicit SettingGetterImplKDE(base::Environment* env_var_getter) 864 explicit SettingGetterImplKDE(base::Environment* env_var_getter)
859 : inotify_fd_(-1), 865 : inotify_fd_(-1),
860 notify_delegate_(NULL), 866 notify_delegate_(nullptr),
861 debounce_timer_(new base::OneShotTimer()), 867 debounce_timer_(new base::OneShotTimer()),
862 indirect_manual_(false), 868 indirect_manual_(false),
863 auto_no_pac_(false), 869 auto_no_pac_(false),
864 reversed_bypass_list_(false), 870 reversed_bypass_list_(false),
865 env_var_getter_(env_var_getter), 871 env_var_getter_(env_var_getter),
866 file_task_runner_(NULL) { 872 file_task_runner_(nullptr) {
867 // This has to be called on the UI thread (http://crbug.com/69057). 873 // This has to be called on the UI thread (http://crbug.com/69057).
868 base::ThreadRestrictions::ScopedAllowIO allow_io; 874 base::ThreadRestrictions::ScopedAllowIO allow_io;
869 875
870 // Derive the location of the kde config dir from the environment. 876 // Derive the location of the kde config dir from the environment.
871 std::string home; 877 std::string home;
872 if (env_var_getter->GetVar("KDEHOME", &home) && !home.empty()) { 878 if (env_var_getter->GetVar("KDEHOME", &home) && !home.empty()) {
873 // $KDEHOME is set. Use it unconditionally. 879 // $KDEHOME is set. Use it unconditionally.
874 kde_config_dir_ = KDEHomeToConfigPath(base::FilePath(home)); 880 kde_config_dir_ = KDEHomeToConfigPath(base::FilePath(home));
875 } else { 881 } else {
876 // $KDEHOME is unset. Try to figure out what to use. This seems to be 882 // $KDEHOME is unset. Try to figure out what to use. This seems to be
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 ~SettingGetterImplKDE() override { 932 ~SettingGetterImplKDE() override {
927 // inotify_fd_ should have been closed before now, from 933 // inotify_fd_ should have been closed before now, from
928 // Delegate::OnDestroy(), while running on the file thread. However 934 // Delegate::OnDestroy(), while running on the file thread. However
929 // on exiting the process, it may happen that Delegate::OnDestroy() 935 // on exiting the process, it may happen that Delegate::OnDestroy()
930 // task is left pending on the file loop after the loop was quit, 936 // task is left pending on the file loop after the loop was quit,
931 // and pending tasks may then be deleted without being run. 937 // and pending tasks may then be deleted without being run.
932 // Here in the KDE version, we can safely close the file descriptor 938 // Here in the KDE version, we can safely close the file descriptor
933 // anyway. (Not that it really matters; the process is exiting.) 939 // anyway. (Not that it really matters; the process is exiting.)
934 if (inotify_fd_ >= 0) 940 if (inotify_fd_ >= 0)
935 ShutDown(); 941 ShutDown();
936 DCHECK(inotify_fd_ < 0); 942 DCHECK_LT(inotify_fd_, 0);
937 } 943 }
938 944
939 bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, 945 bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
940 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) 946 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
941 override { 947 override {
942 // This has to be called on the UI thread (http://crbug.com/69057). 948 // This has to be called on the UI thread (http://crbug.com/69057).
943 base::ThreadRestrictions::ScopedAllowIO allow_io; 949 base::ThreadRestrictions::ScopedAllowIO allow_io;
944 DCHECK(inotify_fd_ < 0); 950 DCHECK_LT(inotify_fd_, 0);
945 inotify_fd_ = inotify_init(); 951 inotify_fd_ = inotify_init();
946 if (inotify_fd_ < 0) { 952 if (inotify_fd_ < 0) {
947 PLOG(ERROR) << "inotify_init failed"; 953 PLOG(ERROR) << "inotify_init failed";
948 return false; 954 return false;
949 } 955 }
950 if (!base::SetNonBlocking(inotify_fd_)) { 956 if (!base::SetNonBlocking(inotify_fd_)) {
951 PLOG(ERROR) << "base::SetNonBlocking failed"; 957 PLOG(ERROR) << "base::SetNonBlocking failed";
952 close(inotify_fd_); 958 close(inotify_fd_);
953 inotify_fd_ = -1; 959 inotify_fd_ = -1;
954 return false; 960 return false;
(...skipping 11 matching lines...) Expand all
966 ResetCachedSettings(); 972 ResetCachedSettings();
967 inotify_watcher_.StopWatchingFileDescriptor(); 973 inotify_watcher_.StopWatchingFileDescriptor();
968 close(inotify_fd_); 974 close(inotify_fd_);
969 inotify_fd_ = -1; 975 inotify_fd_ = -1;
970 } 976 }
971 debounce_timer_.reset(); 977 debounce_timer_.reset();
972 } 978 }
973 979
974 bool SetUpNotifications( 980 bool SetUpNotifications(
975 ProxyConfigServiceLinux::Delegate* delegate) override { 981 ProxyConfigServiceLinux::Delegate* delegate) override {
976 DCHECK(inotify_fd_ >= 0); 982 DCHECK_GE(inotify_fd_, 0);
977 DCHECK(file_task_runner_->BelongsToCurrentThread()); 983 DCHECK(file_task_runner_->BelongsToCurrentThread());
978 // We can't just watch the kioslaverc file directly, since KDE will write 984 // We can't just watch the kioslaverc file directly, since KDE will write
979 // a new copy of it and then rename it whenever settings are changed and 985 // a new copy of it and then rename it whenever settings are changed and
980 // inotify watches inodes (so we'll be watching the old deleted file after 986 // inotify watches inodes (so we'll be watching the old deleted file after
981 // the first change, and it will never change again). So, we watch the 987 // the first change, and it will never change again). So, we watch the
982 // directory instead. We then act only on changes to the kioslaverc entry. 988 // directory instead. We then act only on changes to the kioslaverc entry.
983 if (inotify_add_watch(inotify_fd_, kde_config_dir_.value().c_str(), 989 if (inotify_add_watch(inotify_fd_, kde_config_dir_.value().c_str(),
984 IN_MODIFY | IN_MOVED_TO) < 0) { 990 IN_MODIFY | IN_MOVED_TO) < 0) {
985 return false; 991 return false;
986 } 992 }
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 // bypass of local names in GNOME. In KDE, "<local>" is supported 1527 // bypass of local names in GNOME. In KDE, "<local>" is supported
1522 // as a hostname rule. 1528 // as a hostname rule.
1523 1529
1524 // KDE allows one to reverse the bypass rules. 1530 // KDE allows one to reverse the bypass rules.
1525 config->proxy_rules().reverse_bypass = 1531 config->proxy_rules().reverse_bypass =
1526 setting_getter_->BypassListIsReversed(); 1532 setting_getter_->BypassListIsReversed();
1527 1533
1528 return true; 1534 return true;
1529 } 1535 }
1530 1536
1531 ProxyConfigServiceLinux::Delegate::Delegate(base::Environment* env_var_getter) 1537 ProxyConfigServiceLinux::Delegate::Delegate(
1532 : env_var_getter_(env_var_getter) { 1538 std::unique_ptr<base::Environment> env_var_getter)
1539 : env_var_getter_(std::move(env_var_getter)) {
1533 // Figure out which SettingGetterImpl to use, if any. 1540 // Figure out which SettingGetterImpl to use, if any.
1534 switch (base::nix::GetDesktopEnvironment(env_var_getter)) { 1541 switch (base::nix::GetDesktopEnvironment(env_var_getter_.get())) {
1535 case base::nix::DESKTOP_ENVIRONMENT_GNOME: 1542 case base::nix::DESKTOP_ENVIRONMENT_GNOME:
1536 case base::nix::DESKTOP_ENVIRONMENT_UNITY: 1543 case base::nix::DESKTOP_ENVIRONMENT_UNITY:
1537 #if defined(USE_GIO) 1544 #if defined(USE_GIO)
1538 { 1545 {
1539 std::unique_ptr<SettingGetterImplGSettings> gs_getter( 1546 std::unique_ptr<SettingGetterImplGSettings> gs_getter(
1540 new SettingGetterImplGSettings()); 1547 new SettingGetterImplGSettings());
1541 // We have to load symbols and check the GNOME version in use to decide 1548 // We have to load symbols and check the GNOME version in use to decide
1542 // if we should use the gsettings getter. See LoadAndCheckVersion(). 1549 // if we should use the gsettings getter. See LoadAndCheckVersion().
1543 if (gs_getter->LoadAndCheckVersion(env_var_getter)) 1550 if (gs_getter->LoadAndCheckVersion(env_var_getter_.get()))
1544 setting_getter_.reset(gs_getter.release()); 1551 setting_getter_.reset(gs_getter.release());
1545 } 1552 }
1546 #endif 1553 #endif
1547 #if defined(USE_GCONF) 1554 #if defined(USE_GCONF)
1548 // Fall back on gconf if gsettings is unavailable or incorrect. 1555 // Fall back on gconf if gsettings is unavailable or incorrect.
1549 if (!setting_getter_.get()) 1556 if (!setting_getter_)
1550 setting_getter_.reset(new SettingGetterImplGConf()); 1557 setting_getter_.reset(new SettingGetterImplGConf());
1551 #endif 1558 #endif
1552 break; 1559 break;
1553 case base::nix::DESKTOP_ENVIRONMENT_KDE3: 1560 case base::nix::DESKTOP_ENVIRONMENT_KDE3:
1554 case base::nix::DESKTOP_ENVIRONMENT_KDE4: 1561 case base::nix::DESKTOP_ENVIRONMENT_KDE4:
1555 case base::nix::DESKTOP_ENVIRONMENT_KDE5: 1562 case base::nix::DESKTOP_ENVIRONMENT_KDE5:
1556 setting_getter_.reset(new SettingGetterImplKDE(env_var_getter)); 1563 setting_getter_.reset(new SettingGetterImplKDE(env_var_getter_.get()));
1557 break; 1564 break;
1558 case base::nix::DESKTOP_ENVIRONMENT_XFCE: 1565 case base::nix::DESKTOP_ENVIRONMENT_XFCE:
1559 case base::nix::DESKTOP_ENVIRONMENT_OTHER: 1566 case base::nix::DESKTOP_ENVIRONMENT_OTHER:
1560 break; 1567 break;
1561 } 1568 }
1562 } 1569 }
1563 1570
1564 ProxyConfigServiceLinux::Delegate::Delegate( 1571 ProxyConfigServiceLinux::Delegate::Delegate(
1565 base::Environment* env_var_getter, SettingGetter* setting_getter) 1572 std::unique_ptr<base::Environment> env_var_getter,
1566 : env_var_getter_(env_var_getter), setting_getter_(setting_getter) { 1573 SettingGetter* setting_getter)
1567 } 1574 : env_var_getter_(std::move(env_var_getter)),
1575 setting_getter_(setting_getter) {}
1568 1576
1569 void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig( 1577 void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig(
1570 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner, 1578 const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
1571 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 1579 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
1572 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { 1580 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) {
1573 // We should be running on the default glib main loop thread right 1581 // We should be running on the default glib main loop thread right
1574 // now. gconf can only be accessed from this thread. 1582 // now. gconf can only be accessed from this thread.
1575 DCHECK(glib_task_runner->BelongsToCurrentThread()); 1583 DCHECK(glib_task_runner->BelongsToCurrentThread());
1576 glib_task_runner_ = glib_task_runner; 1584 glib_task_runner_ = glib_task_runner;
1577 io_task_runner_ = io_task_runner; 1585 io_task_runner_ = io_task_runner;
(...skipping 10 matching lines...) Expand all
1588 // before this ProxyConfigServiceLinux is passed on to 1596 // before this ProxyConfigServiceLinux is passed on to
1589 // the ProxyService. 1597 // the ProxyService.
1590 1598
1591 // Note: It would be nice to prioritize environment variables 1599 // Note: It would be nice to prioritize environment variables
1592 // and only fall back to gconf if env vars were unset. But 1600 // and only fall back to gconf if env vars were unset. But
1593 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it 1601 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it
1594 // does so even if the proxy mode is set to auto, which would 1602 // does so even if the proxy mode is set to auto, which would
1595 // mislead us. 1603 // mislead us.
1596 1604
1597 bool got_config = false; 1605 bool got_config = false;
1598 if (setting_getter_.get() && 1606 if (setting_getter_ &&
1599 setting_getter_->Init(glib_task_runner, file_task_runner) && 1607 setting_getter_->Init(glib_task_runner, file_task_runner) &&
1600 GetConfigFromSettings(&cached_config_)) { 1608 GetConfigFromSettings(&cached_config_)) {
1601 cached_config_.set_id(1); // Mark it as valid. 1609 cached_config_.set_id(1); // Mark it as valid.
1602 cached_config_.set_source(setting_getter_->GetConfigSource()); 1610 cached_config_.set_source(setting_getter_->GetConfigSource());
1603 VLOG(1) << "Obtained proxy settings from " 1611 VLOG(1) << "Obtained proxy settings from "
1604 << ProxyConfigSourceToString(cached_config_.source()); 1612 << ProxyConfigSourceToString(cached_config_.source());
1605 1613
1606 // If gconf proxy mode is "none", meaning direct, then we take 1614 // If gconf proxy mode is "none", meaning direct, then we take
1607 // that to be a valid config and will not check environment 1615 // that to be a valid config and will not check environment
1608 // variables. The alternative would have been to look for a proxy 1616 // variables. The alternative would have been to look for a proxy
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 const ProxyConfig& new_config) { 1728 const ProxyConfig& new_config) {
1721 DCHECK(io_task_runner_->BelongsToCurrentThread()); 1729 DCHECK(io_task_runner_->BelongsToCurrentThread());
1722 VLOG(1) << "Proxy configuration changed"; 1730 VLOG(1) << "Proxy configuration changed";
1723 cached_config_ = new_config; 1731 cached_config_ = new_config;
1724 FOR_EACH_OBSERVER( 1732 FOR_EACH_OBSERVER(
1725 Observer, observers_, 1733 Observer, observers_,
1726 OnProxyConfigChanged(new_config, ProxyConfigService::CONFIG_VALID)); 1734 OnProxyConfigChanged(new_config, ProxyConfigService::CONFIG_VALID));
1727 } 1735 }
1728 1736
1729 void ProxyConfigServiceLinux::Delegate::PostDestroyTask() { 1737 void ProxyConfigServiceLinux::Delegate::PostDestroyTask() {
1730 if (!setting_getter_.get()) 1738 if (!setting_getter_)
1731 return; 1739 return;
1740
1732 scoped_refptr<base::SingleThreadTaskRunner> shutdown_loop = 1741 scoped_refptr<base::SingleThreadTaskRunner> shutdown_loop =
1733 setting_getter_->GetNotificationTaskRunner(); 1742 setting_getter_->GetNotificationTaskRunner();
1734 if (!shutdown_loop.get() || shutdown_loop->BelongsToCurrentThread()) { 1743 if (!shutdown_loop.get() || shutdown_loop->BelongsToCurrentThread()) {
1735 // Already on the right thread, call directly. 1744 // Already on the right thread, call directly.
1736 // This is the case for the unittests. 1745 // This is the case for the unittests.
1737 OnDestroy(); 1746 OnDestroy();
1738 } else { 1747 } else {
1739 // Post to shutdown thread. Note that on browser shutdown, we may quit 1748 // Post to shutdown thread. Note that on browser shutdown, we may quit
1740 // this MessageLoop and exit the program before ever running this. 1749 // this MessageLoop and exit the program before ever running this.
1741 shutdown_loop->PostTask(FROM_HERE, base::Bind( 1750 shutdown_loop->PostTask(FROM_HERE, base::Bind(
1742 &ProxyConfigServiceLinux::Delegate::OnDestroy, this)); 1751 &ProxyConfigServiceLinux::Delegate::OnDestroy, this));
1743 } 1752 }
1744 } 1753 }
1745 void ProxyConfigServiceLinux::Delegate::OnDestroy() { 1754 void ProxyConfigServiceLinux::Delegate::OnDestroy() {
1746 scoped_refptr<base::SingleThreadTaskRunner> shutdown_loop = 1755 scoped_refptr<base::SingleThreadTaskRunner> shutdown_loop =
1747 setting_getter_->GetNotificationTaskRunner(); 1756 setting_getter_->GetNotificationTaskRunner();
1748 DCHECK(!shutdown_loop.get() || shutdown_loop->BelongsToCurrentThread()); 1757 DCHECK(!shutdown_loop.get() || shutdown_loop->BelongsToCurrentThread());
1749 setting_getter_->ShutDown(); 1758 setting_getter_->ShutDown();
1750 } 1759 }
1751 1760
1752 ProxyConfigServiceLinux::ProxyConfigServiceLinux() 1761 ProxyConfigServiceLinux::ProxyConfigServiceLinux()
1753 : delegate_(new Delegate(base::Environment::Create())) { 1762 : delegate_(new Delegate(base::Environment::Create())) {
1754 } 1763 }
1755 1764
1756 ProxyConfigServiceLinux::~ProxyConfigServiceLinux() { 1765 ProxyConfigServiceLinux::~ProxyConfigServiceLinux() {
1757 delegate_->PostDestroyTask(); 1766 delegate_->PostDestroyTask();
1758 } 1767 }
1759 1768
1760 ProxyConfigServiceLinux::ProxyConfigServiceLinux( 1769 ProxyConfigServiceLinux::ProxyConfigServiceLinux(
1761 base::Environment* env_var_getter) 1770 std::unique_ptr<base::Environment> env_var_getter)
1762 : delegate_(new Delegate(env_var_getter)) { 1771 : delegate_(new Delegate(std::move(env_var_getter))) {}
1763 }
1764 1772
1765 ProxyConfigServiceLinux::ProxyConfigServiceLinux( 1773 ProxyConfigServiceLinux::ProxyConfigServiceLinux(
1766 base::Environment* env_var_getter, SettingGetter* setting_getter) 1774 std::unique_ptr<base::Environment> env_var_getter,
1767 : delegate_(new Delegate(env_var_getter, setting_getter)) { 1775 SettingGetter* setting_getter)
1768 } 1776 : delegate_(new Delegate(std::move(env_var_getter), setting_getter)) {}
1769 1777
1770 void ProxyConfigServiceLinux::AddObserver(Observer* observer) { 1778 void ProxyConfigServiceLinux::AddObserver(Observer* observer) {
1771 delegate_->AddObserver(observer); 1779 delegate_->AddObserver(observer);
1772 } 1780 }
1773 1781
1774 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { 1782 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) {
1775 delegate_->RemoveObserver(observer); 1783 delegate_->RemoveObserver(observer);
1776 } 1784 }
1777 1785
1778 ProxyConfigService::ConfigAvailability 1786 ProxyConfigService::ConfigAvailability
1779 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { 1787 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) {
1780 return delegate_->GetLatestProxyConfig(config); 1788 return delegate_->GetLatestProxyConfig(config);
1781 } 1789 }
1782 1790
1783 } // namespace net 1791 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_config_service_linux.h ('k') | net/proxy/proxy_config_service_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698