Make base::Environment::Create() return unique_ptrs.
BUG=581865
CQ_INCLUDE_TRYBOTS=tryserver.chromium.win:win10_chromium_x64_rel_ng
[email protected]
Review-Url: https://codereview.chromium.org/2094913002
Cr-Commit-Position: refs/heads/master@{#403115}
diff --git a/base/environment.cc b/base/environment.cc
index 9eef429..534a7a8 100644
--- a/base/environment.cc
+++ b/base/environment.cc
@@ -8,6 +8,7 @@
#include <vector>
+#include "base/memory/ptr_util.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -25,7 +26,7 @@
class EnvironmentImpl : public Environment {
public:
- bool GetVar(const char* variable_name, std::string* result) override {
+ bool GetVar(StringPiece variable_name, std::string* result) override {
if (GetVarImpl(variable_name, result))
return true;
@@ -44,19 +45,19 @@
return GetVarImpl(alternate_case_var.c_str(), result);
}
- bool SetVar(const char* variable_name,
+ bool SetVar(StringPiece variable_name,
const std::string& new_value) override {
return SetVarImpl(variable_name, new_value);
}
- bool UnSetVar(const char* variable_name) override {
+ bool UnSetVar(StringPiece variable_name) override {
return UnSetVarImpl(variable_name);
}
private:
- bool GetVarImpl(const char* variable_name, std::string* result) {
+ bool GetVarImpl(StringPiece variable_name, std::string* result) {
#if defined(OS_POSIX)
- const char* env_value = getenv(variable_name);
+ const char* env_value = getenv(variable_name.data());
if (!env_value)
return false;
// Note that the variable may be defined but empty.
@@ -64,8 +65,8 @@
*result = env_value;
return true;
#elif defined(OS_WIN)
- DWORD value_length = ::GetEnvironmentVariable(
- UTF8ToWide(variable_name).c_str(), NULL, 0);
+ DWORD value_length =
+ ::GetEnvironmentVariable(UTF8ToWide(variable_name).c_str(), nullptr, 0);
if (value_length == 0)
return false;
if (result) {
@@ -80,10 +81,10 @@
#endif
}
- bool SetVarImpl(const char* variable_name, const std::string& new_value) {
+ bool SetVarImpl(StringPiece variable_name, const std::string& new_value) {
#if defined(OS_POSIX)
// On success, zero is returned.
- return !setenv(variable_name, new_value.c_str(), 1);
+ return !setenv(variable_name.data(), new_value.c_str(), 1);
#elif defined(OS_WIN)
// On success, a nonzero value is returned.
return !!SetEnvironmentVariable(UTF8ToWide(variable_name).c_str(),
@@ -91,13 +92,13 @@
#endif
}
- bool UnSetVarImpl(const char* variable_name) {
+ bool UnSetVarImpl(StringPiece variable_name) {
#if defined(OS_POSIX)
// On success, zero is returned.
- return !unsetenv(variable_name);
+ return !unsetenv(variable_name.data());
#elif defined(OS_WIN)
// On success, a nonzero value is returned.
- return !!SetEnvironmentVariable(UTF8ToWide(variable_name).c_str(), NULL);
+ return !!SetEnvironmentVariable(UTF8ToWide(variable_name).c_str(), nullptr);
#endif
}
};
@@ -134,12 +135,12 @@
Environment::~Environment() {}
// static
-Environment* Environment::Create() {
- return new EnvironmentImpl();
+std::unique_ptr<Environment> Environment::Create() {
+ return MakeUnique<EnvironmentImpl>();
}
-bool Environment::HasVar(const char* variable_name) {
- return GetVar(variable_name, NULL);
+bool Environment::HasVar(StringPiece variable_name) {
+ return GetVar(variable_name, nullptr);
}
#if defined(OS_WIN)
diff --git a/base/environment.h b/base/environment.h
index 12eeaf7e..3a4ed04 100644
--- a/base/environment.h
+++ b/base/environment.h
@@ -11,6 +11,7 @@
#include "base/base_export.h"
#include "base/strings/string16.h"
+#include "base/strings/string_piece.h"
#include "build/build_config.h"
namespace base {
@@ -27,23 +28,22 @@
public:
virtual ~Environment();
- // Static factory method that returns the implementation that provide the
- // appropriate platform-specific instance.
- static Environment* Create();
+ // Returns the appropriate platform-specific instance.
+ static std::unique_ptr<Environment> Create();
// Gets an environment variable's value and stores it in |result|.
// Returns false if the key is unset.
- virtual bool GetVar(const char* variable_name, std::string* result) = 0;
+ virtual bool GetVar(StringPiece variable_name, std::string* result) = 0;
- // Syntactic sugar for GetVar(variable_name, NULL);
- virtual bool HasVar(const char* variable_name);
+ // Syntactic sugar for GetVar(variable_name, nullptr);
+ virtual bool HasVar(StringPiece variable_name);
// Returns true on success, otherwise returns false.
- virtual bool SetVar(const char* variable_name,
+ virtual bool SetVar(StringPiece variable_name,
const std::string& new_value) = 0;
// Returns true on success, otherwise returns false.
- virtual bool UnSetVar(const char* variable_name) = 0;
+ virtual bool UnSetVar(StringPiece variable_name) = 0;
};
diff --git a/base/files/file_util_unittest.cc b/base/files/file_util_unittest.cc
index 09c9156..153cd9cb 100644
--- a/base/files/file_util_unittest.cc
+++ b/base/files/file_util_unittest.cc
@@ -34,7 +34,6 @@
#include <shlobj.h>
#include <tchar.h>
#include <winioctl.h>
-#include "base/environment.h"
#include "base/win/scoped_handle.h"
#include "base/win/windows_version.h"
#endif
@@ -1407,7 +1406,7 @@
#if defined(OS_WIN)
FilePath from_path =
temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\"));
-#elif defined (OS_POSIX)
+#elif defined(OS_POSIX)
FilePath from_path =
temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir///"));
#endif
@@ -1725,9 +1724,7 @@
EXPECT_EQ(test_case.expected, observed) << " input: " << input.value();
}
- Environment* env = Environment::Create();
- ASSERT_TRUE(!!env);
-
+ std::unique_ptr<Environment> env(Environment::Create());
// To test IsOnNetworkDrive() for remote cases, set up a file server
// and place a file called file.txt on the server e.g.
// \\DC01\TESTSHARE\file.txt
diff --git a/base/nix/xdg_util_unittest.cc b/base/nix/xdg_util_unittest.cc
index a054355..c8e5361 100644
--- a/base/nix/xdg_util_unittest.cc
+++ b/base/nix/xdg_util_unittest.cc
@@ -9,9 +9,9 @@
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
+using ::testing::Eq;
using ::testing::Return;
using ::testing::SetArgumentPointee;
-using ::testing::StrEq;
namespace base {
namespace nix {
@@ -20,9 +20,9 @@
class MockEnvironment : public Environment {
public:
- MOCK_METHOD2(GetVar, bool(const char*, std::string* result));
- MOCK_METHOD2(SetVar, bool(const char*, const std::string& new_value));
- MOCK_METHOD1(UnSetVar, bool(const char*));
+ MOCK_METHOD2(GetVar, bool(StringPiece, std::string* result));
+ MOCK_METHOD2(SetVar, bool(StringPiece, const std::string& new_value));
+ MOCK_METHOD1(UnSetVar, bool(StringPiece));
};
// Needs to be const char* to make gmock happy.
@@ -46,7 +46,7 @@
TEST(XDGUtilTest, GetDesktopEnvironmentGnome) {
MockEnvironment getter;
EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
- EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
+ EXPECT_CALL(getter, GetVar(Eq(kDesktopSession), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kDesktopGnome), Return(true)));
EXPECT_EQ(DESKTOP_ENVIRONMENT_GNOME, GetDesktopEnvironment(&getter));
@@ -55,7 +55,7 @@
TEST(XDGUtilTest, GetDesktopEnvironmentMATE) {
MockEnvironment getter;
EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
- EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
+ EXPECT_CALL(getter, GetVar(Eq(kDesktopSession), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kDesktopMATE), Return(true)));
EXPECT_EQ(DESKTOP_ENVIRONMENT_GNOME, GetDesktopEnvironment(&getter));
@@ -64,7 +64,7 @@
TEST(XDGUtilTest, GetDesktopEnvironmentKDE4) {
MockEnvironment getter;
EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
- EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
+ EXPECT_CALL(getter, GetVar(Eq(kDesktopSession), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kDesktopKDE4), Return(true)));
EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE4, GetDesktopEnvironment(&getter));
@@ -73,7 +73,7 @@
TEST(XDGUtilTest, GetDesktopEnvironmentKDE3) {
MockEnvironment getter;
EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
- EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
+ EXPECT_CALL(getter, GetVar(Eq(kDesktopSession), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kDesktopKDE), Return(true)));
EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE3, GetDesktopEnvironment(&getter));
@@ -82,7 +82,7 @@
TEST(XDGUtilTest, GetDesktopEnvironmentXFCE) {
MockEnvironment getter;
EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
- EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
+ EXPECT_CALL(getter, GetVar(Eq(kDesktopSession), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kDesktopXFCE), Return(true)));
EXPECT_EQ(DESKTOP_ENVIRONMENT_XFCE, GetDesktopEnvironment(&getter));
@@ -91,7 +91,7 @@
TEST(XDGUtilTest, GetXdgDesktopGnome) {
MockEnvironment getter;
EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
- EXPECT_CALL(getter, GetVar(StrEq(kXdgDesktop), _))
+ EXPECT_CALL(getter, GetVar(Eq(kXdgDesktop), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kXdgDesktopGNOME), Return(true)));
EXPECT_EQ(DESKTOP_ENVIRONMENT_GNOME, GetDesktopEnvironment(&getter));
@@ -100,11 +100,11 @@
TEST(XDGUtilTest, GetXdgDesktopGnomeFallback) {
MockEnvironment getter;
EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
- EXPECT_CALL(getter, GetVar(StrEq(kXdgDesktop), _))
+ EXPECT_CALL(getter, GetVar(Eq(kXdgDesktop), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kXdgDesktopUnity), Return(true)));
- EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
- .WillOnce(DoAll(SetArgumentPointee<1>(kDesktopGnomeFallback),
- Return(true)));
+ EXPECT_CALL(getter, GetVar(Eq(kDesktopSession), _))
+ .WillOnce(
+ DoAll(SetArgumentPointee<1>(kDesktopGnomeFallback), Return(true)));
EXPECT_EQ(DESKTOP_ENVIRONMENT_GNOME, GetDesktopEnvironment(&getter));
}
@@ -112,10 +112,10 @@
TEST(XDGUtilTest, GetXdgDesktopKDE5) {
MockEnvironment getter;
EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
- EXPECT_CALL(getter, GetVar(StrEq(kXdgDesktop), _))
+ EXPECT_CALL(getter, GetVar(Eq(kXdgDesktop), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kXdgDesktopKDE), Return(true)));
- EXPECT_CALL(getter, GetVar(StrEq(kKDESession), _))
- .WillOnce(DoAll(SetArgumentPointee<1>(kKDESessionKDE5), Return(true)));
+ EXPECT_CALL(getter, GetVar(Eq(kKDESession), _))
+ .WillOnce(DoAll(SetArgumentPointee<1>(kKDESessionKDE5), Return(true)));
EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE5, GetDesktopEnvironment(&getter));
}
@@ -123,7 +123,7 @@
TEST(XDGUtilTest, GetXdgDesktopKDE4) {
MockEnvironment getter;
EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
- EXPECT_CALL(getter, GetVar(StrEq(kXdgDesktop), _))
+ EXPECT_CALL(getter, GetVar(Eq(kXdgDesktop), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kXdgDesktopKDE), Return(true)));
EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE4, GetDesktopEnvironment(&getter));
@@ -132,7 +132,7 @@
TEST(XDGUtilTest, GetXdgDesktopUnity) {
MockEnvironment getter;
EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
- EXPECT_CALL(getter, GetVar(StrEq(kXdgDesktop), _))
+ EXPECT_CALL(getter, GetVar(Eq(kXdgDesktop), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kXdgDesktopUnity), Return(true)));
EXPECT_EQ(DESKTOP_ENVIRONMENT_UNITY, GetDesktopEnvironment(&getter));
diff --git a/chrome/browser/shell_integration_linux_unittest.cc b/chrome/browser/shell_integration_linux_unittest.cc
index 96a18a0..d6a7120 100644
--- a/chrome/browser/shell_integration_linux_unittest.cc
+++ b/chrome/browser/shell_integration_linux_unittest.cc
@@ -41,26 +41,26 @@
public:
MockEnvironment() {}
- void Set(const std::string& name, const std::string& value) {
- variables_[name] = value;
+ void Set(base::StringPiece name, const std::string& value) {
+ variables_[name.as_string()] = value;
}
- bool GetVar(const char* variable_name, std::string* result) override {
- if (ContainsKey(variables_, variable_name)) {
- *result = variables_[variable_name];
+ bool GetVar(base::StringPiece variable_name, std::string* result) override {
+ if (ContainsKey(variables_, variable_name.as_string())) {
+ *result = variables_[variable_name.as_string()];
return true;
}
return false;
}
- bool SetVar(const char* variable_name,
+ bool SetVar(base::StringPiece variable_name,
const std::string& new_value) override {
ADD_FAILURE();
return false;
}
- bool UnSetVar(const char* variable_name) override {
+ bool UnSetVar(base::StringPiece variable_name) override {
ADD_FAILURE();
return false;
}
diff --git a/net/proxy/proxy_config_service_linux.cc b/net/proxy/proxy_config_service_linux.cc
index d6f89db9..6f9add0 100644
--- a/net/proxy/proxy_config_service_linux.cc
+++ b/net/proxy/proxy_config_service_linux.cc
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <map>
+#include <utility>
#include "base/bind.h"
#include "base/compiler_specific.h"
@@ -94,27 +95,30 @@
}
bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme(
- const char* variable, ProxyServer::Scheme scheme,
+ base::StringPiece variable,
+ ProxyServer::Scheme scheme,
ProxyServer* result_server) {
std::string env_value;
- if (env_var_getter_->GetVar(variable, &env_value)) {
- if (!env_value.empty()) {
- env_value = FixupProxyHostScheme(scheme, env_value);
- ProxyServer proxy_server =
- ProxyServer::FromURI(env_value, ProxyServer::SCHEME_HTTP);
- if (proxy_server.is_valid() && !proxy_server.is_direct()) {
- *result_server = proxy_server;
- return true;
- } else {
- LOG(ERROR) << "Failed to parse environment variable " << variable;
- }
- }
+ if (!env_var_getter_->GetVar(variable, &env_value))
+ return false;
+
+ if (env_value.empty())
+ return false;
+
+ env_value = FixupProxyHostScheme(scheme, env_value);
+ ProxyServer proxy_server =
+ ProxyServer::FromURI(env_value, ProxyServer::SCHEME_HTTP);
+ if (proxy_server.is_valid() && !proxy_server.is_direct()) {
+ *result_server = proxy_server;
+ return true;
}
+ LOG(ERROR) << "Failed to parse environment variable " << variable;
return false;
}
bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVar(
- const char* variable, ProxyServer* result_server) {
+ base::StringPiece variable,
+ ProxyServer* result_server) {
return GetProxyFromEnvVarForScheme(variable, ProxyServer::SCHEME_HTTP,
result_server);
}
@@ -202,10 +206,10 @@
class SettingGetterImplGConf : public ProxyConfigServiceLinux::SettingGetter {
public:
SettingGetterImplGConf()
- : client_(NULL),
+ : client_(nullptr),
system_proxy_id_(0),
system_http_proxy_id_(0),
- notify_delegate_(NULL),
+ notify_delegate_(nullptr),
debounce_timer_(new base::OneShotTimer()) {}
~SettingGetterImplGConf() override {
@@ -246,10 +250,10 @@
if (!client_) {
// It's not clear whether/when this can return NULL.
LOG(ERROR) << "Unable to create a gconf client";
- task_runner_ = NULL;
+ task_runner_ = nullptr;
return false;
}
- GError* error = NULL;
+ GError* error = nullptr;
bool added_system_proxy = false;
// We need to add the directories for which we'll be asking
// for notifications, and we might as well ask to preload them.
@@ -257,22 +261,22 @@
// here to only leave client_ non-NULL if both have been added.
gconf_client_add_dir(client_, "/system/proxy",
GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
- if (error == NULL) {
+ if (!error) {
added_system_proxy = true;
gconf_client_add_dir(client_, "/system/http_proxy",
GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
}
- if (error != NULL) {
- LOG(ERROR) << "Error requesting gconf directory: " << error->message;
- g_error_free(error);
- if (added_system_proxy)
- gconf_client_remove_dir(client_, "/system/proxy", NULL);
- g_object_unref(client_);
- client_ = NULL;
- task_runner_ = NULL;
- return false;
- }
- return true;
+ if (!error)
+ return true;
+
+ LOG(ERROR) << "Error requesting gconf directory: " << error->message;
+ g_error_free(error);
+ if (added_system_proxy)
+ gconf_client_remove_dir(client_, "/system/proxy", nullptr);
+ g_object_unref(client_);
+ client_ = nullptr;
+ task_runner_ = nullptr;
+ return false;
}
void ShutDown() override {
@@ -284,11 +288,11 @@
// own, which is destroyed when the session ends.)
gconf_client_notify_remove(client_, system_http_proxy_id_);
gconf_client_notify_remove(client_, system_proxy_id_);
- gconf_client_remove_dir(client_, "/system/http_proxy", NULL);
- gconf_client_remove_dir(client_, "/system/proxy", NULL);
+ gconf_client_remove_dir(client_, "/system/http_proxy", nullptr);
+ gconf_client_remove_dir(client_, "/system/proxy", nullptr);
g_object_unref(client_);
- client_ = NULL;
- task_runner_ = NULL;
+ client_ = nullptr;
+ task_runner_ = nullptr;
}
debounce_timer_.reset();
}
@@ -297,30 +301,29 @@
ProxyConfigServiceLinux::Delegate* delegate) override {
DCHECK(client_);
DCHECK(task_runner_->BelongsToCurrentThread());
- GError* error = NULL;
+ GError* error = nullptr;
notify_delegate_ = delegate;
// We have to keep track of the IDs returned by gconf_client_notify_add() so
// that we can remove them in ShutDown(). (Otherwise, notifications will be
// delivered to this object after it is deleted, which is bad, m'kay?)
- system_proxy_id_ = gconf_client_notify_add(
- client_, "/system/proxy",
- OnGConfChangeNotification, this,
- NULL, &error);
- if (error == NULL) {
+ system_proxy_id_ = gconf_client_notify_add(client_, "/system/proxy",
+ OnGConfChangeNotification, this,
+ nullptr, &error);
+ if (!error) {
system_http_proxy_id_ = gconf_client_notify_add(
- client_, "/system/http_proxy",
- OnGConfChangeNotification, this,
- NULL, &error);
+ client_, "/system/http_proxy", OnGConfChangeNotification, this,
+ nullptr, &error);
}
- if (error != NULL) {
- LOG(ERROR) << "Error requesting gconf notifications: " << error->message;
- g_error_free(error);
- ShutDown();
- return false;
+ if (!error) {
+ // Simulate a change to avoid possibly losing updates before this point.
+ OnChangeNotification();
+ return true;
}
- // Simulate a change to avoid possibly losing updates before this point.
- OnChangeNotification();
- return true;
+
+ LOG(ERROR) << "Error requesting gconf notifications: " << error->message;
+ g_error_free(error);
+ ShutDown();
+ return false;
}
const scoped_refptr<base::SingleThreadTaskRunner>& GetNotificationTaskRunner()
@@ -390,12 +393,12 @@
bool MatchHostsUsingSuffixMatching() override { return false; }
private:
- bool GetStringByPath(const char* key, std::string* result) {
+ bool GetStringByPath(base::StringPiece key, std::string* result) {
DCHECK(client_);
DCHECK(task_runner_->BelongsToCurrentThread());
- GError* error = NULL;
- gchar* value = gconf_client_get_string(client_, key, &error);
- if (HandleGError(error, key))
+ GError* error = nullptr;
+ gchar* value = gconf_client_get_string(client_, key.data(), &error);
+ if (HandleGError(error, key.data()))
return false;
if (!value)
return false;
@@ -403,15 +406,15 @@
g_free(value);
return true;
}
- bool GetBoolByPath(const char* key, bool* result) {
+ bool GetBoolByPath(base::StringPiece key, bool* result) {
DCHECK(client_);
DCHECK(task_runner_->BelongsToCurrentThread());
- GError* error = NULL;
+ GError* error = nullptr;
// We want to distinguish unset values from values defaulting to
// false. For that we need to use the type-generic
// gconf_client_get() rather than gconf_client_get_bool().
- GConfValue* gconf_value = gconf_client_get(client_, key, &error);
- if (HandleGError(error, key))
+ GConfValue* gconf_value = gconf_client_get(client_, key.data(), &error);
+ if (HandleGError(error, key.data()))
return false;
if (!gconf_value) {
// Unset.
@@ -426,25 +429,26 @@
gconf_value_free(gconf_value);
return true;
}
- bool GetIntByPath(const char* key, int* result) {
+ bool GetIntByPath(base::StringPiece key, int* result) {
DCHECK(client_);
DCHECK(task_runner_->BelongsToCurrentThread());
- GError* error = NULL;
- int value = gconf_client_get_int(client_, key, &error);
- if (HandleGError(error, key))
+ GError* error = nullptr;
+ int value = gconf_client_get_int(client_, key.data(), &error);
+ if (HandleGError(error, key.data()))
return false;
// We don't bother to distinguish an unset value because callers
// don't care. 0 is returned if unset.
*result = value;
return true;
}
- bool GetStringListByPath(const char* key, std::vector<std::string>* result) {
+ bool GetStringListByPath(base::StringPiece key,
+ std::vector<std::string>* result) {
DCHECK(client_);
DCHECK(task_runner_->BelongsToCurrentThread());
- GError* error = NULL;
- GSList* list = gconf_client_get_list(client_, key,
- GCONF_VALUE_STRING, &error);
- if (HandleGError(error, key))
+ GError* error = nullptr;
+ GSList* list =
+ gconf_client_get_list(client_, key.data(), GCONF_VALUE_STRING, &error);
+ if (HandleGError(error, key.data()))
return false;
if (!list)
return false;
@@ -458,14 +462,14 @@
// Logs and frees a glib error. Returns false if there was no error
// (error is NULL).
- bool HandleGError(GError* error, const char* key) {
- if (error != NULL) {
- LOG(ERROR) << "Error getting gconf value for " << key
- << ": " << error->message;
- g_error_free(error);
- return true;
- }
- return false;
+ bool HandleGError(GError* error, base::StringPiece key) {
+ if (!error)
+ return false;
+
+ LOG(ERROR) << "Error getting gconf value for " << key << ": "
+ << error->message;
+ g_error_free(error);
+ return true;
}
// This is the callback from the debounce timer.
@@ -522,12 +526,12 @@
: public ProxyConfigServiceLinux::SettingGetter {
public:
SettingGetterImplGSettings()
- : client_(NULL),
- http_client_(NULL),
- https_client_(NULL),
- ftp_client_(NULL),
- socks_client_(NULL),
- notify_delegate_(NULL),
+ : client_(nullptr),
+ http_client_(nullptr),
+ https_client_(nullptr),
+ ftp_client_(nullptr),
+ socks_client_(nullptr),
+ notify_delegate_(nullptr),
debounce_timer_(new base::OneShotTimer()) {}
~SettingGetterImplGSettings() override {
@@ -547,16 +551,16 @@
ShutDown();
} else {
LOG(WARNING) << "~SettingGetterImplGSettings: leaking gsettings client";
- client_ = NULL;
+ client_ = nullptr;
}
}
DCHECK(!client_);
}
- bool SchemaExists(const char* schema_name) {
+ bool SchemaExists(base::StringPiece schema_name) {
const gchar* const* schemas = libgio_loader_.g_settings_list_schemas();
while (*schemas) {
- if (strcmp(schema_name, static_cast<const char*>(*schemas)) == 0)
+ if (!strcmp(schema_name.data(), static_cast<const char*>(*schemas)))
return true;
schemas++;
}
@@ -599,8 +603,8 @@
g_object_unref(http_client_);
g_object_unref(client_);
// We only need to null client_ because it's the only one that we check.
- client_ = NULL;
- task_runner_ = NULL;
+ client_ = nullptr;
+ task_runner_ = nullptr;
}
debounce_timer_.reset();
}
@@ -705,31 +709,33 @@
bool MatchHostsUsingSuffixMatching() override { return false; }
private:
- bool GetStringByPath(GSettings* client, const char* key,
+ bool GetStringByPath(GSettings* client,
+ base::StringPiece key,
std::string* result) {
DCHECK(task_runner_->BelongsToCurrentThread());
- gchar* value = libgio_loader_.g_settings_get_string(client, key);
+ gchar* value = libgio_loader_.g_settings_get_string(client, key.data());
if (!value)
return false;
*result = value;
g_free(value);
return true;
}
- bool GetBoolByPath(GSettings* client, const char* key, bool* result) {
+ bool GetBoolByPath(GSettings* client, base::StringPiece key, bool* result) {
DCHECK(task_runner_->BelongsToCurrentThread());
*result = static_cast<bool>(
- libgio_loader_.g_settings_get_boolean(client, key));
+ libgio_loader_.g_settings_get_boolean(client, key.data()));
return true;
}
- bool GetIntByPath(GSettings* client, const char* key, int* result) {
+ bool GetIntByPath(GSettings* client, base::StringPiece key, int* result) {
DCHECK(task_runner_->BelongsToCurrentThread());
- *result = libgio_loader_.g_settings_get_int(client, key);
+ *result = libgio_loader_.g_settings_get_int(client, key.data());
return true;
}
- bool GetStringListByPath(GSettings* client, const char* key,
+ bool GetStringListByPath(GSettings* client,
+ base::StringPiece key,
std::vector<std::string>* result) {
DCHECK(task_runner_->BelongsToCurrentThread());
- gchar** list = libgio_loader_.g_settings_get_strv(client, key);
+ gchar** list = libgio_loader_.g_settings_get_strv(client, key.data());
if (!list)
return false;
for (size_t i = 0; list[i]; ++i) {
@@ -821,9 +827,9 @@
}
}
- GSettings* client = NULL;
+ GSettings* client = nullptr;
if (SchemaExists(kProxyGConfSchema)) {
- ANNOTATE_SCOPED_MEMORY_LEAK; // http://crbug.com/380782
+ ANNOTATE_SCOPED_MEMORY_LEAK; // http://crbug.com/380782
client = libgio_loader_.g_settings_new(kProxyGConfSchema);
}
if (!client) {
@@ -857,13 +863,13 @@
public:
explicit SettingGetterImplKDE(base::Environment* env_var_getter)
: inotify_fd_(-1),
- notify_delegate_(NULL),
+ notify_delegate_(nullptr),
debounce_timer_(new base::OneShotTimer()),
indirect_manual_(false),
auto_no_pac_(false),
reversed_bypass_list_(false),
env_var_getter_(env_var_getter),
- file_task_runner_(NULL) {
+ file_task_runner_(nullptr) {
// This has to be called on the UI thread (http://crbug.com/69057).
base::ThreadRestrictions::ScopedAllowIO allow_io;
@@ -933,7 +939,7 @@
// anyway. (Not that it really matters; the process is exiting.)
if (inotify_fd_ >= 0)
ShutDown();
- DCHECK(inotify_fd_ < 0);
+ DCHECK_LT(inotify_fd_, 0);
}
bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
@@ -941,7 +947,7 @@
override {
// This has to be called on the UI thread (http://crbug.com/69057).
base::ThreadRestrictions::ScopedAllowIO allow_io;
- DCHECK(inotify_fd_ < 0);
+ DCHECK_LT(inotify_fd_, 0);
inotify_fd_ = inotify_init();
if (inotify_fd_ < 0) {
PLOG(ERROR) << "inotify_init failed";
@@ -973,7 +979,7 @@
bool SetUpNotifications(
ProxyConfigServiceLinux::Delegate* delegate) override {
- DCHECK(inotify_fd_ >= 0);
+ DCHECK_GE(inotify_fd_, 0);
DCHECK(file_task_runner_->BelongsToCurrentThread());
// We can't just watch the kioslaverc file directly, since KDE will write
// a new copy of it and then rename it whenever settings are changed and
@@ -1528,10 +1534,11 @@
return true;
}
-ProxyConfigServiceLinux::Delegate::Delegate(base::Environment* env_var_getter)
- : env_var_getter_(env_var_getter) {
+ProxyConfigServiceLinux::Delegate::Delegate(
+ std::unique_ptr<base::Environment> env_var_getter)
+ : env_var_getter_(std::move(env_var_getter)) {
// Figure out which SettingGetterImpl to use, if any.
- switch (base::nix::GetDesktopEnvironment(env_var_getter)) {
+ switch (base::nix::GetDesktopEnvironment(env_var_getter_.get())) {
case base::nix::DESKTOP_ENVIRONMENT_GNOME:
case base::nix::DESKTOP_ENVIRONMENT_UNITY:
#if defined(USE_GIO)
@@ -1540,20 +1547,20 @@
new SettingGetterImplGSettings());
// We have to load symbols and check the GNOME version in use to decide
// if we should use the gsettings getter. See LoadAndCheckVersion().
- if (gs_getter->LoadAndCheckVersion(env_var_getter))
+ if (gs_getter->LoadAndCheckVersion(env_var_getter_.get()))
setting_getter_.reset(gs_getter.release());
}
#endif
#if defined(USE_GCONF)
// Fall back on gconf if gsettings is unavailable or incorrect.
- if (!setting_getter_.get())
+ if (!setting_getter_)
setting_getter_.reset(new SettingGetterImplGConf());
#endif
break;
case base::nix::DESKTOP_ENVIRONMENT_KDE3:
case base::nix::DESKTOP_ENVIRONMENT_KDE4:
case base::nix::DESKTOP_ENVIRONMENT_KDE5:
- setting_getter_.reset(new SettingGetterImplKDE(env_var_getter));
+ setting_getter_.reset(new SettingGetterImplKDE(env_var_getter_.get()));
break;
case base::nix::DESKTOP_ENVIRONMENT_XFCE:
case base::nix::DESKTOP_ENVIRONMENT_OTHER:
@@ -1562,9 +1569,10 @@
}
ProxyConfigServiceLinux::Delegate::Delegate(
- base::Environment* env_var_getter, SettingGetter* setting_getter)
- : env_var_getter_(env_var_getter), setting_getter_(setting_getter) {
-}
+ std::unique_ptr<base::Environment> env_var_getter,
+ SettingGetter* setting_getter)
+ : env_var_getter_(std::move(env_var_getter)),
+ setting_getter_(setting_getter) {}
void ProxyConfigServiceLinux::Delegate::SetUpAndFetchInitialConfig(
const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner,
@@ -1595,7 +1603,7 @@
// mislead us.
bool got_config = false;
- if (setting_getter_.get() &&
+ if (setting_getter_ &&
setting_getter_->Init(glib_task_runner, file_task_runner) &&
GetConfigFromSettings(&cached_config_)) {
cached_config_.set_id(1); // Mark it as valid.
@@ -1727,8 +1735,9 @@
}
void ProxyConfigServiceLinux::Delegate::PostDestroyTask() {
- if (!setting_getter_.get())
+ if (!setting_getter_)
return;
+
scoped_refptr<base::SingleThreadTaskRunner> shutdown_loop =
setting_getter_->GetNotificationTaskRunner();
if (!shutdown_loop.get() || shutdown_loop->BelongsToCurrentThread()) {
@@ -1758,14 +1767,13 @@
}
ProxyConfigServiceLinux::ProxyConfigServiceLinux(
- base::Environment* env_var_getter)
- : delegate_(new Delegate(env_var_getter)) {
-}
+ std::unique_ptr<base::Environment> env_var_getter)
+ : delegate_(new Delegate(std::move(env_var_getter))) {}
ProxyConfigServiceLinux::ProxyConfigServiceLinux(
- base::Environment* env_var_getter, SettingGetter* setting_getter)
- : delegate_(new Delegate(env_var_getter, setting_getter)) {
-}
+ std::unique_ptr<base::Environment> env_var_getter,
+ SettingGetter* setting_getter)
+ : delegate_(new Delegate(std::move(env_var_getter), setting_getter)) {}
void ProxyConfigServiceLinux::AddObserver(Observer* observer) {
delegate_->AddObserver(observer);
diff --git a/net/proxy/proxy_config_service_linux.h b/net/proxy/proxy_config_service_linux.h
index 1425372..4832c20 100644
--- a/net/proxy/proxy_config_service_linux.h
+++ b/net/proxy/proxy_config_service_linux.h
@@ -31,8 +31,6 @@
// settings from environment variables, gconf, gsettings, or kioslaverc (KDE).
class NET_EXPORT_PRIVATE ProxyConfigServiceLinux : public ProxyConfigService {
public:
-
- // Forward declaration of Delegate.
class Delegate;
class SettingGetter {
@@ -168,12 +166,12 @@
class Delegate : public base::RefCountedThreadSafe<Delegate> {
public:
- // Constructor receives env var getter implementation to use, and
- // takes ownership of it. This is the normal constructor.
- explicit Delegate(base::Environment* env_var_getter);
- // Constructor receives setting and env var getter implementations
- // to use, and takes ownership of them. Used for testing.
- Delegate(base::Environment* env_var_getter, SettingGetter* setting_getter);
+ // Normal constructor.
+ explicit Delegate(std::unique_ptr<base::Environment> env_var_getter);
+
+ // Constructor for testing.
+ Delegate(std::unique_ptr<base::Environment> env_var_getter,
+ SettingGetter* setting_getter);
// Synchronously obtains the proxy configuration. If gconf,
// gsettings, or kioslaverc are used, also enables notifications for
@@ -216,11 +214,12 @@
// Obtains an environment variable's value. Parses a proxy server
// specification from it and puts it in result. Returns true if the
// requested variable is defined and the value valid.
- bool GetProxyFromEnvVarForScheme(const char* variable,
+ bool GetProxyFromEnvVarForScheme(base::StringPiece variable,
ProxyServer::Scheme scheme,
ProxyServer* result_server);
// As above but with scheme set to HTTP, for convenience.
- bool GetProxyFromEnvVar(const char* variable, ProxyServer* result_server);
+ bool GetProxyFromEnvVar(base::StringPiece variable,
+ ProxyServer* result_server);
// Fills proxy config from environment variables. Returns true if
// variables were found and the configuration is valid.
bool GetConfigFromEnv(ProxyConfig* config);
@@ -277,9 +276,11 @@
// Usual constructor
ProxyConfigServiceLinux();
+
// For testing: take alternate setting and env var getter implementations.
- explicit ProxyConfigServiceLinux(base::Environment* env_var_getter);
- ProxyConfigServiceLinux(base::Environment* env_var_getter,
+ explicit ProxyConfigServiceLinux(
+ std::unique_ptr<base::Environment> env_var_getter);
+ ProxyConfigServiceLinux(std::unique_ptr<base::Environment> env_var_getter,
SettingGetter* setting_getter);
~ProxyConfigServiceLinux() override;
diff --git a/net/proxy/proxy_config_service_linux_unittest.cc b/net/proxy/proxy_config_service_linux_unittest.cc
index 2c353c82..ae17d54 100644
--- a/net/proxy/proxy_config_service_linux_unittest.cc
+++ b/net/proxy/proxy_config_service_linux_unittest.cc
@@ -35,13 +35,19 @@
struct EnvVarValues {
// The strange capitalization is so that the field matches the
// environment variable name exactly.
- const char *DESKTOP_SESSION, *HOME,
- *KDEHOME, *KDE_SESSION_VERSION,
- *XDG_CURRENT_DESKTOP,
- *auto_proxy, *all_proxy,
- *http_proxy, *https_proxy, *ftp_proxy,
- *SOCKS_SERVER, *SOCKS_VERSION,
- *no_proxy;
+ const char* DESKTOP_SESSION;
+ const char* HOME;
+ const char* KDEHOME;
+ const char* KDE_SESSION_VERSION;
+ const char* XDG_CURRENT_DESKTOP;
+ const char* auto_proxy;
+ const char* all_proxy;
+ const char* http_proxy;
+ const char* https_proxy;
+ const char* ftp_proxy;
+ const char* SOCKS_SERVER;
+ const char* SOCKS_VERSION;
+ const char* no_proxy;
};
// Undo macro pollution from GDK includes (from message_loop.h).
@@ -57,12 +63,21 @@
// Set of values for all gconf settings that we might query.
struct GConfValues {
// strings
- const char *mode, *autoconfig_url,
- *http_host, *secure_host, *ftp_host, *socks_host;
+ const char* mode;
+ const char* autoconfig_url;
+ const char* http_host;
+ const char* secure_host;
+ const char* ftp_host;
+ const char* socks_host;
// integers
- int http_port, secure_port, ftp_port, socks_port;
+ int http_port;
+ int secure_port;
+ int ftp_port;
+ int socks_port;
// booleans
- BoolSettingValue use_proxy, same_proxy, use_auth;
+ BoolSettingValue use_proxy;
+ BoolSettingValue same_proxy;
+ BoolSettingValue use_auth;
// string list
std::vector<std::string> ignore_hosts;
};
@@ -75,7 +90,7 @@
// Gets the value from its location
value_type Get(key_type key) {
- typename map_type::const_iterator it = settings.find(key);
+ auto it = settings.find(key);
// In case there's a typo or the unittest becomes out of sync.
CHECK(it != settings.end()) << "key " << key << " not found";
value_type* value_ptr = it->second;
@@ -88,7 +103,7 @@
class MockEnvironment : public base::Environment {
public:
MockEnvironment() {
-#define ENTRY(x) table[#x] = &values.x
+#define ENTRY(x) table_[#x] = &values.x
ENTRY(DESKTOP_SESSION);
ENTRY(HOME);
ENTRY(KDEHOME);
@@ -113,24 +128,23 @@
}
// Begin base::Environment implementation.
- bool GetVar(const char* variable_name, std::string* result) override {
- std::map<std::string, const char**>::iterator it =
- table.find(variable_name);
- if (it != table.end() && *(it->second) != NULL) {
- // Note that the variable may be defined but empty.
- *result = *(it->second);
- return true;
- }
- return false;
+ bool GetVar(base::StringPiece variable_name, std::string* result) override {
+ auto it = table_.find(variable_name);
+ if (it == table_.end() || !*it->second)
+ return false;
+
+ // Note that the variable may be defined but empty.
+ *result = *(it->second);
+ return true;
}
- bool SetVar(const char* variable_name,
+ bool SetVar(base::StringPiece variable_name,
const std::string& new_value) override {
ADD_FAILURE();
return false;
}
- bool UnSetVar(const char* variable_name) override {
+ bool UnSetVar(base::StringPiece variable_name) override {
ADD_FAILURE();
return false;
}
@@ -140,7 +154,7 @@
EnvVarValues values;
private:
- std::map<std::string, const char**> table;
+ std::map<base::StringPiece, const char**> table_;
};
class MockSettingGetter
@@ -688,10 +702,10 @@
for (size_t i = 0; i < arraysize(tests); ++i) {
SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i,
tests[i].description.c_str()));
- MockEnvironment* env = new MockEnvironment;
+ std::unique_ptr<MockEnvironment> env(new MockEnvironment);
MockSettingGetter* setting_getter = new MockSettingGetter;
SynchConfigGetter sync_config_getter(
- new ProxyConfigServiceLinux(env, setting_getter));
+ new ProxyConfigServiceLinux(std::move(env), setting_getter));
ProxyConfig config;
setting_getter->values = tests[i].values;
sync_config_getter.SetupAndInitialFetch();
@@ -722,298 +736,307 @@
GURL pac_url;
ProxyRulesExpectation proxy_rules;
} tests[] = {
- {
- TEST_DESC("No proxying"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- NULL, // auto_proxy
- NULL, // all_proxy
- NULL, NULL, NULL, // per-proto proxies
- NULL, NULL, // SOCKS
- "*", // no_proxy
+ {
+ TEST_DESC("No proxying"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ nullptr, // auto_proxy
+ nullptr, // all_proxy
+ nullptr, nullptr, nullptr, // per-proto proxies
+ nullptr, nullptr, // SOCKS
+ "*", // no_proxy
+ },
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Empty(),
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Empty(),
- },
+ {
+ TEST_DESC("Auto detect"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ "", // auto_proxy
+ nullptr, // all_proxy
+ nullptr, nullptr, nullptr, // per-proto proxies
+ nullptr, nullptr, // SOCKS
+ nullptr, // no_proxy
+ },
- {
- TEST_DESC("Auto detect"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- "", // auto_proxy
- NULL, // all_proxy
- NULL, NULL, NULL, // per-proto proxies
- NULL, NULL, // SOCKS
- NULL, // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ true, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Empty(),
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- true, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Empty(),
- },
+ {
+ TEST_DESC("Valid PAC URL"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ "http://wpad/wpad.dat", // auto_proxy
+ nullptr, // all_proxy
+ nullptr, nullptr, nullptr, // per-proto proxies
+ nullptr, nullptr, // SOCKS
+ nullptr, // no_proxy
+ },
- {
- TEST_DESC("Valid PAC URL"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- "http://wpad/wpad.dat", // auto_proxy
- NULL, // all_proxy
- NULL, NULL, NULL, // per-proto proxies
- NULL, NULL, // SOCKS
- NULL, // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL("http://wpad/wpad.dat"), // pac_url
+ ProxyRulesExpectation::Empty(),
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL("http://wpad/wpad.dat"), // pac_url
- ProxyRulesExpectation::Empty(),
- },
+ {
+ TEST_DESC("Invalid PAC URL"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ "wpad.dat", // auto_proxy
+ nullptr, // all_proxy
+ nullptr, nullptr, nullptr, // per-proto proxies
+ nullptr, nullptr, // SOCKS
+ nullptr, // no_proxy
+ },
- {
- TEST_DESC("Invalid PAC URL"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- "wpad.dat", // auto_proxy
- NULL, // all_proxy
- NULL, NULL, NULL, // per-proto proxies
- NULL, NULL, // SOCKS
- NULL, // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Empty(),
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Empty(),
- },
+ {
+ TEST_DESC("Single-host in proxy list"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ nullptr, // auto_proxy
+ "www.google.com", // all_proxy
+ nullptr, nullptr, nullptr, // per-proto proxies
+ nullptr, nullptr, // SOCKS
+ nullptr, // no_proxy
+ },
- {
- TEST_DESC("Single-host in proxy list"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- NULL, // auto_proxy
- "www.google.com", // all_proxy
- NULL, NULL, NULL, // per-proto proxies
- NULL, NULL, // SOCKS
- NULL, // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Single("www.google.com:80", // single proxy
+ ""), // bypass rules
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Single(
- "www.google.com:80", // single proxy
- ""), // bypass rules
- },
+ {
+ TEST_DESC("Single-host, different port"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ nullptr, // auto_proxy
+ "www.google.com:99", // all_proxy
+ nullptr, nullptr, nullptr, // per-proto proxies
+ nullptr, nullptr, // SOCKS
+ nullptr, // no_proxy
+ },
- {
- TEST_DESC("Single-host, different port"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- NULL, // auto_proxy
- "www.google.com:99", // all_proxy
- NULL, NULL, NULL, // per-proto proxies
- NULL, NULL, // SOCKS
- NULL, // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Single("www.google.com:99", // single
+ ""), // bypass rules
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Single(
- "www.google.com:99", // single
- ""), // bypass rules
- },
+ {
+ TEST_DESC("Tolerate a scheme"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ nullptr, // auto_proxy
+ "http://www.google.com:99", // all_proxy
+ nullptr, nullptr, nullptr, // per-proto proxies
+ nullptr, nullptr, // SOCKS
+ nullptr, // no_proxy
+ },
- {
- TEST_DESC("Tolerate a scheme"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- NULL, // auto_proxy
- "http://www.google.com:99", // all_proxy
- NULL, NULL, NULL, // per-proto proxies
- NULL, NULL, // SOCKS
- NULL, // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Single("www.google.com:99", // single proxy
+ ""), // bypass rules
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Single(
- "www.google.com:99", // single proxy
- ""), // bypass rules
- },
+ {
+ TEST_DESC("Per-scheme proxy rules"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ nullptr, // auto_proxy
+ nullptr, // all_proxy
+ "www.google.com:80", "www.foo.com:110",
+ "ftp.foo.com:121", // per-proto
+ nullptr, nullptr, // SOCKS
+ nullptr, // no_proxy
+ },
- {
- TEST_DESC("Per-scheme proxy rules"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- NULL, // auto_proxy
- NULL, // all_proxy
- "www.google.com:80", "www.foo.com:110", "ftp.foo.com:121", // per-proto
- NULL, NULL, // SOCKS
- NULL, // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:80", // http
+ "www.foo.com:110", // https
+ "ftp.foo.com:121", // ftp
+ ""), // bypass rules
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "www.foo.com:110", // https
- "ftp.foo.com:121", // ftp
- ""), // bypass rules
- },
+ {
+ TEST_DESC("socks"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ nullptr, // auto_proxy
+ "", // all_proxy
+ nullptr, nullptr, nullptr, // per-proto proxies
+ "socks.com:888", nullptr, // SOCKS
+ nullptr, // no_proxy
+ },
- {
- TEST_DESC("socks"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- NULL, // auto_proxy
- "", // all_proxy
- NULL, NULL, NULL, // per-proto proxies
- "socks.com:888", NULL, // SOCKS
- NULL, // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Single(
+ "socks5://socks.com:888", // single proxy
+ ""), // bypass rules
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Single(
- "socks5://socks.com:888", // single proxy
- ""), // bypass rules
- },
+ {
+ TEST_DESC("socks4"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ nullptr, // auto_proxy
+ "", // all_proxy
+ nullptr, nullptr, nullptr, // per-proto proxies
+ "socks.com:888", "4", // SOCKS
+ nullptr, // no_proxy
+ },
- {
- TEST_DESC("socks4"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- NULL, // auto_proxy
- "", // all_proxy
- NULL, NULL, NULL, // per-proto proxies
- "socks.com:888", "4", // SOCKS
- NULL, // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Single(
+ "socks4://socks.com:888", // single proxy
+ ""), // bypass rules
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Single(
- "socks4://socks.com:888", // single proxy
- ""), // bypass rules
- },
+ {
+ TEST_DESC("socks default port"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ nullptr, // auto_proxy
+ "", // all_proxy
+ nullptr, nullptr, nullptr, // per-proto proxies
+ "socks.com", nullptr, // SOCKS
+ nullptr, // no_proxy
+ },
- {
- TEST_DESC("socks default port"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- NULL, // auto_proxy
- "", // all_proxy
- NULL, NULL, NULL, // per-proto proxies
- "socks.com", NULL, // SOCKS
- NULL, // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Single(
+ "socks5://socks.com:1080", // single proxy
+ ""), // bypass rules
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Single(
- "socks5://socks.com:1080", // single proxy
- ""), // bypass rules
- },
+ {
+ TEST_DESC("bypass"),
+ {
+ // Input.
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ nullptr, // auto_proxy
+ "www.google.com", // all_proxy
+ nullptr, nullptr, nullptr, // per-proto
+ nullptr, nullptr, // SOCKS
+ ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // no_proxy
+ },
- {
- TEST_DESC("bypass"),
- { // Input.
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- NULL, // auto_proxy
- "www.google.com", // all_proxy
- NULL, NULL, NULL, // per-proto
- NULL, NULL, // SOCKS
- ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Single(
+ "www.google.com:80",
+ "*.google.com,*foo.com:99,1.2.3.4:22,127.0.0.1/8"),
},
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Single(
- "www.google.com:80",
- "*.google.com,*foo.com:99,1.2.3.4:22,127.0.0.1/8"),
- },
};
for (size_t i = 0; i < arraysize(tests); ++i) {
SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i,
tests[i].description.c_str()));
- MockEnvironment* env = new MockEnvironment;
+ std::unique_ptr<MockEnvironment> env(new MockEnvironment);
+ env->values = tests[i].values;
MockSettingGetter* setting_getter = new MockSettingGetter;
SynchConfigGetter sync_config_getter(
- new ProxyConfigServiceLinux(env, setting_getter));
+ new ProxyConfigServiceLinux(std::move(env), setting_getter));
ProxyConfig config;
- env->values = tests[i].values;
sync_config_getter.SetupAndInitialFetch();
ProxyConfigService::ConfigAvailability availability =
sync_config_getter.SyncGetLatestProxyConfig(&config);
@@ -1028,10 +1051,10 @@
}
TEST_F(ProxyConfigServiceLinuxTest, GconfNotification) {
- MockEnvironment* env = new MockEnvironment;
+ std::unique_ptr<MockEnvironment> env(new MockEnvironment);
MockSettingGetter* setting_getter = new MockSettingGetter;
ProxyConfigServiceLinux* service =
- new ProxyConfigServiceLinux(env, setting_getter);
+ new ProxyConfigServiceLinux(std::move(env), setting_getter);
SynchConfigGetter sync_config_getter(service);
ProxyConfig config;
@@ -1074,452 +1097,442 @@
GURL pac_url;
ProxyRulesExpectation proxy_rules;
} tests[] = {
- {
- TEST_DESC("No proxying"),
+ {
+ TEST_DESC("No proxying"),
- // Input.
- "[Proxy Settings]\nProxyType=0\n",
- {}, // env_values
+ // Input.
+ "[Proxy Settings]\nProxyType=0\n",
+ {}, // env_values
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Empty(),
- },
-
- {
- TEST_DESC("Auto detect"),
-
- // Input.
- "[Proxy Settings]\nProxyType=3\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- true, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Empty(),
- },
-
- {
- TEST_DESC("Valid PAC URL"),
-
- // Input.
- "[Proxy Settings]\nProxyType=2\n"
- "Proxy Config Script=http://wpad/wpad.dat\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL("http://wpad/wpad.dat"), // pac_url
- ProxyRulesExpectation::Empty(),
- },
-
- {
- TEST_DESC("Valid PAC file without file://"),
-
- // Input.
- "[Proxy Settings]\nProxyType=2\n"
- "Proxy Config Script=/wpad/wpad.dat\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL("file:///wpad/wpad.dat"), // pac_url
- ProxyRulesExpectation::Empty(),
- },
-
- {
- TEST_DESC("Per-scheme proxy rules"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
- "httpsProxy=www.foo.com\nftpProxy=ftp.foo.com\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "www.foo.com:80", // https
- "ftp.foo.com:80", // http
- ""), // bypass rules
- },
-
- {
- TEST_DESC("Only HTTP proxy specified"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\n"
- "httpProxy=www.google.com\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "", // https
- "", // ftp
- ""), // bypass rules
- },
-
- {
- TEST_DESC("Only HTTP proxy specified, different port"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\n"
- "httpProxy=www.google.com:88\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:88", // http
- "", // https
- "", // ftp
- ""), // bypass rules
- },
-
- {
- TEST_DESC("Only HTTP proxy specified, different port, space-delimited"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\n"
- "httpProxy=www.google.com 88\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:88", // http
- "", // https
- "", // ftp
- ""), // bypass rules
- },
-
- {
- TEST_DESC("Bypass *.google.com"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
- "NoProxyFor=.google.com\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "", // https
- "", // ftp
- "*.google.com"), // bypass rules
- },
-
- {
- TEST_DESC("Bypass *.google.com and *.kde.org"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
- "NoProxyFor=.google.com,.kde.org\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "", // https
- "", // ftp
- "*.google.com,*.kde.org"), // bypass rules
- },
-
- {
- TEST_DESC("Correctly parse bypass list with ReversedException"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
- "NoProxyFor=.google.com\nReversedException=true\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerSchemeWithBypassReversed(
- "www.google.com:80", // http
- "", // https
- "", // ftp
- "*.google.com"), // bypass rules
- },
-
- {
- TEST_DESC("socks"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\nsocksProxy=socks.com 888\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Single(
- "socks5://socks.com:888", // single proxy
- ""), // bypass rules
- },
-
- {
- TEST_DESC("socks4"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\nsocksProxy=socks4://socks.com 888\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Single(
- "socks4://socks.com:888", // single proxy
- ""), // bypass rules
- },
-
- {
- TEST_DESC("Treat all hostname patterns as wildcard patterns"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
- "NoProxyFor=google.com,kde.org,<local>\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "", // https
- "", // ftp
- "*google.com,*kde.org,<local>"), // bypass rules
- },
-
- {
- TEST_DESC("Allow trailing whitespace after boolean value"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
- "NoProxyFor=.google.com\nReversedException=true \n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerSchemeWithBypassReversed(
- "www.google.com:80", // http
- "", // https
- "", // ftp
- "*.google.com"), // bypass rules
- },
-
- {
- TEST_DESC("Ignore settings outside [Proxy Settings]"),
-
- // Input.
- "httpsProxy=www.foo.com\n[Proxy Settings]\nProxyType=1\n"
- "httpProxy=www.google.com\n[Other Section]\nftpProxy=ftp.foo.com\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "", // https
- "", // ftp
- ""), // bypass rules
- },
-
- {
- TEST_DESC("Handle CRLF line endings"),
-
- // Input.
- "[Proxy Settings]\r\nProxyType=1\r\nhttpProxy=www.google.com\r\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "", // https
- "", // ftp
- ""), // bypass rules
- },
-
- {
- TEST_DESC("Handle blank lines and mixed line endings"),
-
- // Input.
- "[Proxy Settings]\r\n\nProxyType=1\n\r\nhttpProxy=www.google.com\n\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "", // https
- "", // ftp
- ""), // bypass rules
- },
-
- {
- TEST_DESC("Handle localized settings"),
-
- // Input.
- "[Proxy Settings]\nProxyType[$e]=1\nhttpProxy[$e]=www.google.com\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "", // https
- "", // ftp
- ""), // bypass rules
- },
-
- {
- TEST_DESC("Ignore malformed localized settings"),
-
- // Input.
- "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
- "httpsProxy$e]=www.foo.com\nftpProxy=ftp.foo.com\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "", // https
- "ftp.foo.com:80", // ftp
- ""), // bypass rules
- },
-
- {
- TEST_DESC("Handle strange whitespace"),
-
- // Input.
- "[Proxy Settings]\nProxyType [$e] =2\n"
- " Proxy Config Script = http:// foo\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL("http:// foo"), // pac_url
- ProxyRulesExpectation::Empty(),
- },
-
- {
- TEST_DESC("Ignore all of a line which is too long"),
-
- // Input.
- std::string("[Proxy Settings]\nProxyType=1\nftpProxy=ftp.foo.com\n") +
- long_line + "httpsProxy=www.foo.com\nhttpProxy=www.google.com\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.google.com:80", // http
- "", // https
- "ftp.foo.com:80", // ftp
- ""), // bypass rules
- },
-
- {
- TEST_DESC("Indirect Proxy - no env vars set"),
-
- // Input.
- "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n"
- "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n",
- {}, // env_values
-
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::Empty(),
- },
-
- {
- TEST_DESC("Indirect Proxy - with env vars set"),
-
- // Input.
- "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n"
- "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n",
- { // env_values
- NULL, // DESKTOP_SESSION
- NULL, // HOME
- NULL, // KDEHOME
- NULL, // KDE_SESSION_VERSION
- NULL, // XDG_CURRENT_DESKTOP
- NULL, // auto_proxy
- NULL, // all_proxy
- "www.normal.com", // http_proxy
- "www.secure.com", // https_proxy
- "ftp.foo.com", // ftp_proxy
- NULL, NULL, // SOCKS
- ".google.com, .kde.org", // no_proxy
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Empty(),
},
- // Expected result.
- ProxyConfigService::CONFIG_VALID,
- false, // auto_detect
- GURL(), // pac_url
- ProxyRulesExpectation::PerScheme(
- "www.normal.com:80", // http
- "www.secure.com:80", // https
- "ftp.foo.com:80", // ftp
- "*.google.com,*.kde.org"), // bypass rules
- },
+ {
+ TEST_DESC("Auto detect"),
+ // Input.
+ "[Proxy Settings]\nProxyType=3\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ true, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Empty(),
+ },
+
+ {
+ TEST_DESC("Valid PAC URL"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=2\n"
+ "Proxy Config Script=http://wpad/wpad.dat\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL("http://wpad/wpad.dat"), // pac_url
+ ProxyRulesExpectation::Empty(),
+ },
+
+ {
+ TEST_DESC("Valid PAC file without file://"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=2\n"
+ "Proxy Config Script=/wpad/wpad.dat\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL("file:///wpad/wpad.dat"), // pac_url
+ ProxyRulesExpectation::Empty(),
+ },
+
+ {
+ TEST_DESC("Per-scheme proxy rules"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
+ "httpsProxy=www.foo.com\nftpProxy=ftp.foo.com\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:80", // http
+ "www.foo.com:80", // https
+ "ftp.foo.com:80", // http
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC("Only HTTP proxy specified"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\n"
+ "httpProxy=www.google.com\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC("Only HTTP proxy specified, different port"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\n"
+ "httpProxy=www.google.com:88\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:88", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC(
+ "Only HTTP proxy specified, different port, space-delimited"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\n"
+ "httpProxy=www.google.com 88\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:88", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC("Bypass *.google.com"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
+ "NoProxyFor=.google.com\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:80", // http
+ "", // https
+ "", // ftp
+ "*.google.com"), // bypass rules
+ },
+
+ {
+ TEST_DESC("Bypass *.google.com and *.kde.org"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
+ "NoProxyFor=.google.com,.kde.org\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ "*.google.com,*.kde.org"), // bypass rules
+ },
+
+ {
+ TEST_DESC("Correctly parse bypass list with ReversedException"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
+ "NoProxyFor=.google.com\nReversedException=true\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerSchemeWithBypassReversed(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ "*.google.com"), // bypass rules
+ },
+
+ {
+ TEST_DESC("socks"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\nsocksProxy=socks.com 888\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Single(
+ "socks5://socks.com:888", // single proxy
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC("socks4"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\nsocksProxy=socks4://socks.com 888\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Single(
+ "socks4://socks.com:888", // single proxy
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC("Treat all hostname patterns as wildcard patterns"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
+ "NoProxyFor=google.com,kde.org,<local>\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ "*google.com,*kde.org,<local>"), // bypass rules
+ },
+
+ {
+ TEST_DESC("Allow trailing whitespace after boolean value"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
+ "NoProxyFor=.google.com\nReversedException=true \n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerSchemeWithBypassReversed(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ "*.google.com"), // bypass rules
+ },
+
+ {
+ TEST_DESC("Ignore settings outside [Proxy Settings]"),
+
+ // Input.
+ "httpsProxy=www.foo.com\n[Proxy Settings]\nProxyType=1\n"
+ "httpProxy=www.google.com\n[Other Section]\nftpProxy=ftp.foo.com\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC("Handle CRLF line endings"),
+
+ // Input.
+ "[Proxy Settings]\r\nProxyType=1\r\nhttpProxy=www.google.com\r\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC("Handle blank lines and mixed line endings"),
+
+ // Input.
+ "[Proxy Settings]\r\n\nProxyType=1\n\r\nhttpProxy=www.google.com\n\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC("Handle localized settings"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType[$e]=1\nhttpProxy[$e]=www.google.com\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC("Ignore malformed localized settings"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
+ "httpsProxy$e]=www.foo.com\nftpProxy=ftp.foo.com\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:80", // http
+ "", // https
+ "ftp.foo.com:80", // ftp
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC("Handle strange whitespace"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType [$e] =2\n"
+ " Proxy Config Script = http:// foo\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL("http:// foo"), // pac_url
+ ProxyRulesExpectation::Empty(),
+ },
+
+ {
+ TEST_DESC("Ignore all of a line which is too long"),
+
+ // Input.
+ std::string("[Proxy Settings]\nProxyType=1\nftpProxy=ftp.foo.com\n") +
+ long_line + "httpsProxy=www.foo.com\nhttpProxy=www.google.com\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme("www.google.com:80", // http
+ "", // https
+ "ftp.foo.com:80", // ftp
+ ""), // bypass rules
+ },
+
+ {
+ TEST_DESC("Indirect Proxy - no env vars set"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n"
+ "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n",
+ {}, // env_values
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::Empty(),
+ },
+
+ {
+ TEST_DESC("Indirect Proxy - with env vars set"),
+
+ // Input.
+ "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n"
+ "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n",
+ {
+ // env_values
+ nullptr, // DESKTOP_SESSION
+ nullptr, // HOME
+ nullptr, // KDEHOME
+ nullptr, // KDE_SESSION_VERSION
+ nullptr, // XDG_CURRENT_DESKTOP
+ nullptr, // auto_proxy
+ nullptr, // all_proxy
+ "www.normal.com", // http_proxy
+ "www.secure.com", // https_proxy
+ "ftp.foo.com", // ftp_proxy
+ nullptr, nullptr, // SOCKS
+ ".google.com, .kde.org", // no_proxy
+ },
+
+ // Expected result.
+ ProxyConfigService::CONFIG_VALID,
+ false, // auto_detect
+ GURL(), // pac_url
+ ProxyRulesExpectation::PerScheme(
+ "www.normal.com:80", // http
+ "www.secure.com:80", // https
+ "ftp.foo.com:80", // ftp
+ "*.google.com,*.kde.org"), // bypass rules
+ },
};
for (size_t i = 0; i < arraysize(tests); ++i) {
SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i,
tests[i].description.c_str()));
- MockEnvironment* env = new MockEnvironment;
+ std::unique_ptr<MockEnvironment> env(new MockEnvironment);
env->values = tests[i].env_values;
// Force the KDE getter to be used and tell it where the test is.
env->values.DESKTOP_SESSION = "kde4";
env->values.KDEHOME = kde_home_.value().c_str();
SynchConfigGetter sync_config_getter(
- new ProxyConfigServiceLinux(env));
+ new ProxyConfigServiceLinux(std::move(env)));
ProxyConfig config;
// Overwrite the kioslaverc file.
base::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(),
@@ -1561,11 +1574,11 @@
CHECK(!base::DirectoryExists(kde4_home_));
{ SCOPED_TRACE("KDE4, no .kde4 directory, verify fallback");
- MockEnvironment* env = new MockEnvironment;
+ std::unique_ptr<MockEnvironment> env(new MockEnvironment);
env->values.DESKTOP_SESSION = "kde4";
env->values.HOME = user_home_.value().c_str();
SynchConfigGetter sync_config_getter(
- new ProxyConfigServiceLinux(env));
+ new ProxyConfigServiceLinux(std::move(env)));
ProxyConfig config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
@@ -1581,11 +1594,11 @@
CHECK(base::PathExists(kioslaverc4_));
{ SCOPED_TRACE("KDE4, .kde4 directory present, use it");
- MockEnvironment* env = new MockEnvironment;
+ std::unique_ptr<MockEnvironment> env(new MockEnvironment);
env->values.DESKTOP_SESSION = "kde4";
env->values.HOME = user_home_.value().c_str();
SynchConfigGetter sync_config_getter(
- new ProxyConfigServiceLinux(env));
+ new ProxyConfigServiceLinux(std::move(env)));
ProxyConfig config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
@@ -1595,11 +1608,11 @@
}
{ SCOPED_TRACE("KDE3, .kde4 directory present, ignore it");
- MockEnvironment* env = new MockEnvironment;
+ std::unique_ptr<MockEnvironment> env(new MockEnvironment);
env->values.DESKTOP_SESSION = "kde";
env->values.HOME = user_home_.value().c_str();
SynchConfigGetter sync_config_getter(
- new ProxyConfigServiceLinux(env));
+ new ProxyConfigServiceLinux(std::move(env)));
ProxyConfig config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
@@ -1609,12 +1622,12 @@
}
{ SCOPED_TRACE("KDE4, .kde4 directory present, KDEHOME set to .kde");
- MockEnvironment* env = new MockEnvironment;
+ std::unique_ptr<MockEnvironment> env(new MockEnvironment);
env->values.DESKTOP_SESSION = "kde4";
env->values.HOME = user_home_.value().c_str();
env->values.KDEHOME = kde_home_.value().c_str();
SynchConfigGetter sync_config_getter(
- new ProxyConfigServiceLinux(env));
+ new ProxyConfigServiceLinux(std::move(env)));
ProxyConfig config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
@@ -1628,11 +1641,11 @@
base::TouchFile(kde4_config_, base::Time(), base::Time());
{ SCOPED_TRACE("KDE4, very old .kde4 directory present, use .kde");
- MockEnvironment* env = new MockEnvironment;
+ std::unique_ptr<MockEnvironment> env(new MockEnvironment);
env->values.DESKTOP_SESSION = "kde4";
env->values.HOME = user_home_.value().c_str();
SynchConfigGetter sync_config_getter(
- new ProxyConfigServiceLinux(env));
+ new ProxyConfigServiceLinux(std::move(env)));
ProxyConfig config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
@@ -1648,11 +1661,12 @@
{
SCOPED_TRACE("KDE5, .kde and .kde4 present, use .config");
- MockEnvironment* env = new MockEnvironment;
+ std::unique_ptr<MockEnvironment> env(new MockEnvironment);
env->values.XDG_CURRENT_DESKTOP = "KDE";
env->values.KDE_SESSION_VERSION = "5";
env->values.HOME = user_home_.value().c_str();
- SynchConfigGetter sync_config_getter(new ProxyConfigServiceLinux(env));
+ SynchConfigGetter sync_config_getter(
+ new ProxyConfigServiceLinux(std::move(env)));
ProxyConfig config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
diff --git a/sandbox/linux/suid/client/setuid_sandbox_client.cc b/sandbox/linux/suid/client/setuid_sandbox_client.cc
index 12ef7f9f..ca73d46 100644
--- a/sandbox/linux/suid/client/setuid_sandbox_client.cc
+++ b/sandbox/linux/suid/client/setuid_sandbox_client.cc
@@ -10,6 +10,7 @@
#include <unistd.h>
#include <string>
+#include <utility>
#include "base/environment.h"
#include "base/files/scoped_file.h"
@@ -62,13 +63,12 @@
namespace sandbox {
SetuidSandboxClient* SetuidSandboxClient::Create() {
- base::Environment* environment(base::Environment::Create());
- CHECK(environment);
- return new SetuidSandboxClient(environment);
+ return new SetuidSandboxClient(base::Environment::Create());
}
-SetuidSandboxClient::SetuidSandboxClient(base::Environment* env)
- : env_(env), sandboxed_(false) {
+SetuidSandboxClient::SetuidSandboxClient(std::unique_ptr<base::Environment> env)
+ : env_(std::move(env)), sandboxed_(false) {
+ DCHECK(env_);
}
SetuidSandboxClient::~SetuidSandboxClient() {
diff --git a/sandbox/linux/suid/client/setuid_sandbox_client.h b/sandbox/linux/suid/client/setuid_sandbox_client.h
index d1cff42..21ddab6 100644
--- a/sandbox/linux/suid/client/setuid_sandbox_client.h
+++ b/sandbox/linux/suid/client/setuid_sandbox_client.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SANDBOX_LINUX_SUID_SETUID_SANDBOX_CLIENT_H_
-#define SANDBOX_LINUX_SUID_SETUID_SANDBOX_CLIENT_H_
+#ifndef SANDBOX_LINUX_SUID_CLIENT_SETUID_SANDBOX_CLIENT_H_
+#define SANDBOX_LINUX_SUID_CLIENT_SETUID_SANDBOX_CLIENT_H_
#include <memory>
@@ -58,7 +58,7 @@
bool IsSandboxed() const;
private:
- explicit SetuidSandboxClient(base::Environment* env);
+ explicit SetuidSandboxClient(std::unique_ptr<base::Environment> env);
// Holds the environment. Will never be NULL.
std::unique_ptr<base::Environment> env_;
@@ -69,4 +69,4 @@
} // namespace sandbox
-#endif // SANDBOX_LINUX_SUID_SETUID_SANDBOX_CLIENT_H_
+#endif // SANDBOX_LINUX_SUID_CLIENT_SETUID_SANDBOX_CLIENT_H_
diff --git a/sandbox/linux/suid/client/setuid_sandbox_host.cc b/sandbox/linux/suid/client/setuid_sandbox_host.cc
index 278f1d2..24608ec 100644
--- a/sandbox/linux/suid/client/setuid_sandbox_host.cc
+++ b/sandbox/linux/suid/client/setuid_sandbox_host.cc
@@ -29,13 +29,15 @@
#include "sandbox/linux/suid/common/sandbox.h"
#include "sandbox/linux/suid/common/suid_unsafe_environment_variables.h"
+namespace sandbox {
+
namespace {
// Set an environment variable that reflects the API version we expect from the
// setuid sandbox. Old versions of the sandbox will ignore this.
void SetSandboxAPIEnvironmentVariable(base::Environment* env) {
- env->SetVar(sandbox::kSandboxEnvironmentApiRequest,
- base::IntToString(sandbox::kSUIDSandboxApiNumber));
+ env->SetVar(kSandboxEnvironmentApiRequest,
+ base::IntToString(kSUIDSandboxApiNumber));
}
// Unset environment variables that are expected to be set by the setuid
@@ -44,11 +46,9 @@
void UnsetExpectedEnvironmentVariables(base::EnvironmentMap* env_map) {
DCHECK(env_map);
const base::NativeEnvironmentString environment_vars[] = {
- sandbox::kSandboxDescriptorEnvironmentVarName,
- sandbox::kSandboxHelperPidEnvironmentVarName,
- sandbox::kSandboxEnvironmentApiProvides,
- sandbox::kSandboxPIDNSEnvironmentVarName,
- sandbox::kSandboxNETNSEnvironmentVarName,
+ kSandboxDescriptorEnvironmentVarName, kSandboxHelperPidEnvironmentVarName,
+ kSandboxEnvironmentApiProvides, kSandboxPIDNSEnvironmentVarName,
+ kSandboxNETNSEnvironmentVarName,
};
for (size_t i = 0; i < arraysize(environment_vars); ++i) {
@@ -64,7 +64,7 @@
std::string* CreateSavedVariableName(const char* env_var) {
char* const saved_env_var = SandboxSavedEnvironmentVariable(env_var);
if (!saved_env_var)
- return NULL;
+ return nullptr;
std::string* saved_env_var_copy = new std::string(saved_env_var);
// SandboxSavedEnvironmentVariable is the C function that we wrap and uses
// malloc() to allocate memory.
@@ -81,7 +81,7 @@
// Get the saved environment variable corresponding to envvar.
std::unique_ptr<std::string> saved_env_var(
CreateSavedVariableName(env_var));
- if (saved_env_var == NULL)
+ if (!saved_env_var)
continue;
std::string value;
@@ -98,15 +98,13 @@
} // namespace
-namespace sandbox {
-
SetuidSandboxHost* SetuidSandboxHost::Create() {
- base::Environment* environment(base::Environment::Create());
- CHECK(environment);
- return new SetuidSandboxHost(environment);
+ return new SetuidSandboxHost(base::Environment::Create());
}
-SetuidSandboxHost::SetuidSandboxHost(base::Environment* env) : env_(env) {
+SetuidSandboxHost::SetuidSandboxHost(std::unique_ptr<base::Environment> env)
+ : env_(std::move(env)) {
+ DCHECK(env_);
}
SetuidSandboxHost::~SetuidSandboxHost() {
@@ -116,10 +114,7 @@
// the setuid sandbox. TODO(jln): fix this (crbug.com/245376).
bool SetuidSandboxHost::IsDisabledViaEnvironment() {
const char* devel_sandbox_path = GetDevelSandboxPath();
- if (devel_sandbox_path && '\0' == *devel_sandbox_path) {
- return true;
- }
- return false;
+ return devel_sandbox_path && (*devel_sandbox_path == '\0');
}
base::FilePath SetuidSandboxHost::GetSandboxBinaryPath() {
diff --git a/sandbox/linux/suid/client/setuid_sandbox_host.h b/sandbox/linux/suid/client/setuid_sandbox_host.h
index c69c2c0c..b364801 100644
--- a/sandbox/linux/suid/client/setuid_sandbox_host.h
+++ b/sandbox/linux/suid/client/setuid_sandbox_host.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SANDBOX_LINUX_SUID_SETUID_SANDBOX_HOST_H_
-#define SANDBOX_LINUX_SUID_SETUID_SANDBOX_HOST_H_
+#ifndef SANDBOX_LINUX_SUID_CLIENT_SETUID_SANDBOX_HOST_H_
+#define SANDBOX_LINUX_SUID_CLIENT_SETUID_SANDBOX_HOST_H_
#include <memory>
@@ -38,13 +38,16 @@
// The setuid sandbox may still be disabled via the environment.
// This is tracked in crbug.com/245376.
bool IsDisabledViaEnvironment();
+
// Get the sandbox binary path. This method knows about the
// CHROME_DEVEL_SANDBOX environment variable used for user-managed builds. If
// the sandbox binary cannot be found, it will return an empty FilePath.
base::FilePath GetSandboxBinaryPath();
+
// Modify |cmd_line| to launch via the setuid sandbox. Crash if the setuid
// sandbox binary cannot be found. |cmd_line| must not be NULL.
void PrependWrapper(base::CommandLine* cmd_line);
+
// Set-up the launch options for launching via the setuid sandbox. Caller is
// responsible for keeping |dummy_fd| alive until LaunchProcess() completes.
// |options| and |fds_to_remap| must not be NULL.
@@ -53,12 +56,13 @@
void SetupLaunchOptions(base::LaunchOptions* options,
base::FileHandleMappingVector* fds_to_remap,
base::ScopedFD* dummy_fd);
+
// Set-up the environment. This should be done prior to launching the setuid
// helper.
void SetupLaunchEnvironment();
private:
- explicit SetuidSandboxHost(base::Environment* env);
+ explicit SetuidSandboxHost(std::unique_ptr<base::Environment> env);
// Holds the environment. Will never be NULL.
std::unique_ptr<base::Environment> env_;
@@ -68,4 +72,4 @@
} // namespace sandbox
-#endif // SANDBOX_LINUX_SUID_SETUID_SANDBOX_HOST_H_
+#endif // SANDBOX_LINUX_SUID_CLIENT_SETUID_SANDBOX_HOST_H_
diff --git a/sandbox/win/src/address_sanitizer_test.cc b/sandbox/win/src/address_sanitizer_test.cc
index f845ad8b..75fb0eb 100644
--- a/sandbox/win/src/address_sanitizer_test.cc
+++ b/sandbox/win/src/address_sanitizer_test.cc
@@ -21,7 +21,7 @@
class AddressSanitizerTests : public ::testing::Test {
public:
void SetUp() override {
- env_.reset(base::Environment::Create());
+ env_ = base::Environment::Create();
had_asan_options_ = env_->GetVar("ASAN_OPTIONS", &old_asan_options_);
}
@@ -42,7 +42,7 @@
// AddressSanitizer should detect an out of bounds write (heap buffer
// overflow) in this code.
volatile int idx = 42;
- int *volatile blah = new int[42];
+ int* volatile blah = new int[42];
blah[idx] = 42;
delete [] blah;
return SBOX_TEST_FAILED;
@@ -79,7 +79,7 @@
base::FilePath exe;
ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe));
base::FilePath pdb_path = exe.DirName().Append(L"*.pdb");
- ASSERT_TRUE(runner.AddFsRule(sandbox::TargetPolicy::FILES_ALLOW_READONLY,
+ ASSERT_TRUE(runner.AddFsRule(TargetPolicy::FILES_ALLOW_READONLY,
pdb_path.value().c_str()));
env_->SetVar("ASAN_OPTIONS", "exitcode=123");
@@ -105,4 +105,4 @@
}
}
-}
+} // namespace sandbox
diff --git a/ui/base/l10n/l10n_util_unittest.cc b/ui/base/l10n/l10n_util_unittest.cc
index 52498045..f4ff97c 100644
--- a/ui/base/l10n/l10n_util_unittest.cc
+++ b/ui/base/l10n/l10n_util_unittest.cc
@@ -136,7 +136,7 @@
const std::string original_locale = base::i18n::GetConfiguredLocale();
if (kPlatformHasDefaultLocale && kUseLocaleFromEnvironment) {
- env.reset(base::Environment::Create());
+ env = base::Environment::Create();
// Test the support of LANGUAGE environment variable.
base::i18n::SetICUDefaultLocale("en-US");