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

Unified Diff: components/url_fixer/url_fixer.cc

Issue 515973003: Fixed problem with incorrect use of $HOME (breaking multi user ChromeOS) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing unit test Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/url_fixer/url_fixer.cc
diff --git a/components/url_fixer/url_fixer.cc b/components/url_fixer/url_fixer.cc
index a0417328ba18d02fdc122897d683159051c46469..01e5e0eff77523607a868ebdd382087418fedfe2 100644
--- a/components/url_fixer/url_fixer.cc
+++ b/components/url_fixer/url_fixer.cc
@@ -6,11 +6,12 @@
#include <algorithm>
-#if defined(OS_POSIX)
-#include "base/environment.h"
-#endif
#include "base/file_util.h"
+#include "base/files/file_path.h"
#include "base/logging.h"
+#if defined(OS_POSIX)
+#include "base/path_service.h"
+#endif
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "net/base/escape.h"
@@ -122,14 +123,22 @@ std::string FixupHomedir(const std::string& text) {
DCHECK(text.length() > 0 && text[0] == '~');
if (text.length() == 1 || text[1] == '/') {
- const char* home = getenv(base::env_vars::kHome);
+ base::FilePath file_path;
if (url_fixer::home_directory_override)
- home = url_fixer::home_directory_override;
+ file_path = base::FilePath(url_fixer::home_directory_override);
+ else
+ PathService::Get(base::DIR_HOME, &file_path);
+
// We'll probably break elsewhere if $HOME is undefined, but check here
// just in case.
- if (!home)
+ if (file_path.value().empty())
return text;
- return home + text.substr(1);
+ // Append requires to be a relative path, so we have to cut all preceeding
+ // '/' characters.
+ size_t i = 1;
+ while (i < text.length() && text[i] == '/')
+ ++i;
+ return file_path.Append(text.substr(i)).value();
}
// Otherwise, this is a path like ~foobar/baz, where we must expand to
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698